cpuidle: powernv: Don't bounce between low and very low thread priority
Subsystems (2)
PATCH 1/3 cpuidle: powernv: Don't bounce between low and very low thread priority
From: Anton Blanchard <[email protected]>
The core of snooze_loop() continually bounces between low and very low thread priority. Changing thread priorities is an expensive operation that can negatively impact other threads on a core.
All CPUs that can run PowerNV support very low priority, so we can avoid the change completely.
--- drivers/cpuidle/cpuidle-powernv.c | 1 - 1 file changed, 1 deletion(-)
drivers/cpuidle/cpuidle-powernv.c +0 -1
@@ -57,7 +57,6 @@ static int snooze_loop(struct cpuidle_device *dev, snooze_exit_time =get_tb () + snooze_timeout;ppc64_runlatch_off ();while (!need_resched ()) { -HMT_low ();HMT_very_low ();if (snooze_timeout_en &&get_tb () > snooze_exit_time)break ;
Signature · 1 line
2.11.0
PATCH 2/3 cpuidle: powernv: Don't continually set thread priority in snooze_loop()
From: Anton Blanchard <[email protected]>
The powerpc64 kernel exception handlers have preserved thread priorities for a long time now, so there is no need to continually set it.
Just set it once on entry and once exit.
--- drivers/cpuidle/cpuidle-powernv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpuidle/cpuidle-powernv.c +1 -1
@@ -56,8 +56,8 @@ static int snooze_loop(struct cpuidle_device *dev, snooze_exit_time =get_tb () + snooze_timeout;ppc64_runlatch_off (); +HMT_very_low ();while (!need_resched ()) { -HMT_very_low ();if (snooze_timeout_en &&get_tb () > snooze_exit_time)break ; }
Signature · 1 line
2.11.0
Re: [PATCH 2/3] cpuidle: powernv: Don't continually set thread priority in snooze_loop()
Quoted 8 lines · Anton Blanchard
From: Anton Blanchard <[email protected]>
The powerpc64 kernel exception handlers have preserved thread priorities for a long time now, so there is no need to continually set it.
Just set it once on entry and once exit.
Signed-off-by Anton Blanchard <[email protected]>
Quoted 21 lines
--- drivers/cpuidle/cpuidle-powernv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpuidle/cpuidle-powernv.c +1
-1@@ -56,8 +56,8 @@ static int snooze_loop(struct cpuidle_device *dev, snooze_exit_time =get_tb () + snooze_timeout;ppc64_runlatch_off (); +HMT_very_low ();while (!need_resched ()) { -HMT_very_low ();if (snooze_timeout_en &&get_tb () > snooze_exit_time)break ; }Signature · 1 line
2.11.0
PATCH 3/3 cpuidle: powernv: Avoid a branch in the core snooze_loop() loop
In reply to Anton BlanchardFrom: Anton Blanchard <[email protected]>
When in the snooze_loop() we want to take up the least amount of resources. On my version of gcc (6.3), we end up with an extra branch because it predicts snooze_timeout_en to be false, whereas it is almost always true.
Use likely() to avoid the branch and be a little nicer to the other non idle threads on the core.
--- drivers/cpuidle/cpuidle-powernv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpuidle/cpuidle-powernv.c +1 -1
@@ -58,7 +58,7 @@ static int snooze_loop(struct cpuidle_device *dev,ppc64_runlatch_off ();HMT_very_low ();while (!need_resched ()) { -if (snooze_timeout_en &&get_tb () > snooze_exit_time) +if (likely (snooze_timeout_en) &&get_tb () > snooze_exit_time)break ; }
Signature · 1 line
2.11.0
Nicholas Piggin
reviewerRe: [PATCH 3/3] cpuidle: powernv: Avoid a branch in the core snooze_loop() loop
Quoted 9 lines · On Tue, 4 Apr 2017 07:54:14 +1000 Anton Blanchard <[email protected]> wrote:
From: Anton Blanchard <[email protected]>
When in the
snooze_loop()we want to take up the least amount of resources. On my version of gcc (6.3), we end up with an extra branch because it predictssnooze_timeout_ento be false, whereas it is almost always true.Use
likely()to avoid the branch and be a little nicer to the other non idle threads on the core.
Patches 2 and 3 look fine. Should they be replicated to cpuidle-pseries.c as well?
Thanks,
Nick
Quoted 19 lines
Signed-off-by Anton Blanchard <[email protected]>--- drivers/cpuidle/cpuidle-powernv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpuidle/cpuidle-powernv.c +1
-1@@ -58,7 +58,7 @@ static int snooze_loop(struct cpuidle_device *dev,ppc64_runlatch_off ();HMT_very_low ();while (!need_resched ()) { -if (snooze_timeout_en &&get_tb () > snooze_exit_time) +if (likely (snooze_timeout_en) &&get_tb () > snooze_exit_time)break ; }
Re: [PATCH 3/3] cpuidle: powernv: Avoid a branch in the core snooze_loop() loop
In reply to Anton BlanchardQuoted 6 lines · Anton Blanchard
From: Anton Blanchard <[email protected]>
When in the
snooze_loop()we want to take up the least amount of resources. On my version of gcc (6.3), we end up with an extra branch because it predictssnooze_timeout_ento be false, whereas it is almost always true.
By default snooze_timeout_en is true. It will become false only when we do not want to exit the snooze loop and that will be when snooze is the only idle state available in the platform, which is a rare case.
Quoted 4 lines
Use
likely()to avoid the branch and be a little nicer to the other non idle threads on the core.Signed-off-by Anton Blanchard <[email protected]>
Quoted 20 lines
--- drivers/cpuidle/cpuidle-powernv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpuidle/cpuidle-powernv.c +1
-1@@ -58,7 +58,7 @@ static int snooze_loop(struct cpuidle_device *dev,ppc64_runlatch_off ();HMT_very_low ();while (!need_resched ()) { -if (snooze_timeout_en &&get_tb () > snooze_exit_time) +if (likely (snooze_timeout_en) &&get_tb () > snooze_exit_time)break ; }Signature · 1 line
2.11.0
Nicholas Piggin
reviewerQuoted 8 lines · On Tue, 4 Apr 2017 07:54:12 +1000 Anton Blanchard <[email protected]> wrote:
From: Anton Blanchard <[email protected]>
The core of
snooze_loop()continually bounces between low and very low thread priority. Changing thread priorities is an expensive operation that can negatively impact other threads on a core.All CPUs that can run PowerNV support very low priority, so we can avoid the change completely.
This looks good. I have HMT_lowest() which does alt feature patching we can use for pseries and default idle code.
Quoted 9 lines · Nicholas Piggin
Quoted 6 lines · On Tue, 4 Apr 2017 07:54:12 +1000 Anton Blanchard <[email protected]> wrote:
From: Anton Blanchard <[email protected]>
The core of
snooze_loop()continually bounces between low and very low thread priority. Changing thread priorities is an expensive operation that can negatively impact other threads on a core.
Quoted 5 lines
Quoted 2 lines
All CPUs that can run PowerNV support very low priority, so we can avoid the change completely.
This looks good. I have
HMT_lowest()which does alt feature patching we can use for pseries and default idle code.
Alternatively, if we are going to set priority only once in various other places, HMT_low(); HMT_very_low(); should not add to extra cycles. Let me code that up.
--Vaidy
Quoted 10 lines · Anton Blanchard
From: Anton Blanchard <[email protected]>
The core of
snooze_loop()continually bounces between low and very low thread priority. Changing thread priorities is an expensive operation that can negatively impact other threads on a core.All CPUs that can run PowerNV support very low priority, so we can avoid the change completely.
Signed-off-by Anton Blanchard <[email protected]>
Quoted 9 lines
--- drivers/cpuidle/cpuidle-powernv.c | 1 - 1 file changed, 1 deletion(-)drivers/cpuidle/cpuidle-powernv.c +0
-0
drivers/cpuidle/cpuidle-powernv.c static int snooze_loop(struct cpuidle_device *dev, · line 62
Quoted 7 lines
drivers/cpuidle/cpuidle-powernv.c +0
-1@@ -57,7 +57,6 @@ static int snooze_loop(struct cpuidle_device *dev, snooze_exit_time =get_tb () + snooze_timeout;ppc64_runlatch_off ();while (!need_resched ()) { -HMT_low ();HMT_very_low ();if (snooze_timeout_en &&get_tb () > snooze_exit_time)break ;
HMT_low() is legacy and can be removed for powernv platforms.
--Vaidy