]> git.hungrycats.org Git - linux/commitdiff
[PATCH] sched: cleanup init_idle()
authorNick Piggin <nickpiggin@yahoo.com.au>
Tue, 24 Aug 2004 04:06:56 +0000 (21:06 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Tue, 24 Aug 2004 04:06:56 +0000 (21:06 -0700)
Clean up init_idle to not use wake_up_forked_process, then undo all the stuff
that call does.  Instead, do everything in init_idle.

Make double_rq_lock depend on CONFIG_SMP because it is no longer used on UP.

Signed-off-by: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
13 files changed:
arch/alpha/kernel/smp.c
arch/i386/kernel/smpboot.c
arch/i386/mach-voyager/voyager_smp.c
arch/ia64/kernel/smpboot.c
arch/mips/kernel/smp.c
arch/parisc/kernel/smp.c
arch/ppc/kernel/smp.c
arch/ppc64/kernel/smp.c
arch/s390/kernel/smp.c
arch/sh/kernel/smp.c
arch/x86_64/kernel/smpboot.c
init/main.c
kernel/sched.c

index 3a4c9d6e214ec8c8970be865a813987108d17e34..dacacd4d5209892097a72350e96b906bcb4506f3 100644 (file)
@@ -439,8 +439,6 @@ smp_boot_one_cpu(int cpuid)
        if (IS_ERR(idle))
                panic("failed fork for CPU %d", cpuid);
 
-       wake_up_forked_process(idle);
-
        init_idle(idle, cpuid);
        unhash_process(idle);
 
index de91beb190ed7cb1d9a8a1630546bd6aa2343275..75e2533f2330ce79a11efc1c91dede682949dbd3 100644 (file)
@@ -804,16 +804,13 @@ static int __init do_boot_cpu(int apicid)
        idle = fork_by_hand();
        if (IS_ERR(idle))
                panic("failed fork for CPU %d", cpu);
-       wake_up_forked_process(idle);
 
-       /*
-        * We remove it from the pidhash and the runqueue
-        * once we got the process:
-        */
+       /* Make this the idle thread */
        init_idle(idle, cpu);
 
        idle->thread.eip = (unsigned long) start_secondary;
 
+       /* Remove it from the pidhash */
        unhash_process(idle);
 
        /* start_eip had better be page-aligned! */
index ad62185e38a2fadb5cdce0cc0ab1ea5f8a4870a4..11b5ce49ccce8c7a1a7f03978323555c3c53971f 100644 (file)
@@ -591,11 +591,12 @@ do_boot_cpu(__u8 cpu)
        if(IS_ERR(idle))
                panic("failed fork for CPU%d", cpu);
 
-       wake_up_forked_process(idle);
-
+       /* Make this the idle thread */
        init_idle(idle, cpu);
 
        idle->thread.eip = (unsigned long) start_secondary;
+
+       /* Remove it from the pidhash */
        unhash_process(idle);
        /* init_tasks (in sched.c) is indexed logically */
        stack_start.esp = (void *) idle->thread.esp;
index 9a0f7923311dc514a2128f41f4463e31c20e02c3..49234ebe6c2d2095ef602cad4ab2a096871103fb 100644 (file)
@@ -400,14 +400,11 @@ do_boot_cpu (int sapicid, int cpu)
 
        if (IS_ERR(c_idle.idle))
                panic("failed fork for CPU %d", cpu);
-       wake_up_forked_process(c_idle.idle);
 
-       /*
-        * We remove it from the pidhash and the runqueue
-        * once we got the process:
-        */
+       /* Make this the idle thread */
        init_idle(c_idle.idle, cpu);
 
+       /* Remove it from the pidhash */
        unhash_process(c_idle.idle);
 
        task_for_booting_cpu = c_idle.idle;
index 1f917fe93f054ecc0a943ae414325ccfe93359ab..a49288f83e36aa4511d74361f0ab759328aeae7a 100644 (file)
@@ -279,14 +279,10 @@ static int __init do_boot_cpu(int cpu)
        if (IS_ERR(idle))
                panic("failed fork for CPU %d\n", cpu);
 
-       wake_up_forked_process(idle);
-
-       /*
-        * We remove it from the pidhash and the runqueue once we've
-        * got the process:
-        */
+       /* Make this the idle thread */
        init_idle(idle, cpu);
 
+       /* Remove it from the pidhash */
        unhash_process(idle);
 
        prom_boot_secondary(cpu, idle);
index 0f1daa584c9ae36a64e0509e6664d5701c1aace2..7ede5b67e9be7cc4b0600276ea444579ac89208b 100644 (file)
@@ -525,7 +525,6 @@ int __init smp_boot_one_cpu(int cpuid)
        if (IS_ERR(idle))
                panic("SMP: fork failed for CPU:%d", cpuid);
 
-       wake_up_forked_process(idle);
        init_idle(idle, cpuid);
        unhash_process(idle);
        idle->thread_info->cpu = cpuid;
index c28fbf398391c73a871efef14d98f193f4a32c70..0057f95472dfd8cc95b3fbd5a070adfe0eba584d 100644 (file)
@@ -375,8 +375,6 @@ int __cpu_up(unsigned int cpu)
        p = copy_process(CLONE_VM|CLONE_IDLETASK, 0, &regs, 0, NULL, NULL);
        if (IS_ERR(p))
                panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
-       wake_up_forked_process(p);
-
        init_idle(p, cpu);
        unhash_process(p);
 
index b72e964c3a1227226f9e36afeded5b3b5578867e..467a4ccd14092f240463ab1f1d3a7dc709cde0b7 100644 (file)
@@ -811,7 +811,6 @@ static void __init smp_create_idle(unsigned int cpu)
        if (IS_ERR(p))
                panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
 
-       wake_up_forked_process(p);
        init_idle(p, cpu);
        unhash_process(p);
 
index eb8a5161ab99e5b63f7bf0c86441039e2f93212a..c70601ac3cf96b5cd517a735bf0a22a33bd5fb14 100644 (file)
@@ -574,9 +574,12 @@ static void __init smp_create_idle(unsigned int cpu)
        if (IS_ERR(p))
                panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
 
-       wake_up_forked_process(p);
+       /* Make this the idle thread */
        init_idle(p, cpu);
+
+       /* Remove it from the pidhash */
        unhash_process(p);
+
        current_set[cpu] = p;
 }
 
