]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cpufreq: intel_pstate: Use likely() optimization in intel_pstate_sample()
authorYaxiong Tian <tianyaxiong@kylinos.cn>
Fri, 12 Sep 2025 07:35:02 +0000 (15:35 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 19 Sep 2025 21:21:01 +0000 (23:21 +0200)
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>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/intel_pstate.c

index 285051e4a5dd86d65afdf941d5caf0ab03ee01ed..05e440a6aa4a2527b6b7a81d21bf8a7543b34884 100644 (file)
@@ -2542,7 +2542,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;
        }