From: Duncan Sands <baldrick@wanadoo.fr>
To: Pavel Machek <pavel@ucw.cz>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@digeo.com>
Subject: Re: Use of yield() in the kernel
Date: Sun, 20 Oct 2002 11:10:33 +0200 [thread overview]
Message-ID: <200210201110.33254.baldrick@wanadoo.fr> (raw)
In-Reply-To: <20021019220000.GC28445@atrey.karlin.mff.cuni.cz>
> > 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.
next prev parent reply other threads:[~2002-10-20 9:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-15 13:36 Use of yield() in the kernel 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 [this message]
2002-10-22 17:24 ` Mark Mielke
2002-10-22 18:58 ` Duncan Sands
2002-10-25 14:15 ` Duncan Sands
2002-10-20 11:22 ` Duncan Sands
-- strict thread matches above, loose matches on Subject: below --
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=200210201110.33254.baldrick@wanadoo.fr \
--to=baldrick@wanadoo.fr \
--cc=akpm@digeo.com \
--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