idle thread preemption fix
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 27 lines · Linux Kernel Mailing List
ChangeSet 1.2316, 2005/01/08 13:53:41-08:00, [email protected]
[PATCH] idle thread preemption fix
The early bootup stage is pretty fragile because the idle thread is not yet functioning as such and so we need preemption disabled. Whether the bootup fails or not seems to depend on timing details so e.g. the presence of
SCHED_SMTmakes it go away.Disabling preemption explicitly has another advantage: the atomicity check in
schedule()will catch early-bootupschedule()calls from now on.The patch also fixes another preempt-bkl buglet: interrupt-driven forced-preemption didnt go through
preempt_schedule()so it resulted in auto-dropping of the BKL. Now we go throughpreempt_schedule()which properly deals with the BKL.Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>diff -Nru
a/init/main.cb/init/main.cinit/main.c +0
-0@@ -373,6 +373,12 @@ {kernel_thread (init,NULL ,CLONE_FS |CLONE_SIGHAND );
init/main.c line 384
Quoted 10 lines
init/main.c +6
-0numa_default_policy (); +/* +* Re-enable preemption but disable interrupts to make sure +* we dont get preempted until we schedule() in cpu_idle(). +*/ +local_irq_disable (); +preempt_enable_no_resched ();unlock_kernel ();cpu_idle (); }
Whats the purpose of local_irq_disable() here? Locks up my toys in atkbd_init or IP hash foo functions.
Quoted 2 lines · Olaf Hering
Whats the purpose of
local_irq_disable()here? Locks up my toys inatkbd_initor IP hash foo functions.
fix already posted a couple of days ago, see:
--
Quoted 4 lines · Benjamin Herrenschmidt
Hi Ingo !
Could you explain me precisely what is the race you are fixing by adding
local_irq_disable()torest_init()?
it can be bad for the idle task to hold the BKL and to have preemption enabled - in such a situation the scheduler will get confused if an interrupt triggers a forced preemption in that small window. But it's not necessary to keep IRQs disabled after the BKL has been dropped. In fact i think IRQ-disabling doesnt have to be done at all, the patch below ought to solve this scenario equally well, and should solve the PPC side-effects too.
Tested ontop of 2.6.11-rc2 on x86 PREEMPT+SMP and PREEMPT+!SMP (which IIRC were the config variants that triggered the original problem), on an SMP and on a UP system.
Ingo
init/main.c renamed from init/main.c.orig +2 -7
@@ -373,14 +373,9 @@ static void noinline rest_init(void) {kernel_thread (init,NULL ,CLONE_FS |CLONE_SIGHAND );numa_default_policy (); -/* -* Re-enable preemption but disable interrupts to make sure -* we dont get preempted until we schedule() in cpu_idle(). -*/ -local_irq_disable (); -preempt_enable_no_resched ();unlock_kernel (); -cpu_idle (); +preempt_enable_no_resched (); +cpu_idle (); }/* Check for early params. */