
From: Arjan van de Ven <arjanv@redhat.com>

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: Andrew Morton <akpm@osdl.org>
---

 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	Wed Jul  7 14:12:46 2004
+++ 25-akpm/include/linux/kernel.h	Wed Jul  7 14:12:46 2004
@@ -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	Wed Jul  7 14:12:46 2004
+++ 25-akpm/init/main.c	Wed Jul  7 14:12:46 2004
@@ -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	Wed Jul  7 14:12:46 2004
+++ 25-akpm/kernel/sched.c	Wed Jul  7 14:12:46 2004
@@ -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.
_
