Lines Matching full:cpu
20 #include <linux/cpu.h>
105 * to account for cpu idle period
140 * Stores the per cpu model P state limits and current P state.
195 * struct cpudata - Per CPU instance data storage
196 * @cpu: CPU number for this instance data
202 * @pstate: Stores P state limits for this CPU
203 * @vid: Stores VID limits for this CPU
226 * @sched_flags: Store scheduler flags for possible cross CPU update
230 * This structure stores per CPU instance data for all CPUs.
233 int cpu; member
272 * struct pstate_funcs - Per CPU model specific callbacks
282 * Core and Atom CPU models have different way to get P State limits. This
335 /* The work item is needed to avoid CPU hotplug locking issues */
343 static void intel_pstate_set_itmt_prio(int cpu) in intel_pstate_set_itmt_prio() argument
349 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_set_itmt_prio()
358 sched_set_itmt_core_prio(cppc_perf.highest_perf, cpu); in intel_pstate_set_itmt_prio()
369 * This code can be run during CPU online under the in intel_pstate_set_itmt_prio()
370 * CPU hotplug locks, so sched_set_itmt_support() in intel_pstate_set_itmt_prio()
379 static int intel_pstate_get_cppc_guranteed(int cpu) in intel_pstate_get_cppc_guranteed() argument
384 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_get_cppc_guranteed()
395 static void intel_pstate_set_itmt_prio(int cpu) in intel_pstate_set_itmt_prio() argument
402 struct cpudata *cpu; in intel_pstate_init_acpi_perf_limits() local
407 intel_pstate_set_itmt_prio(policy->cpu); in intel_pstate_init_acpi_perf_limits()
414 cpu = all_cpu_data[policy->cpu]; in intel_pstate_init_acpi_perf_limits()
416 ret = acpi_processor_register_performance(&cpu->acpi_perf_data, in intel_pstate_init_acpi_perf_limits()
417 policy->cpu); in intel_pstate_init_acpi_perf_limits()
426 if (cpu->acpi_perf_data.control_register.space_id != in intel_pstate_init_acpi_perf_limits()
434 if (cpu->acpi_perf_data.state_count < 2) in intel_pstate_init_acpi_perf_limits()
437 pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu); in intel_pstate_init_acpi_perf_limits()
438 for (i = 0; i < cpu->acpi_perf_data.state_count; i++) { in intel_pstate_init_acpi_perf_limits()
440 (i == cpu->acpi_perf_data.state ? '*' : ' '), i, in intel_pstate_init_acpi_perf_limits()
441 (u32) cpu->acpi_perf_data.states[i].core_frequency, in intel_pstate_init_acpi_perf_limits()
442 (u32) cpu->acpi_perf_data.states[i].power, in intel_pstate_init_acpi_perf_limits()
443 (u32) cpu->acpi_perf_data.states[i].control); in intel_pstate_init_acpi_perf_limits()
458 cpu->acpi_perf_data.states[0].core_frequency = in intel_pstate_init_acpi_perf_limits()
460 cpu->valid_pss_table = true; in intel_pstate_init_acpi_perf_limits()
466 cpu->valid_pss_table = false; in intel_pstate_init_acpi_perf_limits()
467 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_init_acpi_perf_limits()
472 struct cpudata *cpu; in intel_pstate_exit_perf_limits() local
474 cpu = all_cpu_data[policy->cpu]; in intel_pstate_exit_perf_limits()
475 if (!cpu->valid_pss_table) in intel_pstate_exit_perf_limits()
478 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_exit_perf_limits()
496 static int intel_pstate_get_cppc_guranteed(int cpu) in intel_pstate_get_cppc_guranteed() argument
505 struct cpudata *cpu; in update_turbo_state() local
507 cpu = all_cpu_data[0]; in update_turbo_state()
511 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); in update_turbo_state()
516 struct cpudata *cpu = all_cpu_data[0]; in min_perf_pct_min() local
517 int turbo_pstate = cpu->pstate.turbo_pstate; in min_perf_pct_min()
520 (cpu->pstate.min_pstate * 100 / turbo_pstate) : 0; in min_perf_pct_min()
531 ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_get_epb()
548 epp = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, in intel_pstate_get_epp()
562 static int intel_pstate_set_epb(int cpu, s16 pref) in intel_pstate_set_epb() argument
570 ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_set_epb()
575 wrmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, epb); in intel_pstate_set_epb()
644 static int intel_pstate_set_epp(struct cpudata *cpu, u32 epp) in intel_pstate_set_epp() argument
653 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_set_epp()
662 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_set_epp()
663 ret = wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_set_epp()
665 cpu->epp_cached = epp; in intel_pstate_set_epp()
698 ret = intel_pstate_set_epb(cpu_data->cpu, epp); in intel_pstate_set_energy_pref_index()
725 struct cpudata *cpu = all_cpu_data[policy->cpu]; in store_energy_performance_preference() local
761 ret = intel_pstate_set_energy_pref_index(cpu, ret, raw, epp); in store_energy_performance_preference()
765 * target CPU before the EPP update and restarted after it, in store_energy_performance_preference()
770 epp = ret ? epp_values[ret - 1] : cpu->epp_default; in store_energy_performance_preference()
772 if (cpu->epp_cached != epp) { in store_energy_performance_preference()
776 ret = intel_pstate_set_epp(cpu, epp); in store_energy_performance_preference()
791 struct cpudata *cpu_data = all_cpu_data[policy->cpu]; in show_energy_performance_preference()
808 struct cpudata *cpu; in show_base_frequency() local
812 ratio = intel_pstate_get_cppc_guranteed(policy->cpu); in show_base_frequency()
814 rdmsrl_on_cpu(policy->cpu, MSR_HWP_CAPABILITIES, &cap); in show_base_frequency()
818 cpu = all_cpu_data[policy->cpu]; in show_base_frequency()
820 return sprintf(buf, "%d\n", ratio * cpu->pstate.scaling); in show_base_frequency()
832 static void intel_pstate_get_hwp_max(struct cpudata *cpu, int *phy_max, in intel_pstate_get_hwp_max() argument
837 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_CAPABILITIES, &cap); in intel_pstate_get_hwp_max()
838 WRITE_ONCE(cpu->hwp_cap_cached, cap); in intel_pstate_get_hwp_max()
847 static void intel_pstate_hwp_set(unsigned int cpu) in intel_pstate_hwp_set() argument
849 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_hwp_set()
860 rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value); in intel_pstate_hwp_set()
903 intel_pstate_set_epb(cpu, epp); in intel_pstate_hwp_set()
907 wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_set()
910 static void intel_pstate_hwp_offline(struct cpudata *cpu) in intel_pstate_hwp_offline() argument
912 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_offline()
922 value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached); in intel_pstate_hwp_offline()
923 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_hwp_offline()
927 min_perf = HWP_LOWEST_PERF(cpu->hwp_cap_cached); in intel_pstate_hwp_offline()
937 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_offline()
964 static void intel_pstate_hwp_reenable(struct cpudata *cpu) in intel_pstate_hwp_reenable() argument
966 intel_pstate_hwp_enable(cpu); in intel_pstate_hwp_reenable()
967 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, READ_ONCE(cpu->hwp_req_cached)); in intel_pstate_hwp_reenable()
972 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_suspend() local
974 pr_debug("CPU %d suspending\n", cpu->cpu); in intel_pstate_suspend()
976 cpu->suspended = true; in intel_pstate_suspend()
983 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_resume() local
985 pr_debug("CPU %d resuming\n", cpu->cpu); in intel_pstate_resume()
993 if (cpu->suspended && hwp_active) { in intel_pstate_resume()
997 intel_pstate_hwp_reenable(cpu); in intel_pstate_resume()
1002 cpu->suspended = false; in intel_pstate_resume()
1009 int cpu; in intel_pstate_update_policies() local
1011 for_each_possible_cpu(cpu) in intel_pstate_update_policies()
1012 cpufreq_update_policy(cpu); in intel_pstate_update_policies()
1015 static void intel_pstate_update_max_freq(unsigned int cpu) in intel_pstate_update_max_freq() argument
1017 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); in intel_pstate_update_max_freq()
1023 cpudata = all_cpu_data[cpu]; in intel_pstate_update_max_freq()
1032 static void intel_pstate_update_limits(unsigned int cpu) in intel_pstate_update_limits() argument
1044 for_each_possible_cpu(cpu) in intel_pstate_update_limits()
1045 intel_pstate_update_max_freq(cpu); in intel_pstate_update_limits()
1047 cpufreq_update_policy(cpu); in intel_pstate_update_limits()
1092 struct cpudata *cpu; in show_turbo_pct() local
1103 cpu = all_cpu_data[0]; in show_turbo_pct()
1105 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1106 no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1118 struct cpudata *cpu; in show_num_pstates() local
1128 cpu = all_cpu_data[0]; in show_num_pstates()
1129 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_num_pstates()
1189 struct cpudata *cpu = all_cpu_data[0]; in store_no_turbo() local
1190 int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate; in store_no_turbo()
1213 struct cpudata *cpu = all_cpu_data[i]; in update_qos_request() local
1226 intel_pstate_get_hwp_max(cpu, &turbo_max, &max_state); in update_qos_request()
1228 turbo_max = cpu->pstate.turbo_pstate; in update_qos_request()
1238 freq *= cpu->pstate.scaling; in update_qos_request()
1241 pr_warn("Failed to update freq constraint: CPU%d\n", i); in update_qos_request()
1405 * If per cpu limits are enforced there are no global limits, so in intel_pstate_sysfs_expose_params()
1466 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00); in intel_pstate_hwp_enable()
1468 wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1); in intel_pstate_hwp_enable()
1698 static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) in intel_pstate_set_pstate() argument
1700 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_set_pstate()
1701 cpu->pstate.current_pstate = pstate; in intel_pstate_set_pstate()
1704 * the CPU being updated, so force the register update to run on the in intel_pstate_set_pstate()
1705 * right CPU. in intel_pstate_set_pstate()
1707 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_pstate_set_pstate()
1708 pstate_funcs.get_val(cpu, pstate)); in intel_pstate_set_pstate()
1711 static void intel_pstate_set_min_pstate(struct cpudata *cpu) in intel_pstate_set_min_pstate() argument
1713 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); in intel_pstate_set_min_pstate()
1716 static void intel_pstate_max_within_limits(struct cpudata *cpu) in intel_pstate_max_within_limits() argument
1718 int pstate = max(cpu->pstate.min_pstate, cpu->max_perf_ratio); in intel_pstate_max_within_limits()
1721 intel_pstate_set_pstate(cpu, pstate); in intel_pstate_max_within_limits()
1724 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) in intel_pstate_get_cpu_pstates() argument
1726 cpu->pstate.min_pstate = pstate_funcs.get_min(); in intel_pstate_get_cpu_pstates()
1727 cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical(); in intel_pstate_get_cpu_pstates()
1728 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(); in intel_pstate_get_cpu_pstates()
1729 cpu->pstate.scaling = pstate_funcs.get_scaling(); in intel_pstate_get_cpu_pstates()
1734 intel_pstate_get_hwp_max(cpu, &phy_max, ¤t_max); in intel_pstate_get_cpu_pstates()
1735 cpu->pstate.turbo_freq = phy_max * cpu->pstate.scaling; in intel_pstate_get_cpu_pstates()
1736 cpu->pstate.turbo_pstate = phy_max; in intel_pstate_get_cpu_pstates()
1737 cpu->pstate.max_pstate = HWP_GUARANTEED_PERF(READ_ONCE(cpu->hwp_cap_cached)); in intel_pstate_get_cpu_pstates()
1739 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling; in intel_pstate_get_cpu_pstates()
1740 cpu->pstate.max_pstate = pstate_funcs.get_max(); in intel_pstate_get_cpu_pstates()
1742 cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling; in intel_pstate_get_cpu_pstates()
1745 cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift(); in intel_pstate_get_cpu_pstates()
1748 pstate_funcs.get_vid(cpu); in intel_pstate_get_cpu_pstates()
1750 intel_pstate_set_min_pstate(cpu); in intel_pstate_get_cpu_pstates()
1761 static inline void intel_pstate_hwp_boost_up(struct cpudata *cpu) in intel_pstate_hwp_boost_up() argument
1763 u64 hwp_req = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_boost_up()
1783 if (max_limit == min_limit || cpu->hwp_boost_min >= max_limit) in intel_pstate_hwp_boost_up()
1786 if (!cpu->hwp_boost_min) in intel_pstate_hwp_boost_up()
1787 cpu->hwp_boost_min = min_limit; in intel_pstate_hwp_boost_up()
1790 boost_level1 = (HWP_GUARANTEED_PERF(cpu->hwp_cap_cached) + min_limit) >> 1; in intel_pstate_hwp_boost_up()
1792 if (cpu->hwp_boost_min < boost_level1) in intel_pstate_hwp_boost_up()
1793 cpu->hwp_boost_min = boost_level1; in intel_pstate_hwp_boost_up()
1794 else if (cpu->hwp_boost_min < HWP_GUARANTEED_PERF(cpu->hwp_cap_cached)) in intel_pstate_hwp_boost_up()
1795 cpu->hwp_boost_min = HWP_GUARANTEED_PERF(cpu->hwp_cap_cached); in intel_pstate_hwp_boost_up()
1796 else if (cpu->hwp_boost_min == HWP_GUARANTEED_PERF(cpu->hwp_cap_cached) && in intel_pstate_hwp_boost_up()
1797 max_limit != HWP_GUARANTEED_PERF(cpu->hwp_cap_cached)) in intel_pstate_hwp_boost_up()
1798 cpu->hwp_boost_min = max_limit; in intel_pstate_hwp_boost_up()
1802 hwp_req = (hwp_req & ~GENMASK_ULL(7, 0)) | cpu->hwp_boost_min; in intel_pstate_hwp_boost_up()
1804 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_up()
1807 static inline void intel_pstate_hwp_boost_down(struct cpudata *cpu) in intel_pstate_hwp_boost_down() argument
1809 if (cpu->hwp_boost_min) { in intel_pstate_hwp_boost_down()
1813 expired = time_after64(cpu->sample.time, cpu->last_update + in intel_pstate_hwp_boost_down()
1816 wrmsrl(MSR_HWP_REQUEST, cpu->hwp_req_cached); in intel_pstate_hwp_boost_down()
1817 cpu->hwp_boost_min = 0; in intel_pstate_hwp_boost_down()
1820 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_down()
1823 static inline void intel_pstate_update_util_hwp_local(struct cpudata *cpu, in intel_pstate_update_util_hwp_local() argument
1826 cpu->sample.time = time; in intel_pstate_update_util_hwp_local()
1828 if (cpu->sched_flags & SCHED_CPUFREQ_IOWAIT) { in intel_pstate_update_util_hwp_local()
1831 cpu->sched_flags = 0; in intel_pstate_update_util_hwp_local()
1835 * some IO bound activity is scheduled on this CPU with just in intel_pstate_update_util_hwp_local()
1839 if (time_before64(time, cpu->last_io_update + 2 * TICK_NSEC)) in intel_pstate_update_util_hwp_local()
1842 cpu->last_io_update = time; in intel_pstate_update_util_hwp_local()
1845 intel_pstate_hwp_boost_up(cpu); in intel_pstate_update_util_hwp_local()
1848 intel_pstate_hwp_boost_down(cpu); in intel_pstate_update_util_hwp_local()
1855 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util_hwp() local
1857 cpu->sched_flags |= flags; in intel_pstate_update_util_hwp()
1859 if (smp_processor_id() == cpu->cpu) in intel_pstate_update_util_hwp()
1860 intel_pstate_update_util_hwp_local(cpu, time); in intel_pstate_update_util_hwp()
1863 static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu) in intel_pstate_calc_avg_perf() argument
1865 struct sample *sample = &cpu->sample; in intel_pstate_calc_avg_perf()
1870 static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time) in intel_pstate_sample() argument
1880 if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) { in intel_pstate_sample()
1886 cpu->last_sample_time = cpu->sample.time; in intel_pstate_sample()
1887 cpu->sample.time = time; in intel_pstate_sample()
1888 cpu->sample.aperf = aperf; in intel_pstate_sample()
1889 cpu->sample.mperf = mperf; in intel_pstate_sample()
1890 cpu->sample.tsc = tsc; in intel_pstate_sample()
1891 cpu->sample.aperf -= cpu->prev_aperf; in intel_pstate_sample()
1892 cpu->sample.mperf -= cpu->prev_mperf; in intel_pstate_sample()
1893 cpu->sample.tsc -= cpu->prev_tsc; in intel_pstate_sample()
1895 cpu->prev_aperf = aperf; in intel_pstate_sample()
1896 cpu->prev_mperf = mperf; in intel_pstate_sample()
1897 cpu->prev_tsc = tsc; in intel_pstate_sample()
1905 if (cpu->last_sample_time) { in intel_pstate_sample()
1906 intel_pstate_calc_avg_perf(cpu); in intel_pstate_sample()
1912 static inline int32_t get_avg_frequency(struct cpudata *cpu) in get_avg_frequency() argument
1914 return mul_ext_fp(cpu->sample.core_avg_perf, cpu_khz); in get_avg_frequency()
1917 static inline int32_t get_avg_pstate(struct cpudata *cpu) in get_avg_pstate() argument
1919 return mul_ext_fp(cpu->pstate.max_pstate_physical, in get_avg_pstate()
1920 cpu->sample.core_avg_perf); in get_avg_pstate()
1923 static inline int32_t get_target_pstate(struct cpudata *cpu) in get_target_pstate() argument
1925 struct sample *sample = &cpu->sample; in get_target_pstate()
1929 busy_frac = div_fp(sample->mperf << cpu->aperf_mperf_shift, in get_target_pstate()
1932 if (busy_frac < cpu->iowait_boost) in get_target_pstate()
1933 busy_frac = cpu->iowait_boost; in get_target_pstate()
1938 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in get_target_pstate()
1941 if (target < cpu->pstate.min_pstate) in get_target_pstate()
1942 target = cpu->pstate.min_pstate; in get_target_pstate()
1948 * loss related to moving the workload from one CPU to another within in get_target_pstate()
1951 avg_pstate = get_avg_pstate(cpu); in get_target_pstate()
1958 static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) in intel_pstate_prepare_request() argument
1960 int min_pstate = max(cpu->pstate.min_pstate, cpu->min_perf_ratio); in intel_pstate_prepare_request()
1961 int max_pstate = max(min_pstate, cpu->max_perf_ratio); in intel_pstate_prepare_request()
1966 static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) in intel_pstate_update_pstate() argument
1968 if (pstate == cpu->pstate.current_pstate) in intel_pstate_update_pstate()
1971 cpu->pstate.current_pstate = pstate; in intel_pstate_update_pstate()
1972 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate)); in intel_pstate_update_pstate()
1975 static void intel_pstate_adjust_pstate(struct cpudata *cpu) in intel_pstate_adjust_pstate() argument
1977 int from = cpu->pstate.current_pstate; in intel_pstate_adjust_pstate()
1983 target_pstate = get_target_pstate(cpu); in intel_pstate_adjust_pstate()
1984 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_pstate_adjust_pstate()
1985 trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_adjust_pstate()
1986 intel_pstate_update_pstate(cpu, target_pstate); in intel_pstate_adjust_pstate()
1988 sample = &cpu->sample; in intel_pstate_adjust_pstate()
1992 cpu->pstate.current_pstate, in intel_pstate_adjust_pstate()
1996 get_avg_frequency(cpu), in intel_pstate_adjust_pstate()
1997 fp_toint(cpu->iowait_boost * 100)); in intel_pstate_adjust_pstate()
2003 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util() local
2007 if (smp_processor_id() != cpu->cpu) in intel_pstate_update_util()
2010 delta_ns = time - cpu->last_update; in intel_pstate_update_util()
2012 /* Start over if the CPU may have been idle. */ in intel_pstate_update_util()
2014 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2015 } else if (cpu->iowait_boost >= ONE_EIGHTH_FP) { in intel_pstate_update_util()
2016 cpu->iowait_boost <<= 1; in intel_pstate_update_util()
2017 if (cpu->iowait_boost > int_tofp(1)) in intel_pstate_update_util()
2018 cpu->iowait_boost = int_tofp(1); in intel_pstate_update_util()
2020 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2022 } else if (cpu->iowait_boost) { in intel_pstate_update_util()
2023 /* Clear iowait_boost if the CPU may have been idle. */ in intel_pstate_update_util()
2025 cpu->iowait_boost = 0; in intel_pstate_update_util()
2027 cpu->iowait_boost >>= 1; in intel_pstate_update_util()
2029 cpu->last_update = time; in intel_pstate_update_util()
2030 delta_ns = time - cpu->sample.time; in intel_pstate_update_util()
2034 if (intel_pstate_sample(cpu, time)) in intel_pstate_update_util()
2035 intel_pstate_adjust_pstate(cpu); in intel_pstate_update_util()
2127 struct cpudata *cpu; in intel_pstate_init_cpu() local
2129 cpu = all_cpu_data[cpunum]; in intel_pstate_init_cpu()
2131 if (!cpu) { in intel_pstate_init_cpu()
2132 cpu = kzalloc(sizeof(*cpu), GFP_KERNEL); in intel_pstate_init_cpu()
2133 if (!cpu) in intel_pstate_init_cpu()
2136 all_cpu_data[cpunum] = cpu; in intel_pstate_init_cpu()
2138 cpu->cpu = cpunum; in intel_pstate_init_cpu()
2140 cpu->epp_default = -EINVAL; in intel_pstate_init_cpu()
2145 intel_pstate_hwp_enable(cpu); in intel_pstate_init_cpu()
2154 * S3 if the CPU was offline during the whole system/resume in intel_pstate_init_cpu()
2157 intel_pstate_hwp_reenable(cpu); in intel_pstate_init_cpu()
2160 cpu->epp_powersave = -EINVAL; in intel_pstate_init_cpu()
2161 cpu->epp_policy = 0; in intel_pstate_init_cpu()
2163 intel_pstate_get_cpu_pstates(cpu); in intel_pstate_init_cpu()
2165 pr_debug("controlling: cpu %d\n", cpunum); in intel_pstate_init_cpu()
2172 struct cpudata *cpu = all_cpu_data[cpu_num]; in intel_pstate_set_update_util_hook() local
2177 if (cpu->update_util_set) in intel_pstate_set_update_util_hook()
2181 cpu->sample.time = 0; in intel_pstate_set_update_util_hook()
2182 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, in intel_pstate_set_update_util_hook()
2186 cpu->update_util_set = true; in intel_pstate_set_update_util_hook()
2189 static void intel_pstate_clear_update_util_hook(unsigned int cpu) in intel_pstate_clear_update_util_hook() argument
2191 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_clear_update_util_hook()
2196 cpufreq_remove_update_util_hook(cpu); in intel_pstate_clear_update_util_hook()
2201 static int intel_pstate_get_max_freq(struct cpudata *cpu) in intel_pstate_get_max_freq() argument
2204 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_get_max_freq()
2207 static void intel_pstate_update_perf_limits(struct cpudata *cpu, in intel_pstate_update_perf_limits() argument
2221 intel_pstate_get_hwp_max(cpu, &turbo_max, &max_state); in intel_pstate_update_perf_limits()
2224 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in intel_pstate_update_perf_limits()
2225 turbo_max = cpu->pstate.turbo_pstate; in intel_pstate_update_perf_limits()
2227 max_freq = max_state * cpu->pstate.scaling; in intel_pstate_update_perf_limits()
2238 pr_debug("cpu:%d max_state %d min_policy_perf:%d max_policy_perf:%d\n", in intel_pstate_update_perf_limits()
2239 cpu->cpu, max_state, min_policy_perf, max_policy_perf); in intel_pstate_update_perf_limits()
2243 cpu->min_perf_ratio = min_policy_perf; in intel_pstate_update_perf_limits()
2244 cpu->max_perf_ratio = max_policy_perf; in intel_pstate_update_perf_limits()
2253 pr_debug("cpu:%d global_min:%d global_max:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2256 cpu->min_perf_ratio = max(min_policy_perf, global_min); in intel_pstate_update_perf_limits()
2257 cpu->min_perf_ratio = min(cpu->min_perf_ratio, max_policy_perf); in intel_pstate_update_perf_limits()
2258 cpu->max_perf_ratio = min(max_policy_perf, global_max); in intel_pstate_update_perf_limits()
2259 cpu->max_perf_ratio = max(min_policy_perf, cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2262 cpu->min_perf_ratio = min(cpu->min_perf_ratio, in intel_pstate_update_perf_limits()
2263 cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2266 pr_debug("cpu:%d max_perf_ratio:%d min_perf_ratio:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2267 cpu->max_perf_ratio, in intel_pstate_update_perf_limits()
2268 cpu->min_perf_ratio); in intel_pstate_update_perf_limits()
2273 struct cpudata *cpu; in intel_pstate_set_policy() local
2281 cpu = all_cpu_data[policy->cpu]; in intel_pstate_set_policy()
2282 cpu->policy = policy->policy; in intel_pstate_set_policy()
2286 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_pstate_set_policy()
2288 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { in intel_pstate_set_policy()
2293 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2294 intel_pstate_max_within_limits(cpu); in intel_pstate_set_policy()
2296 intel_pstate_set_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2306 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2307 intel_pstate_hwp_set(policy->cpu); in intel_pstate_set_policy()
2315 static void intel_pstate_adjust_policy_max(struct cpudata *cpu, in intel_pstate_adjust_policy_max() argument
2319 cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && in intel_pstate_adjust_policy_max()
2321 policy->max > cpu->pstate.max_freq) { in intel_pstate_adjust_policy_max()
2327 static void intel_pstate_verify_cpu_policy(struct cpudata *cpu, in intel_pstate_verify_cpu_policy() argument
2336 intel_pstate_get_hwp_max(cpu, &turbo_max, &max_state); in intel_pstate_verify_cpu_policy()
2337 max_freq = max_state * cpu->pstate.scaling; in intel_pstate_verify_cpu_policy()
2339 max_freq = intel_pstate_get_max_freq(cpu); in intel_pstate_verify_cpu_policy()
2343 intel_pstate_adjust_policy_max(cpu, policy); in intel_pstate_verify_cpu_policy()
2348 intel_pstate_verify_cpu_policy(all_cpu_data[policy->cpu], policy); in intel_pstate_verify_policy()
2355 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_offline() local
2357 pr_debug("CPU %d going offline\n", cpu->cpu); in intel_pstate_cpu_offline()
2359 if (cpu->suspended) in intel_pstate_cpu_offline()
2363 * If the CPU is an SMT thread and it goes offline with the performance in intel_pstate_cpu_offline()
2366 * performance on CPU offline to prevent that from happening. in intel_pstate_cpu_offline()
2369 intel_pstate_hwp_offline(cpu); in intel_pstate_cpu_offline()
2371 intel_pstate_set_min_pstate(cpu); in intel_pstate_cpu_offline()
2380 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_online() local
2382 pr_debug("CPU %d going online\n", cpu->cpu); in intel_pstate_cpu_online()
2391 intel_pstate_hwp_reenable(cpu); in intel_pstate_cpu_online()
2392 cpu->suspended = false; in intel_pstate_cpu_online()
2400 pr_debug("CPU %d stopping\n", policy->cpu); in intel_pstate_stop_cpu()
2402 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_stop_cpu()
2407 pr_debug("CPU %d exiting\n", policy->cpu); in intel_pstate_cpu_exit()
2416 struct cpudata *cpu; in __intel_pstate_cpu_init() local
2419 rc = intel_pstate_init_cpu(policy->cpu); in __intel_pstate_cpu_init()
2423 cpu = all_cpu_data[policy->cpu]; in __intel_pstate_cpu_init()
2425 cpu->max_perf_ratio = 0xFF; in __intel_pstate_cpu_init()
2426 cpu->min_perf_ratio = 0; in __intel_pstate_cpu_init()
2428 policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling; in __intel_pstate_cpu_init()
2429 policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling; in __intel_pstate_cpu_init()
2432 policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling; in __intel_pstate_cpu_init()
2436 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in __intel_pstate_cpu_init()
2437 policy->cpuinfo.max_freq *= cpu->pstate.scaling; in __intel_pstate_cpu_init()
2443 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in __intel_pstate_cpu_init()
2469 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_init() local
2471 cpu->epp_cached = intel_pstate_get_epp(cpu, 0); in intel_pstate_cpu_init()
2494 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_verify_policy() local
2496 intel_pstate_verify_cpu_policy(cpu, policy); in intel_cpufreq_verify_policy()
2497 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_cpufreq_verify_policy()
2518 static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, int old_pstate) in intel_cpufreq_trace() argument
2525 if (!intel_pstate_sample(cpu, ktime_get())) in intel_cpufreq_trace()
2528 sample = &cpu->sample; in intel_cpufreq_trace()
2532 cpu->pstate.current_pstate, in intel_cpufreq_trace()
2536 get_avg_frequency(cpu), in intel_cpufreq_trace()
2537 fp_toint(cpu->iowait_boost * 100)); in intel_cpufreq_trace()
2540 static void intel_cpufreq_adjust_hwp(struct cpudata *cpu, u32 target_pstate, in intel_cpufreq_adjust_hwp() argument
2543 u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev; in intel_cpufreq_adjust_hwp()
2553 value |= HWP_MAX_PERF(strict ? target_pstate : cpu->max_perf_ratio); in intel_cpufreq_adjust_hwp()
2558 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_adjust_hwp()
2562 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_cpufreq_adjust_hwp()
2565 static void intel_cpufreq_adjust_perf_ctl(struct cpudata *cpu, in intel_cpufreq_adjust_perf_ctl() argument
2570 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_adjust_perf_ctl()
2572 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_cpufreq_adjust_perf_ctl()
2573 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_adjust_perf_ctl()
2579 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_update_pstate() local
2580 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_update_pstate()
2582 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_cpufreq_update_pstate()
2584 intel_cpufreq_adjust_hwp(cpu, target_pstate, in intel_cpufreq_update_pstate()
2586 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2588 intel_cpufreq_adjust_perf_ctl(cpu, target_pstate, fast_switch); in intel_cpufreq_update_pstate()
2589 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2592 intel_cpufreq_trace(cpu, fast_switch ? INTEL_PSTATE_TRACE_FAST_SWITCH : in intel_cpufreq_update_pstate()
2602 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_target() local
2615 target_pstate = DIV_ROUND_UP(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2618 target_pstate = freqs.new / cpu->pstate.scaling; in intel_cpufreq_target()
2621 target_pstate = DIV_ROUND_CLOSEST(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2627 freqs.new = target_pstate * cpu->pstate.scaling; in intel_cpufreq_target()
2637 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_fast_switch() local
2642 target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); in intel_cpufreq_fast_switch()
2646 return target_pstate * cpu->pstate.scaling; in intel_cpufreq_fast_switch()
2653 struct cpudata *cpu; in intel_cpufreq_cpu_init() local
2656 dev = get_cpu_device(policy->cpu); in intel_cpufreq_cpu_init()
2674 cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_init()
2679 intel_pstate_get_hwp_max(cpu, &turbo_max, &max_state); in intel_cpufreq_cpu_init()
2681 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, &value); in intel_cpufreq_cpu_init()
2682 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_cpu_init()
2683 cpu->epp_cached = intel_pstate_get_epp(cpu, value); in intel_cpufreq_cpu_init()
2685 turbo_max = cpu->pstate.turbo_pstate; in intel_cpufreq_cpu_init()
2690 min_freq *= cpu->pstate.scaling; in intel_cpufreq_cpu_init()
2692 max_freq *= cpu->pstate.scaling; in intel_cpufreq_cpu_init()
2754 unsigned int cpu; in intel_pstate_driver_cleanup() local
2757 for_each_online_cpu(cpu) { in intel_pstate_driver_cleanup()
2758 if (all_cpu_data[cpu]) { in intel_pstate_driver_cleanup()
2760 intel_pstate_clear_update_util_hook(cpu); in intel_pstate_driver_cleanup()
2762 kfree(all_cpu_data[cpu]); in intel_pstate_driver_cleanup()
2763 all_cpu_data[cpu] = NULL; in intel_pstate_driver_cleanup()
3074 pr_info("CPU model not supported\n"); in intel_pstate_init()