cpu: Remove incorrect BUG_ON
Commit-ID: 51a96c77815e7f139892a6e9c8275a50e9baebdf Gitweb: http://git.kernel.org/tip/51a96c77815e7f139892a6e9c8275a50e9baebdf Author: Peter Zijlstra <[email protected]> AuthorDate: Fri, 19 Nov 2010 20:37:53 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 Nov 2010 10:29:08 +0100
cpu: Remove incorrect BUG_ON
Oleg mentioned that there is no actual guarantee the dying cpu's migration thread is actually finished running when we get there, so replace the BUG_ON() with a spinloop waiting for it.
LKML-Reference: <new-submission>
--- kernel/cpu.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/cpu.c +4 -1
@@ -249,8 +249,11 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)* The migration_call() CPU_DYING callback will have removed all * runnable tasks from the cpu, there's only the idle task left now * that the migration thread is done doing the stop_machine thing. +* +* Wait for the stop thread to go away. */ -BUG_ON (!idle_cpu (cpu)); +while (!idle_cpu (cpu)) +cpu_relax ();/* This actually kills the CPU. */ __cpu_die (cpu);
kernel/cpu.c static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) · line 256
Quoted 13 lines · tip-bot for Peter Zijlstra
kernel/cpu.c +4
-1@@ -249,8 +249,11 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)* The migration_call() CPU_DYING callback will have removed all * runnable tasks from the cpu, there's only the idle task left now * that the migration thread is done doing the stop_machine thing. +* +* Wait for the stop thread to go away. */ -BUG_ON (!idle_cpu (cpu)); +while (!idle_cpu (cpu)) +cpu_relax ();
Yes... but I still can't understand why should we wait at all.
Peter, I am just curious, help ;)
Oleg.
Quoted 17 lines · Oleg Nesterov
kernel/cpu.c static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) · line 256
Quoted 13 lines · tip-bot for Peter Zijlstra
kernel/cpu.c +4
-1@@ -249,8 +249,11 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)* The migration_call() CPU_DYING callback will have removed all * runnable tasks from the cpu, there's only the idle task left now * that the migration thread is done doing the stop_machine thing. +* +* Wait for the stop thread to go away. */ -BUG_ON (!idle_cpu (cpu)); +while (!idle_cpu (cpu)) +cpu_relax ();Yes... but I still can't understand why should we wait at all.
Quoted 1 line
Peter, I am just curious, help ;)
Ah,. uhm,. you mean, not do anything at all?
Dunno, really, let me try and read the code there.
Quoted 4 lines · Peter Zijlstra
Ah,. uhm,. you mean, not do anything at all?
Dunno, really, let me try and read the code there.
Thanks. This is very minor of course, but it would be nice to undestand the reason. To me it looks unneeded, but I don't trust myself. (snippets from my previous email below).
With or without this change, even if we know that rq->idle is running we can't know if it (say) already started play_dead_common() or not.
We are going to call __cpu_die(), afaics it should do the necessary synchronization in any case.
For example, native_cpu_die() waits for cpu_state == CPU_DEAD in a loop. Of course it should work in practice (it also does msleep), but in theory there is no guarantee.
So. Can't we just remove this wait-loop? We know that rq->idle will be scheduled "soon", I don't understand why it is necessary to ensure that context_switch() has already happened.
Oleg.
Quoted 9 lines · Oleg Nesterov
Quoted 3 lines
Ah,. uhm,. you mean, not do anything at all?
Dunno, really, let me try and read the code there.
Thanks. This is very minor of course, but it would be nice to undestand the reason. To me it looks unneeded, but I don't trust myself. (snippets from my previous email below).
I think because the call to __cpu_die (-> native_cpu_die) relies on the remote cpu running the idle thread, and the CPU_DEAD notifier callback wants to run with the guarantee the remote cpu is in fact dead as a doornail.
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Oleg Nesterov
Quoted 2 lines
Ah,. uhm,. you mean, not do anything at all?
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Dunno, really, let me try and read the code there.
Thanks. This is very minor of course, but it would be nice to undestand the reason. To me it looks unneeded, but I don't trust myself. (snippets from my previous email below).
I think because the call to
__cpu_die(->native_cpu_die) relies on the remote cpu running the idle thread,
How? It can't. By the time __cpu_die() is called, we do not even know whether context_switch() was finished. All we know is that rq->curr = idle.
native_cpu_die() correctly waits in a loop until the idle thread sets CPU_DEAD.
And I think every smp_ops->cpu_die() implementation should synhcronize with ->cpu_disable(), otherwise it is buggy.
Quoted 3 lines
and the
CPU_DEADnotifier callback
wants to run with the guarantee the remote cpu is in fact dead as a doornail.
I think __cpu_die() should ensure it is dead.
OK. This is really minor. Perhaps it is safer to keep this wait just to preserve the current behaviour.
Oleg.