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(unsigned int cpu, int *phy_max, in intel_pstate_get_hwp_max() argument
837 rdmsrl_on_cpu(cpu, MSR_HWP_CAPABILITIES, &cap); in intel_pstate_get_hwp_max()
838 WRITE_ONCE(all_cpu_data[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
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 = pstate_funcs.get_max(); in intel_pstate_get_cpu_pstates()
1728 cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical(); in intel_pstate_get_cpu_pstates()
1729 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(); in intel_pstate_get_cpu_pstates()
1730 cpu->pstate.scaling = pstate_funcs.get_scaling(); in intel_pstate_get_cpu_pstates()
1731 cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling; in intel_pstate_get_cpu_pstates()
1736 intel_pstate_get_hwp_max(cpu->cpu, &phy_max, ¤t_max); in intel_pstate_get_cpu_pstates()
1737 cpu->pstate.turbo_freq = phy_max * cpu->pstate.scaling; in intel_pstate_get_cpu_pstates()
1738 cpu->pstate.turbo_pstate = phy_max; in intel_pstate_get_cpu_pstates()
1740 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling; in intel_pstate_get_cpu_pstates()
1744 cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift(); in intel_pstate_get_cpu_pstates()
1747 pstate_funcs.get_vid(cpu); in intel_pstate_get_cpu_pstates()
1749 intel_pstate_set_min_pstate(cpu); in intel_pstate_get_cpu_pstates()
1760 static inline void intel_pstate_hwp_boost_up(struct cpudata *cpu) in intel_pstate_hwp_boost_up() argument
1762 u64 hwp_req = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_boost_up()
1782 if (max_limit == min_limit || cpu->hwp_boost_min >= max_limit) in intel_pstate_hwp_boost_up()
1785 if (!cpu->hwp_boost_min) in intel_pstate_hwp_boost_up()
1786 cpu->hwp_boost_min = min_limit; in intel_pstate_hwp_boost_up()
1789 boost_level1 = (HWP_GUARANTEED_PERF(cpu->hwp_cap_cached) + min_limit) >> 1; in intel_pstate_hwp_boost_up()
1791 if (cpu->hwp_boost_min < boost_level1) in intel_pstate_hwp_boost_up()
1792 cpu->hwp_boost_min = boost_level1; in intel_pstate_hwp_boost_up()
1793 else if (cpu->hwp_boost_min < HWP_GUARANTEED_PERF(cpu->hwp_cap_cached)) in intel_pstate_hwp_boost_up()
1794 cpu->hwp_boost_min = HWP_GUARANTEED_PERF(cpu->hwp_cap_cached); in intel_pstate_hwp_boost_up()
1795 else if (cpu->hwp_boost_min == HWP_GUARANTEED_PERF(cpu->hwp_cap_cached) && in intel_pstate_hwp_boost_up()
1796 max_limit != HWP_GUARANTEED_PERF(cpu->hwp_cap_cached)) in intel_pstate_hwp_boost_up()
1797 cpu->hwp_boost_min = max_limit; in intel_pstate_hwp_boost_up()
1801 hwp_req = (hwp_req & ~GENMASK_ULL(7, 0)) | cpu->hwp_boost_min; in intel_pstate_hwp_boost_up()
1803 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_up()
1806 static inline void intel_pstate_hwp_boost_down(struct cpudata *cpu) in intel_pstate_hwp_boost_down() argument
1808 if (cpu->hwp_boost_min) { in intel_pstate_hwp_boost_down()
1812 expired = time_after64(cpu->sample.time, cpu->last_update + in intel_pstate_hwp_boost_down()
1815 wrmsrl(MSR_HWP_REQUEST, cpu->hwp_req_cached); in intel_pstate_hwp_boost_down()
1816 cpu->hwp_boost_min = 0; in intel_pstate_hwp_boost_down()
1819 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_down()
1822 static inline void intel_pstate_update_util_hwp_local(struct cpudata *cpu, in intel_pstate_update_util_hwp_local() argument
1825 cpu->sample.time = time; in intel_pstate_update_util_hwp_local()
1827 if (cpu->sched_flags & SCHED_CPUFREQ_IOWAIT) { in intel_pstate_update_util_hwp_local()
1830 cpu->sched_flags = 0; in intel_pstate_update_util_hwp_local()
1834 * some IO bound activity is scheduled on this CPU with just in intel_pstate_update_util_hwp_local()
1838 if (time_before64(time, cpu->last_io_update + 2 * TICK_NSEC)) in intel_pstate_update_util_hwp_local()
1841 cpu->last_io_update = time; in intel_pstate_update_util_hwp_local()
1844 intel_pstate_hwp_boost_up(cpu); in intel_pstate_update_util_hwp_local()
1847 intel_pstate_hwp_boost_down(cpu); in intel_pstate_update_util_hwp_local()
1854 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util_hwp() local
1856 cpu->sched_flags |= flags; in intel_pstate_update_util_hwp()
1858 if (smp_processor_id() == cpu->cpu) in intel_pstate_update_util_hwp()
1859 intel_pstate_update_util_hwp_local(cpu, time); in intel_pstate_update_util_hwp()
1862 static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu) in intel_pstate_calc_avg_perf() argument
1864 struct sample *sample = &cpu->sample; in intel_pstate_calc_avg_perf()
1869 static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time) in intel_pstate_sample() argument
1879 if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) { in intel_pstate_sample()
1885 cpu->last_sample_time = cpu->sample.time; in intel_pstate_sample()
1886 cpu->sample.time = time; in intel_pstate_sample()
1887 cpu->sample.aperf = aperf; in intel_pstate_sample()
1888 cpu->sample.mperf = mperf; in intel_pstate_sample()
1889 cpu->sample.tsc = tsc; in intel_pstate_sample()
1890 cpu->sample.aperf -= cpu->prev_aperf; in intel_pstate_sample()
1891 cpu->sample.mperf -= cpu->prev_mperf; in intel_pstate_sample()
1892 cpu->sample.tsc -= cpu->prev_tsc; in intel_pstate_sample()
1894 cpu->prev_aperf = aperf; in intel_pstate_sample()
1895 cpu->prev_mperf = mperf; in intel_pstate_sample()
1896 cpu->prev_tsc = tsc; in intel_pstate_sample()
1904 if (cpu->last_sample_time) { in intel_pstate_sample()
1905 intel_pstate_calc_avg_perf(cpu); in intel_pstate_sample()
1911 static inline int32_t get_avg_frequency(struct cpudata *cpu) in get_avg_frequency() argument
1913 return mul_ext_fp(cpu->sample.core_avg_perf, cpu_khz); in get_avg_frequency()
1916 static inline int32_t get_avg_pstate(struct cpudata *cpu) in get_avg_pstate() argument
1918 return mul_ext_fp(cpu->pstate.max_pstate_physical, in get_avg_pstate()
1919 cpu->sample.core_avg_perf); in get_avg_pstate()
1922 static inline int32_t get_target_pstate(struct cpudata *cpu) in get_target_pstate() argument
1924 struct sample *sample = &cpu->sample; in get_target_pstate()
1928 busy_frac = div_fp(sample->mperf << cpu->aperf_mperf_shift, in get_target_pstate()
1931 if (busy_frac < cpu->iowait_boost) in get_target_pstate()
1932 busy_frac = cpu->iowait_boost; in get_target_pstate()
1937 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in get_target_pstate()
1940 if (target < cpu->pstate.min_pstate) in get_target_pstate()
1941 target = cpu->pstate.min_pstate; in get_target_pstate()
1947 * loss related to moving the workload from one CPU to another within in get_target_pstate()
1950 avg_pstate = get_avg_pstate(cpu); in get_target_pstate()
1957 static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) in intel_pstate_prepare_request() argument
1959 int min_pstate = max(cpu->pstate.min_pstate, cpu->min_perf_ratio); in intel_pstate_prepare_request()
1960 int max_pstate = max(min_pstate, cpu->max_perf_ratio); in intel_pstate_prepare_request()
1965 static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) in intel_pstate_update_pstate() argument
1967 if (pstate == cpu->pstate.current_pstate) in intel_pstate_update_pstate()
1970 cpu->pstate.current_pstate = pstate; in intel_pstate_update_pstate()
1971 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate)); in intel_pstate_update_pstate()
1974 static void intel_pstate_adjust_pstate(struct cpudata *cpu) in intel_pstate_adjust_pstate() argument
1976 int from = cpu->pstate.current_pstate; in intel_pstate_adjust_pstate()
1982 target_pstate = get_target_pstate(cpu); in intel_pstate_adjust_pstate()
1983 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_pstate_adjust_pstate()
1984 trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_adjust_pstate()
1985 intel_pstate_update_pstate(cpu, target_pstate); in intel_pstate_adjust_pstate()
1987 sample = &cpu->sample; in intel_pstate_adjust_pstate()
1991 cpu->pstate.current_pstate, in intel_pstate_adjust_pstate()
1995 get_avg_frequency(cpu), in intel_pstate_adjust_pstate()
1996 fp_toint(cpu->iowait_boost * 100)); in intel_pstate_adjust_pstate()
2002 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util() local
2006 if (smp_processor_id() != cpu->cpu) in intel_pstate_update_util()
2009 delta_ns = time - cpu->last_update; in intel_pstate_update_util()
2011 /* Start over if the CPU may have been idle. */ in intel_pstate_update_util()
2013 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2014 } else if (cpu->iowait_boost >= ONE_EIGHTH_FP) { in intel_pstate_update_util()
2015 cpu->iowait_boost <<= 1; in intel_pstate_update_util()
2016 if (cpu->iowait_boost > int_tofp(1)) in intel_pstate_update_util()
2017 cpu->iowait_boost = int_tofp(1); in intel_pstate_update_util()
2019 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2021 } else if (cpu->iowait_boost) { in intel_pstate_update_util()
2022 /* Clear iowait_boost if the CPU may have been idle. */ in intel_pstate_update_util()
2024 cpu->iowait_boost = 0; in intel_pstate_update_util()
2026 cpu->iowait_boost >>= 1; in intel_pstate_update_util()
2028 cpu->last_update = time; in intel_pstate_update_util()
2029 delta_ns = time - cpu->sample.time; in intel_pstate_update_util()
2033 if (intel_pstate_sample(cpu, time)) in intel_pstate_update_util()
2034 intel_pstate_adjust_pstate(cpu); in intel_pstate_update_util()
2126 struct cpudata *cpu; in intel_pstate_init_cpu() local
2128 cpu = all_cpu_data[cpunum]; in intel_pstate_init_cpu()
2130 if (!cpu) { in intel_pstate_init_cpu()
2131 cpu = kzalloc(sizeof(*cpu), GFP_KERNEL); in intel_pstate_init_cpu()
2132 if (!cpu) in intel_pstate_init_cpu()
2135 all_cpu_data[cpunum] = cpu; in intel_pstate_init_cpu()
2137 cpu->cpu = cpunum; in intel_pstate_init_cpu()
2139 cpu->epp_default = -EINVAL; in intel_pstate_init_cpu()
2144 intel_pstate_hwp_enable(cpu); in intel_pstate_init_cpu()
2153 * S3 if the CPU was offline during the whole system/resume in intel_pstate_init_cpu()
2156 intel_pstate_hwp_reenable(cpu); in intel_pstate_init_cpu()
2159 cpu->epp_powersave = -EINVAL; in intel_pstate_init_cpu()
2160 cpu->epp_policy = 0; in intel_pstate_init_cpu()
2162 intel_pstate_get_cpu_pstates(cpu); in intel_pstate_init_cpu()
2164 pr_debug("controlling: cpu %d\n", cpunum); in intel_pstate_init_cpu()
2171 struct cpudata *cpu = all_cpu_data[cpu_num]; in intel_pstate_set_update_util_hook() local
2176 if (cpu->update_util_set) in intel_pstate_set_update_util_hook()
2180 cpu->sample.time = 0; in intel_pstate_set_update_util_hook()
2181 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, in intel_pstate_set_update_util_hook()
2185 cpu->update_util_set = true; in intel_pstate_set_update_util_hook()
2188 static void intel_pstate_clear_update_util_hook(unsigned int cpu) in intel_pstate_clear_update_util_hook() argument
2190 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_clear_update_util_hook()
2195 cpufreq_remove_update_util_hook(cpu); in intel_pstate_clear_update_util_hook()
2200 static int intel_pstate_get_max_freq(struct cpudata *cpu) in intel_pstate_get_max_freq() argument
2203 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_get_max_freq()
2206 static void intel_pstate_update_perf_limits(struct cpudata *cpu, in intel_pstate_update_perf_limits() argument
2210 int max_freq = intel_pstate_get_max_freq(cpu); in intel_pstate_update_perf_limits()
2220 intel_pstate_get_hwp_max(cpu->cpu, &turbo_max, &max_state); in intel_pstate_update_perf_limits()
2223 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in intel_pstate_update_perf_limits()
2224 turbo_max = cpu->pstate.turbo_pstate; in intel_pstate_update_perf_limits()
2236 pr_debug("cpu:%d max_state %d min_policy_perf:%d max_policy_perf:%d\n", in intel_pstate_update_perf_limits()
2237 cpu->cpu, max_state, min_policy_perf, max_policy_perf); in intel_pstate_update_perf_limits()
2241 cpu->min_perf_ratio = min_policy_perf; in intel_pstate_update_perf_limits()
2242 cpu->max_perf_ratio = max_policy_perf; in intel_pstate_update_perf_limits()
2251 pr_debug("cpu:%d global_min:%d global_max:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2254 cpu->min_perf_ratio = max(min_policy_perf, global_min); in intel_pstate_update_perf_limits()
2255 cpu->min_perf_ratio = min(cpu->min_perf_ratio, max_policy_perf); in intel_pstate_update_perf_limits()
2256 cpu->max_perf_ratio = min(max_policy_perf, global_max); in intel_pstate_update_perf_limits()
2257 cpu->max_perf_ratio = max(min_policy_perf, cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2260 cpu->min_perf_ratio = min(cpu->min_perf_ratio, in intel_pstate_update_perf_limits()
2261 cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2264 pr_debug("cpu:%d max_perf_ratio:%d min_perf_ratio:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2265 cpu->max_perf_ratio, in intel_pstate_update_perf_limits()
2266 cpu->min_perf_ratio); in intel_pstate_update_perf_limits()
2271 struct cpudata *cpu; in intel_pstate_set_policy() local
2279 cpu = all_cpu_data[policy->cpu]; in intel_pstate_set_policy()
2280 cpu->policy = policy->policy; in intel_pstate_set_policy()
2284 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_pstate_set_policy()
2286 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { in intel_pstate_set_policy()
2291 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2292 intel_pstate_max_within_limits(cpu); in intel_pstate_set_policy()
2294 intel_pstate_set_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2304 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2305 intel_pstate_hwp_set(policy->cpu); in intel_pstate_set_policy()
2313 static void intel_pstate_adjust_policy_max(struct cpudata *cpu, in intel_pstate_adjust_policy_max() argument
2317 cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && in intel_pstate_adjust_policy_max()
2319 policy->max > cpu->pstate.max_freq) { in intel_pstate_adjust_policy_max()
2325 static void intel_pstate_verify_cpu_policy(struct cpudata *cpu, in intel_pstate_verify_cpu_policy() argument
2330 intel_pstate_get_max_freq(cpu)); in intel_pstate_verify_cpu_policy()
2332 intel_pstate_adjust_policy_max(cpu, policy); in intel_pstate_verify_cpu_policy()
2337 intel_pstate_verify_cpu_policy(all_cpu_data[policy->cpu], policy); in intel_pstate_verify_policy()
2344 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_offline() local
2346 pr_debug("CPU %d going offline\n", cpu->cpu); in intel_pstate_cpu_offline()
2348 if (cpu->suspended) in intel_pstate_cpu_offline()
2352 * If the CPU is an SMT thread and it goes offline with the performance in intel_pstate_cpu_offline()
2355 * performance on CPU offline to prevent that from happening. in intel_pstate_cpu_offline()
2358 intel_pstate_hwp_offline(cpu); in intel_pstate_cpu_offline()
2360 intel_pstate_set_min_pstate(cpu); in intel_pstate_cpu_offline()
2369 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_online() local
2371 pr_debug("CPU %d going online\n", cpu->cpu); in intel_pstate_cpu_online()
2380 intel_pstate_hwp_reenable(cpu); in intel_pstate_cpu_online()
2381 cpu->suspended = false; in intel_pstate_cpu_online()
2389 pr_debug("CPU %d stopping\n", policy->cpu); in intel_pstate_stop_cpu()
2391 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_stop_cpu()
2396 pr_debug("CPU %d exiting\n", policy->cpu); in intel_pstate_cpu_exit()
2405 struct cpudata *cpu; in __intel_pstate_cpu_init() local
2408 rc = intel_pstate_init_cpu(policy->cpu); in __intel_pstate_cpu_init()
2412 cpu = all_cpu_data[policy->cpu]; in __intel_pstate_cpu_init()
2414 cpu->max_perf_ratio = 0xFF; in __intel_pstate_cpu_init()
2415 cpu->min_perf_ratio = 0; in __intel_pstate_cpu_init()
2417 policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling; in __intel_pstate_cpu_init()
2418 policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling; in __intel_pstate_cpu_init()
2421 policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling; in __intel_pstate_cpu_init()
2425 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in __intel_pstate_cpu_init()
2426 policy->cpuinfo.max_freq *= cpu->pstate.scaling; in __intel_pstate_cpu_init()
2432 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in __intel_pstate_cpu_init()
2458 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_init() local
2460 cpu->epp_cached = intel_pstate_get_epp(cpu, 0); in intel_pstate_cpu_init()
2483 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_verify_policy() local
2485 intel_pstate_verify_cpu_policy(cpu, policy); in intel_cpufreq_verify_policy()
2486 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_cpufreq_verify_policy()
2507 static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, int old_pstate) in intel_cpufreq_trace() argument
2514 if (!intel_pstate_sample(cpu, ktime_get())) in intel_cpufreq_trace()
2517 sample = &cpu->sample; in intel_cpufreq_trace()
2521 cpu->pstate.current_pstate, in intel_cpufreq_trace()
2525 get_avg_frequency(cpu), in intel_cpufreq_trace()
2526 fp_toint(cpu->iowait_boost * 100)); in intel_cpufreq_trace()
2529 static void intel_cpufreq_adjust_hwp(struct cpudata *cpu, u32 target_pstate, in intel_cpufreq_adjust_hwp() argument
2532 u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev; in intel_cpufreq_adjust_hwp()
2542 value |= HWP_MAX_PERF(strict ? target_pstate : cpu->max_perf_ratio); in intel_cpufreq_adjust_hwp()
2547 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_adjust_hwp()
2551 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_cpufreq_adjust_hwp()
2554 static void intel_cpufreq_adjust_perf_ctl(struct cpudata *cpu, in intel_cpufreq_adjust_perf_ctl() argument
2559 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_adjust_perf_ctl()
2561 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_cpufreq_adjust_perf_ctl()
2562 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_adjust_perf_ctl()
2568 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_update_pstate() local
2569 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_update_pstate()
2571 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_cpufreq_update_pstate()
2573 intel_cpufreq_adjust_hwp(cpu, target_pstate, in intel_cpufreq_update_pstate()
2575 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2577 intel_cpufreq_adjust_perf_ctl(cpu, target_pstate, fast_switch); in intel_cpufreq_update_pstate()
2578 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2581 intel_cpufreq_trace(cpu, fast_switch ? INTEL_PSTATE_TRACE_FAST_SWITCH : in intel_cpufreq_update_pstate()
2591 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_target() local
2604 target_pstate = DIV_ROUND_UP(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2607 target_pstate = freqs.new / cpu->pstate.scaling; in intel_cpufreq_target()
2610 target_pstate = DIV_ROUND_CLOSEST(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2616 freqs.new = target_pstate * cpu->pstate.scaling; in intel_cpufreq_target()
2626 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_fast_switch() local
2631 target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); in intel_cpufreq_fast_switch()
2635 return target_pstate * cpu->pstate.scaling; in intel_cpufreq_fast_switch()
2642 struct cpudata *cpu; in intel_cpufreq_cpu_init() local
2645 dev = get_cpu_device(policy->cpu); in intel_cpufreq_cpu_init()
2663 cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_init()
2668 intel_pstate_get_hwp_max(policy->cpu, &turbo_max, &max_state); in intel_cpufreq_cpu_init()
2670 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, &value); in intel_cpufreq_cpu_init()
2671 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_cpu_init()
2672 cpu->epp_cached = intel_pstate_get_epp(cpu, value); in intel_cpufreq_cpu_init()
2674 turbo_max = cpu->pstate.turbo_pstate; in intel_cpufreq_cpu_init()
2679 min_freq *= cpu->pstate.scaling; in intel_cpufreq_cpu_init()
2681 max_freq *= cpu->pstate.scaling; in intel_cpufreq_cpu_init()
2743 unsigned int cpu; in intel_pstate_driver_cleanup() local
2746 for_each_online_cpu(cpu) { in intel_pstate_driver_cleanup()
2747 if (all_cpu_data[cpu]) { in intel_pstate_driver_cleanup()
2749 intel_pstate_clear_update_util_hook(cpu); in intel_pstate_driver_cleanup()
2751 kfree(all_cpu_data[cpu]); in intel_pstate_driver_cleanup()
2752 all_cpu_data[cpu] = NULL; in intel_pstate_driver_cleanup()
3044 pr_info("CPU model not supported\n"); in intel_pstate_init()