Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'pm-cpufreq-x86', 'pm-cpufreq-docs' and 'intel_pstate'

* pm-cpufreq-x86:
cpufreq: x86: Make scaling_cur_freq behave more as expected

* pm-cpufreq-docs:
cpufreq: docs: Add missing cpuinfo_cur_freq description

* intel_pstate:
cpufreq: intel_pstate: Drop ->get from intel_pstate structure

+34 -22
+8
Documentation/admin-guide/pm/cpufreq.rst
··· 237 237 This attribute is not present if the scaling driver in use does not 238 238 support it. 239 239 240 + ``cpuinfo_cur_freq`` 241 + Current frequency of the CPUs belonging to this policy as obtained from 242 + the hardware (in KHz). 243 + 244 + This is expected to be the frequency the hardware actually runs at. 245 + If that frequency cannot be determined, this attribute should not 246 + be present. 247 + 240 248 ``cpuinfo_max_freq`` 241 249 Maximum possible operating frequency the CPUs belonging to this policy 242 250 can run at (in kHz).
+26 -14
arch/x86/kernel/cpu/aperfmperf.c
··· 8 8 * This file is licensed under GPLv2. 9 9 */ 10 10 11 - #include <linux/jiffies.h> 11 + #include <linux/delay.h> 12 + #include <linux/ktime.h> 12 13 #include <linux/math64.h> 13 14 #include <linux/percpu.h> 14 15 #include <linux/smp.h> 15 16 16 17 struct aperfmperf_sample { 17 18 unsigned int khz; 18 - unsigned long jiffies; 19 + ktime_t time; 19 20 u64 aperf; 20 21 u64 mperf; 21 22 }; 22 23 23 24 static DEFINE_PER_CPU(struct aperfmperf_sample, samples); 25 + 26 + #define APERFMPERF_CACHE_THRESHOLD_MS 10 27 + #define APERFMPERF_REFRESH_DELAY_MS 20 28 + #define APERFMPERF_STALE_THRESHOLD_MS 1000 24 29 25 30 /* 26 31 * aperfmperf_snapshot_khz() ··· 38 33 u64 aperf, aperf_delta; 39 34 u64 mperf, mperf_delta; 40 35 struct aperfmperf_sample *s = this_cpu_ptr(&samples); 36 + ktime_t now = ktime_get(); 37 + s64 time_delta = ktime_ms_delta(now, s->time); 41 38 42 - /* Don't bother re-computing within 10 ms */ 43 - if (time_before(jiffies, s->jiffies + HZ/100)) 39 + /* Don't bother re-computing within the cache threshold time. */ 40 + if (time_delta < APERFMPERF_CACHE_THRESHOLD_MS) 44 41 return; 45 42 46 43 rdmsrl(MSR_IA32_APERF, aperf); ··· 58 51 if (mperf_delta == 0) 59 52 return; 60 53 61 - /* 62 - * if (cpu_khz * aperf_delta) fits into ULLONG_MAX, then 63 - * khz = (cpu_khz * aperf_delta) / mperf_delta 64 - */ 65 - if (div64_u64(ULLONG_MAX, cpu_khz) > aperf_delta) 66 - s->khz = div64_u64((cpu_khz * aperf_delta), mperf_delta); 67 - else /* khz = aperf_delta / (mperf_delta / cpu_khz) */ 68 - s->khz = div64_u64(aperf_delta, 69 - div64_u64(mperf_delta, cpu_khz)); 70 - s->jiffies = jiffies; 54 + s->time = now; 71 55 s->aperf = aperf; 72 56 s->mperf = mperf; 57 + 58 + /* If the previous iteration was too long ago, discard it. */ 59 + if (time_delta > APERFMPERF_STALE_THRESHOLD_MS) 60 + s->khz = 0; 61 + else 62 + s->khz = div64_u64((cpu_khz * aperf_delta), mperf_delta); 73 63 } 74 64 75 65 unsigned int arch_freq_get_on_cpu(int cpu) 76 66 { 67 + unsigned int khz; 68 + 77 69 if (!cpu_khz) 78 70 return 0; 79 71 80 72 if (!static_cpu_has(X86_FEATURE_APERFMPERF)) 81 73 return 0; 82 74 75 + smp_call_function_single(cpu, aperfmperf_snapshot_khz, NULL, 1); 76 + khz = per_cpu(samples.khz, cpu); 77 + if (khz) 78 + return khz; 79 + 80 + msleep(APERFMPERF_REFRESH_DELAY_MS); 83 81 smp_call_function_single(cpu, aperfmperf_snapshot_khz, NULL, 1); 84 82 85 83 return per_cpu(samples.khz, cpu);
-8
drivers/cpufreq/intel_pstate.c
··· 1922 1922 return 0; 1923 1923 } 1924 1924 1925 - static unsigned int intel_pstate_get(unsigned int cpu_num) 1926 - { 1927 - struct cpudata *cpu = all_cpu_data[cpu_num]; 1928 - 1929 - return cpu ? get_avg_frequency(cpu) : 0; 1930 - } 1931 - 1932 1925 static void intel_pstate_set_update_util_hook(unsigned int cpu_num) 1933 1926 { 1934 1927 struct cpudata *cpu = all_cpu_data[cpu_num]; ··· 2162 2169 .setpolicy = intel_pstate_set_policy, 2163 2170 .suspend = intel_pstate_hwp_save_state, 2164 2171 .resume = intel_pstate_resume, 2165 - .get = intel_pstate_get, 2166 2172 .init = intel_pstate_cpu_init, 2167 2173 .exit = intel_pstate_cpu_exit, 2168 2174 .stop_cpu = intel_pstate_stop_cpu,