Skip to content

Commit 555bbe6

Browse files
dhananjay-AMDsuperm1
authored andcommitted
cpufreq/amd-pstate: Convert all perf values to u8
All perf values are always within 0-255 range, hence convert their datatype to u8 everywhere. Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com> Link: https://lore.kernel.org/r/20250205112523.201101-7-dhananjay.ugwekar@amd.com Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
1 parent e9869c8 commit 555bbe6

3 files changed

Lines changed: 62 additions & 62 deletions

File tree

drivers/cpufreq/amd-pstate-trace.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
TRACE_EVENT(amd_pstate_perf,
2626

27-
TP_PROTO(unsigned long min_perf,
28-
unsigned long target_perf,
29-
unsigned long capacity,
27+
TP_PROTO(u8 min_perf,
28+
u8 target_perf,
29+
u8 capacity,
3030
u64 freq,
3131
u64 mperf,
3232
u64 aperf,
@@ -47,9 +47,9 @@ TRACE_EVENT(amd_pstate_perf,
4747
),
4848

4949
TP_STRUCT__entry(
50-
__field(unsigned long, min_perf)
51-
__field(unsigned long, target_perf)
52-
__field(unsigned long, capacity)
50+
__field(u8, min_perf)
51+
__field(u8, target_perf)
52+
__field(u8, capacity)
5353
__field(unsigned long long, freq)
5454
__field(unsigned long long, mperf)
5555
__field(unsigned long long, aperf)
@@ -70,10 +70,10 @@ TRACE_EVENT(amd_pstate_perf,
7070
__entry->fast_switch = fast_switch;
7171
),
7272

73-
TP_printk("amd_min_perf=%lu amd_des_perf=%lu amd_max_perf=%lu freq=%llu mperf=%llu aperf=%llu tsc=%llu cpu_id=%u fast_switch=%s",
74-
(unsigned long)__entry->min_perf,
75-
(unsigned long)__entry->target_perf,
76-
(unsigned long)__entry->capacity,
73+
TP_printk("amd_min_perf=%hhu amd_des_perf=%hhu amd_max_perf=%hhu freq=%llu mperf=%llu aperf=%llu tsc=%llu cpu_id=%u fast_switch=%s",
74+
(u8)__entry->min_perf,
75+
(u8)__entry->target_perf,
76+
(u8)__entry->capacity,
7777
(unsigned long long)__entry->freq,
7878
(unsigned long long)__entry->mperf,
7979
(unsigned long long)__entry->aperf,
@@ -86,10 +86,10 @@ TRACE_EVENT(amd_pstate_perf,
8686
TRACE_EVENT(amd_pstate_epp_perf,
8787

8888
TP_PROTO(unsigned int cpu_id,
89-
unsigned int highest_perf,
90-
unsigned int epp,
91-
unsigned int min_perf,
92-
unsigned int max_perf,
89+
u8 highest_perf,
90+
u8 epp,
91+
u8 min_perf,
92+
u8 max_perf,
9393
bool boost
9494
),
9595

@@ -102,10 +102,10 @@ TRACE_EVENT(amd_pstate_epp_perf,
102102

103103
TP_STRUCT__entry(
104104
__field(unsigned int, cpu_id)
105-
__field(unsigned int, highest_perf)
106-
__field(unsigned int, epp)
107-
__field(unsigned int, min_perf)
108-
__field(unsigned int, max_perf)
105+
__field(u8, highest_perf)
106+
__field(u8, epp)
107+
__field(u8, min_perf)
108+
__field(u8, max_perf)
109109
__field(bool, boost)
110110
),
111111

@@ -118,12 +118,12 @@ TRACE_EVENT(amd_pstate_epp_perf,
118118
__entry->boost = boost;
119119
),
120120

121-
TP_printk("cpu%u: [%u<->%u]/%u, epp=%u, boost=%u",
121+
TP_printk("cpu%u: [%hhu<->%hhu]/%hhu, epp=%hhu, boost=%u",
122122
(unsigned int)__entry->cpu_id,
123-
(unsigned int)__entry->min_perf,
124-
(unsigned int)__entry->max_perf,
125-
(unsigned int)__entry->highest_perf,
126-
(unsigned int)__entry->epp,
123+
(u8)__entry->min_perf,
124+
(u8)__entry->max_perf,
125+
(u8)__entry->highest_perf,
126+
(u8)__entry->epp,
127127
(bool)__entry->boost
128128
)
129129
);

drivers/cpufreq/amd-pstate.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static inline int get_mode_idx_from_str(const char *str, size_t size)
186186
static DEFINE_MUTEX(amd_pstate_limits_lock);
187187
static DEFINE_MUTEX(amd_pstate_driver_lock);
188188

189-
static s16 msr_get_epp(struct amd_cpudata *cpudata)
189+
static u8 msr_get_epp(struct amd_cpudata *cpudata)
190190
{
191191
u64 value;
192192
int ret;
@@ -207,7 +207,7 @@ static inline s16 amd_pstate_get_epp(struct amd_cpudata *cpudata)
207207
return static_call(amd_pstate_get_epp)(cpudata);
208208
}
209209

210-
static s16 shmem_get_epp(struct amd_cpudata *cpudata)
210+
static u8 shmem_get_epp(struct amd_cpudata *cpudata)
211211
{
212212
u64 epp;
213213
int ret;
@@ -218,11 +218,11 @@ static s16 shmem_get_epp(struct amd_cpudata *cpudata)
218218
return ret;
219219
}
220220

221-
return (s16)(epp & 0xff);
221+
return FIELD_GET(AMD_CPPC_EPP_PERF_MASK, epp);
222222
}
223223

224-
static int msr_update_perf(struct amd_cpudata *cpudata, u32 min_perf,
225-
u32 des_perf, u32 max_perf, u32 epp, bool fast_switch)
224+
static int msr_update_perf(struct amd_cpudata *cpudata, u8 min_perf,
225+
u8 des_perf, u8 max_perf, u8 epp, bool fast_switch)
226226
{
227227
u64 value, prev;
228228

@@ -257,15 +257,15 @@ static int msr_update_perf(struct amd_cpudata *cpudata, u32 min_perf,
257257
DEFINE_STATIC_CALL(amd_pstate_update_perf, msr_update_perf);
258258

259259
static inline int amd_pstate_update_perf(struct amd_cpudata *cpudata,
260-
u32 min_perf, u32 des_perf,
261-
u32 max_perf, u32 epp,
260+
u8 min_perf, u8 des_perf,
261+
u8 max_perf, u8 epp,
262262
bool fast_switch)
263263
{
264264
return static_call(amd_pstate_update_perf)(cpudata, min_perf, des_perf,
265265
max_perf, epp, fast_switch);
266266
}
267267

268-
static int msr_set_epp(struct amd_cpudata *cpudata, u32 epp)
268+
static int msr_set_epp(struct amd_cpudata *cpudata, u8 epp)
269269
{
270270
u64 value, prev;
271271
int ret;
@@ -292,12 +292,12 @@ static int msr_set_epp(struct amd_cpudata *cpudata, u32 epp)
292292

293293
DEFINE_STATIC_CALL(amd_pstate_set_epp, msr_set_epp);
294294

295-
static inline int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp)
295+
static inline int amd_pstate_set_epp(struct amd_cpudata *cpudata, u8 epp)
296296
{
297297
return static_call(amd_pstate_set_epp)(cpudata, epp);
298298
}
299299

300-
static int shmem_set_epp(struct amd_cpudata *cpudata, u32 epp)
300+
static int shmem_set_epp(struct amd_cpudata *cpudata, u8 epp)
301301
{
302302
int ret;
303303
struct cppc_perf_ctrls perf_ctrls;
@@ -320,7 +320,7 @@ static int amd_pstate_set_energy_pref_index(struct cpufreq_policy *policy,
320320
int pref_index)
321321
{
322322
struct amd_cpudata *cpudata = policy->driver_data;
323-
int epp;
323+
u8 epp;
324324

325325
if (!pref_index)
326326
epp = cpudata->epp_default;
@@ -479,8 +479,8 @@ static inline int amd_pstate_init_perf(struct amd_cpudata *cpudata)
479479
return static_call(amd_pstate_init_perf)(cpudata);
480480
}
481481

482-
static int shmem_update_perf(struct amd_cpudata *cpudata, u32 min_perf,
483-
u32 des_perf, u32 max_perf, u32 epp, bool fast_switch)
482+
static int shmem_update_perf(struct amd_cpudata *cpudata, u8 min_perf,
483+
u8 des_perf, u8 max_perf, u8 epp, bool fast_switch)
484484
{
485485
struct cppc_perf_ctrls perf_ctrls;
486486

@@ -531,14 +531,14 @@ static inline bool amd_pstate_sample(struct amd_cpudata *cpudata)
531531
return true;
532532
}
533533

534-
static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,
535-
u32 des_perf, u32 max_perf, bool fast_switch, int gov_flags)
534+
static void amd_pstate_update(struct amd_cpudata *cpudata, u8 min_perf,
535+
u8 des_perf, u8 max_perf, bool fast_switch, int gov_flags)
536536
{
537537
unsigned long max_freq;
538538
struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu);
539-
u32 nominal_perf = READ_ONCE(cpudata->nominal_perf);
539+
u8 nominal_perf = READ_ONCE(cpudata->nominal_perf);
540540

541-
des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);
541+
des_perf = clamp_t(u8, des_perf, min_perf, max_perf);
542542

543543
max_freq = READ_ONCE(cpudata->max_limit_freq);
544544
policy->cur = div_u64(des_perf * max_freq, max_perf);
@@ -550,7 +550,7 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,
550550

551551
/* limit the max perf when core performance boost feature is disabled */
552552
if (!cpudata->boost_supported)
553-
max_perf = min_t(unsigned long, nominal_perf, max_perf);
553+
max_perf = min_t(u8, nominal_perf, max_perf);
554554

555555
if (trace_amd_pstate_perf_enabled() && amd_pstate_sample(cpudata)) {
556556
trace_amd_pstate_perf(min_perf, des_perf, max_perf, cpudata->freq,
@@ -591,7 +591,8 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy_data)
591591

592592
static int amd_pstate_update_min_max_limit(struct cpufreq_policy *policy)
593593
{
594-
u32 max_limit_perf, min_limit_perf, max_perf, max_freq;
594+
u8 max_limit_perf, min_limit_perf, max_perf;
595+
u32 max_freq;
595596
struct amd_cpudata *cpudata = policy->driver_data;
596597

597598
max_perf = READ_ONCE(cpudata->highest_perf);
@@ -615,7 +616,7 @@ static int amd_pstate_update_freq(struct cpufreq_policy *policy,
615616
{
616617
struct cpufreq_freqs freqs;
617618
struct amd_cpudata *cpudata = policy->driver_data;
618-
unsigned long des_perf, cap_perf;
619+
u8 des_perf, cap_perf;
619620

620621
if (!cpudata->max_freq)
621622
return -ENODEV;
@@ -670,8 +671,7 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
670671
unsigned long target_perf,
671672
unsigned long capacity)
672673
{
673-
unsigned long max_perf, min_perf, des_perf,
674-
cap_perf, min_limit_perf;
674+
u8 max_perf, min_perf, des_perf, cap_perf, min_limit_perf;
675675
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
676676
struct amd_cpudata *cpudata;
677677

@@ -905,8 +905,8 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
905905
{
906906
int ret;
907907
u32 min_freq, max_freq;
908-
u32 highest_perf, nominal_perf, nominal_freq;
909-
u32 lowest_nonlinear_perf, lowest_nonlinear_freq;
908+
u8 highest_perf, nominal_perf, lowest_nonlinear_perf;
909+
u32 nominal_freq, lowest_nonlinear_freq;
910910
struct cppc_perf_caps cppc_perf;
911911

912912
ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
@@ -1113,7 +1113,7 @@ static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *poli
11131113
static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy,
11141114
char *buf)
11151115
{
1116-
u32 perf;
1116+
u8 perf;
11171117
struct amd_cpudata *cpudata = policy->driver_data;
11181118

11191119
perf = READ_ONCE(cpudata->highest_perf);
@@ -1124,7 +1124,7 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy,
11241124
static ssize_t show_amd_pstate_prefcore_ranking(struct cpufreq_policy *policy,
11251125
char *buf)
11261126
{
1127-
u32 perf;
1127+
u8 perf;
11281128
struct amd_cpudata *cpudata = policy->driver_data;
11291129

11301130
perf = READ_ONCE(cpudata->prefcore_ranking);
@@ -1187,7 +1187,7 @@ static ssize_t show_energy_performance_preference(
11871187
struct cpufreq_policy *policy, char *buf)
11881188
{
11891189
struct amd_cpudata *cpudata = policy->driver_data;
1190-
int preference;
1190+
u8 preference;
11911191

11921192
switch (cpudata->epp_cached) {
11931193
case AMD_CPPC_EPP_PERFORMANCE:
@@ -1549,7 +1549,7 @@ static void amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy)
15491549
static int amd_pstate_epp_update_limit(struct cpufreq_policy *policy)
15501550
{
15511551
struct amd_cpudata *cpudata = policy->driver_data;
1552-
u32 epp;
1552+
u8 epp;
15531553

15541554
amd_pstate_update_min_max_limit(policy);
15551555

@@ -1598,7 +1598,7 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
15981598
static int amd_pstate_epp_reenable(struct cpufreq_policy *policy)
15991599
{
16001600
struct amd_cpudata *cpudata = policy->driver_data;
1601-
u64 max_perf;
1601+
u8 max_perf;
16021602
int ret;
16031603

16041604
ret = amd_pstate_cppc_enable(true);
@@ -1635,7 +1635,7 @@ static int amd_pstate_epp_cpu_online(struct cpufreq_policy *policy)
16351635
static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
16361636
{
16371637
struct amd_cpudata *cpudata = policy->driver_data;
1638-
int min_perf;
1638+
u8 min_perf;
16391639

16401640
if (cpudata->suspended)
16411641
return 0;

drivers/cpufreq/amd-pstate.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ struct amd_cpudata {
7070
struct freq_qos_request req[2];
7171
u64 cppc_req_cached;
7272

73-
u32 highest_perf;
74-
u32 nominal_perf;
75-
u32 lowest_nonlinear_perf;
76-
u32 lowest_perf;
77-
u32 prefcore_ranking;
78-
u32 min_limit_perf;
79-
u32 max_limit_perf;
73+
u8 highest_perf;
74+
u8 nominal_perf;
75+
u8 lowest_nonlinear_perf;
76+
u8 lowest_perf;
77+
u8 prefcore_ranking;
78+
u8 min_limit_perf;
79+
u8 max_limit_perf;
8080
u32 min_limit_freq;
8181
u32 max_limit_freq;
8282

@@ -93,11 +93,11 @@ struct amd_cpudata {
9393
bool hw_prefcore;
9494

9595
/* EPP feature related attributes*/
96-
s16 epp_cached;
96+
u8 epp_cached;
9797
u32 policy;
9898
u64 cppc_cap1_cached;
9999
bool suspended;
100-
s16 epp_default;
100+
u8 epp_default;
101101
};
102102

103103
/*

0 commit comments

Comments
 (0)