Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5bfb5d69 authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds
Browse files

[PATCH] sched: disable preempt in idle tasks



Run idle threads with preempt disabled.

Also corrected a bugs in arm26's cpu_idle (make it actually call schedule()).
How did it ever work before?

Might fix the CPU hotplugging hang which Nigel Cunningham noted.

We think the bug hits if the idle thread is preempted after checking
need_resched() and before going to sleep, then the CPU offlined.

After calling stop_machine_run, the CPU eventually returns from preemption and
into the idle thread and goes to sleep.  The CPU will continue executing
previous idle and have no chance to call play_dead.

By disabling preemption until we are ready to explicitly schedule, this bug is
fixed and the idle threads generally become more robust.

From: alexs <ashepard@u.washington.edu>

  PPC build fix

From: Yoichi Yuasa <yuasa@hh.iij4u.or.jp>

  MIPS build fix

Signed-off-by: default avatarNick Piggin <npiggin@suse.de>
Signed-off-by: default avatarYoichi Yuasa <yuasa@hh.iij4u.or.jp>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ede3d0fb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -116,13 +116,13 @@ void cpu_idle(void)

		if (!idle)
			idle = default_idle;
		preempt_disable();
		leds_event(led_idle_start);
		while (!need_resched())
			idle();
		leds_event(led_idle_end);
		preempt_enable();
		preempt_enable_no_resched();
		schedule();
		preempt_disable();
	}
}

+4 −1
Original line number Diff line number Diff line
@@ -256,7 +256,9 @@ void __cpuexit cpu_die(void)
asmlinkage void __cpuinit secondary_start_kernel(void)
{
	struct mm_struct *mm = &init_mm;
	unsigned int cpu = smp_processor_id();
	unsigned int cpu;

	cpu = smp_processor_id();

	printk("CPU%u: Booted secondary processor\n", cpu);

@@ -273,6 +275,7 @@ asmlinkage void __cpuinit secondary_start_kernel(void)
	local_flush_tlb_all();

	cpu_init();
	preempt_disable();

	/*
	 * Give the platform a chance to do its own initialisation.
+5 −7
Original line number Diff line number Diff line
@@ -74,15 +74,13 @@ __setup("hlt", hlt_setup);
void cpu_idle(void)
{
	/* endless idle loop with no priority at all */
	preempt_disable();
	while (1) {
		while (!need_resched()) {
			local_irq_disable();
			if (!need_resched() && !hlt_counter)
				local_irq_enable();
		}
	}
		while (!need_resched())
			cpu_relax();
		preempt_enable_no_resched();
		schedule();
		preempt_disable();
	}
}

static char reboot_mode = 'h';
+1 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ void __init smp_callin(void)
	REG_WR(intr_vect, irq_regs[cpu], rw_mask, vect_mask);
	unmask_irq(IPI_INTR_VECT);
	unmask_irq(TIMER_INTR_VECT);
	preempt_disable();
	local_irq_enable();

	cpu_set(cpu, cpu_online_map);
+2 −0
Original line number Diff line number Diff line
@@ -218,7 +218,9 @@ void cpu_idle (void)
				idle = default_idle;
			idle();
		}
		preempt_enable_no_resched();
		schedule();
		preempt_disable();
	}
}

Loading