From: Arjan van de Ven Another patch from the Ingo series; it detects attempts to schedule() before the scheduler is initialized. This is done by having a 2nd BOOTING stage inbetween SYSTEM_BOOTIMG and SYSTEM_RUNNING. An additional future step (not included here) can then be to check this state in might_sleep(), however even without tht this check is useful for finding this hard-to-debug case otherwise. Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton --- 25-akpm/include/linux/kernel.h | 1 + 25-akpm/init/main.c | 1 + 25-akpm/kernel/sched.c | 1 + 3 files changed, 3 insertions(+) diff -puN include/linux/kernel.h~detect-too-early-schedule-attempts include/linux/kernel.h --- 25/include/linux/kernel.h~detect-too-early-schedule-attempts 2004-07-12 21:40:20.247095608 -0700 +++ 25-akpm/include/linux/kernel.h 2004-07-12 21:40:20.254094544 -0700 @@ -134,6 +134,7 @@ extern const char *print_tainted(void); /* Values used for system_state */ extern enum system_states { SYSTEM_BOOTING, + SYSTEM_BOOTING_SCHEDULER_OK, SYSTEM_RUNNING, SYSTEM_HALT, SYSTEM_POWER_OFF, diff -puN init/main.c~detect-too-early-schedule-attempts init/main.c --- 25/init/main.c~detect-too-early-schedule-attempts 2004-07-12 21:40:20.249095304 -0700 +++ 25-akpm/init/main.c 2004-07-12 21:40:20.255094392 -0700 @@ -399,6 +399,7 @@ static void noinline rest_init(void) { kernel_thread(init, NULL, CLONE_FS | CLONE_SIGHAND); numa_default_policy(); + system_state = SYSTEM_BOOTING_SCHEDULER_OK; unlock_kernel(); cpu_idle(); } diff -puN kernel/sched.c~detect-too-early-schedule-attempts kernel/sched.c --- 25/kernel/sched.c~detect-too-early-schedule-attempts 2004-07-12 21:40:20.251095000 -0700 +++ 25-akpm/kernel/sched.c 2004-07-12 21:40:20.258093936 -0700 @@ -2150,6 +2150,7 @@ asmlinkage void __sched schedule(void) unsigned long run_time; int cpu, idx; + WARN_ON(system_state == SYSTEM_BOOTING); /* * Test if we are atomic. Since do_exit() needs to call into * schedule() atomically, we ignore that path for now. _