index adb8eae9f39ccd4afce2396bb176d907b9897d9b..05f009ce22de5eaaf2bb978a5c87728124148d3b 100644 (file)
@@ -106,8 +106,6 @@ int __cpu_up(unsigned int cpu)
        if (IS_ERR(tsk))
                panic("Failed forking idle task for cpu %d\n", cpu);
        
-       wake_up_forked_process(tsk);
-
        init_idle(tsk, cpu);
        unhash_process(tsk);
        
index af49e0ccd548305268fc81d79a6f30121b3bf351..0152e8941e0cbd48e8ed24a4e7f608666c6ec2a1 100644 (file)
@@ -578,15 +578,12 @@ static void __init do_boot_cpu (int apicid)
        idle = fork_by_hand();
        if (IS_ERR(idle))
                panic("failed fork for CPU %d", cpu);
-       wake_up_forked_process(idle);   
        x86_cpu_to_apicid[cpu] = apicid;
 
-       /*
-        * We remove it from the pidhash and the runqueue
-        * once we got the process:
-        */
+       /* Make this the idle thread */
        init_idle(idle,cpu);
 
+       /* Remove it from the pidhash */
        unhash_process(idle);
 
        cpu_pda[cpu].pcurrent = idle;
index 46fe75c96308f7d4b957fe7870c4df9fef2fcb1d..d1c2a7aa1924e4dc7c3f6c631a70c4c0c6273421 100644 (file)
@@ -472,6 +472,14 @@ asmlinkage void __init start_kernel(void)
         */
        sched_init();
 
+       /*
+        * Make us the idle thread. Technically, schedule() should not be
+        * called from this thread, however somewhere below it might be,
+        * but because we are the idle thread, we just pick up running again
+        * when this runqueue becomes "idle".
+        */
+       init_idle(current, smp_processor_id());
+
        build_all_zonelists();
        page_alloc_init();
        printk("Kernel command line: %s\n", saved_command_line);
@@ -538,13 +546,6 @@ asmlinkage void __init start_kernel(void)
 
        acpi_early_init(); /* before LAPIC and SMP init */
 
-       /* 
-        *      We count on the initial thread going ok 
-        *      Like idlers init is an unlocked kernel thread, which will
-        *      make syscalls (and thus be locked).
-        */
-       init_idle(current, smp_processor_id());
-
        /* Do the rest non-__init'ed, we're now alive */
        rest_init();
 }
