Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2061372ybl; Sun, 19 Jan 2020 18:04:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzKyNPBYh0lTOiBg1/5AxTAXQW5JHcYVkjDN3VGyjEKSAmf0ixJ6X7UD6/SOnUaZ7qBwUGp X-Received: by 2002:a05:6830:612:: with SMTP id w18mr14480408oti.264.1579485894384; Sun, 19 Jan 2020 18:04:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579485894; cv=none; d=google.com; s=arc-20160816; b=SMi2TzavPK6Sk9nHPzLjfl25hxZMjc2A3Z87IxzPjiNAL1VsZJxBFrotwxfXo2z1y+ bdT5E712I1AhK0yP874h4LD6uyFQbboF2tuyVBCttNwb90y1bnGpxLrHyteKZ8kV04mQ kyLF71PXSk20gVrHKqHxTbYq8xl5hmUhDeEUYaX+5sp9iT0LbANdpQfFIAhl2/YP0zUZ TpeIKDDa43J+UcUTJzilAV9e0gNqQjCa8dAVIDNfFGc/hKci1tLVvCccAEbH7Lt9PqiX Fu6m7HIp2VYs5XQ8+2gSqNxcQt0wL3i6KKOHck/dtf6M+TIhZaCZjAHU7v34DI2232uA J6vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=mj26jMSAo0vmVVwsfqiJL5Eo4UBNcepoEnXhQAIKg+k=; b=RQRyt4JFQw7jZ7NXdMAEtmC6er/Y6g1k0xH9iGkZMDkuST68wQ8J6YmSbU3ZNYj0bV 3JfaPgR5LPNB/aJyKKH6lfXfeQXZc8OXol2dK79dQVt/9I1seH5sE5z2lEUEmwLm44wG mzC7K8K01Si3HLayf9A7hBBRl5I04WRguO8BkXZj7J4oNSLgYPrOuzXcwzqUQ+s+39a+ oUC1pmNe1hkxuHIhFBLr2TMWyTXcbsrbTGP3Vl8UF/EMIs6fJpV9CWsPCL7a7Zx1a0Il ThxyP0LwotRl3XcoZU/mOFolyuQX0Pwn5NQqCgSyFUbdk576qkRJPAUuDhncGTRsUajI UICw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XHWlK1Ot; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si17242968oie.20.2020.01.19.18.04.27; Sun, 19 Jan 2020 18:04:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XHWlK1Ot; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729011AbgATCCh (ORCPT + 99 others); Sun, 19 Jan 2020 21:02:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:43800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728931AbgATCCh (ORCPT ); Sun, 19 Jan 2020 21:02:37 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 24A7620678; Mon, 20 Jan 2020 02:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579485756; bh=IgWnmFG4IWCDZ7oFxlaJMqo1c+sGlwmV3F6Rqf7BC48=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=XHWlK1OtrHCH+uzYyEW9WBn0OcAE7z/KrNkeW4ZdgQgSUKxkCIuPfhNsa5BOdxdHy XFca+kRq/mYPxdlrRRWoaRBqHfWxwsoFwFOMfrqJZ1Suda4wJIzTBoo9BGHN/k7cHv xJPxDMDEP6SmH4IsgZYupmw9IzpG7kDnoBXxU3O4= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id E4B9635227EF; Sun, 19 Jan 2020 18:02:35 -0800 (PST) Date: Sun, 19 Jan 2020 18:02:35 -0800 From: "Paul E. McKenney" To: Andrea Parri Cc: linux-kernel@vger.kernel.org, Tejun Heo , Lai Jiangshan Subject: Re: [PATCH] workqueue: Document (some) memory-ordering properties of {queue,schedule}_work() Message-ID: <20200120020235.GA8126@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200118215820.7646-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200118215820.7646-1-parri.andrea@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 18, 2020 at 10:58:20PM +0100, Andrea Parri wrote: > It's desirable to be able to rely on the following property: All stores > preceding (in program order) a call to a successful queue_work() will be > visible from the CPU which will execute the queued work by the time such > work executes, e.g., > > { x is initially 0 } > > CPU0 CPU1 > > WRITE_ONCE(x, 1); [ "work" is being executed ] > r0 = queue_work(wq, work); r1 = READ_ONCE(x); > > Forbids: r0 == true && r1 == 0 > > The current implementation of queue_work() provides such memory-ordering > property: > > - In __queue_work(), the ->lock spinlock is acquired. > > - On the other side, in worker_thread(), this same ->lock is held > when dequeueing work. > > So the locking ordering makes things work out. > > Add this property to the DocBook headers of {queue,schedule}_work(). > > Suggested-by: Paul E. McKenney > Signed-off-by: Andrea Parri Acked-by: Paul E. McKenney An alternative to Randy's suggestion of dropping the comma following the "cf." is to just drop that whole phrase. I will let you and Randy work that one out, though. ;-) > --- > include/linux/workqueue.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h > index 4261d1c6e87b1..4fef6c38b0536 100644 > --- a/include/linux/workqueue.h > +++ b/include/linux/workqueue.h > @@ -487,6 +487,19 @@ extern void wq_worker_comm(char *buf, size_t size, struct task_struct *task); > * > * We queue the work to the CPU on which it was submitted, but if the CPU dies > * it can be processed by another CPU. > + * > + * Memory-ordering properties: If it returns %true, guarantees that all stores > + * preceding the call to queue_work() in the program order will be visible from > + * the CPU which will execute @work by the time such work executes, e.g., > + * > + * { x is initially 0 } > + * > + * CPU0 CPU1 > + * > + * WRITE_ONCE(x, 1); [ @work is being executed ] > + * r0 = queue_work(wq, work); r1 = READ_ONCE(x); > + * > + * Forbids: r0 == true && r1 == 0 > */ > static inline bool queue_work(struct workqueue_struct *wq, > struct work_struct *work) > @@ -546,6 +559,9 @@ static inline bool schedule_work_on(int cpu, struct work_struct *work) > * This puts a job in the kernel-global workqueue if it was not already > * queued and leaves it in the same position on the kernel-global > * workqueue otherwise. > + * > + * Shares the same memory-ordering properties of queue_work(), c.f., the > + * DocBook header of queue_work(). > */ > static inline bool schedule_work(struct work_struct *work) > { > -- > 2.24.0 >