lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.64.0811141630590.6783@hs20-bc2-1.build.redhat.com>
Date:	Fri, 14 Nov 2008 16:41:45 -0500 (EST)
From:	Mikulas Patocka <mpatocka@...hat.com>
To:	Peter Zijlstra <peterz@...radead.org>
cc:	Alan Cox <alan@...rguk.ukuu.org.uk>, linux-kernel@...r.kernel.org,
	mingo@...e.hu, rml@...h9.net, Alasdair G Kergon <agk@...hat.com>,
	Milan Broz <mbroz@...hat.com>
Subject: Re: Active waiting with yield()

On Fri, 14 Nov 2008, Peter Zijlstra wrote:

> 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).

So, use msleep(1) instead of yield() ?

Mikulas

> 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.
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