index d588bae6f02b1f64d2a5e5a635a30be03deb5ca4..c58ae1c88052e9a8a26f06107241b9966b08436e 100644 (file)
@@ -1121,6 +1121,15 @@ unsigned long nr_iowait(void)
        return sum;
 }
 
+enum idle_type
+{
+       IDLE,
+       NOT_IDLE,
+       NEWLY_IDLE,
+};
+
+#ifdef CONFIG_SMP
+
 /*
  * double_rq_lock - safely lock two runqueues
  *
@@ -1155,14 +1164,20 @@ static void double_rq_unlock(runqueue_t *rq1, runqueue_t *rq2)
                spin_unlock(&rq2->lock);
 }
 
-enum idle_type
+/*
+ * double_lock_balance - lock the busiest runqueue, this_rq is locked already.
+ */
+static void double_lock_balance(runqueue_t *this_rq, runqueue_t *busiest)
 {
-       IDLE,
-       NOT_IDLE,
-       NEWLY_IDLE,
-};
-
-#ifdef CONFIG_SMP
+       if (unlikely(!spin_trylock(&busiest->lock))) {
+               if (busiest < this_rq) {
+                       spin_unlock(&this_rq->lock);
+                       spin_lock(&busiest->lock);
+                       spin_lock(&this_rq->lock);
+               } else
+                       spin_lock(&busiest->lock);
+       }
+}
 
 /*
  * find_idlest_cpu - find the least busy runqueue.
@@ -1357,21 +1372,6 @@ out:
        put_cpu();
 }
 
-/*
- * double_lock_balance - lock the busiest runqueue, this_rq is locked already.
- */
-static void double_lock_balance(runqueue_t *this_rq, runqueue_t *busiest)
-{
-       if (unlikely(!spin_trylock(&busiest->lock))) {
-               if (busiest < this_rq) {
-                       spin_unlock(&this_rq->lock);
-                       spin_lock(&busiest->lock);
-                       spin_lock(&this_rq->lock);
-               } else
-                       spin_lock(&busiest->lock);
-       }
-}
-
 /*
  * pull_task - move a task from a remote runqueue to the local runqueue.
  * Both runqueues must be locked.
@@ -2209,6 +2209,15 @@ need_resched:
        prev = current;
        rq = this_rq();
 
+       /*
+        * The idle thread is not allowed to schedule!
+        * Remove this check after it has been exercised a bit.
+        */
+       if (unlikely(current == rq->idle) && current->state != TASK_RUNNING) {
+               printk(KERN_ERR "bad: scheduling from the idle thread!\n");
+               dump_stack();
+       }
+
        release_kernel_lock(prev);
        now = sched_clock();
        if (likely(now - prev->timestamp < NS_MAX_SLEEP_AVG))
@@ -3268,21 +3277,20 @@ void show_state(void)
 
 void __devinit init_idle(task_t *idle, int cpu)
 {
-       runqueue_t *idle_rq = cpu_rq(cpu), *rq = cpu_rq(task_cpu(idle));
+       runqueue_t *rq = cpu_rq(cpu);
        unsigned long flags;
 
-       local_irq_save(flags);
-       double_rq_lock(idle_rq, rq);
-
-       idle_rq->curr = idle_rq->idle = idle;
-       deactivate_task(idle, rq);
+       idle->sleep_avg = 0;
+       idle->interactive_credit = 0;
        idle->array = NULL;
        idle->prio = MAX_PRIO;
        idle->state = TASK_RUNNING;
        set_task_cpu(idle, cpu);
-       double_rq_unlock(idle_rq, rq);
+
+       spin_lock_irqsave(&rq->lock, flags);
+       rq->curr = rq->idle = idle;
        set_tsk_need_resched(idle);
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&rq->lock, flags);
 
        /* Set the preempt count _outside_ the spinlocks! */
 #ifdef CONFIG_PREEMPT
@@ -3959,15 +3967,6 @@ void __init sched_init(void)
                        __set_bit(MAX_PRIO, array->bitmap);
                }
        }
-       /*
-        * We have to do a little magic to get the first
-        * thread right in SMP mode.
-        */
-       rq = this_rq();
-       rq->curr = current;
-       rq->idle = current;
-       set_task_cpu(current, smp_processor_id());
-       wake_up_forked_process(current);
 
        /*
         * The boot idle thread does lazy MMU switching as well: