From: Ingo Molnar <mingo@elte.hu>
To: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Andrew Morton <akpm@osdl.org>, Florin Iucha <florin@iucha.net>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Linux 2.6.20-rc2
Date: Tue, 26 Dec 2006 17:37:13 +0100 [thread overview]
Message-ID: <20061226163713.GA9047@elte.hu> (raw)
In-Reply-To: <20061226162616.GA6756@elte.hu>
* Ingo Molnar <mingo@elte.hu> wrote:
> > I've had at least one more occurrence of it:
> >
> > [ 78.804940] BUG: scheduling while atomic: kbd/0x20000000/3444
> > [ 78.804944]
> > [ 78.804945] Call Trace:
>
> ok, i can think of a simpler scenario:
> add_preempt_count(PREEMPT_ACTIVE) /twice/, nested into each other.
doh - the BKL! That does a down() in a PREEMPT_ACTIVE section, which can
trigger cond_resched(). The fix is to check for PREEMPT_ACTIVE in
cond_resched(). (and only in cond_resched())
Updated fix (against -rc2) attached.
Ingo
---------------------->
Subject: [patch] sched: fix cond_resched_softirq() offset
From: Ingo Molnar <mingo@elte.hu>
remove the __resched_legal() check: it is conceptually broken.
The biggest problem it had is that it can mask buggy cond_resched()
calls. A cond_resched() call is only legal if we are not in an
atomic context, with two narrow exceptions:
- if the system is booting
- a reacquire_kernel_lock() down() done while PREEMPT_ACTIVE is set
But __resched_legal() hid this and just silently returned whenever
these primitives were called from invalid contexts. (Same goes for
cond_resched_locked() and cond_resched_softirq()).
furthermore, the __legal_resched(0) call was buggy in that it caused
unnecessarily long softirq latencies via cond_resched_softirq(). (which
is only called from softirq-off sections, hence the code did nothing.)
the fix is to resurrect the efficiency of the might_sleep checks and to
only allow the narrow exceptions.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/sched.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
Index: linux/kernel/sched.c
===================================================================
--- linux.orig/kernel/sched.c
+++ linux/kernel/sched.c
@@ -4617,17 +4617,6 @@ asmlinkage long sys_sched_yield(void)
return 0;
}
-static inline int __resched_legal(int expected_preempt_count)
-{
-#ifdef CONFIG_PREEMPT
- if (unlikely(preempt_count() != expected_preempt_count))
- return 0;
-#endif
- if (unlikely(system_state != SYSTEM_RUNNING))
- return 0;
- return 1;
-}
-
static void __cond_resched(void)
{
#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
@@ -4647,7 +4636,8 @@ static void __cond_resched(void)
int __sched cond_resched(void)
{
- if (need_resched() && __resched_legal(0)) {
+ if (need_resched() && !(preempt_count() & PREEMPT_ACTIVE) &&
+ system_state == SYSTEM_RUNNING) {
__cond_resched();
return 1;
}
@@ -4673,7 +4663,7 @@ int cond_resched_lock(spinlock_t *lock)
ret = 1;
spin_lock(lock);
}
- if (need_resched() && __resched_legal(1)) {
+ if (need_resched() && system_state == SYSTEM_RUNNING) {
spin_release(&lock->dep_map, 1, _THIS_IP_);
_raw_spin_unlock(lock);
preempt_enable_no_resched();
@@ -4689,7 +4679,7 @@ int __sched cond_resched_softirq(void)
{
BUG_ON(!in_softirq());
- if (need_resched() && __resched_legal(0)) {
+ if (need_resched() && system_state == SYSTEM_RUNNING) {
raw_local_irq_disable();
_local_bh_enable();
raw_local_irq_enable();
next prev parent reply other threads:[~2006-12-26 16:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-25 22:40 Linux 2.6.20-rc2 Florin Iucha
2006-12-25 22:56 ` Florin Iucha
2006-12-25 23:06 ` Trond Myklebust
2006-12-26 1:30 ` Florin Iucha
2006-12-26 10:25 ` Andrew Morton
2006-12-26 12:40 ` Ingo Molnar
2006-12-26 14:20 ` Florin Iucha
2006-12-26 15:22 ` Ingo Molnar
[not found] ` <20061226234206.GD22307@iucha.net>
[not found] ` <20061226234253.GA7523@elte.hu>
2006-12-27 1:50 ` Florin Iucha
2006-12-26 15:36 ` Randy Dunlap
2006-12-26 16:26 ` Ingo Molnar
2006-12-26 16:37 ` Ingo Molnar [this message]
2006-12-26 17:44 ` Fabio Comolli
2007-01-03 12:33 ` Jiri Kosina
-- strict thread matches above, loose matches on Subject: below --
2006-12-24 4:49 Linus Torvalds
2006-12-24 13:58 ` Alessandro Suardi
2006-12-24 14:49 ` Jeff Garzik
2006-12-24 17:13 ` Andreas Schwab
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=20061226163713.GA9047@elte.hu \
--to=mingo@elte.hu \
--cc=akpm@osdl.org \
--cc=florin@iucha.net \
--cc=linux-kernel@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.