From: Mark Mielke <mark@mark.mielke.cc>
To: Duncan Sands <baldrick@wanadoo.fr>
Cc: Pavel Machek <pavel@ucw.cz>,
linux-kernel@vger.kernel.org, Andrew Morton <akpm@digeo.com>
Subject: Re: Use of yield() in the kernel
Date: Tue, 22 Oct 2002 13:24:04 -0400 [thread overview]
Message-ID: <20021022172404.GB1314@mark.mielke.cc> (raw)
In-Reply-To: <200210201110.33254.baldrick@wanadoo.fr>
Would it be sensible to add a "yield_short()" function to the kernel?
mark
On Sun, Oct 20, 2002 at 11:10:33AM +0200, Duncan Sands wrote:
> > > Hi Pavel, I agree. I have some questions about the code though:
> > > when you come across a thread with (p->flags & PF_FROZEN), why
> > > break out of the loop? Why not just skip this thread and go on to
> > > the
> >
> > There's "continue;" in there, and it should "just skip this thread".
> > Pavel
>
> I meant, why not just do as in the following code (I've changed
> INTERESTING also, for same reason, as explained below):
>
> do {
> todo = 0;
> read_lock(&tasklist_lock);
> do_each_thread(g, p) {
> unsigned long flags;
>
> if (
> !(p->flags & PF_IOTHREAD) &&
> (p != current) &&
> (p->state != TASK_ZOMBIE) &&
> !(p->flags & PF_FROZEN)
> ) {
>
> /* FIXME: smp problem here: we may not access other process' flags
> without locking */
> p->flags |= PF_FREEZE;
> spin_lock_irqsave(&p->sig->siglock, flags);
> signal_wake_up(p);
> spin_unlock_irqrestore(&p->sig->siglock, flags);
> todo++;
> }
> } while_each_thread(g, p);
> read_unlock(&tasklist_lock);
> yield();
> if (time_after(jiffies, start_time + TIMEOUT)) {
> printk( "\n" );
> printk(KERN_ERR " stopping tasks failed (%d tasks remaining)\n", todo );
> return todo;
> }
> } while(todo);
>
> The reason is that yield(), which sends the current task to the expired list,
> can take a long time before it runs again. With the current code, every time
> you meet, for example, a kernel thread you break out of the loop, perform
> a yield (= wait a long time), before going on to the next thread. This could
> take forever. With code like that above, you mark as many tasks frozen as
> possible, with as few yields as possible. Isn't that better?
>
> Ciao,
>
> Duncan.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
mark@mielke.cc/markm@ncf.ca/markm@nortelnetworks.com __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada
One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...
http://mark.mielke.cc/
next prev parent reply other threads:[~2002-10-22 17:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-15 13:36 Duncan Sands
2002-10-15 15:15 ` Ingo Molnar
2002-10-15 17:12 ` John Levon
2002-10-17 6:36 ` Duncan Sands
2002-10-18 18:26 ` Pavel Machek
2002-10-19 12:25 ` Duncan Sands
2002-10-19 22:00 ` Pavel Machek
2002-10-20 9:10 ` Duncan Sands
2002-10-22 17:24 ` Mark Mielke [this message]
2002-10-22 18:58 ` Duncan Sands
2002-10-25 14:15 ` Duncan Sands
2002-10-20 11:22 ` Duncan Sands
2002-10-15 16:20 Marc-Christian Petersen
2002-10-15 16:27 ` Duncan Sands
2002-10-25 8:43 ` Duncan Sands
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=20021022172404.GB1314@mark.mielke.cc \
--to=mark@mark.mielke.cc \
--cc=akpm@digeo.com \
--cc=baldrick@wanadoo.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
/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®