Lines Matching refs:cpu

229 	int cpu;  member
284 int (*get_max)(int cpu);
285 int (*get_max_physical)(int cpu);
286 int (*get_min)(int cpu);
287 int (*get_turbo)(int cpu);
289 int (*get_cpu_scaling)(int cpu);
352 static void intel_pstate_set_itmt_prio(int cpu) in intel_pstate_set_itmt_prio() argument
358 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_set_itmt_prio()
368 cppc_perf.highest_perf = HWP_HIGHEST_PERF(READ_ONCE(all_cpu_data[cpu]->hwp_cap_cached)); in intel_pstate_set_itmt_prio()
375 sched_set_itmt_core_prio(cppc_perf.highest_perf, cpu); in intel_pstate_set_itmt_prio()
396 static int intel_pstate_get_cppc_guaranteed(int cpu) in intel_pstate_get_cppc_guaranteed() argument
401 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_get_cppc_guaranteed()
411 static int intel_pstate_cppc_get_scaling(int cpu) in intel_pstate_cppc_get_scaling() argument
416 ret = cppc_get_perf_caps(cpu, &cppc_perf); in intel_pstate_cppc_get_scaling()
431 static inline void intel_pstate_set_itmt_prio(int cpu) in intel_pstate_set_itmt_prio() argument
438 struct cpudata *cpu; in intel_pstate_init_acpi_perf_limits() local
443 intel_pstate_set_itmt_prio(policy->cpu); in intel_pstate_init_acpi_perf_limits()
450 cpu = all_cpu_data[policy->cpu]; in intel_pstate_init_acpi_perf_limits()
452 ret = acpi_processor_register_performance(&cpu->acpi_perf_data, in intel_pstate_init_acpi_perf_limits()
453 policy->cpu); in intel_pstate_init_acpi_perf_limits()
462 if (cpu->acpi_perf_data.control_register.space_id != in intel_pstate_init_acpi_perf_limits()
470 if (cpu->acpi_perf_data.state_count < 2) in intel_pstate_init_acpi_perf_limits()
473 pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu); in intel_pstate_init_acpi_perf_limits()
474 for (i = 0; i < cpu->acpi_perf_data.state_count; i++) { in intel_pstate_init_acpi_perf_limits()
476 (i == cpu->acpi_perf_data.state ? '*' : ' '), i, in intel_pstate_init_acpi_perf_limits()
477 (u32) cpu->acpi_perf_data.states[i].core_frequency, in intel_pstate_init_acpi_perf_limits()
478 (u32) cpu->acpi_perf_data.states[i].power, in intel_pstate_init_acpi_perf_limits()
479 (u32) cpu->acpi_perf_data.states[i].control); in intel_pstate_init_acpi_perf_limits()
482 cpu->valid_pss_table = true; in intel_pstate_init_acpi_perf_limits()
488 cpu->valid_pss_table = false; in intel_pstate_init_acpi_perf_limits()
489 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_init_acpi_perf_limits()
494 struct cpudata *cpu; in intel_pstate_exit_perf_limits() local
496 cpu = all_cpu_data[policy->cpu]; in intel_pstate_exit_perf_limits()
497 if (!cpu->valid_pss_table) in intel_pstate_exit_perf_limits()
500 acpi_processor_unregister_performance(policy->cpu); in intel_pstate_exit_perf_limits()
518 static inline int intel_pstate_get_cppc_guaranteed(int cpu) in intel_pstate_get_cppc_guaranteed() argument
523 static int intel_pstate_cppc_get_scaling(int cpu) in intel_pstate_cppc_get_scaling() argument
540 static void intel_pstate_hybrid_hwp_adjust(struct cpudata *cpu) in intel_pstate_hybrid_hwp_adjust() argument
542 int perf_ctl_max_phys = cpu->pstate.max_pstate_physical; in intel_pstate_hybrid_hwp_adjust()
543 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_hybrid_hwp_adjust()
544 int perf_ctl_turbo = pstate_funcs.get_turbo(cpu->cpu); in intel_pstate_hybrid_hwp_adjust()
545 int scaling = cpu->pstate.scaling; in intel_pstate_hybrid_hwp_adjust()
547 pr_debug("CPU%d: perf_ctl_max_phys = %d\n", cpu->cpu, perf_ctl_max_phys); in intel_pstate_hybrid_hwp_adjust()
548 pr_debug("CPU%d: perf_ctl_turbo = %d\n", cpu->cpu, perf_ctl_turbo); in intel_pstate_hybrid_hwp_adjust()
549 pr_debug("CPU%d: perf_ctl_scaling = %d\n", cpu->cpu, perf_ctl_scaling); in intel_pstate_hybrid_hwp_adjust()
550 pr_debug("CPU%d: HWP_CAP guaranteed = %d\n", cpu->cpu, cpu->pstate.max_pstate); in intel_pstate_hybrid_hwp_adjust()
551 pr_debug("CPU%d: HWP_CAP highest = %d\n", cpu->cpu, cpu->pstate.turbo_pstate); in intel_pstate_hybrid_hwp_adjust()
552 pr_debug("CPU%d: HWP-to-frequency scaling factor: %d\n", cpu->cpu, scaling); in intel_pstate_hybrid_hwp_adjust()
554 cpu->pstate.turbo_freq = rounddown(cpu->pstate.turbo_pstate * scaling, in intel_pstate_hybrid_hwp_adjust()
556 cpu->pstate.max_freq = rounddown(cpu->pstate.max_pstate * scaling, in intel_pstate_hybrid_hwp_adjust()
559 cpu->pstate.max_pstate_physical = in intel_pstate_hybrid_hwp_adjust()
563 cpu->pstate.min_freq = cpu->pstate.min_pstate * perf_ctl_scaling; in intel_pstate_hybrid_hwp_adjust()
568 cpu->pstate.min_pstate = DIV_ROUND_UP(cpu->pstate.min_freq, scaling); in intel_pstate_hybrid_hwp_adjust()
574 struct cpudata *cpu; in update_turbo_state() local
576 cpu = all_cpu_data[0]; in update_turbo_state()
580 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); in update_turbo_state()
585 struct cpudata *cpu = all_cpu_data[0]; in min_perf_pct_min() local
586 int turbo_pstate = cpu->pstate.turbo_pstate; in min_perf_pct_min()
589 (cpu->pstate.min_pstate * 100 / turbo_pstate) : 0; in min_perf_pct_min()
600 ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_get_epb()
617 epp = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, in intel_pstate_get_epp()
631 static int intel_pstate_set_epb(int cpu, s16 pref) in intel_pstate_set_epb() argument
639 ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); in intel_pstate_set_epb()
644 wrmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, epb); in intel_pstate_set_epb()
723 static int intel_pstate_set_epp(struct cpudata *cpu, u32 epp) in intel_pstate_set_epp() argument
732 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_set_epp()
741 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_set_epp()
742 ret = wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_set_epp()
744 cpu->epp_cached = epp; in intel_pstate_set_epp()
777 ret = intel_pstate_set_epb(cpu_data->cpu, epp); in intel_pstate_set_energy_pref_index()
804 struct cpudata *cpu = all_cpu_data[policy->cpu]; in store_energy_performance_preference() local
840 ret = intel_pstate_set_energy_pref_index(cpu, ret, raw, epp); in store_energy_performance_preference()
849 epp = ret ? epp_values[ret] : cpu->epp_default; in store_energy_performance_preference()
851 if (cpu->epp_cached != epp) { in store_energy_performance_preference()
855 ret = intel_pstate_set_epp(cpu, epp); in store_energy_performance_preference()
872 struct cpudata *cpu_data = all_cpu_data[policy->cpu]; in show_energy_performance_preference()
889 struct cpudata *cpu = all_cpu_data[policy->cpu]; in show_base_frequency() local
892 ratio = intel_pstate_get_cppc_guaranteed(policy->cpu); in show_base_frequency()
896 rdmsrl_on_cpu(policy->cpu, MSR_HWP_CAPABILITIES, &cap); in show_base_frequency()
900 freq = ratio * cpu->pstate.scaling; in show_base_frequency()
901 if (cpu->pstate.scaling != cpu->pstate.perf_ctl_scaling) in show_base_frequency()
902 freq = rounddown(freq, cpu->pstate.perf_ctl_scaling); in show_base_frequency()
916 static void __intel_pstate_get_hwp_cap(struct cpudata *cpu) in __intel_pstate_get_hwp_cap() argument
920 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_CAPABILITIES, &cap); in __intel_pstate_get_hwp_cap()
921 WRITE_ONCE(cpu->hwp_cap_cached, cap); in __intel_pstate_get_hwp_cap()
922 cpu->pstate.max_pstate = HWP_GUARANTEED_PERF(cap); in __intel_pstate_get_hwp_cap()
923 cpu->pstate.turbo_pstate = HWP_HIGHEST_PERF(cap); in __intel_pstate_get_hwp_cap()
926 static void intel_pstate_get_hwp_cap(struct cpudata *cpu) in intel_pstate_get_hwp_cap() argument
928 int scaling = cpu->pstate.scaling; in intel_pstate_get_hwp_cap()
930 __intel_pstate_get_hwp_cap(cpu); in intel_pstate_get_hwp_cap()
932 cpu->pstate.max_freq = cpu->pstate.max_pstate * scaling; in intel_pstate_get_hwp_cap()
933 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * scaling; in intel_pstate_get_hwp_cap()
934 if (scaling != cpu->pstate.perf_ctl_scaling) { in intel_pstate_get_hwp_cap()
935 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_get_hwp_cap()
937 cpu->pstate.max_freq = rounddown(cpu->pstate.max_freq, in intel_pstate_get_hwp_cap()
939 cpu->pstate.turbo_freq = rounddown(cpu->pstate.turbo_freq, in intel_pstate_get_hwp_cap()
944 static void intel_pstate_hwp_set(unsigned int cpu) in intel_pstate_hwp_set() argument
946 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_hwp_set()
957 rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value); in intel_pstate_hwp_set()
1000 intel_pstate_set_epb(cpu, epp); in intel_pstate_hwp_set()
1004 wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_set()
1009 static void intel_pstate_hwp_offline(struct cpudata *cpu) in intel_pstate_hwp_offline() argument
1011 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_offline()
1014 intel_pstate_disable_hwp_interrupt(cpu); in intel_pstate_hwp_offline()
1023 value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached); in intel_pstate_hwp_offline()
1029 cpu->epp_policy = CPUFREQ_POLICY_UNKNOWN; in intel_pstate_hwp_offline()
1038 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_pstate_hwp_offline()
1041 min_perf = HWP_LOWEST_PERF(READ_ONCE(cpu->hwp_cap_cached)); in intel_pstate_hwp_offline()
1051 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_offline()
1078 static void intel_pstate_hwp_reenable(struct cpudata *cpu) in intel_pstate_hwp_reenable() argument
1080 intel_pstate_hwp_enable(cpu); in intel_pstate_hwp_reenable()
1081 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, READ_ONCE(cpu->hwp_req_cached)); in intel_pstate_hwp_reenable()
1086 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_suspend() local
1088 pr_debug("CPU %d suspending\n", cpu->cpu); in intel_pstate_suspend()
1090 cpu->suspended = true; in intel_pstate_suspend()
1093 intel_pstate_disable_hwp_interrupt(cpu); in intel_pstate_suspend()
1100 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_resume() local
1102 pr_debug("CPU %d resuming\n", cpu->cpu); in intel_pstate_resume()
1110 if (cpu->suspended && hwp_active) { in intel_pstate_resume()
1114 intel_pstate_hwp_reenable(cpu); in intel_pstate_resume()
1119 cpu->suspended = false; in intel_pstate_resume()
1126 int cpu; in intel_pstate_update_policies() local
1128 for_each_possible_cpu(cpu) in intel_pstate_update_policies()
1129 cpufreq_update_policy(cpu); in intel_pstate_update_policies()
1140 static void intel_pstate_update_max_freq(unsigned int cpu) in intel_pstate_update_max_freq() argument
1142 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); in intel_pstate_update_max_freq()
1147 __intel_pstate_update_max_freq(all_cpu_data[cpu], policy); in intel_pstate_update_max_freq()
1152 static void intel_pstate_update_limits(unsigned int cpu) in intel_pstate_update_limits() argument
1164 for_each_possible_cpu(cpu) in intel_pstate_update_limits()
1165 intel_pstate_update_max_freq(cpu); in intel_pstate_update_limits()
1167 cpufreq_update_policy(cpu); in intel_pstate_update_limits()
1212 struct cpudata *cpu; in show_turbo_pct() local
1223 cpu = all_cpu_data[0]; in show_turbo_pct()
1225 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1226 no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1; in show_turbo_pct()
1238 struct cpudata *cpu; in show_num_pstates() local
1248 cpu = all_cpu_data[0]; in show_num_pstates()
1249 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_num_pstates()
1309 struct cpudata *cpu = all_cpu_data[0]; in store_no_turbo() local
1310 int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate; in store_no_turbo()
1334 struct cpudata *cpu = all_cpu_data[i]; in update_qos_request() local
1348 intel_pstate_get_hwp_cap(cpu); in update_qos_request()
1357 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * perf_pct, 100); in update_qos_request()
1599 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpudata->cpu); in intel_pstate_notify_work()
1608 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_STATUS, 0); in intel_pstate_notify_work()
1669 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00); in intel_pstate_disable_hwp_interrupt()
1672 if (cpumask_test_and_clear_cpu(cpudata->cpu, &hwp_intr_enable_mask)) in intel_pstate_disable_hwp_interrupt()
1685 cpumask_set_cpu(cpudata->cpu, &hwp_intr_enable_mask); in intel_pstate_enable_hwp_interrupt()
1689 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x01); in intel_pstate_enable_hwp_interrupt()
1690 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_STATUS, 0); in intel_pstate_enable_hwp_interrupt()
1729 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00); in intel_pstate_hwp_enable()
1731 wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1); in intel_pstate_hwp_enable()
1835 static int core_get_min_pstate(int cpu) in core_get_min_pstate() argument
1839 rdmsrl_on_cpu(cpu, MSR_PLATFORM_INFO, &value); in core_get_min_pstate()
1843 static int core_get_max_pstate_physical(int cpu) in core_get_max_pstate_physical() argument
1847 rdmsrl_on_cpu(cpu, MSR_PLATFORM_INFO, &value); in core_get_max_pstate_physical()
1851 static int core_get_tdp_ratio(int cpu, u64 plat_info) in core_get_tdp_ratio() argument
1861 err = rdmsrl_safe_on_cpu(cpu, MSR_CONFIG_TDP_CONTROL, &tdp_ctrl); in core_get_tdp_ratio()
1867 err = rdmsrl_safe_on_cpu(cpu, tdp_msr, &tdp_ratio); in core_get_tdp_ratio()
1884 static int core_get_max_pstate(int cpu) in core_get_max_pstate() argument
1892 rdmsrl_on_cpu(cpu, MSR_PLATFORM_INFO, &plat_info); in core_get_max_pstate()
1895 tdp_ratio = core_get_tdp_ratio(cpu, plat_info); in core_get_max_pstate()
1904 err = rdmsrl_safe_on_cpu(cpu, MSR_TURBO_ACTIVATION_RATIO, &tar); in core_get_max_pstate()
1919 static int core_get_turbo_pstate(int cpu) in core_get_turbo_pstate() argument
1924 rdmsrl_on_cpu(cpu, MSR_TURBO_RATIO_LIMIT, &value); in core_get_turbo_pstate()
1925 nont = core_get_max_pstate(cpu); in core_get_turbo_pstate()
1948 static int knl_get_turbo_pstate(int cpu) in knl_get_turbo_pstate() argument
1953 rdmsrl_on_cpu(cpu, MSR_TURBO_RATIO_LIMIT, &value); in knl_get_turbo_pstate()
1954 nont = core_get_max_pstate(cpu); in knl_get_turbo_pstate()
1968 static int hwp_get_cpu_scaling(int cpu) in hwp_get_cpu_scaling() argument
1972 smp_call_function_single(cpu, hybrid_get_type, &cpu_type, 1); in hwp_get_cpu_scaling()
1989 return intel_pstate_cppc_get_scaling(cpu); in hwp_get_cpu_scaling()
1992 static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) in intel_pstate_set_pstate() argument
1994 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_set_pstate()
1995 cpu->pstate.current_pstate = pstate; in intel_pstate_set_pstate()
2001 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_pstate_set_pstate()
2002 pstate_funcs.get_val(cpu, pstate)); in intel_pstate_set_pstate()
2005 static void intel_pstate_set_min_pstate(struct cpudata *cpu) in intel_pstate_set_min_pstate() argument
2007 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); in intel_pstate_set_min_pstate()
2010 static void intel_pstate_max_within_limits(struct cpudata *cpu) in intel_pstate_max_within_limits() argument
2012 int pstate = max(cpu->pstate.min_pstate, cpu->max_perf_ratio); in intel_pstate_max_within_limits()
2015 intel_pstate_set_pstate(cpu, pstate); in intel_pstate_max_within_limits()
2018 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) in intel_pstate_get_cpu_pstates() argument
2020 int perf_ctl_max_phys = pstate_funcs.get_max_physical(cpu->cpu); in intel_pstate_get_cpu_pstates()
2023 cpu->pstate.min_pstate = pstate_funcs.get_min(cpu->cpu); in intel_pstate_get_cpu_pstates()
2024 cpu->pstate.max_pstate_physical = perf_ctl_max_phys; in intel_pstate_get_cpu_pstates()
2025 cpu->pstate.perf_ctl_scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
2028 __intel_pstate_get_hwp_cap(cpu); in intel_pstate_get_cpu_pstates()
2031 cpu->pstate.scaling = pstate_funcs.get_cpu_scaling(cpu->cpu); in intel_pstate_get_cpu_pstates()
2032 if (cpu->pstate.scaling != perf_ctl_scaling) in intel_pstate_get_cpu_pstates()
2033 intel_pstate_hybrid_hwp_adjust(cpu); in intel_pstate_get_cpu_pstates()
2035 cpu->pstate.scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
2038 cpu->pstate.scaling = perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
2039 cpu->pstate.max_pstate = pstate_funcs.get_max(cpu->cpu); in intel_pstate_get_cpu_pstates()
2040 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(cpu->cpu); in intel_pstate_get_cpu_pstates()
2043 if (cpu->pstate.scaling == perf_ctl_scaling) { in intel_pstate_get_cpu_pstates()
2044 cpu->pstate.min_freq = cpu->pstate.min_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
2045 cpu->pstate.max_freq = cpu->pstate.max_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
2046 cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * perf_ctl_scaling; in intel_pstate_get_cpu_pstates()
2050 cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift(); in intel_pstate_get_cpu_pstates()
2053 pstate_funcs.get_vid(cpu); in intel_pstate_get_cpu_pstates()
2055 intel_pstate_set_min_pstate(cpu); in intel_pstate_get_cpu_pstates()
2066 static inline void intel_pstate_hwp_boost_up(struct cpudata *cpu) in intel_pstate_hwp_boost_up() argument
2068 u64 hwp_req = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_boost_up()
2069 u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); in intel_pstate_hwp_boost_up()
2089 if (max_limit == min_limit || cpu->hwp_boost_min >= max_limit) in intel_pstate_hwp_boost_up()
2092 if (!cpu->hwp_boost_min) in intel_pstate_hwp_boost_up()
2093 cpu->hwp_boost_min = min_limit; in intel_pstate_hwp_boost_up()
2098 if (cpu->hwp_boost_min < boost_level1) in intel_pstate_hwp_boost_up()
2099 cpu->hwp_boost_min = boost_level1; in intel_pstate_hwp_boost_up()
2100 else if (cpu->hwp_boost_min < HWP_GUARANTEED_PERF(hwp_cap)) in intel_pstate_hwp_boost_up()
2101 cpu->hwp_boost_min = HWP_GUARANTEED_PERF(hwp_cap); in intel_pstate_hwp_boost_up()
2102 else if (cpu->hwp_boost_min == HWP_GUARANTEED_PERF(hwp_cap) && in intel_pstate_hwp_boost_up()
2104 cpu->hwp_boost_min = max_limit; in intel_pstate_hwp_boost_up()
2108 hwp_req = (hwp_req & ~GENMASK_ULL(7, 0)) | cpu->hwp_boost_min; in intel_pstate_hwp_boost_up()
2110 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_up()
2113 static inline void intel_pstate_hwp_boost_down(struct cpudata *cpu) in intel_pstate_hwp_boost_down() argument
2115 if (cpu->hwp_boost_min) { in intel_pstate_hwp_boost_down()
2119 expired = time_after64(cpu->sample.time, cpu->last_update + in intel_pstate_hwp_boost_down()
2122 wrmsrl(MSR_HWP_REQUEST, cpu->hwp_req_cached); in intel_pstate_hwp_boost_down()
2123 cpu->hwp_boost_min = 0; in intel_pstate_hwp_boost_down()
2126 cpu->last_update = cpu->sample.time; in intel_pstate_hwp_boost_down()
2129 static inline void intel_pstate_update_util_hwp_local(struct cpudata *cpu, in intel_pstate_update_util_hwp_local() argument
2132 cpu->sample.time = time; in intel_pstate_update_util_hwp_local()
2134 if (cpu->sched_flags & SCHED_CPUFREQ_IOWAIT) { in intel_pstate_update_util_hwp_local()
2137 cpu->sched_flags = 0; in intel_pstate_update_util_hwp_local()
2145 if (time_before64(time, cpu->last_io_update + 2 * TICK_NSEC)) in intel_pstate_update_util_hwp_local()
2148 cpu->last_io_update = time; in intel_pstate_update_util_hwp_local()
2151 intel_pstate_hwp_boost_up(cpu); in intel_pstate_update_util_hwp_local()
2154 intel_pstate_hwp_boost_down(cpu); in intel_pstate_update_util_hwp_local()
2161 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util_hwp() local
2163 cpu->sched_flags |= flags; in intel_pstate_update_util_hwp()
2165 if (smp_processor_id() == cpu->cpu) in intel_pstate_update_util_hwp()
2166 intel_pstate_update_util_hwp_local(cpu, time); in intel_pstate_update_util_hwp()
2169 static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu) in intel_pstate_calc_avg_perf() argument
2171 struct sample *sample = &cpu->sample; in intel_pstate_calc_avg_perf()
2176 static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time) in intel_pstate_sample() argument
2186 if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) { in intel_pstate_sample()
2192 cpu->last_sample_time = cpu->sample.time; in intel_pstate_sample()
2193 cpu->sample.time = time; in intel_pstate_sample()
2194 cpu->sample.aperf = aperf; in intel_pstate_sample()
2195 cpu->sample.mperf = mperf; in intel_pstate_sample()
2196 cpu->sample.tsc = tsc; in intel_pstate_sample()
2197 cpu->sample.aperf -= cpu->prev_aperf; in intel_pstate_sample()
2198 cpu->sample.mperf -= cpu->prev_mperf; in intel_pstate_sample()
2199 cpu->sample.tsc -= cpu->prev_tsc; in intel_pstate_sample()
2201 cpu->prev_aperf = aperf; in intel_pstate_sample()
2202 cpu->prev_mperf = mperf; in intel_pstate_sample()
2203 cpu->prev_tsc = tsc; in intel_pstate_sample()
2211 if (cpu->last_sample_time) { in intel_pstate_sample()
2212 intel_pstate_calc_avg_perf(cpu); in intel_pstate_sample()
2218 static inline int32_t get_avg_frequency(struct cpudata *cpu) in get_avg_frequency() argument
2220 return mul_ext_fp(cpu->sample.core_avg_perf, cpu_khz); in get_avg_frequency()
2223 static inline int32_t get_avg_pstate(struct cpudata *cpu) in get_avg_pstate() argument
2225 return mul_ext_fp(cpu->pstate.max_pstate_physical, in get_avg_pstate()
2226 cpu->sample.core_avg_perf); in get_avg_pstate()
2229 static inline int32_t get_target_pstate(struct cpudata *cpu) in get_target_pstate() argument
2231 struct sample *sample = &cpu->sample; in get_target_pstate()
2235 busy_frac = div_fp(sample->mperf << cpu->aperf_mperf_shift, in get_target_pstate()
2238 if (busy_frac < cpu->iowait_boost) in get_target_pstate()
2239 busy_frac = cpu->iowait_boost; in get_target_pstate()
2244 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; in get_target_pstate()
2247 if (target < cpu->pstate.min_pstate) in get_target_pstate()
2248 target = cpu->pstate.min_pstate; in get_target_pstate()
2257 avg_pstate = get_avg_pstate(cpu); in get_target_pstate()
2264 static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) in intel_pstate_prepare_request() argument
2266 int min_pstate = max(cpu->pstate.min_pstate, cpu->min_perf_ratio); in intel_pstate_prepare_request()
2267 int max_pstate = max(min_pstate, cpu->max_perf_ratio); in intel_pstate_prepare_request()
2272 static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) in intel_pstate_update_pstate() argument
2274 if (pstate == cpu->pstate.current_pstate) in intel_pstate_update_pstate()
2277 cpu->pstate.current_pstate = pstate; in intel_pstate_update_pstate()
2278 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate)); in intel_pstate_update_pstate()
2281 static void intel_pstate_adjust_pstate(struct cpudata *cpu) in intel_pstate_adjust_pstate() argument
2283 int from = cpu->pstate.current_pstate; in intel_pstate_adjust_pstate()
2289 target_pstate = get_target_pstate(cpu); in intel_pstate_adjust_pstate()
2290 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_pstate_adjust_pstate()
2291 trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_adjust_pstate()
2292 intel_pstate_update_pstate(cpu, target_pstate); in intel_pstate_adjust_pstate()
2294 sample = &cpu->sample; in intel_pstate_adjust_pstate()
2298 cpu->pstate.current_pstate, in intel_pstate_adjust_pstate()
2302 get_avg_frequency(cpu), in intel_pstate_adjust_pstate()
2303 fp_toint(cpu->iowait_boost * 100)); in intel_pstate_adjust_pstate()
2309 struct cpudata *cpu = container_of(data, struct cpudata, update_util); in intel_pstate_update_util() local
2313 if (smp_processor_id() != cpu->cpu) in intel_pstate_update_util()
2316 delta_ns = time - cpu->last_update; in intel_pstate_update_util()
2320 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2321 } else if (cpu->iowait_boost >= ONE_EIGHTH_FP) { in intel_pstate_update_util()
2322 cpu->iowait_boost <<= 1; in intel_pstate_update_util()
2323 if (cpu->iowait_boost > int_tofp(1)) in intel_pstate_update_util()
2324 cpu->iowait_boost = int_tofp(1); in intel_pstate_update_util()
2326 cpu->iowait_boost = ONE_EIGHTH_FP; in intel_pstate_update_util()
2328 } else if (cpu->iowait_boost) { in intel_pstate_update_util()
2331 cpu->iowait_boost = 0; in intel_pstate_update_util()
2333 cpu->iowait_boost >>= 1; in intel_pstate_update_util()
2335 cpu->last_update = time; in intel_pstate_update_util()
2336 delta_ns = time - cpu->sample.time; in intel_pstate_update_util()
2340 if (intel_pstate_sample(cpu, time)) in intel_pstate_update_util()
2341 intel_pstate_adjust_pstate(cpu); in intel_pstate_update_util()
2433 struct cpudata *cpu; in intel_pstate_init_cpu() local
2435 cpu = all_cpu_data[cpunum]; in intel_pstate_init_cpu()
2437 if (!cpu) { in intel_pstate_init_cpu()
2438 cpu = kzalloc(sizeof(*cpu), GFP_KERNEL); in intel_pstate_init_cpu()
2439 if (!cpu) in intel_pstate_init_cpu()
2442 WRITE_ONCE(all_cpu_data[cpunum], cpu); in intel_pstate_init_cpu()
2444 cpu->cpu = cpunum; in intel_pstate_init_cpu()
2446 cpu->epp_default = -EINVAL; in intel_pstate_init_cpu()
2449 intel_pstate_hwp_enable(cpu); in intel_pstate_init_cpu()
2460 intel_pstate_hwp_reenable(cpu); in intel_pstate_init_cpu()
2463 cpu->epp_powersave = -EINVAL; in intel_pstate_init_cpu()
2464 cpu->epp_policy = 0; in intel_pstate_init_cpu()
2466 intel_pstate_get_cpu_pstates(cpu); in intel_pstate_init_cpu()
2475 struct cpudata *cpu = all_cpu_data[cpu_num]; in intel_pstate_set_update_util_hook() local
2480 if (cpu->update_util_set) in intel_pstate_set_update_util_hook()
2484 cpu->sample.time = 0; in intel_pstate_set_update_util_hook()
2485 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, in intel_pstate_set_update_util_hook()
2489 cpu->update_util_set = true; in intel_pstate_set_update_util_hook()
2492 static void intel_pstate_clear_update_util_hook(unsigned int cpu) in intel_pstate_clear_update_util_hook() argument
2494 struct cpudata *cpu_data = all_cpu_data[cpu]; in intel_pstate_clear_update_util_hook()
2499 cpufreq_remove_update_util_hook(cpu); in intel_pstate_clear_update_util_hook()
2504 static int intel_pstate_get_max_freq(struct cpudata *cpu) in intel_pstate_get_max_freq() argument
2507 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_get_max_freq()
2510 static void intel_pstate_update_perf_limits(struct cpudata *cpu, in intel_pstate_update_perf_limits() argument
2514 int perf_ctl_scaling = cpu->pstate.perf_ctl_scaling; in intel_pstate_update_perf_limits()
2530 if (hwp_active && cpu->pstate.scaling != perf_ctl_scaling) { in intel_pstate_update_perf_limits()
2531 int scaling = cpu->pstate.scaling; in intel_pstate_update_perf_limits()
2541 cpu->cpu, min_policy_perf, max_policy_perf); in intel_pstate_update_perf_limits()
2545 cpu->min_perf_ratio = min_policy_perf; in intel_pstate_update_perf_limits()
2546 cpu->max_perf_ratio = max_policy_perf; in intel_pstate_update_perf_limits()
2548 int turbo_max = cpu->pstate.turbo_pstate; in intel_pstate_update_perf_limits()
2556 pr_debug("cpu:%d global_min:%d global_max:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2559 cpu->min_perf_ratio = max(min_policy_perf, global_min); in intel_pstate_update_perf_limits()
2560 cpu->min_perf_ratio = min(cpu->min_perf_ratio, max_policy_perf); in intel_pstate_update_perf_limits()
2561 cpu->max_perf_ratio = min(max_policy_perf, global_max); in intel_pstate_update_perf_limits()
2562 cpu->max_perf_ratio = max(min_policy_perf, cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2565 cpu->min_perf_ratio = min(cpu->min_perf_ratio, in intel_pstate_update_perf_limits()
2566 cpu->max_perf_ratio); in intel_pstate_update_perf_limits()
2569 pr_debug("cpu:%d max_perf_ratio:%d min_perf_ratio:%d\n", cpu->cpu, in intel_pstate_update_perf_limits()
2570 cpu->max_perf_ratio, in intel_pstate_update_perf_limits()
2571 cpu->min_perf_ratio); in intel_pstate_update_perf_limits()
2576 struct cpudata *cpu; in intel_pstate_set_policy() local
2584 cpu = all_cpu_data[policy->cpu]; in intel_pstate_set_policy()
2585 cpu->policy = policy->policy; in intel_pstate_set_policy()
2589 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_pstate_set_policy()
2591 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { in intel_pstate_set_policy()
2596 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2597 intel_pstate_max_within_limits(cpu); in intel_pstate_set_policy()
2599 intel_pstate_set_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2609 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_set_policy()
2610 intel_pstate_hwp_set(policy->cpu); in intel_pstate_set_policy()
2623 static void intel_pstate_adjust_policy_max(struct cpudata *cpu, in intel_pstate_adjust_policy_max() argument
2627 cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && in intel_pstate_adjust_policy_max()
2629 policy->max > cpu->pstate.max_freq) { in intel_pstate_adjust_policy_max()
2635 static void intel_pstate_verify_cpu_policy(struct cpudata *cpu, in intel_pstate_verify_cpu_policy() argument
2642 intel_pstate_get_hwp_cap(cpu); in intel_pstate_verify_cpu_policy()
2644 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_verify_cpu_policy()
2646 max_freq = intel_pstate_get_max_freq(cpu); in intel_pstate_verify_cpu_policy()
2650 intel_pstate_adjust_policy_max(cpu, policy); in intel_pstate_verify_cpu_policy()
2655 intel_pstate_verify_cpu_policy(all_cpu_data[policy->cpu], policy); in intel_pstate_verify_policy()
2662 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_offline() local
2664 pr_debug("CPU %d going offline\n", cpu->cpu); in intel_cpufreq_cpu_offline()
2666 if (cpu->suspended) in intel_cpufreq_cpu_offline()
2676 intel_pstate_hwp_offline(cpu); in intel_cpufreq_cpu_offline()
2678 intel_pstate_set_min_pstate(cpu); in intel_cpufreq_cpu_offline()
2687 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_online() local
2689 pr_debug("CPU %d going online\n", cpu->cpu); in intel_pstate_cpu_online()
2698 intel_pstate_hwp_reenable(cpu); in intel_pstate_cpu_online()
2699 cpu->suspended = false; in intel_pstate_cpu_online()
2707 intel_pstate_clear_update_util_hook(policy->cpu); in intel_pstate_cpu_offline()
2714 pr_debug("CPU %d exiting\n", policy->cpu); in intel_pstate_cpu_exit()
2723 struct cpudata *cpu; in __intel_pstate_cpu_init() local
2726 rc = intel_pstate_init_cpu(policy->cpu); in __intel_pstate_cpu_init()
2730 cpu = all_cpu_data[policy->cpu]; in __intel_pstate_cpu_init()
2732 cpu->max_perf_ratio = 0xFF; in __intel_pstate_cpu_init()
2733 cpu->min_perf_ratio = 0; in __intel_pstate_cpu_init()
2736 policy->cpuinfo.min_freq = cpu->pstate.min_freq; in __intel_pstate_cpu_init()
2740 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in __intel_pstate_cpu_init()
2766 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_init() local
2768 cpu->epp_cached = intel_pstate_get_epp(cpu, 0); in intel_pstate_cpu_init()
2790 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_verify_policy() local
2792 intel_pstate_verify_cpu_policy(cpu, policy); in intel_cpufreq_verify_policy()
2793 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_cpufreq_verify_policy()
2814 static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, int old_pstate) in intel_cpufreq_trace() argument
2821 if (!intel_pstate_sample(cpu, ktime_get())) in intel_cpufreq_trace()
2824 sample = &cpu->sample; in intel_cpufreq_trace()
2828 cpu->pstate.current_pstate, in intel_cpufreq_trace()
2832 get_avg_frequency(cpu), in intel_cpufreq_trace()
2833 fp_toint(cpu->iowait_boost * 100)); in intel_cpufreq_trace()
2836 static void intel_cpufreq_hwp_update(struct cpudata *cpu, u32 min, u32 max, in intel_cpufreq_hwp_update() argument
2839 u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev; in intel_cpufreq_hwp_update()
2853 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_hwp_update()
2857 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_cpufreq_hwp_update()
2860 static void intel_cpufreq_perf_ctl_update(struct cpudata *cpu, in intel_cpufreq_perf_ctl_update() argument
2865 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_perf_ctl_update()
2867 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_cpufreq_perf_ctl_update()
2868 pstate_funcs.get_val(cpu, target_pstate)); in intel_cpufreq_perf_ctl_update()
2874 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_update_pstate() local
2875 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_update_pstate()
2877 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); in intel_cpufreq_update_pstate()
2880 target_pstate : cpu->max_perf_ratio; in intel_cpufreq_update_pstate()
2882 intel_cpufreq_hwp_update(cpu, target_pstate, max_pstate, 0, in intel_cpufreq_update_pstate()
2885 intel_cpufreq_perf_ctl_update(cpu, target_pstate, fast_switch); in intel_cpufreq_update_pstate()
2888 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2890 intel_cpufreq_trace(cpu, fast_switch ? INTEL_PSTATE_TRACE_FAST_SWITCH : in intel_cpufreq_update_pstate()
2900 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_target() local
2913 target_pstate = DIV_ROUND_UP(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2916 target_pstate = freqs.new / cpu->pstate.scaling; in intel_cpufreq_target()
2919 target_pstate = DIV_ROUND_CLOSEST(freqs.new, cpu->pstate.scaling); in intel_cpufreq_target()
2925 freqs.new = target_pstate * cpu->pstate.scaling; in intel_cpufreq_target()
2935 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_fast_switch() local
2940 target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); in intel_cpufreq_fast_switch()
2944 return target_pstate * cpu->pstate.scaling; in intel_cpufreq_fast_switch()
2952 struct cpudata *cpu = all_cpu_data[cpunum]; in intel_cpufreq_adjust_perf() local
2953 u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); in intel_cpufreq_adjust_perf()
2954 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_adjust_perf()
2971 if (min_pstate < cpu->pstate.min_pstate) in intel_cpufreq_adjust_perf()
2972 min_pstate = cpu->pstate.min_pstate; in intel_cpufreq_adjust_perf()
2974 if (min_pstate < cpu->min_perf_ratio) in intel_cpufreq_adjust_perf()
2975 min_pstate = cpu->min_perf_ratio; in intel_cpufreq_adjust_perf()
2977 max_pstate = min(cap_pstate, cpu->max_perf_ratio); in intel_cpufreq_adjust_perf()
2983 intel_cpufreq_hwp_update(cpu, min_pstate, max_pstate, target_pstate, true); in intel_cpufreq_adjust_perf()
2985 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_adjust_perf()
2986 intel_cpufreq_trace(cpu, INTEL_PSTATE_TRACE_FAST_SWITCH, old_pstate); in intel_cpufreq_adjust_perf()
2992 struct cpudata *cpu; in intel_cpufreq_cpu_init() local
2996 dev = get_cpu_device(policy->cpu); in intel_cpufreq_cpu_init()
3014 cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_cpu_init()
3021 intel_pstate_get_hwp_cap(cpu); in intel_cpufreq_cpu_init()
3023 rdmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, &value); in intel_cpufreq_cpu_init()
3024 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_cpu_init()
3026 cpu->epp_cached = intel_pstate_get_epp(cpu, value); in intel_cpufreq_cpu_init()
3031 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * global.min_perf_pct, 100); in intel_cpufreq_cpu_init()
3040 freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * global.max_perf_pct, 100); in intel_cpufreq_cpu_init()
3081 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_suspend() local
3082 u64 value = READ_ONCE(cpu->hwp_req_cached); in intel_cpufreq_suspend()
3090 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_cpufreq_suspend()
3091 WRITE_ONCE(cpu->hwp_req_cached, value); in intel_cpufreq_suspend()
3116 unsigned int cpu; in intel_pstate_driver_cleanup() local
3119 for_each_online_cpu(cpu) { in intel_pstate_driver_cleanup()
3120 if (all_cpu_data[cpu]) { in intel_pstate_driver_cleanup()
3122 intel_pstate_clear_update_util_hook(cpu); in intel_pstate_driver_cleanup()
3125 kfree(all_cpu_data[cpu]); in intel_pstate_driver_cleanup()
3126 WRITE_ONCE(all_cpu_data[cpu], NULL); in intel_pstate_driver_cleanup()