Lines Matching refs:cpu

228 	int cpu;  member
288 int (*get_cpu_scaling)(int cpu);
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()
359 cppc_perf.highest_perf = HWP_HIGHEST_PERF(READ_ONCE(all_cpu_data[cpu]->hwp_cap_cached)); in intel_pstate_set_itmt_prio()
366 sched_set_itmt_core_prio(cppc_perf.highest_perf, cpu); in intel_pstate_set_itmt_prio()
387 static int intel_pstate_get_cppc_guaranteed(int cpu) in intel_pstate_get_cppc_guaranteed() argument
392 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_get_cppc_guaranteed()
402 static u32 intel_pstate_cppc_nominal(int cpu) in intel_pstate_cppc_nominal() argument
406 if (cppc_get_nominal_perf(cpu, &nominal_perf)) in intel_pstate_cppc_nominal()
412 static inline void intel_pstate_set_itmt_prio(int cpu) in intel_pstate_set_itmt_prio() argument
419 struct cpudata *cpu; in intel_pstate_init_acpi_perf_limits() local
424 intel_pstate_set_itmt_prio(policy->cpu); in intel_pstate_init_acpi_perf_limits()
431 cpu = all_cpu_data[policy->cpu]; in intel_pstate_init_acpi_perf_limits()
433 ret = acpi_processor_register_performance(&cpu->acpi_perf_data, in intel_pstate_init_acpi_perf_limits()
434 policy->cpu); in intel_pstate_init_acpi_perf_limits()
443 if (cpu->acpi_perf_data.control_register.space_id != in intel_pstate_init_acpi_perf_limits()
451 if (cpu->acpi_perf_data.state_count < 2) in intel_pstate_init_acpi_perf_limits()
454 pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu); in intel_pstate_init_acpi_perf_limits()
455 for (i = 0; i < cpu->acpi_perf_data.state_count; i++) { in intel_pstate_init_acpi_perf_limits()
457 (i == cpu->acpi_perf_data.state ? '*' : ' '), i, in intel_pstate_init_acpi_perf_limits()
458 (u32) cpu->acpi_perf_data.states[i].core_frequency, in intel_pstate_init_acpi_perf_limits()
459 (u32) cpu->acpi_perf_data.states[i].power, in intel_pstate_init_acpi_perf_limits()
460 (u32) cpu->acpi_perf_data.states[i].control); in intel_pstate_init_acpi_perf_limits()
475 cpu->acpi_perf_data.states[0].core_frequency = in intel_pstate_init_acpi_perf_limits()
477 cpu->valid_pss_table = true; in intel_pstate_init_acpi_perf_limits()
483 cpu->valid_pss_table = false; in intel_pstate_init_acpi_perf_limits()
484 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_init_acpi_perf_limits()
489 struct cpudata *cpu; in intel_pstate_exit_perf_limits() local
491 cpu = all_cpu_data[policy->cpu]; in intel_pstate_exit_perf_limits()
492 if (!cpu->valid_pss_table) in intel_pstate_exit_perf_limits()
495 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_exit_perf_limits()
513 static inline int intel_pstate_get_cppc_guaranteed(int cpu) in intel_pstate_get_cppc_guaranteed() argument
530 static void intel_pstate_hybrid_hwp_adjust(struct cpudata *cpu) in intel_pstate_hybrid_hwp_adjust() argument
532 int perf_ctl_max_phys = cpu->pstate.max_pstate_physical; in intel_pstate_hybrid_hwp_adjust()
533 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_hybrid_hwp_adjust()
536 int scaling = cpu->pstate.scaling; in intel_pstate_hybrid_hwp_adjust()
538 pr_debug("CPU%d: perf_ctl_max_phys = %d\n", cpu->cpu, perf_ctl_max_phys); in intel_pstate_hybrid_hwp_adjust()
539 pr_debug("CPU%d: perf_ctl_max = %d\n", cpu->cpu, pstate_funcs.get_max()); in intel_pstate_hybrid_hwp_adjust()
540 pr_debug("CPU%d: perf_ctl_turbo = %d\n", cpu->cpu, perf_ctl_turbo); in intel_pstate_hybrid_hwp_adjust()
541 pr_debug("CPU%d: perf_ctl_scaling = %d\n", cpu->cpu, perf_ctl_scaling); in intel_pstate_hybrid_hwp_adjust()
542 pr_debug("CPU%d: HWP_CAP guaranteed = %d\n", cpu->cpu, cpu->pstate.max_pstate); in intel_pstate_hybrid_hwp_adjust()
543 pr_debug("CPU%d: HWP_CAP highest = %d\n", cpu->cpu, cpu->pstate.turbo_pstate); in intel_pstate_hybrid_hwp_adjust()
544 pr_debug("CPU%d: HWP-to-frequency scaling factor: %d\n", cpu->cpu, scaling); in intel_pstate_hybrid_hwp_adjust()
553 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * scaling; in intel_pstate_hybrid_hwp_adjust()
554 if (turbo_freq < cpu->pstate.turbo_freq) { in intel_pstate_hybrid_hwp_adjust()
555 cpu->pstate.turbo_freq = turbo_freq; in intel_pstate_hybrid_hwp_adjust()
556 scaling = DIV_ROUND_UP(turbo_freq, cpu->pstate.turbo_pstate); in intel_pstate_hybrid_hwp_adjust()
557 cpu->pstate.scaling = scaling; in intel_pstate_hybrid_hwp_adjust()
560 cpu->cpu, scaling); in intel_pstate_hybrid_hwp_adjust()
563 cpu->pstate.max_freq = rounddown(cpu->pstate.max_pstate * scaling, in intel_pstate_hybrid_hwp_adjust()
566 cpu->pstate.max_pstate_physical = in intel_pstate_hybrid_hwp_adjust()
570 cpu->pstate.min_freq = cpu->pstate.min_pstate * perf_ctl_scaling; in intel_pstate_hybrid_hwp_adjust()
575 cpu->pstate.min_pstate = DIV_ROUND_UP(cpu->pstate.min_freq, scaling); in intel_pstate_hybrid_hwp_adjust()
581 struct cpudata *cpu; in update_turbo_state() local
583 cpu = all_cpu_data[0]; in update_turbo_state()
587 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); in update_turbo_state()
592 struct cpudata *cpu = all_cpu_data[0]; in min_perf_pct_min() local
593 int turbo_pstate = cpu->pstate.turbo_pstate; in min_perf_pct_min()
596 (cpu->pstate.min_pstate * 100 / turbo_pstate) : 0; in min_perf_pct_min()
607 ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_get_epb()
624 epp = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, in intel_pstate_get_epp()
638 static int intel_pstate_set_epb(int cpu, s16 pref) in intel_pstate_set_epb() argument
646 ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_set_epb()
651 wrmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, epb); in intel_pstate_set_epb()
720 static int intel_pstate_set_epp(struct cpudata *cpu, u32 epp) in intel_pstate_set_epp() argument
729 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_set_epp()
738 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_set_epp()
739 ret = wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_set_epp()
741 cpu->epp_cached = epp; in intel_pstate_set_epp()
774 ret = intel_pstate_set_epb(cpu_data->cpu, epp); in intel_pstate_set_energy_pref_index()
801 struct cpudata *cpu = all_cpu_data[policy->cpu]; in store_energy_performance_preference() local
837 ret = intel_pstate_set_energy_pref_index(cpu, ret, raw, epp); in store_energy_performance_preference()
846 epp = ret ? epp_values[ret - 1] : cpu->epp_default; in store_energy_performance_preference()
848 if (cpu->epp_cached != epp) { in store_energy_performance_preference()
852 ret = intel_pstate_set_epp(cpu, epp); in store_energy_performance_preference()
867 struct cpudata *cpu_data = all_cpu_data[policy->cpu]; in show_energy_performance_preference()
884 struct cpudata *cpu = all_cpu_data[policy->cpu]; in show_base_frequency() local
887 ratio = intel_pstate_get_cppc_guaranteed(policy->cpu); in show_base_frequency()
891 rdmsrl_on_cpu(policy->cpu, MSR_HWP_CAPABILITIES, &cap); in show_base_frequency()
895 freq = ratio * cpu->pstate.scaling; in show_base_frequency()
896 if (cpu->pstate.scaling != cpu->pstate.perf_ctl_scaling) in show_base_frequency()
897 freq = rounddown(freq, cpu->pstate.perf_ctl_scaling); in show_base_frequency()
911 static void __intel_pstate_get_hwp_cap(struct cpudata *cpu) in __intel_pstate_get_hwp_cap() argument
915 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_CAPABILITIES, &cap); in __intel_pstate_get_hwp_cap()
916 WRITE_ONCE(cpu->hwp_cap_cached, cap); in __intel_pstate_get_hwp_cap()
917 cpu->pstate.max_pstate = HWP_GUARANTEED_PERF(cap); in __intel_pstate_get_hwp_cap()
918 cpu->pstate.turbo_pstate = HWP_HIGHEST_PERF(cap); in __intel_pstate_get_hwp_cap()
921 static void intel_pstate_get_hwp_cap(struct cpudata *cpu) in intel_pstate_get_hwp_cap() argument
923 int scaling = cpu->pstate.scaling; in intel_pstate_get_hwp_cap()
925 __intel_pstate_get_hwp_cap(cpu); in intel_pstate_get_hwp_cap()
927 cpu->pstate.max_freq = cpu->pstate.max_pstate * scaling; in intel_pstate_get_hwp_cap()
928 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * scaling; in intel_pstate_get_hwp_cap()
929 if (scaling != cpu->pstate.perf_ctl_scaling) { in intel_pstate_get_hwp_cap()
930 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_get_hwp_cap()
932 cpu->pstate.max_freq = rounddown(cpu->pstate.max_freq, in intel_pstate_get_hwp_cap()
934 cpu->pstate.turbo_freq = rounddown(cpu->pstate.turbo_freq, in intel_pstate_get_hwp_cap()
939 static void intel_pstate_hwp_set(unsigned int cpu) in intel_pstate_hwp_set() argument
941 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_hwp_set()
952 rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value); in intel_pstate_hwp_set()
995 intel_pstate_set_epb(cpu, epp); in intel_pstate_hwp_set()
999 wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_set()
1004 static void intel_pstate_hwp_offline(struct cpudata *cpu) in intel_pstate_hwp_offline() argument
1006 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_offline()
1009 intel_pstate_disable_hwp_interrupt(cpu); in intel_pstate_hwp_offline()
1018 value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached); in intel_pstate_hwp_offline()
1024 cpu->epp_policy = CPUFREQ_POLICY_UNKNOWN; in intel_pstate_hwp_offline()
1033 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_hwp_offline()
1036 min_perf = HWP_LOWEST_PERF(READ_ONCE(cpu->hwp_cap_cached)); in intel_pstate_hwp_offline()
1046 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_offline()
1073 static void intel_pstate_hwp_reenable(struct cpudata *cpu) in intel_pstate_hwp_reenable() argument
1075 intel_pstate_hwp_enable(cpu); in intel_pstate_hwp_reenable()
1076 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, READ_ONCE(cpu->hwp_req_cached)); in intel_pstate_hwp_reenable()
1081 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_suspend() local
1083 pr_debug("CPU %d suspending\n", cpu->cpu); in intel_pstate_suspend()
1085 cpu->suspended = true; in intel_pstate_suspend()
1088 intel_pstate_disable_hwp_interrupt(cpu); in intel_pstate_suspend()
1095 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_resume() local
1097 pr_debug("CPU %d resuming\n", cpu->cpu); in intel_pstate_resume()
1105 if (cpu->suspended && hwp_active) { in intel_pstate_resume()
1109 intel_pstate_hwp_reenable(cpu); in intel_pstate_resume()
1114 cpu->suspended = false; in intel_pstate_resume()
1121 int cpu; in intel_pstate_update_policies() local
1123 for_each_possible_cpu(cpu) in intel_pstate_update_policies()
1124 cpufreq_update_policy(cpu); in intel_pstate_update_policies()
1127 static void intel_pstate_update_max_freq(unsigned int cpu) in intel_pstate_update_max_freq() argument
1129 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); in intel_pstate_update_max_freq()
1135 cpudata = all_cpu_data[cpu]; in intel_pstate_update_max_freq()
1144 static void intel_pstate_update_limits(unsigned int cpu) in intel_pstate_update_limits() argument
1156 for_each_possible_cpu(cpu) in intel_pstate_update_limits()
1157 intel_pstate_update_max_freq(cpu); in intel_pstate_update_limits()
1159 cpufreq_update_policy(cpu); in intel_pstate_update_limits()
1204 struct cpudata *cpu; in show_turbo_pct() local
1215 cpu = all_cpu_data[0]; in show_turbo_pct()
1217 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1218 no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1230 struct cpudata *cpu; in show_num_pstates() local
1240 cpu = all_cpu_data[0]; in show_num_pstates()
1241 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_num_pstates()
1301 struct cpudata *cpu = all_cpu_data[0]; in store_no_turbo() local
1302 int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate; in store_no_turbo()
1325 struct cpudata *cpu = all_cpu_data[i]; in update_qos_request() local
1339 intel_pstate_get_hwp_cap(cpu); in update_qos_request()
1348 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * perf_pct, 100); in update_qos_request()
1588 cpufreq_update_policy(cpudata->cpu); in intel_pstate_notify_work()
1589 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_STATUS, 0); in intel_pstate_notify_work()
1650 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00); in intel_pstate_disable_hwp_interrupt()
1653 if (cpumask_test_and_clear_cpu(cpudata->cpu, &hwp_intr_enable_mask)) in intel_pstate_disable_hwp_interrupt()
1666 cpumask_set_cpu(cpudata->cpu, &hwp_intr_enable_mask); in intel_pstate_enable_hwp_interrupt()
1670 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x01); in intel_pstate_enable_hwp_interrupt()
1671 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_STATUS, 0); in intel_pstate_enable_hwp_interrupt()
1679 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00); in intel_pstate_hwp_enable()
1681 wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1); in intel_pstate_hwp_enable()
1916 static int hybrid_get_cpu_scaling(int cpu) in hybrid_get_cpu_scaling() argument
1919 intel_pstate_cppc_nominal(cpu)); in hybrid_get_cpu_scaling()
1925 int cpu; in intel_pstate_cppc_set_cpu_scaling() local
1927 for_each_present_cpu(cpu) { in intel_pstate_cppc_set_cpu_scaling()
1928 u32 nominal_perf = intel_pstate_cppc_nominal(cpu); in intel_pstate_cppc_set_cpu_scaling()
1945 static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) in intel_pstate_set_pstate() argument
1947 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_set_pstate()
1948 cpu->pstate.current_pstate = pstate; in intel_pstate_set_pstate()
1954 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_pstate_set_pstate()
1955 pstate_funcs.get_val(cpu, pstate)); in intel_pstate_set_pstate()
1958 static void intel_pstate_set_min_pstate(struct cpudata *cpu) in intel_pstate_set_min_pstate() argument
1960 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); in intel_pstate_set_min_pstate()
1963 static void intel_pstate_max_within_limits(struct cpudata *cpu) in intel_pstate_max_within_limits() argument
1965 int pstate = max(cpu->pstate.min_pstate, cpu->max_perf_ratio); in intel_pstate_max_within_limits()
1968 intel_pstate_set_pstate(cpu, pstate); in intel_pstate_max_within_limits()
1971 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) in intel_pstate_get_cpu_pstates() argument
1976 cpu->pstate.min_pstate = pstate_funcs.get_min(); in intel_pstate_get_cpu_pstates()
1977 cpu->pstate.max_pstate_physical = perf_ctl_max_phys; in intel_pstate_get_cpu_pstates()
1978 cpu->pstate.perf_ctl_scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1981 __intel_pstate_get_hwp_cap(cpu); in intel_pstate_get_cpu_pstates()
1984 cpu->pstate.scaling = pstate_funcs.get_cpu_scaling(cpu->cpu); in intel_pstate_get_cpu_pstates()
1985 if (cpu->pstate.scaling != perf_ctl_scaling) in intel_pstate_get_cpu_pstates()
1986 intel_pstate_hybrid_hwp_adjust(cpu); in intel_pstate_get_cpu_pstates()
1988 cpu->pstate.scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1991 cpu->pstate.scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1992 cpu->pstate.max_pstate = pstate_funcs.get_max(); in intel_pstate_get_cpu_pstates()
1993 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(); in intel_pstate_get_cpu_pstates()
1996 if (cpu->pstate.scaling == perf_ctl_scaling) { in intel_pstate_get_cpu_pstates()
1997 cpu->pstate.min_freq = cpu->pstate.min_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1998 cpu->pstate.max_freq = cpu->pstate.max_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
1999 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
2003 cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift(); in intel_pstate_get_cpu_pstates()
2006 pstate_funcs.get_vid(cpu); in intel_pstate_get_cpu_pstates()
2008 intel_pstate_set_min_pstate(cpu); in intel_pstate_get_cpu_pstates()
2019 static inline void intel_pstate_hwp_boost_up(struct cpudata *cpu) in intel_pstate_hwp_boost_up() argument
2021 u64 hwp_req = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_boost_up()
2022 u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); in intel_pstate_hwp_boost_up()
2042 if (max_limit == min_limit || cpu->hwp_boost_min >= max_limit) in intel_pstate_hwp_boost_up()
2045 if (!cpu->hwp_boost_min) in intel_pstate_hwp_boost_up()
2046 cpu->hwp_boost_min = min_limit; in intel_pstate_hwp_boost_up()
2051 if (cpu->hwp_boost_min < boost_level1) in intel_pstate_hwp_boost_up()
2052 cpu->hwp_boost_min = boost_level1; in intel_pstate_hwp_boost_up()
2053 else if (cpu->hwp_boost_min < HWP_GUARANTEED_PERF(hwp_cap)) in intel_pstate_hwp_boost_up()
2054 cpu->hwp_boost_min = HWP_GUARANTEED_PERF(hwp_cap); in intel_pstate_hwp_boost_up()
2055 else if (cpu->hwp_boost_min == HWP_GUARANTEED_PERF(hwp_cap) && in intel_pstate_hwp_boost_up()
2057 cpu->hwp_boost_min = max_limit; in intel_pstate_hwp_boost_up()
2061 hwp_req = (hwp_req & ~GENMASK_ULL(7, 0)) | cpu->hwp_boost_min; in intel_pstate_hwp_boost_up()
2063 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_up()
2066 static inline void intel_pstate_hwp_boost_down(struct cpudata *cpu) in intel_pstate_hwp_boost_down() argument
2068 if (cpu->hwp_boost_min) { in intel_pstate_hwp_boost_down()
2072 expired = time_after64(cpu->sample.time, cpu->last_update + in intel_pstate_hwp_boost_down()
2075 wrmsrl(MSR_HWP_REQUEST, cpu->hwp_req_cached); in intel_pstate_hwp_boost_down()
2076 cpu->hwp_boost_min = 0; in intel_pstate_hwp_boost_down()
2079 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_down()
2082 static inline void intel_pstate_update_util_hwp_local(struct cpudata *cpu, in intel_pstate_update_util_hwp_local() argument
2085 cpu->sample.time = time; in intel_pstate_update_util_hwp_local()
2087 if (cpu->sched_flags & SCHED_CPUFREQ_IOWAIT) { in intel_pstate_update_util_hwp_local()
2090 cpu->sched_flags = 0; in intel_pstate_update_util_hwp_local()
2098 if (time_before64(time, cpu->last_io_update + 2 * TICK_NSEC)) in intel_pstate_update_util_hwp_local()
2101 cpu->last_io_update = time; in intel_pstate_update_util_hwp_local()
2104 intel_pstate_hwp_boost_up(cpu); in intel_pstate_update_util_hwp_local()
2107 intel_pstate_hwp_boost_down(cpu); in intel_pstate_update_util_hwp_local()
2114 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util_hwp() local
2116 cpu->sched_flags |= flags; in intel_pstate_update_util_hwp()
2118 if (smp_processor_id() == cpu->cpu) in intel_pstate_update_util_hwp()
2119 intel_pstate_update_util_hwp_local(cpu, time); in intel_pstate_update_util_hwp()
2122 static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu) in intel_pstate_calc_avg_perf() argument
2124 struct sample *sample = &cpu->sample; in intel_pstate_calc_avg_perf()
2129 static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time) in intel_pstate_sample() argument
2139 if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) { in intel_pstate_sample()
2145 cpu->last_sample_time = cpu->sample.time; in intel_pstate_sample()
2146 cpu->sample.time = time; in intel_pstate_sample()
2147 cpu->sample.aperf = aperf; in intel_pstate_sample()
2148 cpu->sample.mperf = mperf; in intel_pstate_sample()
2149 cpu->sample.tsc = tsc; in intel_pstate_sample()
2150 cpu->sample.aperf -= cpu->prev_aperf; in intel_pstate_sample()
2151 cpu->sample.mperf -= cpu->prev_mperf; in intel_pstate_sample()
2152 cpu->sample.tsc -= cpu->prev_tsc; in intel_pstate_sample()
2154 cpu->prev_aperf = aperf; in intel_pstate_sample()
2155 cpu->prev_mperf = mperf; in intel_pstate_sample()
2156 cpu->prev_tsc = tsc; in intel_pstate_sample()
2164 if (cpu->last_sample_time) { in intel_pstate_sample()
2165 intel_pstate_calc_avg_perf(cpu); in intel_pstate_sample()
2171 static inline int32_t get_avg_frequency(struct cpudata *cpu) in get_avg_frequency() argument
2173 return mul_ext_fp(cpu->sample.core_avg_perf, cpu_khz); in get_avg_frequency()
2176 static inline int32_t get_avg_pstate(struct cpudata *cpu) in get_avg_pstate() argument
2178 return mul_ext_fp(cpu->pstate.max_pstate_physical, in get_avg_pstate()
2179 cpu->sample.core_avg_perf); in get_avg_pstate()
2182 static inline int32_t get_target_pstate(struct cpudata *cpu) in get_target_pstate() argument
2184 struct sample *sample = &cpu->sample; in get_target_pstate()
2188 busy_frac = div_fp(sample->mperf << cpu->aperf_mperf_shift, in get_target_pstate()
2191 if (busy_frac < cpu->iowait_boost) in get_target_pstate()
2192 busy_frac = cpu->iowait_boost; in get_target_pstate()
2197 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in get_target_pstate()
2200 if (target < cpu->pstate.min_pstate) in get_target_pstate()
2201 target = cpu->pstate.min_pstate; in get_target_pstate()
2210 avg_pstate = get_avg_pstate(cpu); in get_target_pstate()
2217 static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) in intel_pstate_prepare_request() argument
2219 int min_pstate = max(cpu->pstate.min_pstate, cpu->min_perf_ratio); in intel_pstate_prepare_request()
2220 int max_pstate = max(min_pstate, cpu->max_perf_ratio); in intel_pstate_prepare_request()
2225 static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) in intel_pstate_update_pstate() argument
2227 if (pstate == cpu->pstate.current_pstate) in intel_pstate_update_pstate()
2230 cpu->pstate.current_pstate = pstate; in intel_pstate_update_pstate()
2231 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate)); in intel_pstate_update_pstate()
2234 static void intel_pstate_adjust_pstate(struct cpudata *cpu) in intel_pstate_adjust_pstate() argument
2236 int from = cpu->pstate.current_pstate; in intel_pstate_adjust_pstate()
2242 target_pstate = get_target_pstate(cpu); in intel_pstate_adjust_pstate()
2243 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_pstate_adjust_pstate()
2244 trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_adjust_pstate()
2245 intel_pstate_update_pstate(cpu, target_pstate); in intel_pstate_adjust_pstate()
2247 sample = &cpu->sample; in intel_pstate_adjust_pstate()
2251 cpu->pstate.current_pstate, in intel_pstate_adjust_pstate()
2255 get_avg_frequency(cpu), in intel_pstate_adjust_pstate()
2256 fp_toint(cpu->iowait_boost * 100)); in intel_pstate_adjust_pstate()
2262 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util() local
2266 if (smp_processor_id() != cpu->cpu) in intel_pstate_update_util()
2269 delta_ns = time - cpu->last_update; in intel_pstate_update_util()
2273 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2274 } else if (cpu->iowait_boost >= ONE_EIGHTH_FP) { in intel_pstate_update_util()
2275 cpu->iowait_boost <<= 1; in intel_pstate_update_util()
2276 if (cpu->iowait_boost > int_tofp(1)) in intel_pstate_update_util()
2277 cpu->iowait_boost = int_tofp(1); in intel_pstate_update_util()
2279 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2281 } else if (cpu->iowait_boost) { in intel_pstate_update_util()
2284 cpu->iowait_boost = 0; in intel_pstate_update_util()
2286 cpu->iowait_boost >>= 1; in intel_pstate_update_util()
2288 cpu->last_update = time; in intel_pstate_update_util()
2289 delta_ns = time - cpu->sample.time; in intel_pstate_update_util()
2293 if (intel_pstate_sample(cpu, time)) in intel_pstate_update_util()
2294 intel_pstate_adjust_pstate(cpu); in intel_pstate_update_util()
2389 struct cpudata *cpu; in intel_pstate_init_cpu() local
2391 cpu = all_cpu_data[cpunum]; in intel_pstate_init_cpu()
2393 if (!cpu) { in intel_pstate_init_cpu()
2394 cpu = kzalloc(sizeof(*cpu), GFP_KERNEL); in intel_pstate_init_cpu()
2395 if (!cpu) in intel_pstate_init_cpu()
2398 WRITE_ONCE(all_cpu_data[cpunum], cpu); in intel_pstate_init_cpu()
2400 cpu->cpu = cpunum; in intel_pstate_init_cpu()
2402 cpu->epp_default = -EINVAL; in intel_pstate_init_cpu()
2407 intel_pstate_hwp_enable(cpu); in intel_pstate_init_cpu()
2419 intel_pstate_hwp_reenable(cpu); in intel_pstate_init_cpu()
2422 cpu->epp_powersave = -EINVAL; in intel_pstate_init_cpu()
2423 cpu->epp_policy = 0; in intel_pstate_init_cpu()
2425 intel_pstate_get_cpu_pstates(cpu); in intel_pstate_init_cpu()
2434 struct cpudata *cpu = all_cpu_data[cpu_num]; in intel_pstate_set_update_util_hook() local
2439 if (cpu->update_util_set) in intel_pstate_set_update_util_hook()
2443 cpu->sample.time = 0; in intel_pstate_set_update_util_hook()
2444 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, in intel_pstate_set_update_util_hook()
2448 cpu->update_util_set = true; in intel_pstate_set_update_util_hook()
2451 static void intel_pstate_clear_update_util_hook(unsigned int cpu) in intel_pstate_clear_update_util_hook() argument
2453 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_clear_update_util_hook()
2458 cpufreq_remove_update_util_hook(cpu); in intel_pstate_clear_update_util_hook()
2463 static int intel_pstate_get_max_freq(struct cpudata *cpu) in intel_pstate_get_max_freq() argument
2466 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_get_max_freq()
2469 static void intel_pstate_update_perf_limits(struct cpudata *cpu, in intel_pstate_update_perf_limits() argument
2473 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_update_perf_limits()
2490 intel_pstate_get_hwp_cap(cpu); in intel_pstate_update_perf_limits()
2492 if (cpu->pstate.scaling != perf_ctl_scaling) { in intel_pstate_update_perf_limits()
2493 int scaling = cpu->pstate.scaling; in intel_pstate_update_perf_limits()
2504 cpu->cpu, min_policy_perf, max_policy_perf); in intel_pstate_update_perf_limits()
2508 cpu->min_perf_ratio = min_policy_perf; in intel_pstate_update_perf_limits()
2509 cpu->max_perf_ratio = max_policy_perf; in intel_pstate_update_perf_limits()
2511 int turbo_max = cpu->pstate.turbo_pstate; in intel_pstate_update_perf_limits()
2519 pr_debug("cpu:%d global_min:%d global_max:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2522 cpu->min_perf_ratio = max(min_policy_perf, global_min); in intel_pstate_update_perf_limits()
2523 cpu->min_perf_ratio = min(cpu->min_perf_ratio, max_policy_perf); in intel_pstate_update_perf_limits()
2524 cpu->max_perf_ratio = min(max_policy_perf, global_max); in intel_pstate_update_perf_limits()
2525 cpu->max_perf_ratio = max(min_policy_perf, cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2528 cpu->min_perf_ratio = min(cpu->min_perf_ratio, in intel_pstate_update_perf_limits()
2529 cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2532 pr_debug("cpu:%d max_perf_ratio:%d min_perf_ratio:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2533 cpu->max_perf_ratio, in intel_pstate_update_perf_limits()
2534 cpu->min_perf_ratio); in intel_pstate_update_perf_limits()
2539 struct cpudata *cpu; in intel_pstate_set_policy() local
2547 cpu = all_cpu_data[policy->cpu]; in intel_pstate_set_policy()
2548 cpu->policy = policy->policy; in intel_pstate_set_policy()
2552 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_pstate_set_policy()
2554 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { in intel_pstate_set_policy()
2559 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2560 intel_pstate_max_within_limits(cpu); in intel_pstate_set_policy()
2562 intel_pstate_set_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2572 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2573 intel_pstate_hwp_set(policy->cpu); in intel_pstate_set_policy()
2581 static void intel_pstate_adjust_policy_max(struct cpudata *cpu, in intel_pstate_adjust_policy_max() argument
2585 cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && in intel_pstate_adjust_policy_max()
2587 policy->max > cpu->pstate.max_freq) { in intel_pstate_adjust_policy_max()
2593 static void intel_pstate_verify_cpu_policy(struct cpudata *cpu, in intel_pstate_verify_cpu_policy() argument
2600 intel_pstate_get_hwp_cap(cpu); in intel_pstate_verify_cpu_policy()
2602 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_verify_cpu_policy()
2604 max_freq = intel_pstate_get_max_freq(cpu); in intel_pstate_verify_cpu_policy()
2608 intel_pstate_adjust_policy_max(cpu, policy); in intel_pstate_verify_cpu_policy()
2613 intel_pstate_verify_cpu_policy(all_cpu_data[policy->cpu], policy); in intel_pstate_verify_policy()
2620 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_offline() local
2622 pr_debug("CPU %d going offline\n", cpu->cpu); in intel_cpufreq_cpu_offline()
2624 if (cpu->suspended) in intel_cpufreq_cpu_offline()
2634 intel_pstate_hwp_offline(cpu); in intel_cpufreq_cpu_offline()
2636 intel_pstate_set_min_pstate(cpu); in intel_cpufreq_cpu_offline()
2645 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_online() local
2647 pr_debug("CPU %d going online\n", cpu->cpu); in intel_pstate_cpu_online()
2656 intel_pstate_hwp_reenable(cpu); in intel_pstate_cpu_online()
2657 cpu->suspended = false; in intel_pstate_cpu_online()
2665 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_cpu_offline()
2672 pr_debug("CPU %d exiting\n", policy->cpu); in intel_pstate_cpu_exit()
2681 struct cpudata *cpu; in __intel_pstate_cpu_init() local
2684 rc = intel_pstate_init_cpu(policy->cpu); in __intel_pstate_cpu_init()
2688 cpu = all_cpu_data[policy->cpu]; in __intel_pstate_cpu_init()
2690 cpu->max_perf_ratio = 0xFF; in __intel_pstate_cpu_init()
2691 cpu->min_perf_ratio = 0; in __intel_pstate_cpu_init()
2694 policy->cpuinfo.min_freq = cpu->pstate.min_freq; in __intel_pstate_cpu_init()
2698 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in __intel_pstate_cpu_init()
2724 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_init() local
2726 cpu->epp_cached = intel_pstate_get_epp(cpu, 0); in intel_pstate_cpu_init()
2748 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_verify_policy() local
2750 intel_pstate_verify_cpu_policy(cpu, policy); in intel_cpufreq_verify_policy()
2751 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_cpufreq_verify_policy()
2772 static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, int old_pstate) in intel_cpufreq_trace() argument
2779 if (!intel_pstate_sample(cpu, ktime_get())) in intel_cpufreq_trace()
2782 sample = &cpu->sample; in intel_cpufreq_trace()
2786 cpu->pstate.current_pstate, in intel_cpufreq_trace()
2790 get_avg_frequency(cpu), in intel_cpufreq_trace()
2791 fp_toint(cpu->iowait_boost * 100)); in intel_cpufreq_trace()
2794 static void intel_cpufreq_hwp_update(struct cpudata *cpu, u32 min, u32 max, in intel_cpufreq_hwp_update() argument
2797 u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev; in intel_cpufreq_hwp_update()
2811 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_hwp_update()
2815 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_cpufreq_hwp_update()
2818 static void intel_cpufreq_perf_ctl_update(struct cpudata *cpu, in intel_cpufreq_perf_ctl_update() argument
2823 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_perf_ctl_update()
2825 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_cpufreq_perf_ctl_update()
2826 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_perf_ctl_update()
2832 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_update_pstate() local
2833 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_update_pstate()
2835 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_cpufreq_update_pstate()
2838 target_pstate : cpu->max_perf_ratio; in intel_cpufreq_update_pstate()
2840 intel_cpufreq_hwp_update(cpu, target_pstate, max_pstate, 0, in intel_cpufreq_update_pstate()
2843 intel_cpufreq_perf_ctl_update(cpu, target_pstate, fast_switch); in intel_cpufreq_update_pstate()
2846 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2848 intel_cpufreq_trace(cpu, fast_switch ? INTEL_PSTATE_TRACE_FAST_SWITCH : in intel_cpufreq_update_pstate()
2858 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_target() local
2871 target_pstate = DIV_ROUND_UP(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2874 target_pstate = freqs.new / cpu->pstate.scaling; in intel_cpufreq_target()
2877 target_pstate = DIV_ROUND_CLOSEST(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2883 freqs.new = target_pstate * cpu->pstate.scaling; in intel_cpufreq_target()
2893 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_fast_switch() local
2898 target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); in intel_cpufreq_fast_switch()
2902 return target_pstate * cpu->pstate.scaling; in intel_cpufreq_fast_switch()
2910 struct cpudata *cpu = all_cpu_data[cpunum]; in intel_cpufreq_adjust_perf() local
2911 u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); in intel_cpufreq_adjust_perf()
2912 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_adjust_perf()
2929 if (min_pstate < cpu->pstate.min_pstate) in intel_cpufreq_adjust_perf()
2930 min_pstate = cpu->pstate.min_pstate; in intel_cpufreq_adjust_perf()
2932 if (min_pstate < cpu->min_perf_ratio) in intel_cpufreq_adjust_perf()
2933 min_pstate = cpu->min_perf_ratio; in intel_cpufreq_adjust_perf()
2935 max_pstate = min(cap_pstate, cpu->max_perf_ratio); in intel_cpufreq_adjust_perf()
2941 intel_cpufreq_hwp_update(cpu, min_pstate, max_pstate, target_pstate, true); in intel_cpufreq_adjust_perf()
2943 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_adjust_perf()
2944 intel_cpufreq_trace(cpu, INTEL_PSTATE_TRACE_FAST_SWITCH, old_pstate); in intel_cpufreq_adjust_perf()
2950 struct cpudata *cpu; in intel_cpufreq_cpu_init() local
2954 dev = get_cpu_device(policy->cpu); in intel_cpufreq_cpu_init()
2972 cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_init()
2979 intel_pstate_get_hwp_cap(cpu); in intel_cpufreq_cpu_init()
2981 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, &value); in intel_cpufreq_cpu_init()
2982 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_cpu_init()
2984 cpu->epp_cached = intel_pstate_get_epp(cpu, value); in intel_cpufreq_cpu_init()
2989 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * global.min_perf_pct, 100); in intel_cpufreq_cpu_init()
2998 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * global.max_perf_pct, 100); in intel_cpufreq_cpu_init()
3039 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_suspend() local
3040 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_cpufreq_suspend()
3048 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_cpufreq_suspend()
3049 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_suspend()
3074 unsigned int cpu; in intel_pstate_driver_cleanup() local
3077 for_each_online_cpu(cpu) { in intel_pstate_driver_cleanup()
3078 if (all_cpu_data[cpu]) { in intel_pstate_driver_cleanup()
3080 intel_pstate_clear_update_util_hook(cpu); in intel_pstate_driver_cleanup()
3083 kfree(all_cpu_data[cpu]); in intel_pstate_driver_cleanup()
3084 WRITE_ONCE(all_cpu_data[cpu], NULL); in intel_pstate_driver_cleanup()