drivers/cpufreq/intel_pstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The comment above the condition `if (cpu->last_sample_time)` clearly
indicates that the branch is taken for the vast majority of invocations
after the first sample in a cycle. The first sample is a one-time
initialization case.
Add likely() hint to the condition to improve branch prediction for
this performance-critical path in intel_pstate_sample().
Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
---
drivers/cpufreq/intel_pstate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 2519eb527468..d540f2ab9a52 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -2531,7 +2531,7 @@ static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time)
* that sample.time will always be reset before setting the utilization
* update hook and make the caller skip the sample then.
*/
- if (cpu->last_sample_time) {
+ if (likely(cpu->last_sample_time)) {
intel_pstate_calc_avg_perf(cpu);
return true;
}
--
2.25.1
On Fri, Sep 12, 2025 at 9:35 AM Yaxiong Tian <tianyaxiong@kylinos.cn> wrote: > > The comment above the condition `if (cpu->last_sample_time)` clearly > indicates that the branch is taken for the vast majority of invocations > after the first sample in a cycle. The first sample is a one-time > initialization case. > > Add likely() hint to the condition to improve branch prediction for > this performance-critical path in intel_pstate_sample(). > > Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn> > --- > drivers/cpufreq/intel_pstate.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c > index 2519eb527468..d540f2ab9a52 100644 > --- a/drivers/cpufreq/intel_pstate.c > +++ b/drivers/cpufreq/intel_pstate.c > @@ -2531,7 +2531,7 @@ static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time) > * that sample.time will always be reset before setting the utilization > * update hook and make the caller skip the sample then. > */ > - if (cpu->last_sample_time) { > + if (likely(cpu->last_sample_time)) { > intel_pstate_calc_avg_perf(cpu); > return true; > } > -- Applied as 6.18 material, thanks!
© 2016 - 2025 Red Hat, Inc.