Linux Documentation
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>
Subject: Re: [PATCH] workqueue: doc: Call out the non-reentrance conditions
Date: Mon, 18 Oct 2021 12:26:46 +0100	[thread overview]
Message-ID: <YW1Z9rFpGl/j70HT@casper.infradead.org> (raw)
In-Reply-To: <YWznsr6qnCpErKJi@boqun-archlinux>

On Mon, Oct 18, 2021 at 11:19:14AM +0800, Boqun Feng wrote:
> On Mon, Oct 18, 2021 at 03:17:53AM +0100, Matthew Wilcox wrote:
> > On Mon, Oct 18, 2021 at 09:31:17AM +0800, Boqun Feng wrote:
> > > @@ -391,6 +387,23 @@ the stack trace of the offending worker thread. ::
> > >  The work item's function should be trivially visible in the stack
> > >  trace.
> > >  
> > > +Non-reentrance Conditions
> > > +=========================
> > > +
> > > +Workqueue guarantees that a work item cannot be re-entrant if the following
> > > +conditions hold after a work item gets queued:
> > > +
> > > +        1. The work function hasn't been changed.
> > > +        2. No one queues the work item to another workqueue.
> > > +        3. The work item hasn't been reinitiated.
> > > +
> > > +In other words, if the above conditions hold, the work item is guaranteed to be
> > > +executed by at most one worker system-wide at any given time.
> > > +
> > > +Note that requeuing the work item (to the same queue) in the self function
> > > +doesn't break these conditions, so it's safe to do. Otherwise, caution is
> > > +required when breaking the conditions inside a work function.
> > > +
> > 
> > I'd like to suggest that this be added to the Guidelines section
> 
> Good idea, Guidelines section is a better place to put these, since it's
> for users.
> 
> > instead:
> > 
> > * A work item will not normally be processed on multiple CPUs at the
> 
> Precisely speaking, it should be "by mutliple workers" instead of "on
> multiple CPUs", because two workers of tw unbound workqueue may process
> the same work item on the same CPU, and that's problematic since
> processing work is preemptible.
> 
> >   same time.  It can happen if the work function is changed, the work
> >   item is queued to multiple queues or the work function is
> >   reinitialised after being queued.
> 
> I end up with something like below, I still want to keep the keyword
> "reentrant" for searching, because sometimes one may forget this
> particular aspect after reading the whole doc for a while, the keyword
> can help locate the lines faster (Ok, the fact is that "one" was me
> ;-)).
> 
> * A work item will not normally be processed by multiple workers at the
>   same time, i.e. it's non-reentrant.  However it can happen if the work
>   function is changed, the work item is queued to multiple queues or the
>   work item is reinitialised after being queued.
> 
> Thoughts? Thank for the suggestion!

Looks good to me!

  reply	other threads:[~2021-10-18 11:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-18  1:31 [PATCH] workqueue: doc: Call out the non-reentrance conditions Boqun Feng
2021-10-18  2:17 ` Matthew Wilcox
2021-10-18  3:19   ` Boqun Feng
2021-10-18 11:26     ` Matthew Wilcox [this message]
2021-10-19 17:47 ` Tejun Heo
2021-10-20  5:40   ` Boqun Feng
2021-10-20 16:18     ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YW1Z9rFpGl/j70HT@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=boqun.feng@gmail.com \
    --cc=corbet@lwn.net \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox