From: Kyle Moffett <mrmacman_g4@mac.com>
To: Jesper Juhl <jesper.juhl@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>,
David Schwartz <davids@webmaster.com>,
linux-kernel@vger.kernel.org
Subject: Re: yield API
Date: Wed, 12 Dec 2007 23:43:51 -0500 [thread overview]
Message-ID: <54633429-AF8F-4A9F-9141-B70B74A8359E@mac.com> (raw)
In-Reply-To: <9a8748490712121439u34863df9r6ff8d4eadb39705f@mail.gmail.com>
On Dec 12, 2007, at 17:39:15, Jesper Juhl wrote:
> On 02/10/2007, Ingo Molnar <mingo@elte.hu> wrote:
>> sched_yield() has been around for a decade (about three times
>> longer than futexes were around), so if it's useful, it sure
>> should have grown some 'crown jewel' app that uses it and shows
>> off its advantages, compared to other locking approaches, right?
>
> I have one example of sched_yield() use in a real app.
> Unfortunately it's proprietary so I can't show you the source, but
> I can tell you how it's used.
>
> The case is this: Process A forks process B. Process B does some
> work that takes aproximately between 50 and 1000ms to complete
> (varies), then it creates a file and continues to do other work.
> Process A needs to wait for the file B creates before it can
> continue. Process A *could* immediately go into some kind of "check
> for file; sleep n ms" loop, but instead it starts off by calling
> sched_yield() to give process B a chance to run and hopefully get
> to the point where it has created the file before process A is
> again scheduled and starts to look for it - after the single sched
> yield call, process A does indeed go into a "check for file; sleep
> 250ms;" loop, but most of the time the initial sched_yield() call
> actually results in the file being present without having to loop
> like that.
That is a *terrible* disgusting way to use yield. Better options:
(1) inotify/dnotify
(2) create a "foo.lock" file and put the mutex in that
(3) just start with the check-file-and-sleep loop.
> Now is this the best way to handle this situation? No. Does it
> work better than just doing the wait loop from the start? Yes.
It works better than doing the wait-loop from the start? What
evidence do you provide to support this assertion? Specifically, in
the first case you tell the kernel "I'm waiting for something but I
don't know what it is or how long it will take"; while in the second
case you tell the kernel "I'm waiting for something that will take
exactly X milliseconds, even though I don't know what it is. If you
really want something similar to the old behavior then just replace
the "sched_yield()" call with a proper sleep for the estimated time
it will take the program to create the file.
> Is this a good way to use sched_yield()? Maybe, maybe not. But it
> *is* an actual use of the API in a real app.
We weren't looking for "actual uses", especially not in binary-only
apps. What we are looking for is optimal uses of sched_yield(); ones
where that is the best alternative. This... certainly isn't.
Cheers,
Kyle Moffett
next prev parent reply other threads:[~2007-12-13 4:44 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-26 8:52 Network slowdown due to CFS Martin Michlmayr
2007-09-26 9:34 ` Ingo Molnar
2007-09-26 9:47 ` Ingo Molnar
2007-09-26 10:08 ` Martin Michlmayr
2007-09-26 10:18 ` Ingo Molnar
2007-09-26 10:20 ` Mike Galbraith
2007-09-26 10:23 ` Mike Galbraith
2007-09-26 10:48 ` Martin Michlmayr
2007-09-26 11:21 ` Ingo Molnar
2007-09-26 11:29 ` Martin Michlmayr
2007-09-26 12:00 ` David Schwartz
2007-09-26 13:31 ` Ingo Molnar
2007-09-26 15:40 ` Stephen Hemminger
2007-09-26 15:46 ` Stephen Hemminger
2007-09-27 9:30 ` Jarek Poplawski
2007-09-27 9:46 ` Ingo Molnar
2007-09-27 12:27 ` Jarek Poplawski
2007-09-27 13:31 ` Ingo Molnar
2007-09-27 14:42 ` Jarek Poplawski
2007-09-28 6:10 ` Nick Piggin
2007-10-01 8:43 ` Jarek Poplawski
2007-10-01 16:25 ` Ingo Molnar
2007-10-01 16:49 ` David Schwartz
2007-10-01 17:31 ` Ingo Molnar
2007-10-01 18:23 ` David Schwartz
2007-10-02 6:06 ` Ingo Molnar
2007-10-02 6:47 ` Andi Kleen
2007-10-03 8:02 ` Jarek Poplawski
2007-10-03 8:16 ` Ingo Molnar
2007-10-03 8:56 ` Jarek Poplawski
2007-10-03 9:10 ` Ingo Molnar
2007-10-03 9:50 ` Jarek Poplawski
2007-10-03 10:55 ` Dmitry Adamushko
2007-10-03 10:58 ` Dmitry Adamushko
2007-10-03 11:20 ` Jarek Poplawski
2007-10-03 11:22 ` Ingo Molnar
2007-10-03 11:40 ` Jarek Poplawski
2007-10-03 11:56 ` yield Ingo Molnar
2007-10-03 12:16 ` yield Jarek Poplawski
2007-10-07 7:18 ` Network slowdown due to CFS Ingo Molnar
2007-10-04 5:33 ` Casey Dahlin
2007-10-02 6:08 ` Ingo Molnar
2007-10-02 6:26 ` Ingo Molnar
2007-10-02 6:46 ` yield API Ingo Molnar
2007-10-02 11:50 ` linux-os (Dick Johnson)
2007-10-02 15:24 ` Douglas McNaught
2007-10-02 21:57 ` Eric St-Laurent
2007-12-12 22:39 ` Jesper Juhl
2007-12-13 4:43 ` Kyle Moffett [this message]
2007-12-13 20:10 ` David Schwartz
2007-10-01 19:53 ` Network slowdown due to CFS Arjan van de Ven
2007-10-01 22:17 ` David Schwartz
2007-10-01 22:35 ` Arjan van de Ven
2007-10-01 22:44 ` David Schwartz
2007-10-01 22:55 ` Arjan van de Ven
2007-10-02 15:37 ` David Schwartz
2007-10-03 7:15 ` Jarek Poplawski
2007-10-03 11:31 ` Helge Hafting
2007-10-04 0:31 ` Rusty Russell
2007-10-01 16:55 ` Chris Friesen
2007-10-01 17:09 ` Ingo Molnar
2007-10-01 17:45 ` Chris Friesen
2007-10-01 19:09 ` iperf yield usage Ingo Molnar
2007-10-02 9:03 ` Network slowdown due to CFS Jarek Poplawski
2007-10-02 13:39 ` Jarek Poplawski
2007-10-02 9:26 ` Jarek Poplawski
2007-09-27 9:49 ` Ingo Molnar
2007-09-27 10:54 ` Martin Michlmayr
2007-09-27 10:56 ` Ingo Molnar
2007-09-27 11:12 ` Martin Michlmayr
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=54633429-AF8F-4A9F-9141-B70B74A8359E@mac.com \
--to=mrmacman_g4@mac.com \
--cc=davids@webmaster.com \
--cc=jesper.juhl@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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®