mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cpuidle: menu: Remove incorrect unlikely() annotation
@ 2026-01-05 14:37 Breno Leitao
  2026-01-05 15:17 ` Christian Loehle
  2026-01-09 20:54 ` Rafael J. Wysocki
  0 siblings, 2 replies; 4+ messages in thread
From: Breno Leitao @ 2026-01-05 14:37 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano
  Cc: linux-pm, linux-kernel, kernel-team, Breno Leitao

The unlikely() annotation on the early-return condition in menu_select()
is incorrect on systems with only one idle state (e.g., ARM64 servers
with a single ACPI LPI state). Branch profiling shows 100% misprediction
on such systems since drv->state_count <= 1 is always true.

On platforms where only state0 is available, this path is the common
case, not an unlikely edge case. Remove the misleading annotation to
let the branch predictor learn the actual behavior.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/cpuidle/governors/menu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 64d6f7a1c776..ef9c5a84643e 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -271,7 +271,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 		data->bucket = BUCKETS - 1;
 	}
 
-	if (unlikely(drv->state_count <= 1 || latency_req == 0) ||
+	if (drv->state_count <= 1 || latency_req == 0 ||
 	    ((data->next_timer_ns < drv->states[1].target_residency_ns ||
 	      latency_req < drv->states[1].exit_latency_ns) &&
 	     !dev->states_usage[0].disable)) {

---
base-commit: 34aa263125b6732375abcb908d73d98169154bb5
change-id: 20260105-annotated_idle-d6b614ecd207

Best regards,
--  
Breno Leitao <leitao@debian.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpuidle: menu: Remove incorrect unlikely() annotation
  2026-01-05 14:37 [PATCH] cpuidle: menu: Remove incorrect unlikely() annotation Breno Leitao
@ 2026-01-05 15:17 ` Christian Loehle
  2026-01-05 16:41   ` Breno Leitao
  2026-01-09 20:54 ` Rafael J. Wysocki
  1 sibling, 1 reply; 4+ messages in thread
From: Christian Loehle @ 2026-01-05 15:17 UTC (permalink / raw)
  To: Breno Leitao, Rafael J. Wysocki, Daniel Lezcano
  Cc: linux-pm, linux-kernel, kernel-team

On 1/5/26 14:37, Breno Leitao wrote:
> The unlikely() annotation on the early-return condition in menu_select()
> is incorrect on systems with only one idle state (e.g., ARM64 servers
> with a single ACPI LPI state). Branch profiling shows 100% misprediction
> on such systems since drv->state_count <= 1 is always true.
> 
> On platforms where only state0 is available, this path is the common
> case, not an unlikely edge case. Remove the misleading annotation to
> let the branch predictor learn the actual behavior.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  drivers/cpuidle/governors/menu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
> index 64d6f7a1c776..ef9c5a84643e 100644
> --- a/drivers/cpuidle/governors/menu.c
> +++ b/drivers/cpuidle/governors/menu.c
> @@ -271,7 +271,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
>  		data->bucket = BUCKETS - 1;
>  	}
>  
> -	if (unlikely(drv->state_count <= 1 || latency_req == 0) ||
> +	if (drv->state_count <= 1 || latency_req == 0 ||
>  	    ((data->next_timer_ns < drv->states[1].target_residency_ns ||
>  	      latency_req < drv->states[1].exit_latency_ns) &&
>  	     !dev->states_usage[0].disable)) {
> 
> ---
> base-commit: 34aa263125b6732375abcb908d73d98169154bb5
> change-id: 20260105-annotated_idle-d6b614ecd207
> 
> Best regards,
> --  
> Breno Leitao <leitao@debian.org>
> 
> 

Fine with me per se, I don't think the unlikely() annotation makes a
difference for the 'good case' either, but if you run into this I'd be curious
if you can see a difference with menu (which should stop the tick on every idle enter
regardless) and teo (which should never stop the tick on state_count == 1).
Alternative you can also just change the menu branch to not stop the tick.
I'd like to know if we need something more sophisticated generally here.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpuidle: menu: Remove incorrect unlikely() annotation
  2026-01-05 15:17 ` Christian Loehle
@ 2026-01-05 16:41   ` Breno Leitao
  0 siblings, 0 replies; 4+ messages in thread
From: Breno Leitao @ 2026-01-05 16:41 UTC (permalink / raw)
  To: Christian Loehle
  Cc: Rafael J. Wysocki, Daniel Lezcano, linux-pm, linux-kernel, kernel-team

On Mon, Jan 05, 2026 at 03:17:05PM +0000, Christian Loehle wrote:
> On 1/5/26 14:37, Breno Leitao wrote:
> > The unlikely() annotation on the early-return condition in menu_select()
> > is incorrect on systems with only one idle state (e.g., ARM64 servers
> > with a single ACPI LPI state). Branch profiling shows 100% misprediction
> > on such systems since drv->state_count <= 1 is always true.
> > 
> > On platforms where only state0 is available, this path is the common
> > case, not an unlikely edge case. Remove the misleading annotation to
> > let the branch predictor learn the actual behavior.
> > 
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> > ---
> >  drivers/cpuidle/governors/menu.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
> > index 64d6f7a1c776..ef9c5a84643e 100644
> > --- a/drivers/cpuidle/governors/menu.c
> > +++ b/drivers/cpuidle/governors/menu.c
> > @@ -271,7 +271,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
> >  		data->bucket = BUCKETS - 1;
> >  	}
> >  
> > -	if (unlikely(drv->state_count <= 1 || latency_req == 0) ||
> > +	if (drv->state_count <= 1 || latency_req == 0 ||
> >  	    ((data->next_timer_ns < drv->states[1].target_residency_ns ||
> >  	      latency_req < drv->states[1].exit_latency_ns) &&
> >  	     !dev->states_usage[0].disable)) {
> > 
> > ---
> > base-commit: 34aa263125b6732375abcb908d73d98169154bb5
> > change-id: 20260105-annotated_idle-d6b614ecd207
> > 
> > Best regards,
> > --  
> > Breno Leitao <leitao@debian.org>
> > 
> > 
> 
> Fine with me per se, I don't think the unlikely() annotation makes a
> difference for the 'good case' either, but if you run into this I'd be curious
> if you can see a difference with menu (which should stop the tick on every idle enter
> regardless) and teo (which should never stop the tick on state_count == 1).
> Alternative you can also just change the menu branch to not stop the tick.
> I'd like to know if we need something more sophisticated generally here.

Probably not. I am just running PROFILE_ANNOTATED_BRANCHES tests on some
production arm64 host and addressing those that are making wrong
assumptions.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpuidle: menu: Remove incorrect unlikely() annotation
  2026-01-05 14:37 [PATCH] cpuidle: menu: Remove incorrect unlikely() annotation Breno Leitao
  2026-01-05 15:17 ` Christian Loehle
@ 2026-01-09 20:54 ` Rafael J. Wysocki
  1 sibling, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2026-01-09 20:54 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Rafael J. Wysocki, Daniel Lezcano, linux-pm, linux-kernel, kernel-team

On Mon, Jan 5, 2026 at 3:38 PM Breno Leitao <leitao@debian.org> wrote:
>
> The unlikely() annotation on the early-return condition in menu_select()
> is incorrect on systems with only one idle state (e.g., ARM64 servers
> with a single ACPI LPI state). Branch profiling shows 100% misprediction
> on such systems since drv->state_count <= 1 is always true.
>
> On platforms where only state0 is available, this path is the common
> case, not an unlikely edge case. Remove the misleading annotation to
> let the branch predictor learn the actual behavior.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  drivers/cpuidle/governors/menu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
> index 64d6f7a1c776..ef9c5a84643e 100644
> --- a/drivers/cpuidle/governors/menu.c
> +++ b/drivers/cpuidle/governors/menu.c
> @@ -271,7 +271,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
>                 data->bucket = BUCKETS - 1;
>         }
>
> -       if (unlikely(drv->state_count <= 1 || latency_req == 0) ||
> +       if (drv->state_count <= 1 || latency_req == 0 ||
>             ((data->next_timer_ns < drv->states[1].target_residency_ns ||
>               latency_req < drv->states[1].exit_latency_ns) &&
>              !dev->states_usage[0].disable)) {
>
> ---

Applied as 6.20 material, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-09 20:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 14:37 [PATCH] cpuidle: menu: Remove incorrect unlikely() annotation Breno Leitao
2026-01-05 15:17 ` Christian Loehle
2026-01-05 16:41   ` Breno Leitao
2026-01-09 20:54 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®