From: Ingo Molnar <mingo@elte.hu>
To: Andrew Morton <akpm@osdl.org>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>, linux-kernel@vger.kernel.org
Subject: [patch] remove set_tsk_need_resched() from init_idle()
Date: Tue, 24 May 2005 14:15:41 +0200 [thread overview]
Message-ID: <20050524121541.GA17049@elte.hu> (raw)
this patch (ontop of the current -mm scheduler patchset, in particular
ontop of Nick's idle-thread optimization patches) tweaks cpu_idle()
semantics a bit: it changes the idle loops (that do preemption) to call
the first schedule() without checking for need_resched().
the advantage is that as a result we dont have to set the idle thread's
NEED_RESCHED flag in init_idle(), which in turn makes cond_resched()
even more of an invariant: it can be called even from init code without
it having any effect. A cond resched in the init codepath hangs
otherwise.
this patch, while having no negative side-effects, enables wider use of
cond_resched()s. (which might happen in the stock kernel too, but it's
particulary important for voluntary-preempt)
(note that for now this patch only covers architectures that use
kernel/Kconfig.preempt, but all other architectures will work just fine
too.)
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/i386/kernel/process.c | 2 +-
arch/ppc64/kernel/idle.c | 11 +++++------
arch/x86_64/kernel/process.c | 3 +--
kernel/sched.c | 12 +++++++++++-
4 files changed, 18 insertions(+), 10 deletions(-)
--- linux/kernel/sched.c.orig
+++ linux/kernel/sched.c
@@ -4163,6 +4163,17 @@ void show_state(void)
read_unlock(&tasklist_lock);
}
+/**
+ * init_idle - set up an idle thread for a given CPU
+ * @idle: task in question
+ * @cpu: cpu the idle task belongs to
+ *
+ * NOTE: this function does not set the idle thread's NEED_RESCHED
+ * flag, to make booting more robust. Architecture-level cpu_idle()
+ * functions should structure their idle loop to call the first
+ * schedule() unconditionally, and to check for need_resched() only
+ * afterwards.
+ */
void __devinit init_idle(task_t *idle, int cpu)
{
runqueue_t *rq = cpu_rq(cpu);
@@ -4180,7 +4191,6 @@ void __devinit init_idle(task_t *idle, i
#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
idle->oncpu = 1;
#endif
- set_tsk_need_resched(idle);
spin_unlock_irqrestore(&rq->lock, flags);
/* Set the preempt count _outside_ the spinlocks! */
--- linux/arch/x86_64/kernel/process.c.orig
+++ linux/arch/x86_64/kernel/process.c
@@ -164,6 +164,7 @@ void cpu_idle (void)
{
/* endless idle loop with no priority at all */
while (1) {
+ schedule();
while (!need_resched()) {
void (*idle)(void);
@@ -176,8 +177,6 @@ void cpu_idle (void)
idle = default_idle;
idle();
}
-
- schedule();
}
}
--- linux/arch/ppc64/kernel/idle.c.orig
+++ linux/arch/ppc64/kernel/idle.c
@@ -86,6 +86,7 @@ static int iSeries_idle(void)
lpaca = get_paca();
while (1) {
+ schedule();
if (lpaca->lppaca.shared_proc) {
if (ItLpQueue_isLpIntPending(lpaca->lpqueue_ptr))
process_iSeries_events();
@@ -110,8 +111,6 @@ static int iSeries_idle(void)
set_need_resched();
}
}
-
- schedule();
}
return 0;
@@ -125,6 +124,10 @@ static int default_idle(void)
unsigned int cpu = smp_processor_id();
while (1) {
+ schedule();
+ if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
+ cpu_die();
+
oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
if (!oldval) {
@@ -145,10 +148,6 @@ static int default_idle(void)
} else {
set_need_resched();
}
-
- schedule();
- if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
- cpu_die();
}
return 0;
--- linux/arch/i386/kernel/process.c.orig
+++ linux/arch/i386/kernel/process.c
@@ -181,6 +181,7 @@ void cpu_idle(void)
/* endless idle loop with no priority at all */
while (1) {
+ schedule();
while (!need_resched()) {
void (*idle)(void);
@@ -199,7 +200,6 @@ void cpu_idle(void)
__get_cpu_var(irq_stat).idle_timestamp = jiffies;
idle();
}
- schedule();
}
}
next reply other threads:[~2005-05-24 12:16 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-24 12:15 Ingo Molnar [this message]
2005-05-24 13:21 ` [patch] Voluntary Kernel Preemption, 2.6.12-rc4-mm2 Ingo Molnar
2005-05-24 14:56 ` Christoph Hellwig
2005-05-24 15:09 ` Ingo Molnar
2005-05-24 15:21 ` Nick Piggin
2005-05-24 15:33 ` Arjan van de Ven
2005-05-24 15:34 ` Nick Piggin
2005-05-24 15:39 ` Ingo Molnar
2005-05-24 15:59 ` Nick Piggin
2005-05-24 16:11 ` Ingo Molnar
2005-05-25 19:48 ` Christoph Hellwig
2005-05-24 14:06 ` [patch] remove set_tsk_need_resched() from init_idle() Ingo Molnar
2005-05-24 15:02 ` Nick Piggin
2005-05-24 15:05 ` Ingo Molnar
2005-05-24 15:24 ` Nick Piggin
2005-05-24 15:27 ` Ingo Molnar
2005-05-24 15:42 ` Ingo Molnar
2005-05-24 16:00 ` Nick Piggin
2005-05-25 12:24 ` Andrew Morton
2005-05-25 13:51 ` Ingo Molnar
2005-05-25 13:58 ` Ingo Molnar
2005-05-28 16:32 ` Russell King
2005-05-28 18:51 ` Ingo Molnar
2005-05-29 4:05 ` Nick Piggin
2005-05-29 6:01 ` Ingo Molnar
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=20050524121541.GA17049@elte.hu \
--to=mingo@elte.hu \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nickpiggin@yahoo.com.au \
/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