PATCH: Fix race in cpu_down (hotplug cpu)
Hmm... managed to miss a word at the end of the first para and thus not make sense. Let's try again.
----------
Hi.
There is a race condition in taking down a cpu (kernel/cpu.c::cpu_down). A cpu can already be idling when we clear its online flag, and we do not force the idle task to reschedule. This results in __cpu_die timing out. A simple fix is to force the idle task on the cpu going down to reschedule.
Without the patch below, Suspend2 get into a deadlock at resume time when this issue occurs. I could not complete 20 cycles without seeing the issue. With the patch below, I have completed 75 cycles on the trot without problems.
Please apply.
kernel/cpu.c +3 -0
@@ -126,6 +126,9 @@ int cpu_down(unsigned int cpu)while (!idle_cpu (cpu))yield (); +/* CPU may have idled before we set its offline flag. */ +set_tsk_need_resched (idle_task (cpu)); +/* This actually kills the CPU. */ __cpu_die (cpu);
Quoted 3 lines · Nigel Cunningham
There is a race condition in taking down a cpu (kernel/cpu.c::cpu_down). A cpu can already be idling when we clear its online flag, and we do not force the idle task to reschedule. This results in
__cpu_dietiming out.
"when we clear its online flag" - This happens in take_cpu_down in the context of stopmachine thread. take_cpu_down also ensures that idle thread runs when it returns (sched_idle_next). So when idle thread runs, it should notice that it is offline and invoke play_dead. So I don't understand why __cpu_die should time out.
Signature · 5 lines
Thanks and Regards, Srivatsa Vaddagiri, Linux Technology Center, IBM Software Labs, Bangalore, INDIA - 560017