Lines Matching +full:min +full:- +full:sample +full:- +full:time

1 // SPDX-License-Identifier: GPL-2.0-only
34 #include <asm/intel-family.h>
51 #define ONE_EIGHTH_FP ((int64_t)1 << (FRAC_BITS - 3))
73 mask = (1 << FRAC_BITS) - 1; in ceiling_fp()
100 * struct sample - Store performance sample
102 * performance during last sample period
107 * read from APERF MSR between last and current sample
109 * read from MPERF MSR between last and current sample
110 * @tsc: Difference of time stamp counter between last and
111 * current sample
112 * @time: Current time from scheduler
114 * This structure is used in the cpudata structure to store performance sample
117 struct sample { struct
123 u64 time; member
127 * struct pstate_data - Store P state data
129 * @min_pstate: Min P state possible for this platform
154 * struct vid_data - Stores voltage information data
155 * @min: VID data for this platform corresponding to
159 * @ratio: Ratio of (vid max - vid min) /
160 * (max P state - Min P State)
167 int min; member
174 * struct global_params - Global parameters, mostly tunable via sysfs.
175 * @no_turbo: Whether or not to use turbo P-states.
176 * @turbo_disabled: Whether or not turbo P-states are available at all,
178 * not the maximum reported turbo P-state is different from
179 * the maximum reported non-turbo one.
182 * P-state capacity.
184 * P-state capacity.
195 * struct cpudata - Per CPU instance data storage
200 * @iowait_boost: iowait-related boost fraction
201 * @last_update: Time of the last update.
204 * @last_sample_time: Last Sample time
209 * @prev_cummulative_iowait: IO Wait time difference from last and
210 * current sample
211 * @sample: Storage for storing last Sample data
222 * @epp_cached Cached HWP energy-performance preference value
225 * @last_io_update: Last time when IO wake flag was set
227 * @hwp_boost_min: Last HWP boosted min performance
249 struct sample sample; member
272 * struct pstate_funcs - Per CPU model specific callbacks
356 * update them at any time after it has been called. in intel_pstate_set_itmt_prio()
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()
459 policy->cpuinfo.max_freq / 1000; 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()
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()
498 return -ENOTSUPP; in intel_pstate_get_cppc_guranteed()
511 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); in update_turbo_state()
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()
529 return -ENXIO; in intel_pstate_get_epb()
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()
568 return -ENXIO; in intel_pstate_set_epb()
584 *-------------------------------------
609 int index = -EINVAL; in intel_pstate_get_energy_pref_index()
630 * 0x00-0x03 : Performance in intel_pstate_get_energy_pref_index()
631 * 0x04-0x07 : Balance performance in intel_pstate_get_energy_pref_index()
632 * 0x08-0x0B : Balance power in intel_pstate_get_energy_pref_index()
633 * 0x0C-0x0F : Power in intel_pstate_get_energy_pref_index()
651 * intel_pstate_hwp_boost_down() at any time. in intel_pstate_set_epp()
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()
674 int epp = -EINVAL; in intel_pstate_set_energy_pref_index()
678 epp = cpu_data->epp_default; in intel_pstate_set_energy_pref_index()
683 else if (epp == -EINVAL) in intel_pstate_set_energy_pref_index()
684 epp = epp_values[pref_index - 1]; in intel_pstate_set_energy_pref_index()
691 if (epp > 0 && cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) in intel_pstate_set_energy_pref_index()
692 return -EBUSY; in intel_pstate_set_energy_pref_index()
696 if (epp == -EINVAL) in intel_pstate_set_energy_pref_index()
697 epp = (pref_index - 1) << 2; in intel_pstate_set_energy_pref_index()
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()
733 return -EINVAL; in store_energy_performance_preference()
735 ret = match_string(energy_perf_strings, -1, str_preference); in store_energy_performance_preference()
745 return -EINVAL; in store_energy_performance_preference()
756 return -EAGAIN; in store_energy_performance_preference()
766 * which is super-heavy-weight, so make sure it is worth doing 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()
791 struct cpudata *cpu_data = all_cpu_data[policy->cpu]; in show_energy_performance_preference()
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()
838 WRITE_ONCE(all_cpu_data[cpu]->hwp_cap_cached, cap); in intel_pstate_get_hwp_max()
850 int max, min; in intel_pstate_hwp_set() local
854 max = cpu_data->max_perf_ratio; in intel_pstate_hwp_set()
855 min = cpu_data->min_perf_ratio; in intel_pstate_hwp_set()
857 if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) in intel_pstate_hwp_set()
858 min = max; in intel_pstate_hwp_set()
863 value |= HWP_MIN_PERF(min); in intel_pstate_hwp_set()
868 if (cpu_data->epp_policy == cpu_data->policy) in intel_pstate_hwp_set()
871 cpu_data->epp_policy = cpu_data->policy; in intel_pstate_hwp_set()
873 if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) { in intel_pstate_hwp_set()
875 cpu_data->epp_powersave = epp; in intel_pstate_hwp_set()
883 if (cpu_data->epp_powersave < 0) in intel_pstate_hwp_set()
889 * - Policy is not changed in intel_pstate_hwp_set()
890 * - user has manually changed in intel_pstate_hwp_set()
891 * - Error reading EPB in intel_pstate_hwp_set()
897 epp = cpu_data->epp_powersave; in intel_pstate_hwp_set()
906 WRITE_ONCE(cpu_data->hwp_req_cached, value); in intel_pstate_hwp_set()
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()
933 /* Set EPP to min */ in intel_pstate_hwp_offline()
937 wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); in intel_pstate_hwp_offline()
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()
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()
985 pr_debug("CPU %d resuming\n", cpu->cpu); in intel_pstate_resume()
993 if (cpu->suspended && hwp_active) { in intel_pstate_resume()
996 /* Re-enable HWP, because "online" has not done that. */ in intel_pstate_resume()
1002 cpu->suspended = false; in intel_pstate_resume()
1024 policy->cpuinfo.max_freq = global.turbo_disabled_mf ? in intel_pstate_update_max_freq()
1025 cpudata->pstate.max_freq : cpudata->pstate.turbo_freq; in intel_pstate_update_max_freq()
1083 ret = intel_pstate_update_status(buf, p ? p - buf : count); in store_status()
1100 return -EAGAIN; 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()
1108 turbo_pct = 100 - fp_toint(mul_fp(turbo_fp, int_tofp(100))); in show_turbo_pct()
1125 return -EAGAIN; in show_num_pstates()
1129 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; in show_num_pstates()
1145 return -EAGAIN; in show_no_turbo()
1167 return -EINVAL; in store_no_turbo()
1173 return -EAGAIN; in store_no_turbo()
1183 return -EPERM; in store_no_turbo()
1190 int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate; in store_no_turbo()
1219 req = policy->driver_data; in update_qos_request()
1228 turbo_max = cpu->pstate.turbo_pstate; in update_qos_request()
1238 freq *= cpu->pstate.scaling; in update_qos_request()
1253 return -EINVAL; in store_max_perf_pct()
1259 return -EAGAIN; in store_max_perf_pct()
1286 return -EINVAL; in store_min_perf_pct()
1292 return -EAGAIN; in store_min_perf_pct()
1396 &cpu_subsys.dev_root->kobj); 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()
1469 if (cpudata->epp_default == -EINVAL) in intel_pstate_hwp_enable()
1470 cpudata->epp_default = intel_pstate_get_epp(cpudata, 0); in intel_pstate_hwp_enable()
1507 vid_fp = cpudata->vid.min + mul_fp( in atom_get_val()
1508 int_tofp(pstate - cpudata->pstate.min_pstate), in atom_get_val()
1509 cpudata->vid.ratio); in atom_get_val()
1511 vid_fp = clamp_t(int32_t, vid_fp, cpudata->vid.min, cpudata->vid.max); in atom_get_val()
1514 if (pstate > cpudata->pstate.max_pstate) in atom_get_val()
1515 vid = cpudata->vid.turbo; in atom_get_val()
1524 /* Defined in Table 35-6 from SDM (Sept 2015) */ in silvermont_get_scaling()
1539 /* Defined in Table 35-10 from SDM (Sept 2015) */ in airmont_get_scaling()
1556 cpudata->vid.min = int_tofp((value >> 8) & 0x7f); in atom_get_vid()
1557 cpudata->vid.max = int_tofp((value >> 16) & 0x7f); in atom_get_vid()
1558 cpudata->vid.ratio = div_fp( in atom_get_vid()
1559 cpudata->vid.max - cpudata->vid.min, in atom_get_vid()
1560 int_tofp(cpudata->pstate.max_pstate - in atom_get_vid()
1561 cpudata->pstate.min_pstate)); in atom_get_vid()
1564 cpudata->vid.turbo = value & 0x7f; in atom_get_vid()
1613 return -ENXIO; in core_get_tdp_ratio()
1642 if (tdp_ratio - 1 == tar_levels) { in core_get_max_pstate()
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()
1707 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_pstate_set_pstate()
1713 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); in intel_pstate_set_min_pstate()
1718 int pstate = max(cpu->pstate.min_pstate, cpu->max_perf_ratio); in intel_pstate_max_within_limits()
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, &current_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()
1753 * Long hold time will keep high perf limits for long time,
1762 u64 hwp_req = READ_ONCE(cpu->hwp_req_cached); in intel_pstate_hwp_boost_up()
1768 * Cases to consider (User changes via sysfs or boot time): in intel_pstate_hwp_boost_up()
1769 * If, P0 (Turbo max) = P1 (Guaranteed max) = min: in intel_pstate_hwp_boost_up()
1771 * If, P0 (Turbo max) > P1 (Guaranteed max) = min: in intel_pstate_hwp_boost_up()
1773 * If, P0 (Turbo max) = P1 (Guaranteed max) > min: in intel_pstate_hwp_boost_up()
1775 * (min + p1)/2 and P1. in intel_pstate_hwp_boost_up()
1776 * If, P0 (Turbo max) > P1 (Guaranteed max) > min: in intel_pstate_hwp_boost_up()
1778 * (min + p1)/2, P1 and P0. in intel_pstate_hwp_boost_up()
1781 /* If max and min are equal or already at max, nothing to boost */ 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()
1788 /* level at half way mark between min and guranteed */ 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()
1808 if (cpu->hwp_boost_min) { in intel_pstate_hwp_boost_down()
1811 /* Check if we are idle for hold time to boost down */ 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()
1823 u64 time) 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()
1832 * Set iowait_boost flag and update time. Since IO WAIT flag in intel_pstate_update_util_hwp_local()
1833 * is set all the time, we can't just conclude that there is 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()
1852 u64 time, unsigned int flags) in intel_pstate_update_util_hwp() argument
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()
1864 struct sample *sample = &cpu->sample; in intel_pstate_calc_avg_perf() local
1866 sample->core_avg_perf = div_ext_fp(sample->aperf, sample->mperf); 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()
1898 * First time this function is invoked in a given cycle, all of the in intel_pstate_sample()
1899 * previous sample data fields are equal to zero or stale and they must in intel_pstate_sample()
1901 * that sample.time will always be reset before setting the utilization in intel_pstate_sample()
1902 * update hook and make the caller skip the sample then. in intel_pstate_sample()
1904 if (cpu->last_sample_time) { in intel_pstate_sample()
1913 return mul_ext_fp(cpu->sample.core_avg_perf, cpu_khz); in get_avg_frequency()
1918 return mul_ext_fp(cpu->pstate.max_pstate_physical, in get_avg_pstate()
1919 cpu->sample.core_avg_perf); in get_avg_pstate()
1924 struct sample *sample = &cpu->sample; in get_target_pstate() local
1928 busy_frac = div_fp(sample->mperf << cpu->aperf_mperf_shift, in get_target_pstate()
1929 sample->tsc); 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()
1934 sample->busy_scaled = busy_frac * 100; 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()
1944 * If the average P-state during the previous cycle was higher than the in get_target_pstate()
1952 target += (avg_pstate - target) >> 1; in get_target_pstate()
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()
1967 if (pstate == cpu->pstate.current_pstate) in intel_pstate_update_pstate()
1970 cpu->pstate.current_pstate = pstate; in intel_pstate_update_pstate()
1976 int from = cpu->pstate.current_pstate; in intel_pstate_adjust_pstate()
1977 struct sample *sample; in intel_pstate_adjust_pstate() local
1984 trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); in intel_pstate_adjust_pstate()
1987 sample = &cpu->sample; in intel_pstate_adjust_pstate()
1988 trace_pstate_sample(mul_ext_fp(100, sample->core_avg_perf), in intel_pstate_adjust_pstate()
1989 fp_toint(sample->busy_scaled), in intel_pstate_adjust_pstate()
1991 cpu->pstate.current_pstate, in intel_pstate_adjust_pstate()
1992 sample->mperf, in intel_pstate_adjust_pstate()
1993 sample->aperf, in intel_pstate_adjust_pstate()
1994 sample->tsc, in intel_pstate_adjust_pstate()
1996 fp_toint(cpu->iowait_boost * 100)); in intel_pstate_adjust_pstate()
1999 static void intel_pstate_update_util(struct update_util_data *data, u64 time, in intel_pstate_update_util() argument
2006 if (smp_processor_id() != cpu->cpu) in intel_pstate_update_util()
2009 delta_ns = time - cpu->last_update; 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()
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()
2133 return -ENOMEM; in intel_pstate_init_cpu()
2137 cpu->cpu = cpunum; in intel_pstate_init_cpu()
2139 cpu->epp_default = -EINVAL; in intel_pstate_init_cpu()
2152 * Re-enable HWP in case this happens after a resume from ACPI 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()
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()
2192 if (!cpu_data->update_util_set) in intel_pstate_clear_update_util_hook()
2196 cpu_data->update_util_set = false; in intel_pstate_clear_update_util_hook()
2203 cpu->pstate.max_freq : cpu->pstate.turbo_freq; in intel_pstate_get_max_freq()
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()
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()
2246 /* Global limits are in percent of the maximum turbo P-state. */ 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()
2273 if (!policy->cpuinfo.max_freq) in intel_pstate_set_policy()
2274 return -ENODEV; in intel_pstate_set_policy()
2276 pr_debug("set_policy cpuinfo.max %u policy->max %u\n", in intel_pstate_set_policy()
2277 policy->cpuinfo.max_freq, policy->max); in intel_pstate_set_policy()
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()
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()
2317 cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && in intel_pstate_adjust_policy_max()
2318 policy->max < policy->cpuinfo.max_freq && in intel_pstate_adjust_policy_max()
2319 policy->max > cpu->pstate.max_freq) { in intel_pstate_adjust_policy_max()
2320 pr_debug("policy->max > max non turbo frequency\n"); in intel_pstate_adjust_policy_max()
2321 policy->max = policy->cpuinfo.max_freq; in intel_pstate_adjust_policy_max()
2329 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, 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()
2346 pr_debug("CPU %d going offline\n", cpu->cpu); in intel_pstate_cpu_offline()
2348 if (cpu->suspended) in intel_pstate_cpu_offline()
2369 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_online()
2371 pr_debug("CPU %d going online\n", cpu->cpu); in intel_pstate_cpu_online()
2377 * Re-enable HWP and clear the "suspended" flag to let "resume" 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()
2398 policy->fast_switch_possible = false; in intel_pstate_cpu_exit()
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()
2424 policy->cpuinfo.max_freq = global.turbo_disabled ? 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()
2433 if (max_freq < policy->cpuinfo.max_freq) in __intel_pstate_cpu_init()
2434 policy->cpuinfo.max_freq = max_freq; in __intel_pstate_cpu_init()
2439 policy->fast_switch_possible = true; in __intel_pstate_cpu_init()
2455 policy->policy = CPUFREQ_POLICY_POWERSAVE; in intel_pstate_cpu_init()
2458 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_pstate_cpu_init()
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()
2486 intel_pstate_update_perf_limits(cpu, policy->min, policy->max); in intel_cpufreq_verify_policy()
2495 * core_avg_perf) is not needed and so is re-assigned to indicate if the
2498 * (or performance or core_avg_perf) have a fixed y-axis from 0 to 100%,
2509 struct sample *sample; in intel_cpufreq_trace() local
2517 sample = &cpu->sample; in intel_cpufreq_trace()
2521 cpu->pstate.current_pstate, in intel_cpufreq_trace()
2522 sample->mperf, in intel_cpufreq_trace()
2523 sample->aperf, in intel_cpufreq_trace()
2524 sample->tsc, in intel_cpufreq_trace()
2526 fp_toint(cpu->iowait_boost * 100)); in intel_cpufreq_trace()
2532 u64 prev = READ_ONCE(cpu->hwp_req_cached), value = prev; in intel_cpufreq_adjust_hwp()
2538 * The entire MSR needs to be updated in order to update the HWP min 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()
2561 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, in intel_cpufreq_adjust_perf_ctl()
2568 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_update_pstate()
2569 int old_pstate = cpu->pstate.current_pstate; in intel_cpufreq_update_pstate()
2574 policy->strict_target, fast_switch); in intel_cpufreq_update_pstate()
2575 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2578 cpu->pstate.current_pstate = target_pstate; in intel_cpufreq_update_pstate()
2591 struct cpudata *cpu = all_cpu_data[policy->cpu]; in intel_cpufreq_target()
2597 freqs.old = policy->cur; in intel_cpufreq_target()
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()
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()
2645 dev = get_cpu_device(policy->cpu); in intel_cpufreq_cpu_init()
2647 return -ENODEV; in intel_cpufreq_cpu_init()
2653 policy->cpuinfo.transition_latency = INTEL_CPUFREQ_TRANSITION_LATENCY; in intel_cpufreq_cpu_init()
2655 policy->cur = policy->cpuinfo.min_freq; in intel_cpufreq_cpu_init()
2659 ret = -ENOMEM; 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()
2669 policy->transition_delay_us = INTEL_CPUFREQ_TRANSITION_DELAY_HWP; 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()
2675 policy->transition_delay_us = INTEL_CPUFREQ_TRANSITION_DELAY; 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()
2683 ret = freq_qos_add_request(&policy->constraints, req, FREQ_QOS_MIN, in intel_cpufreq_cpu_init()
2686 dev_err(dev, "Failed to add min-freq constraint (%d)\n", ret); in intel_cpufreq_cpu_init()
2690 ret = freq_qos_add_request(&policy->constraints, req + 1, FREQ_QOS_MAX, in intel_cpufreq_cpu_init()
2693 dev_err(dev, "Failed to add max-freq constraint (%d)\n", ret); in intel_cpufreq_cpu_init()
2697 policy->driver_data = req; in intel_cpufreq_cpu_init()
2715 req = policy->driver_data; in intel_cpufreq_cpu_exit()
2795 return -EINVAL; in intel_pstate_update_status()
2798 return -EBUSY; in intel_pstate_update_status()
2828 return -EINVAL; in intel_pstate_update_status()
2841 return -ENODEV; in intel_pstate_msrs_not_valid()
2848 pstate_funcs.get_max = funcs->get_max; in copy_cpu_funcs()
2849 pstate_funcs.get_max_physical = funcs->get_max_physical; in copy_cpu_funcs()
2850 pstate_funcs.get_min = funcs->get_min; in copy_cpu_funcs()
2851 pstate_funcs.get_turbo = funcs->get_turbo; in copy_cpu_funcs()
2852 pstate_funcs.get_scaling = funcs->get_scaling; in copy_cpu_funcs()
2853 pstate_funcs.get_val = funcs->get_val; in copy_cpu_funcs()
2854 pstate_funcs.get_vid = funcs->get_vid; in copy_cpu_funcs()
2855 pstate_funcs.get_aperf_mperf_shift = funcs->get_aperf_mperf_shift; in copy_cpu_funcs()
2873 status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); in intel_pstate_no_acpi_pss()
2878 if (pss && pss->type == ACPI_TYPE_PACKAGE) { in intel_pstate_no_acpi_pss()
2916 if (acpi_has_method(pr->handle, "_PPC")) in intel_pstate_has_acpi_ppc()
2928 /* Hardware vendor-specific info that has its own power management modes */
2931 {"ORACLE", "X4-2 ", 0, ACPI_SIG_FADT, all_versions, NULL, PPC},
2932 {"ORACLE", "X4-2L ", 0, ACPI_SIG_FADT, all_versions, NULL, PPC},
2933 {"ORACLE", "X4-2B ", 0, ACPI_SIG_FADT, all_versions, NULL, PPC},
2934 {"ORACLE", "X3-2 ", 0, ACPI_SIG_FADT, all_versions, NULL, PPC},
2935 {"ORACLE", "X3-2L ", 0, ACPI_SIG_FADT, all_versions, NULL, PPC},
2936 {"ORACLE", "X3-2B ", 0, ACPI_SIG_FADT, all_versions, NULL, PPC},
2943 {"ORACLE", "X6-2 ", 0, ACPI_SIG_FADT, all_versions, NULL, PPC},
2986 * It may be unsafe to request P-states control from SMM if _PPC support in intel_pstate_request_control_from_smm()
3017 return -ENODEV; in intel_pstate_init()
3020 return -ENODEV; in intel_pstate_init()
3032 hwp_mode_bdw = id->driver_data; in intel_pstate_init()
3045 return -ENODEV; in intel_pstate_init()
3048 copy_cpu_funcs((struct pstate_funcs *)id->driver_data); in intel_pstate_init()
3053 return -ENODEV; in intel_pstate_init()
3065 pr_info("P-states controlled by the platform\n"); in intel_pstate_init()
3066 return -ENODEV; in intel_pstate_init()
3070 return -ENOTSUPP; in intel_pstate_init()
3072 pr_info("Intel P-state driver initializing\n"); in intel_pstate_init()
3076 return -ENOMEM; in intel_pstate_init()
3109 return -EINVAL; in intel_pstate_setup()
3139 MODULE_DESCRIPTION("'intel_pstate' - P state driver Intel Core processors");