mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, rml@tech9.net, Alasdair G Kergon <agk@redhat.com>,
	Milan Broz <mbroz@redhat.com>
Subject: Active waiting with yield()
Date: Fri, 14 Nov 2008 13:59:55 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0811141327100.22830@hs20-bc2-1.build.redhat.com> (raw)

Hi

Every time I write yield() somewhere into my code, there comes a comment 
"real-time people don't like yield()". Without any explanation why yield() 
is not suitable at that specific point, just that "people don't like it".

We all know that waiting with yield() is bad for general code that 
processes requests, because repeated scheduling wastes extra CPU time and 
the process waiting for some event with yield() is woken up late. In these 
normal cases, wait queues should be used.

However, there is code where in my opinion using yield() for waiting is 
appropriate, for example:

* driver unload --- check the count of outstanding requests and call 
yield() repeatedly until it goes to zero, then unload.
* some rare race contition --- a workaround for a race that triggers once 
per hour for one user in several years doesn't really have to be fast.

A typical example where yield() can be used is a driver that counts a 
number of outstanding requests --- when the user tries to unload the 
driver, the driver will make sure that new requests won't come, repeatedly 
yield()s until the count of requests reaches zero and then destroys its 
data structures.

Here, yield() has some advantages over wait queues, because:

* reduced size of data structures (and reduced cache footprint for the hot 
path that actually processes requests)
* slightly reduced code size even on the hot path (no need to wake up an 
empty queue)
* less possibility for bugs coming from the fact that someone forgets to 
wake the queue up

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.

--- but people complain even if I use yield() in these cases. None of 
those complains contains any valid technical argument --- just that 
"someone said that yield() is bad". Is there a real reason why yield() in 
these cases is bad? (for example that with some real-time patches, 
yield()ing high-priority thread would be spinning forever, killing the 
system?) Or should I use msleep(1) instead? Or should wait queues really 
be used even in those performance-insensitive cases?

Mikulas

             reply	other threads:[~2008-11-14 19:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-14 18:59 Mikulas Patocka [this message]
2008-11-14 19:06 ` Alan Cox
2008-11-14 19:34   ` Mikulas Patocka
2008-11-14 20:57     ` Peter Zijlstra
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=Pine.LNX.4.64.0811141327100.22830@hs20-bc2-1.build.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=agk@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbroz@redhat.com \
    --cc=mingo@elte.hu \
    --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

all inboxes | Powered by JetHome®