All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarek Poplawski <jarkao2@o2.pl>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: "Maciej W\. Rozycki" <macro@linux-mips.org>,
	Andy Fleming <afleming@freescale.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jeff Garzik <jgarzik@pobox.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] flush_work_sync vs. flush_scheduled_work Re: [PATCH] PHYLIB: IRQ event workqueue handling fixes
Date: Fri, 19 Oct 2007 09:50:14 +0200	[thread overview]
Message-ID: <20071019075014.GA1765@ff.dom.local> (raw)
In-Reply-To: <20071018154819.GA425@tv-sign.ru>

On Thu, Oct 18, 2007 at 07:48:19PM +0400, Oleg Nesterov wrote:
> On 10/18, Jarek Poplawski wrote:
> >
> > +/**
> > + * flush_work_sync - block until a work_struct's callback has terminated
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Hmm...
> 
> > + * Similar to cancel_work_sync() but will only busy wait (without cancel)
> > + * if the work is queued.
> 
> Yes, it won't block, but will spin in busy-wait loop until all other works
> scheduled before this work are finished. Not good. After that it really
> blocks waiting for this work to complete.
> 
> And I am a bit confused. We can't use flush_workqueue() because some of the
> queued work_structs may take rtnl_lock, yes? But in that case we can't use
> the new flush_work_sync() helper as well, no?

OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOPS!

Of course, we can't!!! I remembered there was this issue long time
ago, but then I've had some break in tracking net & workqueue. So,
while reading this patch I was alarmed at first, and self-misled
later. I think, there is definitely needed some warning about
locking (or unlocking) during these flush_ & cancel_ functions.
(Btw, I've very much wondered now, why I didn't notice at that 'old'
time, that you added such a great feature (wrt. locking) and I even
didn't notice this...). 

So, Maciej (and other readers of this thread) - I withdraw my false
opinion from my second message here: it's very wrong to call this
sched_work_sync() with rtnl_lock(). It's only less probable to lockup
with this than with flush_schedule_work().

> 
> If we can't just cancel the work, can't we do something like
> 
> 	if (cancel_work_sync(w))
> 		w->func(w);
> 
> instead?
> 
> > +void flush_work_sync(struct work_struct *work)
> > +{
> > +	int ret;
> > +
> > +	do {
> > +		ret = work_pending(work);
> > +		wait_on_work(work);
> > +		if (ret)
> > +			cpu_relax();
> > +	} while (ret);
> > +}
> 
> If we really the new helper, perhaps we can make it a bit better?
> 
> 1. Modify insert_work() to take the "struct list_head *at" parameter instead
>    of "int tail". I think this patch will also cleanup the code a bit, and
>    shrink a couple of bytes from .text

Looks like a very good idea, but I need more time to rethink this.
Probably some code example should be helpful.

> 
> 2. flush_work_sync() inserts a barrier right after this work and blocks.
>    We still need some retry logic to handle the queueing is in progress
>    of course, but we won't spin waiting for the other works.

Until monday I should have an opinion on that (today a bit under
fire...).

> 
> What do you think?

Since there is no gain wrt. locking with my current proposal, I
withdraw this patch of course.

It looks like my wrong patch was great idea because we got this very
precious Oleg's opinion! (I know I'm a genius sometimes...)

Thanks very much,
Jarek P.

  parent reply	other threads:[~2007-10-19  7:47 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-19 14:38 [PATCH] PHYLIB: IRQ event workqueue handling fixes Maciej W. Rozycki
2007-09-20 23:53 ` Andrew Morton
2007-09-21 12:51   ` Maciej W. Rozycki
2007-09-21 18:42     ` Andrew Morton
2007-10-15 12:53 ` Jarek Poplawski
2007-10-15 17:03   ` Maciej W. Rozycki
2007-10-16  6:21     ` Jarek Poplawski
2007-10-16 17:19       ` Maciej W. Rozycki
2007-10-17  8:58         ` Jarek Poplawski
2007-10-17  9:08           ` Benjamin Herrenschmidt
2007-10-17  9:09           ` Jarek Poplawski
2007-10-18  6:31           ` Jarek Poplawski
2007-10-18  7:05             ` [PATCH] flush_work_sync vs. flush_scheduled_work " Jarek Poplawski
2007-10-18 15:48               ` Oleg Nesterov
2007-10-18 15:58                 ` Maciej W. Rozycki
2007-10-19  7:50                 ` Jarek Poplawski [this message]
2007-10-19  8:01                   ` Jarek Poplawski
2007-10-22  6:11                   ` Jarek Poplawski
2007-10-22 18:02                     ` Oleg Nesterov
2007-10-23  6:59                       ` Jarek Poplawski
2007-10-23  9:21                       ` Jarek Poplawski
2007-10-19  8:00                 ` Johannes Berg
2007-10-18 11:37             ` Maciej W. Rozycki
2007-10-18 11:30           ` Maciej W. Rozycki
2007-10-18 14:37             ` Jarek Poplawski
2007-10-18 15:31               ` Maciej W. Rozycki
2007-10-19  8:17             ` Jarek Poplawski
2007-10-19 12:57               ` Maciej W. Rozycki
2007-10-19 11:38             ` Maciej W. Rozycki
2007-10-19 14:39               ` Jarek Poplawski
2007-10-19 17:58                 ` Maciej W. Rozycki
2007-10-19 21:46                 ` Benjamin Herrenschmidt

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=20071019075014.GA1765@ff.dom.local \
    --to=jarkao2@o2.pl \
    --cc=afleming@freescale.com \
    --cc=akpm@linux-foundation.org \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=macro@linux-mips.org \
    --cc=netdev@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.