Lines Matching full:cpu

20 #include <linux/cpu.h>
95 * to account for cpu idle period
131 * Stores the per cpu model P state limits and current P state.
188 * struct cpudata - Per CPU instance data storage
189 * @cpu: CPU number for this instance data
195 * @pstate: Stores P state limits for this CPU
196 * @vid: Stores VID limits for this CPU
219 * @sched_flags: Store scheduler flags for possible cross CPU update
223 * This structure stores per CPU instance data for all CPUs.
226 int cpu; member
265 * struct pstate_funcs - Per CPU model specific callbacks
271 * @get_cpu_scaling: Get frequency scaling factor for a given cpu
276 * Core and Atom CPU models have different way to get P State limits. This
285 int (*get_cpu_scaling)(int cpu);
330 /* The work item is needed to avoid CPU hotplug locking issues */
338 static void intel_pstate_set_itmt_prio(int cpu) in intel_pstate_set_itmt_prio() argument
344 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_set_itmt_prio()
353 sched_set_itmt_core_prio(cppc_perf.highest_perf, cpu); in intel_pstate_set_itmt_prio()
364 * This code can be run during CPU online under the in intel_pstate_set_itmt_prio()
365 * CPU hotplug locks, so sched_set_itmt_support() in intel_pstate_set_itmt_prio()
374 static int intel_pstate_get_cppc_guaranteed(int cpu) in intel_pstate_get_cppc_guaranteed() argument
379 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_get_cppc_guaranteed()
389 static u32 intel_pstate_cppc_nominal(int cpu) in intel_pstate_cppc_nominal() argument
393 if (cppc_get_nominal_perf(cpu, &nominal_perf)) in intel_pstate_cppc_nominal()
399 static inline void intel_pstate_set_itmt_prio(int cpu) in intel_pstate_set_itmt_prio() argument
406 struct cpudata *cpu; in intel_pstate_init_acpi_perf_limits() local
411 intel_pstate_set_itmt_prio(policy->cpu); in intel_pstate_init_acpi_perf_limits()
418 cpu = all_cpu_data[policy->cpu]; in intel_pstate_init_acpi_perf_limits()
420 ret = acpi_processor_register_performance(&cpu->acpi_perf_data, in intel_pstate_init_acpi_perf_limits()
421 policy->cpu); in intel_pstate_init_acpi_perf_limits()
430 if (cpu->acpi_perf_data.control_register.space_id != in intel_pstate_init_acpi_perf_limits()
438 if (cpu->acpi_perf_data.state_count < 2) in intel_pstate_init_acpi_perf_limits()
441 pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu); in intel_pstate_init_acpi_perf_limits()
442 for (i = 0; i < cpu->acpi_perf_data.state_count; i++) { in intel_pstate_init_acpi_perf_limits()
444 (i == cpu->acpi_perf_data.state ? '*' : ' '), i, in intel_pstate_init_acpi_perf_limits()
445 (u32) cpu->acpi_perf_data.states[i].core_frequency, in intel_pstate_init_acpi_perf_limits()
446 (u32) cpu->acpi_perf_data.states[i].power, in intel_pstate_init_acpi_perf_limits()
447 (u32) cpu->acpi_perf_data.states[i].control); in intel_pstate_init_acpi_perf_limits()
462 cpu->acpi_perf_data.states[0].core_frequency = in intel_pstate_init_acpi_perf_limits()
464 cpu->valid_pss_table = true; in intel_pstate_init_acpi_perf_limits()
470 cpu->valid_pss_table = false; in intel_pstate_init_acpi_perf_limits()
471 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_init_acpi_perf_limits()
476 struct cpudata *cpu; in intel_pstate_exit_perf_limits() local
478 cpu = all_cpu_data[policy->cpu]; in intel_pstate_exit_perf_limits()
479 if (!cpu->valid_pss_table) in intel_pstate_exit_perf_limits()
482 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_exit_perf_limits()
500 static inline int intel_pstate_get_cppc_guaranteed(int cpu) in intel_pstate_get_cppc_guaranteed() argument
508 * @cpu: Target CPU.
512 * scaling factor between HWP performance levels and CPU frequency will be less
513 * than the scaling factor between P-state values and CPU frequency.
515 * In that case, adjust the CPU parameters used in computations accordingly.
517 static void intel_pstate_hybrid_hwp_adjust(struct cpudata *cpu) in intel_pstate_hybrid_hwp_adjust() argument
519 int perf_ctl_max_phys = cpu->pstate.max_pstate_physical; in intel_pstate_hybrid_hwp_adjust()
520 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_hybrid_hwp_adjust()
523 int scaling = cpu->pstate.scaling; in intel_pstate_hybrid_hwp_adjust()
525 pr_debug("CPU%d: perf_ctl_max_phys = %d\n", cpu->cpu, perf_ctl_max_phys); in intel_pstate_hybrid_hwp_adjust()
526 pr_debug("CPU%d: perf_ctl_max = %d\n", cpu->cpu, pstate_funcs.get_max()); in intel_pstate_hybrid_hwp_adjust()
527 pr_debug("CPU%d: perf_ctl_turbo = %d\n", cpu->cpu, perf_ctl_turbo); in intel_pstate_hybrid_hwp_adjust()
528 pr_debug("CPU%d: perf_ctl_scaling = %d\n", cpu->cpu, perf_ctl_scaling); in intel_pstate_hybrid_hwp_adjust()
529 pr_debug("CPU%d: HWP_CAP guaranteed = %d\n", cpu->cpu, cpu->pstate.max_pstate); in intel_pstate_hybrid_hwp_adjust()
530 pr_debug("CPU%d: HWP_CAP highest = %d\n", cpu->cpu, cpu->pstate.turbo_pstate); in intel_pstate_hybrid_hwp_adjust()
531 pr_debug("CPU%d: HWP-to-frequency scaling factor: %d\n", cpu->cpu, scaling); in intel_pstate_hybrid_hwp_adjust()
540 if (turbo_freq < cpu->pstate.turbo_pstate * scaling) { in intel_pstate_hybrid_hwp_adjust()
541 cpu->pstate.turbo_freq = turbo_freq; in intel_pstate_hybrid_hwp_adjust()
542 scaling = DIV_ROUND_UP(turbo_freq, cpu->pstate.turbo_pstate); in intel_pstate_hybrid_hwp_adjust()
543 cpu->pstate.scaling = scaling; in intel_pstate_hybrid_hwp_adjust()
545 pr_debug("CPU%d: refined HWP-to-frequency scaling factor: %d\n", in intel_pstate_hybrid_hwp_adjust()
546 cpu->cpu, scaling); in intel_pstate_hybrid_hwp_adjust()
549 cpu->pstate.max_freq = rounddown(cpu->pstate.max_pstate * scaling, in intel_pstate_hybrid_hwp_adjust()
552 cpu->pstate.max_pstate_physical = in intel_pstate_hybrid_hwp_adjust()
556 cpu->pstate.min_freq = cpu->pstate.min_pstate * perf_ctl_scaling; in intel_pstate_hybrid_hwp_adjust()
561 cpu->pstate.min_pstate = DIV_ROUND_UP(cpu->pstate.min_freq, scaling); in intel_pstate_hybrid_hwp_adjust()
567 struct cpudata *cpu; in update_turbo_state() local
569 cpu = all_cpu_data[0]; in update_turbo_state()
573 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); in update_turbo_state()
578 struct cpudata *cpu = all_cpu_data[0]; in min_perf_pct_min() local
579 int turbo_pstate = cpu->pstate.turbo_pstate; in min_perf_pct_min()
582 (cpu->pstate.min_pstate * 100 / turbo_pstate) : 0; in min_perf_pct_min()
593 ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_get_epb()
610 epp = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, in intel_pstate_get_epp()
624 static int intel_pstate_set_epb(int cpu, s16 pref) in intel_pstate_set_epb() argument
632 ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_set_epb()
637 wrmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, epb); in intel_pstate_set_epb()
706 static int intel_pstate_set_epp(struct cpudata *cpu, u32 epp) in intel_pstate_set_epp() argument
715 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_set_epp()
724 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_set_epp()
725 ret = wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_set_epp()
727 cpu->epp_cached = epp; in intel_pstate_set_epp()
760 ret = intel_pstate_set_epb(cpu_data->cpu, epp); in intel_pstate_set_energy_pref_index()
787 struct cpudata *cpu = all_cpu_data[policy->cpu]; in store_energy_performance_preference() local
823 ret = intel_pstate_set_energy_pref_index(cpu, ret, raw, epp); in store_energy_performance_preference()
827 * target CPU before the EPP update and restarted after it, in store_energy_performance_preference()
832 epp = ret ? epp_values[ret - 1] : cpu->epp_default; in store_energy_performance_preference()
834 if (cpu->epp_cached != epp) { in store_energy_performance_preference()
838 ret = intel_pstate_set_epp(cpu, epp); in store_energy_performance_preference()
853 struct cpudata *cpu_data = all_cpu_data[policy->cpu]; in show_energy_performance_preference()
870 struct cpudata *cpu = all_cpu_data[policy->cpu]; in show_base_frequency() local
873 ratio = intel_pstate_get_cppc_guaranteed(policy->cpu); in show_base_frequency()
877 rdmsrl_on_cpu(policy->cpu, MSR_HWP_CAPABILITIES, &cap); in show_base_frequency()
881 freq = ratio * cpu->pstate.scaling; in show_base_frequency()
882 if (cpu->pstate.scaling != cpu->pstate.perf_ctl_scaling) in show_base_frequency()
883 freq = rounddown(freq, cpu->pstate.perf_ctl_scaling); in show_base_frequency()
897 static void __intel_pstate_get_hwp_cap(struct cpudata *cpu) in __intel_pstate_get_hwp_cap() argument
901 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_CAPABILITIES, &cap); in __intel_pstate_get_hwp_cap()
902 WRITE_ONCE(cpu->hwp_cap_cached, cap); in __intel_pstate_get_hwp_cap()
903 cpu->pstate.max_pstate = HWP_GUARANTEED_PERF(cap); in __intel_pstate_get_hwp_cap()
904 cpu->pstate.turbo_pstate = HWP_HIGHEST_PERF(cap); in __intel_pstate_get_hwp_cap()
907 static void intel_pstate_get_hwp_cap(struct cpudata *cpu) in intel_pstate_get_hwp_cap() argument
909 int scaling = cpu->pstate.scaling; in intel_pstate_get_hwp_cap()
911 __intel_pstate_get_hwp_cap(cpu); in intel_pstate_get_hwp_cap()
913 cpu->pstate.max_freq = cpu->pstate.max_pstate * scaling; in intel_pstate_get_hwp_cap()
914 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * scaling; in intel_pstate_get_hwp_cap()
915 if (scaling != cpu->pstate.perf_ctl_scaling) { in intel_pstate_get_hwp_cap()
916 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_get_hwp_cap()
918 cpu->pstate.max_freq = rounddown(cpu->pstate.max_freq, in intel_pstate_get_hwp_cap()
920 cpu->pstate.turbo_freq = rounddown(cpu->pstate.turbo_freq, in intel_pstate_get_hwp_cap()
925 static void intel_pstate_hwp_set(unsigned int cpu) in intel_pstate_hwp_set() argument
927 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_hwp_set()
938 rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value); in intel_pstate_hwp_set()
981 intel_pstate_set_epb(cpu, epp); in intel_pstate_hwp_set()
985 wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_set()
988 static void intel_pstate_hwp_offline(struct cpudata *cpu) in intel_pstate_hwp_offline() argument
990 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_offline()
1000 value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached); in intel_pstate_hwp_offline()
1001 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_hwp_offline()
1005 min_perf = HWP_LOWEST_PERF(READ_ONCE(cpu->hwp_cap_cached)); in intel_pstate_hwp_offline()
1015 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_offline()
1042 static void intel_pstate_hwp_reenable(struct cpudata *cpu) in intel_pstate_hwp_reenable() argument
1044 intel_pstate_hwp_enable(cpu); in intel_pstate_hwp_reenable()
1045 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, READ_ONCE(cpu->hwp_req_cached)); in intel_pstate_hwp_reenable()
1050 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_suspend() local
1052 pr_debug("CPU %d suspending\n", cpu->cpu); in intel_pstate_suspend()
1054 cpu->suspended = true; in intel_pstate_suspend()
1061 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_resume() local
1063 pr_debug("CPU %d resuming\n", cpu->cpu); in intel_pstate_resume()
1071 if (cpu->suspended && hwp_active) { in intel_pstate_resume()
1075 intel_pstate_hwp_reenable(cpu); in intel_pstate_resume()
1080 cpu->suspended = false; in intel_pstate_resume()
1087 int cpu; in intel_pstate_update_policies() local
1089 for_each_possible_cpu(cpu) in intel_pstate_update_policies()
1090 cpufreq_update_policy(cpu); in intel_pstate_update_policies()
1093 static void intel_pstate_update_max_freq(unsigned int cpu) in intel_pstate_update_max_freq() argument
1095 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); in intel_pstate_update_max_freq()
1101 cpudata = all_cpu_data[cpu]; in intel_pstate_update_max_freq()
1110 static void intel_pstate_update_limits(unsigned int cpu) in intel_pstate_update_limits() argument
1122 for_each_possible_cpu(cpu) in intel_pstate_update_limits()
1123 intel_pstate_update_max_freq(cpu); in intel_pstate_update_limits()
1125 cpufreq_update_policy(cpu); in intel_pstate_update_limits()
1170 struct cpudata *cpu; in show_turbo_pct() local
1181 cpu = all_cpu_data[0]; in show_turbo_pct()
1183 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1184 no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1196 struct cpudata *cpu; in show_num_pstates() local
1206 cpu = all_cpu_data[0]; in show_num_pstates()
1207 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_num_pstates()
1267 struct cpudata *cpu = all_cpu_data[0]; in store_no_turbo() local
1268 int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate; in store_no_turbo()
1291 struct cpudata *cpu = all_cpu_data[i]; in update_qos_request() local
1305 intel_pstate_get_hwp_cap(cpu); in update_qos_request()
1314 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * perf_pct, 100); in update_qos_request()
1317 pr_warn("Failed to update freq constraint: CPU%d\n", i); in update_qos_request()
1487 * If per cpu limits are enforced there are no global limits, so in intel_pstate_sysfs_expose_params()
1553 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00); in intel_pstate_hwp_enable()
1555 wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1); in intel_pstate_hwp_enable()
1788 static int hybrid_get_cpu_scaling(int cpu) in hybrid_get_cpu_scaling() argument
1791 intel_pstate_cppc_nominal(cpu)); in hybrid_get_cpu_scaling()
1797 int cpu; in intel_pstate_cppc_set_cpu_scaling() local
1799 for_each_present_cpu(cpu) { in intel_pstate_cppc_set_cpu_scaling()
1800 u32 nominal_perf = intel_pstate_cppc_nominal(cpu); in intel_pstate_cppc_set_cpu_scaling()
1817 static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) in intel_pstate_set_pstate() argument
1819 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_set_pstate()
1820 cpu->pstate.current_pstate = pstate; in intel_pstate_set_pstate()
1823 * the CPU being updated, so force the register update to run on the in intel_pstate_set_pstate()
1824 * right CPU. in intel_pstate_set_pstate()
1826 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_pstate_set_pstate()
1827 pstate_funcs.get_val(cpu, pstate)); in intel_pstate_set_pstate()
1830 static void intel_pstate_set_min_pstate(struct cpudata *cpu) in intel_pstate_set_min_pstate() argument
1832 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); in intel_pstate_set_min_pstate()
1835 static void intel_pstate_max_within_limits(struct cpudata *cpu) in intel_pstate_max_within_limits() argument
1837 int pstate = max(cpu->pstate.min_pstate, cpu->max_perf_ratio); in intel_pstate_max_within_limits()
1840 intel_pstate_set_pstate(cpu, pstate); in intel_pstate_max_within_limits()
1843 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) in intel_pstate_get_cpu_pstates() argument
1848 cpu->pstate.min_pstate = pstate_funcs.get_min(); in intel_pstate_get_cpu_pstates()
1849 cpu->pstate.max_pstate_physical = perf_ctl_max_phys; in intel_pstate_get_cpu_pstates()
1850 cpu->pstate.perf_ctl_scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1853 __intel_pstate_get_hwp_cap(cpu); in intel_pstate_get_cpu_pstates()
1856 cpu->pstate.scaling = pstate_funcs.get_cpu_scaling(cpu->cpu); in intel_pstate_get_cpu_pstates()
1857 if (cpu->pstate.scaling != perf_ctl_scaling) in intel_pstate_get_cpu_pstates()
1858 intel_pstate_hybrid_hwp_adjust(cpu); in intel_pstate_get_cpu_pstates()
1860 cpu->pstate.scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1863 cpu->pstate.scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1864 cpu->pstate.max_pstate = pstate_funcs.get_max(); in intel_pstate_get_cpu_pstates()
1865 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(); in intel_pstate_get_cpu_pstates()
1868 if (cpu->pstate.scaling == perf_ctl_scaling) { in intel_pstate_get_cpu_pstates()
1869 cpu->pstate.min_freq = cpu->pstate.min_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1870 cpu->pstate.max_freq = cpu->pstate.max_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1871 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1875 cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift(); in intel_pstate_get_cpu_pstates()
1878 pstate_funcs.get_vid(cpu); in intel_pstate_get_cpu_pstates()
1880 intel_pstate_set_min_pstate(cpu); in intel_pstate_get_cpu_pstates()
1891 static inline void intel_pstate_hwp_boost_up(struct cpudata *cpu) in intel_pstate_hwp_boost_up() argument
1893 u64 hwp_req = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_boost_up()
1894 u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); in intel_pstate_hwp_boost_up()
1914 if (max_limit == min_limit || cpu->hwp_boost_min >= max_limit) in intel_pstate_hwp_boost_up()
1917 if (!cpu->hwp_boost_min) in intel_pstate_hwp_boost_up()
1918 cpu->hwp_boost_min = min_limit; in intel_pstate_hwp_boost_up()
1923 if (cpu->hwp_boost_min < boost_level1) in intel_pstate_hwp_boost_up()
1924 cpu->hwp_boost_min = boost_level1; in intel_pstate_hwp_boost_up()
1925 else if (cpu->hwp_boost_min < HWP_GUARANTEED_PERF(hwp_cap)) in intel_pstate_hwp_boost_up()
1926 cpu->hwp_boost_min = HWP_GUARANTEED_PERF(hwp_cap); in intel_pstate_hwp_boost_up()
1927 else if (cpu->hwp_boost_min == HWP_GUARANTEED_PERF(hwp_cap) && in intel_pstate_hwp_boost_up()
1929 cpu->hwp_boost_min = max_limit; in intel_pstate_hwp_boost_up()
1933 hwp_req = (hwp_req & ~GENMASK_ULL(7, 0)) | cpu->hwp_boost_min; in intel_pstate_hwp_boost_up()
1935 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_up()
1938 static inline void intel_pstate_hwp_boost_down(struct cpudata *cpu) in intel_pstate_hwp_boost_down() argument
1940 if (cpu->hwp_boost_min) { in intel_pstate_hwp_boost_down()
1944 expired = time_after64(cpu->sample.time, cpu->last_update + in intel_pstate_hwp_boost_down()
1947 wrmsrl(MSR_HWP_REQUEST, cpu->hwp_req_cached); in intel_pstate_hwp_boost_down()
1948 cpu->hwp_boost_min = 0; in intel_pstate_hwp_boost_down()
1951 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_down()
1954 static inline void intel_pstate_update_util_hwp_local(struct cpudata *cpu, in intel_pstate_update_util_hwp_local() argument
1957 cpu->sample.time = time; in intel_pstate_update_util_hwp_local()
1959 if (cpu->sched_flags & SCHED_CPUFREQ_IOWAIT) { in intel_pstate_update_util_hwp_local()
1962 cpu->sched_flags = 0; in intel_pstate_update_util_hwp_local()
1966 * some IO bound activity is scheduled on this CPU with just in intel_pstate_update_util_hwp_local()
1970 if (time_before64(time, cpu->last_io_update + 2 * TICK_NSEC)) in intel_pstate_update_util_hwp_local()
1973 cpu->last_io_update = time; in intel_pstate_update_util_hwp_local()
1976 intel_pstate_hwp_boost_up(cpu); in intel_pstate_update_util_hwp_local()
1979 intel_pstate_hwp_boost_down(cpu); in intel_pstate_update_util_hwp_local()
1986 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util_hwp() local
1988 cpu->sched_flags |= flags; in intel_pstate_update_util_hwp()
1990 if (smp_processor_id() == cpu->cpu) in intel_pstate_update_util_hwp()
1991 intel_pstate_update_util_hwp_local(cpu, time); in intel_pstate_update_util_hwp()
1994 static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu) in intel_pstate_calc_avg_perf() argument
1996 struct sample *sample = &cpu->sample; in intel_pstate_calc_avg_perf()
2001 static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time) in intel_pstate_sample() argument
2011 if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) { in intel_pstate_sample()
2017 cpu->last_sample_time = cpu->sample.time; in intel_pstate_sample()
2018 cpu->sample.time = time; in intel_pstate_sample()
2019 cpu->sample.aperf = aperf; in intel_pstate_sample()
2020 cpu->sample.mperf = mperf; in intel_pstate_sample()
2021 cpu->sample.tsc = tsc; in intel_pstate_sample()
2022 cpu->sample.aperf -= cpu->prev_aperf; in intel_pstate_sample()
2023 cpu->sample.mperf -= cpu->prev_mperf; in intel_pstate_sample()
2024 cpu->sample.tsc -= cpu->prev_tsc; in intel_pstate_sample()
2026 cpu->prev_aperf = aperf; in intel_pstate_sample()
2027 cpu->prev_mperf = mperf; in intel_pstate_sample()
2028 cpu->prev_tsc = tsc; in intel_pstate_sample()
2036 if (cpu->last_sample_time) { in intel_pstate_sample()
2037 intel_pstate_calc_avg_perf(cpu); in intel_pstate_sample()
2043 static inline int32_t get_avg_frequency(struct cpudata *cpu) in get_avg_frequency() argument
2045 return mul_ext_fp(cpu->sample.core_avg_perf, cpu_khz); in get_avg_frequency()
2048 static inline int32_t get_avg_pstate(struct cpudata *cpu) in get_avg_pstate() argument
2050 return mul_ext_fp(cpu->pstate.max_pstate_physical, in get_avg_pstate()
2051 cpu->sample.core_avg_perf); in get_avg_pstate()
2054 static inline int32_t get_target_pstate(struct cpudata *cpu) in get_target_pstate() argument
2056 struct sample *sample = &cpu->sample; in get_target_pstate()
2060 busy_frac = div_fp(sample->mperf << cpu->aperf_mperf_shift, in get_target_pstate()
2063 if (busy_frac < cpu->iowait_boost) in get_target_pstate()
2064 busy_frac = cpu->iowait_boost; in get_target_pstate()
2069 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in get_target_pstate()
2072 if (target < cpu->pstate.min_pstate) in get_target_pstate()
2073 target = cpu->pstate.min_pstate; in get_target_pstate()
2079 * loss related to moving the workload from one CPU to another within in get_target_pstate()
2082 avg_pstate = get_avg_pstate(cpu); in get_target_pstate()
2089 static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) in intel_pstate_prepare_request() argument
2091 int min_pstate = max(cpu->pstate.min_pstate, cpu->min_perf_ratio); in intel_pstate_prepare_request()
2092 int max_pstate = max(min_pstate, cpu->max_perf_ratio); in intel_pstate_prepare_request()
2097 static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) in intel_pstate_update_pstate() argument
2099 if (pstate == cpu->pstate.current_pstate) in intel_pstate_update_pstate()
2102 cpu->pstate.current_pstate = pstate; in intel_pstate_update_pstate()
2103 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate)); in intel_pstate_update_pstate()
2106 static void intel_pstate_adjust_pstate(struct cpudata *cpu) in intel_pstate_adjust_pstate() argument
2108 int from = cpu->pstate.current_pstate; in intel_pstate_adjust_pstate()
2114 target_pstate = get_target_pstate(cpu); in intel_pstate_adjust_pstate()
2115 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_pstate_adjust_pstate()
2116 trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_adjust_pstate()
2117 intel_pstate_update_pstate(cpu, target_pstate); in intel_pstate_adjust_pstate()
2119 sample = &cpu->sample; in intel_pstate_adjust_pstate()
2123 cpu->pstate.current_pstate, in intel_pstate_adjust_pstate()
2127 get_avg_frequency(cpu), in intel_pstate_adjust_pstate()
2128 fp_toint(cpu->iowait_boost * 100)); in intel_pstate_adjust_pstate()
2134 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util() local
2138 if (smp_processor_id() != cpu->cpu) in intel_pstate_update_util()
2141 delta_ns = time - cpu->last_update; in intel_pstate_update_util()
2143 /* Start over if the CPU may have been idle. */ in intel_pstate_update_util()
2145 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2146 } else if (cpu->iowait_boost >= ONE_EIGHTH_FP) { in intel_pstate_update_util()
2147 cpu->iowait_boost <<= 1; in intel_pstate_update_util()
2148 if (cpu->iowait_boost > int_tofp(1)) in intel_pstate_update_util()
2149 cpu->iowait_boost = int_tofp(1); in intel_pstate_update_util()
2151 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2153 } else if (cpu->iowait_boost) { in intel_pstate_update_util()
2154 /* Clear iowait_boost if the CPU may have been idle. */ in intel_pstate_update_util()
2156 cpu->iowait_boost = 0; in intel_pstate_update_util()
2158 cpu->iowait_boost >>= 1; in intel_pstate_update_util()
2160 cpu->last_update = time; in intel_pstate_update_util()
2161 delta_ns = time - cpu->sample.time; in intel_pstate_update_util()
2165 if (intel_pstate_sample(cpu, time)) in intel_pstate_update_util()
2166 intel_pstate_adjust_pstate(cpu); in intel_pstate_update_util()
2260 struct cpudata *cpu; in intel_pstate_init_cpu() local
2262 cpu = all_cpu_data[cpunum]; in intel_pstate_init_cpu()
2264 if (!cpu) { in intel_pstate_init_cpu()
2265 cpu = kzalloc(sizeof(*cpu), GFP_KERNEL); in intel_pstate_init_cpu()
2266 if (!cpu) in intel_pstate_init_cpu()
2269 all_cpu_data[cpunum] = cpu; in intel_pstate_init_cpu()
2271 cpu->cpu = cpunum; in intel_pstate_init_cpu()
2273 cpu->epp_default = -EINVAL; in intel_pstate_init_cpu()
2278 intel_pstate_hwp_enable(cpu); in intel_pstate_init_cpu()
2287 * S3 if the CPU was offline during the whole system/resume in intel_pstate_init_cpu()
2290 intel_pstate_hwp_reenable(cpu); in intel_pstate_init_cpu()
2293 cpu->epp_powersave = -EINVAL; in intel_pstate_init_cpu()
2294 cpu->epp_policy = 0; in intel_pstate_init_cpu()
2296 intel_pstate_get_cpu_pstates(cpu); in intel_pstate_init_cpu()
2298 pr_debug("controlling: cpu %d\n", cpunum); in intel_pstate_init_cpu()
2305 struct cpudata *cpu = all_cpu_data[cpu_num]; in intel_pstate_set_update_util_hook() local
2310 if (cpu->update_util_set) in intel_pstate_set_update_util_hook()
2314 cpu->sample.time = 0; in intel_pstate_set_update_util_hook()
2315 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, in intel_pstate_set_update_util_hook()
2319 cpu->update_util_set = true; in intel_pstate_set_update_util_hook()
2322 static void intel_pstate_clear_update_util_hook(unsigned int cpu) in intel_pstate_clear_update_util_hook() argument
2324 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_clear_update_util_hook()
2329 cpufreq_remove_update_util_hook(cpu); in intel_pstate_clear_update_util_hook()
2334 static int intel_pstate_get_max_freq(struct cpudata *cpu) in intel_pstate_get_max_freq() argument
2337 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_get_max_freq()
2340 static void intel_pstate_update_perf_limits(struct cpudata *cpu, in intel_pstate_update_perf_limits() argument
2344 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_update_perf_limits()
2361 intel_pstate_get_hwp_cap(cpu); in intel_pstate_update_perf_limits()
2363 if (cpu->pstate.scaling != perf_ctl_scaling) { in intel_pstate_update_perf_limits()
2364 int scaling = cpu->pstate.scaling; in intel_pstate_update_perf_limits()
2374 pr_debug("cpu:%d min_policy_perf:%d max_policy_perf:%d\n", in intel_pstate_update_perf_limits()
2375 cpu->cpu, min_policy_perf, max_policy_perf); in intel_pstate_update_perf_limits()
2379 cpu->min_perf_ratio = min_policy_perf; in intel_pstate_update_perf_limits()
2380 cpu->max_perf_ratio = max_policy_perf; in intel_pstate_update_perf_limits()
2382 int turbo_max = cpu->pstate.turbo_pstate; in intel_pstate_update_perf_limits()
2390 pr_debug("cpu:%d global_min:%d global_max:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2393 cpu->min_perf_ratio = max(min_policy_perf, global_min); in intel_pstate_update_perf_limits()
2394 cpu->min_perf_ratio = min(cpu->min_perf_ratio, max_policy_perf); in intel_pstate_update_perf_limits()
2395 cpu->max_perf_ratio = min(max_policy_perf, global_max); in intel_pstate_update_perf_limits()
2396 cpu->max_perf_ratio = max(min_policy_perf, cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2399 cpu->min_perf_ratio = min(cpu->min_perf_ratio, in intel_pstate_update_perf_limits()
2400 cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2403 pr_debug("cpu:%d max_perf_ratio:%d min_perf_ratio:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2404 cpu->max_perf_ratio, in intel_pstate_update_perf_limits()
2405 cpu->min_perf_ratio); in intel_pstate_update_perf_limits()
2410 struct cpudata *cpu; in intel_pstate_set_policy() local
2418 cpu = all_cpu_data[policy->cpu]; in intel_pstate_set_policy()
2419 cpu->policy = policy->policy; in intel_pstate_set_policy()
2423 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_pstate_set_policy()
2425 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { in intel_pstate_set_policy()
2430 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2431 intel_pstate_max_within_limits(cpu); in intel_pstate_set_policy()
2433 intel_pstate_set_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2443 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2444 intel_pstate_hwp_set(policy->cpu); in intel_pstate_set_policy()
2452 static void intel_pstate_adjust_policy_max(struct cpudata *cpu, in intel_pstate_adjust_policy_max() argument
2456 cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && in intel_pstate_adjust_policy_max()
2458 policy->max > cpu->pstate.max_freq) { in intel_pstate_adjust_policy_max()
2464 static void intel_pstate_verify_cpu_policy(struct cpudata *cpu, in intel_pstate_verify_cpu_policy() argument
2471 intel_pstate_get_hwp_cap(cpu); in intel_pstate_verify_cpu_policy()
2473 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_verify_cpu_policy()
2475 max_freq = intel_pstate_get_max_freq(cpu); in intel_pstate_verify_cpu_policy()
2479 intel_pstate_adjust_policy_max(cpu, policy); in intel_pstate_verify_cpu_policy()
2484 intel_pstate_verify_cpu_policy(all_cpu_data[policy->cpu], policy); in intel_pstate_verify_policy()
2491 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_offline() local
2493 pr_debug("CPU %d going offline\n", cpu->cpu); in intel_cpufreq_cpu_offline()
2495 if (cpu->suspended) in intel_cpufreq_cpu_offline()
2499 * If the CPU is an SMT thread and it goes offline with the performance in intel_cpufreq_cpu_offline()
2502 * performance on CPU offline to prevent that from happening. in intel_cpufreq_cpu_offline()
2505 intel_pstate_hwp_offline(cpu); in intel_cpufreq_cpu_offline()
2507 intel_pstate_set_min_pstate(cpu); in intel_cpufreq_cpu_offline()
2516 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_online() local
2518 pr_debug("CPU %d going online\n", cpu->cpu); in intel_pstate_cpu_online()
2527 intel_pstate_hwp_reenable(cpu); in intel_pstate_cpu_online()
2528 cpu->suspended = false; in intel_pstate_cpu_online()
2536 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_cpu_offline()
2543 pr_debug("CPU %d exiting\n", policy->cpu); in intel_pstate_cpu_exit()
2552 struct cpudata *cpu; in __intel_pstate_cpu_init() local
2555 rc = intel_pstate_init_cpu(policy->cpu); in __intel_pstate_cpu_init()
2559 cpu = all_cpu_data[policy->cpu]; in __intel_pstate_cpu_init()
2561 cpu->max_perf_ratio = 0xFF; in __intel_pstate_cpu_init()
2562 cpu->min_perf_ratio = 0; in __intel_pstate_cpu_init()
2565 policy->cpuinfo.min_freq = cpu->pstate.min_freq; in __intel_pstate_cpu_init()
2569 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in __intel_pstate_cpu_init()
2595 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_init() local
2597 cpu->epp_cached = intel_pstate_get_epp(cpu, 0); in intel_pstate_cpu_init()
2619 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_verify_policy() local
2621 intel_pstate_verify_cpu_policy(cpu, policy); in intel_cpufreq_verify_policy()
2622 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_cpufreq_verify_policy()
2643 static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, int old_pstate) in intel_cpufreq_trace() argument
2650 if (!intel_pstate_sample(cpu, ktime_get())) in intel_cpufreq_trace()
2653 sample = &cpu->sample; in intel_cpufreq_trace()
2657 cpu->pstate.current_pstate, in intel_cpufreq_trace()
2661 get_avg_frequency(cpu), in intel_cpufreq_trace()
2662 fp_toint(cpu->iowait_boost * 100)); in intel_cpufreq_trace()
2665 static void intel_cpufreq_hwp_update(struct cpudata *cpu, u32 min, u32 max, in intel_cpufreq_hwp_update() argument
2668 u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev; in intel_cpufreq_hwp_update()
2682 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_hwp_update()
2686 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_cpufreq_hwp_update()
2689 static void intel_cpufreq_perf_ctl_update(struct cpudata *cpu, in intel_cpufreq_perf_ctl_update() argument
2694 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_perf_ctl_update()
2696 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_cpufreq_perf_ctl_update()
2697 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_perf_ctl_update()
2703 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_update_pstate() local
2704 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_update_pstate()
2706 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_cpufreq_update_pstate()
2709 target_pstate : cpu->max_perf_ratio; in intel_cpufreq_update_pstate()
2711 intel_cpufreq_hwp_update(cpu, target_pstate, max_pstate, 0, in intel_cpufreq_update_pstate()
2714 intel_cpufreq_perf_ctl_update(cpu, target_pstate, fast_switch); in intel_cpufreq_update_pstate()
2717 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2719 intel_cpufreq_trace(cpu, fast_switch ? INTEL_PSTATE_TRACE_FAST_SWITCH : in intel_cpufreq_update_pstate()
2729 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_target() local
2742 target_pstate = DIV_ROUND_UP(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2745 target_pstate = freqs.new / cpu->pstate.scaling; in intel_cpufreq_target()
2748 target_pstate = DIV_ROUND_CLOSEST(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2754 freqs.new = target_pstate * cpu->pstate.scaling; in intel_cpufreq_target()
2764 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_fast_switch() local
2769 target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); in intel_cpufreq_fast_switch()
2773 return target_pstate * cpu->pstate.scaling; in intel_cpufreq_fast_switch()
2781 struct cpudata *cpu = all_cpu_data[cpunum]; in intel_cpufreq_adjust_perf() local
2782 u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); in intel_cpufreq_adjust_perf()
2783 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_adjust_perf()
2800 if (min_pstate < cpu->pstate.min_pstate) in intel_cpufreq_adjust_perf()
2801 min_pstate = cpu->pstate.min_pstate; in intel_cpufreq_adjust_perf()
2803 if (min_pstate < cpu->min_perf_ratio) in intel_cpufreq_adjust_perf()
2804 min_pstate = cpu->min_perf_ratio; in intel_cpufreq_adjust_perf()
2806 max_pstate = min(cap_pstate, cpu->max_perf_ratio); in intel_cpufreq_adjust_perf()
2812 intel_cpufreq_hwp_update(cpu, min_pstate, max_pstate, target_pstate, true); in intel_cpufreq_adjust_perf()
2814 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_adjust_perf()
2815 intel_cpufreq_trace(cpu, INTEL_PSTATE_TRACE_FAST_SWITCH, old_pstate); in intel_cpufreq_adjust_perf()
2821 struct cpudata *cpu; in intel_cpufreq_cpu_init() local
2825 dev = get_cpu_device(policy->cpu); in intel_cpufreq_cpu_init()
2843 cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_init()
2850 intel_pstate_get_hwp_cap(cpu); in intel_cpufreq_cpu_init()
2852 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, &value); in intel_cpufreq_cpu_init()
2853 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_cpu_init()
2855 cpu->epp_cached = intel_pstate_get_epp(cpu, value); in intel_cpufreq_cpu_init()
2860 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * global.min_perf_pct, 100); in intel_cpufreq_cpu_init()
2869 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * global.max_perf_pct, 100); in intel_cpufreq_cpu_init()
2924 unsigned int cpu; in intel_pstate_driver_cleanup() local
2927 for_each_online_cpu(cpu) { in intel_pstate_driver_cleanup()
2928 if (all_cpu_data[cpu]) { in intel_pstate_driver_cleanup()
2930 intel_pstate_clear_update_util_hook(cpu); in intel_pstate_driver_cleanup()
2932 kfree(all_cpu_data[cpu]); in intel_pstate_driver_cleanup()
2933 all_cpu_data[cpu] = NULL; in intel_pstate_driver_cleanup()
3248 pr_info("CPU model not supported\n"); in intel_pstate_init()