Possible bug in context_swich()?
Dear List,
My previous mails to you have gone unheard... my last chance...
In context_switch() (in linux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.
In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
Thanks in advance.
fabio
Quoted 10 lines · fabio de francesco
Dear List,
My previous mails to you have gone unheard... my last chance...
In
context_switch()(inlinux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
Hi fabio,
The logic was changed in commit 710390d90f143a9ebb87a475215140f426792efd on the basis of a branch hint profiling run. It would guess previous logic was more likely to be correct, unless one is often scheduling between kernel threads, but maybe that happens more often than I expect.
I would suggest trying the branch tracer yourself if you think the current code is wrong for your workload, the config option is PROFILE_ANNOTATED_BRANCHES. I would suggest not profiling the boot process (which will have predominantly kernel threads) and not profiling on an idle system (which may also be relatively heavy on kernel threads).
Quoted 6 lines · fabio de francesco
In
context_switch()(inlinux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
It helps if you CC people, LKML alone is a bit of a gamble.
git blame kernel/sched.c, will tell you that the change you refer to comes from:
commit 710390d90f143a9ebb87a475215140f426792efd
Author: Tim Blechmann <[email protected]> Date: Tue Nov 24 11:55:27 2009 +0100
sched: Optimize branch hint in context_switch()
Branch hint profiling on my nehalem machine showed over 90% incorrect branch hints:
10420275 170645395 94 context_switch sched.c
3043
10408421 171098521 94 context_switch sched.c
3050
LKML-Reference: <[email protected]>
kernel/sched.c +2 -2
@@ -2829,14 +2829,14 @@ context_switch(struct rq *rq, struct task_struct *prev,*/ arch_start_context_switch (prev); -if (unlikely (!mm)) { +if (likely (!mm)) { next->active_mm = oldmm;atomic_inc (&oldmm->mm_count);enter_lazy_tlb (oldmm, next); }else switch_mm (oldmm, mm, next); -if (unlikely (!prev->mm)) { +if (likely (!prev->mm)) { prev->active_mm =NULL ; rq->prev_mm = oldmm; }
Quoted 14 lines · Peter Zijlstra
Quoted 6 lines · fabio de francesco
In
context_switch()(inlinux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
It helps if you CC people, LKML alone is a bit of a gamble.
git blame
kernel/sched.c, will tell you that the change you refer to comes from:
Quoted 8 lines
commit
710390d90f143a9ebb87a475215140f426792efdAuthor: Tim Blechmann <[email protected]> Date: Tue Nov 24 11:55:27 2009 +0100sched: Optimize branch hint in
context_switch()Branch hint profiling on my nehalem machine showed over 90% incorrect branch hints:
That change never made any sense to me, seems Tim must have been measuring a kthread load. I benched at the time, and saw absolutely zero difference one way or the other wrt max ctx rate on my Q6600.
-Mike
Quoted 19 lines · Mike Galbraith
Quoted 18 lines · Peter Zijlstra
Quoted 6 lines · fabio de francesco
In
context_switch()(inlinux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
It helps if you CC people, LKML alone is a bit of a gamble.
git blame
kernel/sched.c, will tell you that the change you refer to comes from:commit
710390d90f143a9ebb87a475215140f426792efdAuthor: Tim Blechmann <[email protected]> Date: Tue Nov 24 11:55:27 2009 +0100
Quoted 8 lines
Quoted 4 lines
sched: Optimize branch hint in
context_switch()Branch hint profiling on my nehalem machine showed over 90% incorrect branch hints:
That change never made any sense to me, seems Tim must have been measuring a kthread load. I benched at the time, and saw absolutely zero difference one way or the other wrt max ctx rate on my Q6600.
One option is to simply remove the whole branch hint.. But lets ask Tim what kind of workload he used..
Quoted 23 lines · Peter Zijlstra
Quoted 22 lines · Mike Galbraith
Quoted 20 lines · Peter Zijlstra
Quoted 6 lines · fabio de francesco
In
context_switch()(inlinux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
It helps if you CC people, LKML alone is a bit of a gamble.
git blame
kernel/sched.c, will tell you that the change you refer to comes from:commit
710390d90f143a9ebb87a475215140f426792efdAuthor: Tim Blechmann <[email protected]> Date: Tue Nov 24 11:55:27 2009 +0100sched: Optimize branch hint in
context_switch()Branch hint profiling on my nehalem machine showed over 90%
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
incorrect branch hints:
That change never made any sense to me, seems Tim must have been measuring a kthread load. I benched at the time, and saw absolutely zero difference one way or the other wrt max ctx rate on my Q6600.
One option is to simply remove the whole branch hint.. But lets ask Tim what kind of workload he used..
i was using a standard desktop workload, nothing special ...
Signature · 6 lines
[email protected] http://tim.klingt.org Wherever we are, what we hear is mostly noise. When we ignore it, it disturbs us. When we listen to it, we find it fascinating. John Cage
Quoted 25 lines · Tim Blechmann
Quoted 24 lines · Peter Zijlstra
Quoted 23 lines · Mike Galbraith
Quoted 22 lines · Peter Zijlstra
Quoted 6 lines · fabio de francesco
In
context_switch()(inlinux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
It helps if you CC people, LKML alone is a bit of a gamble.
git blame
kernel/sched.c, will tell you that the change you refer to comes from:commit
710390d90f143a9ebb87a475215140f426792efdAuthor: Tim Blechmann <[email protected]> Date: Tue Nov 24 11:55:27 2009 +0100sched: Optimize branch hint in
context_switch()Branch hint profiling on my nehalem machine showed over 90%
incorrect branch hints:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
That change never made any sense to me, seems Tim must have been measuring a kthread load. I benched at the time, and saw absolutely zero difference one way or the other wrt max ctx rate on my Q6600.
One option is to simply remove the whole branch hint.. But lets ask Tim what kind of workload he used..
i was using a standard desktop workload, nothing special ...
Just out of curiosity I tried this with two kernel builds on a six way machine with latest git head and got these numbers:
correct incorrect % Function File Line ------- --------- - -------- ---- ---- 644387 484258 42 context_switch sched.c 2851 677534 451199 39 context_switch sched.c 2858
So the hints seem to be rather pointless.
Quoted 26 lines · On Thursday 09 September 2010 13:12:18 Tim Blechmann wrote:
Quoted 25 lines · Peter Zijlstra
Quoted 24 lines · Mike Galbraith
Quoted 23 lines · Peter Zijlstra
Quoted 7 lines · fabio de francesco
In
context_switch()(inlinux/kernel/sched.c), starting with release 2.6.33, two "unlikely" macro have been changed to "likely". I think the previous logic was right while the latter is wrong.In case I am missing something I, please, ask someone to explain the above mentioned inversion of logic through releases.
It helps if you CC people, LKML alone is a bit of a gamble.
git blame
kernel/sched.c, will tell you that the change you refer to comes from:commit
710390d90f143a9ebb87a475215140f426792efdAuthor: Tim Blechmann <[email protected]> Date: Tue Nov 24 11:55:27 2009 +0100sched: Optimize branch hint in
context_switch()Branch hint profiling on my nehalem machine showed over 90%
incorrect branch hints:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
That change never made any sense to me, seems Tim must have been measuring a kthread load. I benched at the time, and saw absolutely zero difference one way or the other wrt max ctx rate on my Q6600.
One option is to simply remove the whole branch hint.. But lets ask Tim what kind of workload he used..
i was using a standard desktop workload, nothing special ...
There could have been just kernel threads ready to run... Could a server or workstation workload behave differently?
fabio