Lines Matching refs:cpudata
125 static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached) in amd_pstate_get_epp() argument
132 epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, in amd_pstate_get_epp()
139 ret = cppc_get_epp_perf(cpudata->cpu, &epp); in amd_pstate_get_epp()
149 static int amd_pstate_get_energy_pref_index(struct amd_cpudata *cpudata) in amd_pstate_get_energy_pref_index() argument
154 epp = amd_pstate_get_epp(cpudata, 0); in amd_pstate_get_energy_pref_index()
178 static int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp) in amd_pstate_set_epp() argument
184 u64 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_set_epp()
188 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_set_epp()
190 ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_set_epp()
192 cpudata->epp_cached = epp; in amd_pstate_set_epp()
195 ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1); in amd_pstate_set_epp()
200 cpudata->epp_cached = epp; in amd_pstate_set_epp()
206 static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata, in amd_pstate_set_energy_pref_index() argument
220 if (epp > 0 && cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { in amd_pstate_set_energy_pref_index()
225 ret = amd_pstate_set_epp(cpudata, epp); in amd_pstate_set_energy_pref_index()
290 static int pstate_init_perf(struct amd_cpudata *cpudata) in pstate_init_perf() argument
295 int ret = rdmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, in pstate_init_perf()
309 WRITE_ONCE(cpudata->highest_perf, highest_perf); in pstate_init_perf()
311 WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1)); in pstate_init_perf()
312 WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1)); in pstate_init_perf()
313 WRITE_ONCE(cpudata->lowest_perf, AMD_CPPC_LOWEST_PERF(cap1)); in pstate_init_perf()
318 static int cppc_init_perf(struct amd_cpudata *cpudata) in cppc_init_perf() argument
323 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in cppc_init_perf()
331 WRITE_ONCE(cpudata->highest_perf, highest_perf); in cppc_init_perf()
333 WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf); in cppc_init_perf()
334 WRITE_ONCE(cpudata->lowest_nonlinear_perf, in cppc_init_perf()
336 WRITE_ONCE(cpudata->lowest_perf, cppc_perf.lowest_perf); in cppc_init_perf()
341 ret = cppc_get_auto_sel_caps(cpudata->cpu, &cppc_perf); in cppc_init_perf()
347 ret = cppc_set_auto_sel(cpudata->cpu, in cppc_init_perf()
358 static inline int amd_pstate_init_perf(struct amd_cpudata *cpudata) in amd_pstate_init_perf() argument
360 return static_call(amd_pstate_init_perf)(cpudata); in amd_pstate_init_perf()
363 static void pstate_update_perf(struct amd_cpudata *cpudata, u32 min_perf, in pstate_update_perf() argument
367 wrmsrl(MSR_AMD_CPPC_REQ, READ_ONCE(cpudata->cppc_req_cached)); in pstate_update_perf()
369 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, in pstate_update_perf()
370 READ_ONCE(cpudata->cppc_req_cached)); in pstate_update_perf()
373 static void cppc_update_perf(struct amd_cpudata *cpudata, in cppc_update_perf() argument
383 cppc_set_perf(cpudata->cpu, &perf_ctrls); in cppc_update_perf()
388 static inline void amd_pstate_update_perf(struct amd_cpudata *cpudata, in amd_pstate_update_perf() argument
392 static_call(amd_pstate_update_perf)(cpudata, min_perf, des_perf, in amd_pstate_update_perf()
396 static inline bool amd_pstate_sample(struct amd_cpudata *cpudata) in amd_pstate_sample() argument
406 if (cpudata->prev.mperf == mperf || cpudata->prev.tsc == tsc) { in amd_pstate_sample()
413 cpudata->cur.aperf = aperf; in amd_pstate_sample()
414 cpudata->cur.mperf = mperf; in amd_pstate_sample()
415 cpudata->cur.tsc = tsc; in amd_pstate_sample()
416 cpudata->cur.aperf -= cpudata->prev.aperf; in amd_pstate_sample()
417 cpudata->cur.mperf -= cpudata->prev.mperf; in amd_pstate_sample()
418 cpudata->cur.tsc -= cpudata->prev.tsc; in amd_pstate_sample()
420 cpudata->prev.aperf = aperf; in amd_pstate_sample()
421 cpudata->prev.mperf = mperf; in amd_pstate_sample()
422 cpudata->prev.tsc = tsc; in amd_pstate_sample()
424 cpudata->freq = div64_u64((cpudata->cur.aperf * cpu_khz), cpudata->cur.mperf); in amd_pstate_sample()
429 static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf, in amd_pstate_update() argument
432 u64 prev = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_update()
451 if (trace_amd_pstate_perf_enabled() && amd_pstate_sample(cpudata)) { in amd_pstate_update()
452 trace_amd_pstate_perf(min_perf, des_perf, max_perf, cpudata->freq, in amd_pstate_update()
453 cpudata->cur.mperf, cpudata->cur.aperf, cpudata->cur.tsc, in amd_pstate_update()
454 cpudata->cpu, (value != prev), fast_switch); in amd_pstate_update()
460 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_update()
462 amd_pstate_update_perf(cpudata, min_perf, des_perf, in amd_pstate_update()
477 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_update_freq() local
480 if (!cpudata->max_freq) in amd_pstate_update_freq()
483 cap_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_update_freq()
484 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_update_freq()
491 cpudata->max_freq); in amd_pstate_update_freq()
502 amd_pstate_update(cpudata, min_perf, des_perf, in amd_pstate_update_freq()
532 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_adjust_perf() local
535 cap_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_adjust_perf()
536 lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); in amd_pstate_adjust_perf()
537 max_freq = READ_ONCE(cpudata->max_freq); in amd_pstate_adjust_perf()
543 min_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_adjust_perf()
558 amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true, in amd_pstate_adjust_perf()
563 static int amd_get_min_freq(struct amd_cpudata *cpudata) in amd_get_min_freq() argument
567 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_min_freq()
575 static int amd_get_max_freq(struct amd_cpudata *cpudata) in amd_get_max_freq() argument
581 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_max_freq()
586 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_get_max_freq()
587 max_perf = READ_ONCE(cpudata->highest_perf); in amd_get_max_freq()
598 static int amd_get_nominal_freq(struct amd_cpudata *cpudata) in amd_get_nominal_freq() argument
602 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_nominal_freq()
610 static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata) in amd_get_lowest_nonlinear_freq() argument
617 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_get_lowest_nonlinear_freq()
622 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_get_lowest_nonlinear_freq()
637 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_set_boost() local
640 if (!cpudata->boost_supported) { in amd_pstate_set_boost()
646 policy->cpuinfo.max_freq = cpudata->max_freq; in amd_pstate_set_boost()
648 policy->cpuinfo.max_freq = cpudata->nominal_freq; in amd_pstate_set_boost()
652 ret = freq_qos_update_request(&cpudata->req[1], in amd_pstate_set_boost()
660 static void amd_pstate_boost_init(struct amd_cpudata *cpudata) in amd_pstate_boost_init() argument
664 highest_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_boost_init()
665 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_pstate_boost_init()
670 cpudata->boost_supported = true; in amd_pstate_boost_init()
683 struct amd_cpudata *cpudata; in amd_pstate_cpu_init() local
694 cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); in amd_pstate_cpu_init()
695 if (!cpudata) in amd_pstate_cpu_init()
698 cpudata->cpu = policy->cpu; in amd_pstate_cpu_init()
700 ret = amd_pstate_init_perf(cpudata); in amd_pstate_cpu_init()
704 min_freq = amd_get_min_freq(cpudata); in amd_pstate_cpu_init()
705 max_freq = amd_get_max_freq(cpudata); in amd_pstate_cpu_init()
706 nominal_freq = amd_get_nominal_freq(cpudata); in amd_pstate_cpu_init()
707 lowest_nonlinear_freq = amd_get_lowest_nonlinear_freq(cpudata); in amd_pstate_cpu_init()
731 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0], in amd_pstate_cpu_init()
738 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[1], in amd_pstate_cpu_init()
746 cpudata->max_freq = max_freq; in amd_pstate_cpu_init()
747 cpudata->min_freq = min_freq; in amd_pstate_cpu_init()
748 cpudata->nominal_freq = nominal_freq; in amd_pstate_cpu_init()
749 cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq; in amd_pstate_cpu_init()
751 policy->driver_data = cpudata; in amd_pstate_cpu_init()
753 amd_pstate_boost_init(cpudata); in amd_pstate_cpu_init()
760 freq_qos_remove_request(&cpudata->req[0]); in amd_pstate_cpu_init()
762 kfree(cpudata); in amd_pstate_cpu_init()
768 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_cpu_exit() local
770 freq_qos_remove_request(&cpudata->req[1]); in amd_pstate_cpu_exit()
771 freq_qos_remove_request(&cpudata->req[0]); in amd_pstate_cpu_exit()
773 kfree(cpudata); in amd_pstate_cpu_exit()
811 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_max_freq() local
813 max_freq = amd_get_max_freq(cpudata); in show_amd_pstate_max_freq()
824 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_lowest_nonlinear_freq() local
826 freq = amd_get_lowest_nonlinear_freq(cpudata); in show_amd_pstate_lowest_nonlinear_freq()
841 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_highest_perf() local
843 perf = READ_ONCE(cpudata->highest_perf); in show_amd_pstate_highest_perf()
865 struct amd_cpudata *cpudata = policy->driver_data; in store_energy_performance_preference() local
878 ret = amd_pstate_set_energy_pref_index(cpudata, ret); in store_energy_performance_preference()
887 struct amd_cpudata *cpudata = policy->driver_data; in show_energy_performance_preference() local
890 preference = amd_pstate_get_energy_pref_index(cpudata); in show_energy_performance_preference()
1097 struct amd_cpudata *cpudata; in amd_pstate_epp_cpu_init() local
1110 cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); in amd_pstate_epp_cpu_init()
1111 if (!cpudata) in amd_pstate_epp_cpu_init()
1114 cpudata->cpu = policy->cpu; in amd_pstate_epp_cpu_init()
1115 cpudata->epp_policy = 0; in amd_pstate_epp_cpu_init()
1117 ret = amd_pstate_init_perf(cpudata); in amd_pstate_epp_cpu_init()
1121 min_freq = amd_get_min_freq(cpudata); in amd_pstate_epp_cpu_init()
1122 max_freq = amd_get_max_freq(cpudata); in amd_pstate_epp_cpu_init()
1123 nominal_freq = amd_get_nominal_freq(cpudata); in amd_pstate_epp_cpu_init()
1124 lowest_nonlinear_freq = amd_get_lowest_nonlinear_freq(cpudata); in amd_pstate_epp_cpu_init()
1138 cpudata->max_freq = max_freq; in amd_pstate_epp_cpu_init()
1139 cpudata->min_freq = min_freq; in amd_pstate_epp_cpu_init()
1140 cpudata->nominal_freq = nominal_freq; in amd_pstate_epp_cpu_init()
1141 cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq; in amd_pstate_epp_cpu_init()
1143 policy->driver_data = cpudata; in amd_pstate_epp_cpu_init()
1145 cpudata->epp_cached = amd_pstate_get_epp(cpudata, 0); in amd_pstate_epp_cpu_init()
1161 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value); in amd_pstate_epp_cpu_init()
1164 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_epp_cpu_init()
1166 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, &value); in amd_pstate_epp_cpu_init()
1169 WRITE_ONCE(cpudata->cppc_cap1_cached, value); in amd_pstate_epp_cpu_init()
1171 amd_pstate_boost_init(cpudata); in amd_pstate_epp_cpu_init()
1176 kfree(cpudata); in amd_pstate_epp_cpu_init()
1189 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_init() local
1194 max_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_epp_init()
1195 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_epp_init()
1197 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_init()
1199 if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) in amd_pstate_epp_init()
1213 if (cpudata->epp_policy == cpudata->policy) in amd_pstate_epp_init()
1216 cpudata->epp_policy = cpudata->policy; in amd_pstate_epp_init()
1219 epp = amd_pstate_get_epp(cpudata, value); in amd_pstate_epp_init()
1228 if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) in amd_pstate_epp_init()
1237 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_epp_init()
1238 amd_pstate_set_epp(cpudata, epp); in amd_pstate_epp_init()
1245 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_set_policy() local
1253 cpudata->policy = policy->policy; in amd_pstate_epp_set_policy()
1260 static void amd_pstate_epp_reenable(struct amd_cpudata *cpudata) in amd_pstate_epp_reenable() argument
1270 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_reenable()
1271 max_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_epp_reenable()
1274 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_epp_reenable()
1277 perf_ctrls.energy_perf = AMD_CPPC_ENERGY_PERF_PREF(cpudata->epp_cached); in amd_pstate_epp_reenable()
1278 cppc_set_perf(cpudata->cpu, &perf_ctrls); in amd_pstate_epp_reenable()
1284 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_cpu_online() local
1286 pr_debug("AMD CPU Core %d going online\n", cpudata->cpu); in amd_pstate_epp_cpu_online()
1289 amd_pstate_epp_reenable(cpudata); in amd_pstate_epp_cpu_online()
1290 cpudata->suspended = false; in amd_pstate_epp_cpu_online()
1298 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_offline() local
1303 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_epp_offline()
1304 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_offline()
1308 cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN; in amd_pstate_epp_offline()
1315 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_epp_offline()
1320 cppc_set_perf(cpudata->cpu, &perf_ctrls); in amd_pstate_epp_offline()
1327 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_cpu_offline() local
1329 pr_debug("AMD CPU Core %d going offline\n", cpudata->cpu); in amd_pstate_epp_cpu_offline()
1331 if (cpudata->suspended) in amd_pstate_epp_cpu_offline()
1349 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_suspend() local
1357 cpudata->suspended = true; in amd_pstate_epp_suspend()
1369 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_resume() local
1371 if (cpudata->suspended) { in amd_pstate_epp_resume()
1375 amd_pstate_epp_reenable(cpudata); in amd_pstate_epp_resume()
1379 cpudata->suspended = false; in amd_pstate_epp_resume()