public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	linux-kernel@vger.kernel.org, mingo@elte.hu, rml@tech9.net,
	Alasdair G Kergon <agk@redhat.com>, Milan Broz <mbroz@redhat.com>
Subject: Re: Active waiting with yield()
Date: Fri, 14 Nov 2008 21:57:01 +0100	[thread overview]
Message-ID: <1226696221.7685.8148.camel@twins> (raw)
In-Reply-To: <Pine.LNX.4.64.0811141412290.12992@hs20-bc2-1.build.redhat.com>

On Fri, 2008-11-14 at 14:34 -0500, Mikulas Patocka wrote:
> 
> On Fri, 14 Nov 2008, Alan Cox wrote:
> 
> > > * driver unload --- check the count of outstanding requests and call 
> > > yield() repeatedly until it goes to zero, then unload.
> > 
> > Use a wakeup when the request count hits zero
> > 
> > > * reduced size of data structures (and reduced cache footprint for the hot 
> > > path that actually processes requests)
> > 
> > The CPU will predict the non-wakeup path if that is normal. You can even
> > make the wakeup use something like
> > 
> > 	if (exiting & count == 0)
> > 
> > to get the prediction righ
> > 
> > > The downside of yield is slower unloading of the driver by few tens of 
> > > miliseconds, but the user doesn't really care about fractions of a second 
> > > when unloading drivers.
> > 
> > And more power usage, plus extremely rude behaviour when virtualising.
> 
> How these unlikely cases can be rude?
> 
> If I have a race condition that gets triggered just for one user in the 
> world when repeatedly loading & unloading a driver for an hour, and I use 
> yield() to solve it, what's wrong with it? A wait queue increases cache 
> footprint for every user. (even if I use preallocated hashed wait queue, 
> it still eats a cacheline to access it and find out that it's empty)

Depending on the situation, yield() might be a NOP and therefore not
wait at all and possibly lock up the machine.

Consider the task in question to be the highest priority RT task on the
system, you doing: while (!condition) yield(); will lock up the system,
because whatever is to make condition true will never get a chance to
run (not considering SMP).

Clearly you don't understand it, please refrain from using it. Use
regular condition variables (waitqueues).

The rules about yield are:

 - You're likely wrong, don't use it.
 - Seriously, you don't need it.
 - If you still think you do, goto 1.

In all of the kernel there is 1 valid use (and it might only be in the
-rt kernel - didn't check mainline recently).

The _ONLY_ valid use case of yield(), is if you have two equal priority
FIFO threads that co-depend. And that situation is almost always
avoidable.


  reply	other threads:[~2008-11-14 20:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-14 18:59 Active waiting with yield() Mikulas Patocka
2008-11-14 19:06 ` Alan Cox
2008-11-14 19:34   ` Mikulas Patocka
2008-11-14 20:57     ` Peter Zijlstra [this message]
2008-11-14 21:41       ` Mikulas Patocka
2008-11-15 22:55         ` Peter Zijlstra
2008-11-17 17:39           ` Mikulas Patocka
2008-11-17 18:01             ` Alan Cox
2008-11-18 14:34               ` Mikulas Patocka
2008-11-18 14:40                 ` Alan Cox
2008-11-18 17:11                   ` Mikulas Patocka
2008-11-18 21:26                     ` Alan Cox
2008-11-20  9:18                       ` Mikulas Patocka
2008-11-19 16:14                     ` Peter Zijlstra
2008-11-18 14:49                 ` Arjan van de Ven
2008-11-18 17:14                   ` Mikulas Patocka
2008-11-14 21:21     ` Alan Cox

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=1226696221.7685.8148.camel@twins \
    --to=peterz@infradead.org \
    --cc=agk@redhat.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbroz@redhat.com \
    --cc=mingo@elte.hu \
    --cc=mpatocka@redhat.com \
    --cc=rml@tech9.net \
    /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