Lines Matching refs:cpudata
123 static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached) in amd_pstate_get_epp() argument
130 epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, in amd_pstate_get_epp()
137 ret = cppc_get_epp_perf(cpudata->cpu, &epp); in amd_pstate_get_epp()
147 static int amd_pstate_get_energy_pref_index(struct amd_cpudata *cpudata) in amd_pstate_get_energy_pref_index() argument
152 epp = amd_pstate_get_epp(cpudata, 0); in amd_pstate_get_energy_pref_index()
176 static int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp) in amd_pstate_set_epp() argument
182 u64 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_set_epp()
186 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_set_epp()
188 ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_set_epp()
190 cpudata->epp_cached = epp; in amd_pstate_set_epp()
193 ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1); in amd_pstate_set_epp()
198 cpudata->epp_cached = epp; in amd_pstate_set_epp()
204 static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata, in amd_pstate_set_energy_pref_index() argument
218 if (epp > 0 && cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { in amd_pstate_set_energy_pref_index()
223 ret = amd_pstate_set_epp(cpudata, epp); in amd_pstate_set_energy_pref_index()
263 static int pstate_init_perf(struct amd_cpudata *cpudata) in pstate_init_perf() argument
268 int ret = rdmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, in pstate_init_perf()
282 WRITE_ONCE(cpudata->highest_perf, highest_perf); in pstate_init_perf()
284 WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1)); in pstate_init_perf()
285 WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1)); in pstate_init_perf()
286 WRITE_ONCE(cpudata->lowest_perf, AMD_CPPC_LOWEST_PERF(cap1)); in pstate_init_perf()
291 static int cppc_init_perf(struct amd_cpudata *cpudata) in cppc_init_perf() argument
296 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in cppc_init_perf()
304 WRITE_ONCE(cpudata->highest_perf, highest_perf); in cppc_init_perf()
306 WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf); in cppc_init_perf()
307 WRITE_ONCE(cpudata->lowest_nonlinear_perf, in cppc_init_perf()
309 WRITE_ONCE(cpudata->lowest_perf, cppc_perf.lowest_perf); in cppc_init_perf()
316 static inline int amd_pstate_init_perf(struct amd_cpudata *cpudata) in amd_pstate_init_perf() argument
318 return static_call(amd_pstate_init_perf)(cpudata); in amd_pstate_init_perf()
321 static void pstate_update_perf(struct amd_cpudata *cpudata, u32 min_perf, in pstate_update_perf() argument
325 wrmsrl(MSR_AMD_CPPC_REQ, READ_ONCE(cpudata->cppc_req_cached)); in pstate_update_perf()
327 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, in pstate_update_perf()
328 READ_ONCE(cpudata->cppc_req_cached)); in pstate_update_perf()
331 static void cppc_update_perf(struct amd_cpudata *cpudata, in cppc_update_perf() argument
341 cppc_set_perf(cpudata->cpu, &perf_ctrls); in cppc_update_perf()
346 static inline void amd_pstate_update_perf(struct amd_cpudata *cpudata, in amd_pstate_update_perf() argument
350 static_call(amd_pstate_update_perf)(cpudata, min_perf, des_perf, in amd_pstate_update_perf()
354 static inline bool amd_pstate_sample(struct amd_cpudata *cpudata) in amd_pstate_sample() argument
364 if (cpudata->prev.mperf == mperf || cpudata->prev.tsc == tsc) { in amd_pstate_sample()
371 cpudata->cur.aperf = aperf; in amd_pstate_sample()
372 cpudata->cur.mperf = mperf; in amd_pstate_sample()
373 cpudata->cur.tsc = tsc; in amd_pstate_sample()
374 cpudata->cur.aperf -= cpudata->prev.aperf; in amd_pstate_sample()
375 cpudata->cur.mperf -= cpudata->prev.mperf; in amd_pstate_sample()
376 cpudata->cur.tsc -= cpudata->prev.tsc; in amd_pstate_sample()
378 cpudata->prev.aperf = aperf; in amd_pstate_sample()
379 cpudata->prev.mperf = mperf; in amd_pstate_sample()
380 cpudata->prev.tsc = tsc; in amd_pstate_sample()
382 cpudata->freq = div64_u64((cpudata->cur.aperf * cpu_khz), cpudata->cur.mperf); in amd_pstate_sample()
387 static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf, in amd_pstate_update() argument
390 u64 prev = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_update()
403 if (trace_amd_pstate_perf_enabled() && amd_pstate_sample(cpudata)) { in amd_pstate_update()
404 trace_amd_pstate_perf(min_perf, des_perf, max_perf, cpudata->freq, in amd_pstate_update()
405 cpudata->cur.mperf, cpudata->cur.aperf, cpudata->cur.tsc, in amd_pstate_update()
406 cpudata->cpu, (value != prev), fast_switch); in amd_pstate_update()
412 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_update()
414 amd_pstate_update_perf(cpudata, min_perf, des_perf, in amd_pstate_update()
430 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_target() local
433 if (!cpudata->max_freq) in amd_pstate_target()
436 cap_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_target()
437 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_target()
444 cpudata->max_freq); in amd_pstate_target()
447 amd_pstate_update(cpudata, min_perf, des_perf, in amd_pstate_target()
462 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_adjust_perf() local
464 cap_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_adjust_perf()
465 lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); in amd_pstate_adjust_perf()
471 min_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_adjust_perf()
482 amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true); in amd_pstate_adjust_perf()
486 static int amd_get_min_freq(struct amd_cpudata *cpudata) in amd_get_min_freq() argument
490 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_min_freq()
498 static int amd_get_max_freq(struct amd_cpudata *cpudata) in amd_get_max_freq() argument
504 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_max_freq()
509 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_get_max_freq()
510 max_perf = READ_ONCE(cpudata->highest_perf); in amd_get_max_freq()
521 static int amd_get_nominal_freq(struct amd_cpudata *cpudata) in amd_get_nominal_freq() argument
525 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_nominal_freq()
533 static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata) in amd_get_lowest_nonlinear_freq() argument
540 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_lowest_nonlinear_freq()
545 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_get_lowest_nonlinear_freq()
560 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_set_boost() local
563 if (!cpudata->boost_supported) { in amd_pstate_set_boost()
569 policy->cpuinfo.max_freq = cpudata->max_freq; in amd_pstate_set_boost()
571 policy->cpuinfo.max_freq = cpudata->nominal_freq; in amd_pstate_set_boost()
575 ret = freq_qos_update_request(&cpudata->req[1], in amd_pstate_set_boost()
583 static void amd_pstate_boost_init(struct amd_cpudata *cpudata) in amd_pstate_boost_init() argument
587 highest_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_boost_init()
588 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_pstate_boost_init()
593 cpudata->boost_supported = true; in amd_pstate_boost_init()
606 struct amd_cpudata *cpudata; in amd_pstate_cpu_init() local
617 cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); in amd_pstate_cpu_init()
618 if (!cpudata) in amd_pstate_cpu_init()
621 cpudata->cpu = policy->cpu; in amd_pstate_cpu_init()
623 ret = amd_pstate_init_perf(cpudata); in amd_pstate_cpu_init()
627 min_freq = amd_get_min_freq(cpudata); in amd_pstate_cpu_init()
628 max_freq = amd_get_max_freq(cpudata); in amd_pstate_cpu_init()
629 nominal_freq = amd_get_nominal_freq(cpudata); in amd_pstate_cpu_init()
630 lowest_nonlinear_freq = amd_get_lowest_nonlinear_freq(cpudata); in amd_pstate_cpu_init()
654 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0], in amd_pstate_cpu_init()
661 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[1], in amd_pstate_cpu_init()
669 cpudata->max_freq = max_freq; in amd_pstate_cpu_init()
670 cpudata->min_freq = min_freq; in amd_pstate_cpu_init()
671 cpudata->nominal_freq = nominal_freq; in amd_pstate_cpu_init()
672 cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq; in amd_pstate_cpu_init()
674 policy->driver_data = cpudata; in amd_pstate_cpu_init()
676 amd_pstate_boost_init(cpudata); in amd_pstate_cpu_init()
683 freq_qos_remove_request(&cpudata->req[0]); in amd_pstate_cpu_init()
685 kfree(cpudata); in amd_pstate_cpu_init()
691 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_cpu_exit() local
693 freq_qos_remove_request(&cpudata->req[1]); in amd_pstate_cpu_exit()
694 freq_qos_remove_request(&cpudata->req[0]); in amd_pstate_cpu_exit()
695 kfree(cpudata); in amd_pstate_cpu_exit()
733 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_max_freq() local
735 max_freq = amd_get_max_freq(cpudata); in show_amd_pstate_max_freq()
746 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_lowest_nonlinear_freq() local
748 freq = amd_get_lowest_nonlinear_freq(cpudata); in show_amd_pstate_lowest_nonlinear_freq()
763 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_highest_perf() local
765 perf = READ_ONCE(cpudata->highest_perf); in show_amd_pstate_highest_perf()
787 struct amd_cpudata *cpudata = policy->driver_data; in store_energy_performance_preference() local
800 ret = amd_pstate_set_energy_pref_index(cpudata, ret); in store_energy_performance_preference()
809 struct amd_cpudata *cpudata = policy->driver_data; in show_energy_performance_preference() local
812 preference = amd_pstate_get_energy_pref_index(cpudata); in show_energy_performance_preference()
941 struct amd_cpudata *cpudata; in amd_pstate_epp_cpu_init() local
954 cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); in amd_pstate_epp_cpu_init()
955 if (!cpudata) in amd_pstate_epp_cpu_init()
958 cpudata->cpu = policy->cpu; in amd_pstate_epp_cpu_init()
959 cpudata->epp_policy = 0; in amd_pstate_epp_cpu_init()
961 ret = amd_pstate_init_perf(cpudata); in amd_pstate_epp_cpu_init()
965 min_freq = amd_get_min_freq(cpudata); in amd_pstate_epp_cpu_init()
966 max_freq = amd_get_max_freq(cpudata); in amd_pstate_epp_cpu_init()
967 nominal_freq = amd_get_nominal_freq(cpudata); in amd_pstate_epp_cpu_init()
968 lowest_nonlinear_freq = amd_get_lowest_nonlinear_freq(cpudata); in amd_pstate_epp_cpu_init()
982 cpudata->max_freq = max_freq; in amd_pstate_epp_cpu_init()
983 cpudata->min_freq = min_freq; in amd_pstate_epp_cpu_init()
984 cpudata->nominal_freq = nominal_freq; in amd_pstate_epp_cpu_init()
985 cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq; in amd_pstate_epp_cpu_init()
987 policy->driver_data = cpudata; in amd_pstate_epp_cpu_init()
989 cpudata->epp_cached = amd_pstate_get_epp(cpudata, 0); in amd_pstate_epp_cpu_init()
1002 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value); in amd_pstate_epp_cpu_init()
1005 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_epp_cpu_init()
1007 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, &value); in amd_pstate_epp_cpu_init()
1010 WRITE_ONCE(cpudata->cppc_cap1_cached, value); in amd_pstate_epp_cpu_init()
1012 amd_pstate_boost_init(cpudata); in amd_pstate_epp_cpu_init()
1017 kfree(cpudata); in amd_pstate_epp_cpu_init()
1031 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_init() local
1036 max_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_epp_init()
1037 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_epp_init()
1039 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_init()
1041 if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) in amd_pstate_epp_init()
1055 if (cpudata->epp_policy == cpudata->policy) in amd_pstate_epp_init()
1058 cpudata->epp_policy = cpudata->policy; in amd_pstate_epp_init()
1061 epp = amd_pstate_get_epp(cpudata, value); in amd_pstate_epp_init()
1070 if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) in amd_pstate_epp_init()
1079 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_epp_init()
1080 amd_pstate_set_epp(cpudata, epp); in amd_pstate_epp_init()
1087 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_set_policy() local
1095 cpudata->policy = policy->policy; in amd_pstate_epp_set_policy()
1102 static void amd_pstate_epp_reenable(struct amd_cpudata *cpudata) in amd_pstate_epp_reenable() argument
1112 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_reenable()
1113 max_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_epp_reenable()
1116 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_epp_reenable()
1119 perf_ctrls.energy_perf = AMD_CPPC_ENERGY_PERF_PREF(cpudata->epp_cached); in amd_pstate_epp_reenable()
1120 cppc_set_perf(cpudata->cpu, &perf_ctrls); in amd_pstate_epp_reenable()
1126 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_cpu_online() local
1128 pr_debug("AMD CPU Core %d going online\n", cpudata->cpu); in amd_pstate_epp_cpu_online()
1131 amd_pstate_epp_reenable(cpudata); in amd_pstate_epp_cpu_online()
1132 cpudata->suspended = false; in amd_pstate_epp_cpu_online()
1140 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_offline() local
1145 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_epp_offline()
1146 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_offline()
1150 cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN; in amd_pstate_epp_offline()
1157 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_epp_offline()
1162 cppc_set_perf(cpudata->cpu, &perf_ctrls); in amd_pstate_epp_offline()
1169 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_cpu_offline() local
1171 pr_debug("AMD CPU Core %d going offline\n", cpudata->cpu); in amd_pstate_epp_cpu_offline()
1173 if (cpudata->suspended) in amd_pstate_epp_cpu_offline()
1191 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_suspend() local
1199 cpudata->suspended = true; in amd_pstate_epp_suspend()
1211 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_resume() local
1213 if (cpudata->suspended) { in amd_pstate_epp_resume()
1217 amd_pstate_epp_reenable(cpudata); in amd_pstate_epp_resume()
1221 cpudata->suspended = false; in amd_pstate_epp_resume()