32
32
33
33
#include "amd-pstate.h"
34
34
35
- /*
36
- * Abbreviations:
37
- * amd_pstate_ut: used as a shortform for AMD P-State unit test.
38
- * It helps to keep variable names smaller, simpler
39
- */
40
- enum amd_pstate_ut_result {
41
- AMD_PSTATE_UT_RESULT_PASS ,
42
- AMD_PSTATE_UT_RESULT_FAIL ,
43
- };
44
35
45
36
struct amd_pstate_ut_struct {
46
37
const char * name ;
47
- void (* func )(u32 index );
48
- enum amd_pstate_ut_result result ;
38
+ int (* func )(u32 index );
49
39
};
50
40
51
41
/*
52
42
* Kernel module for testing the AMD P-State unit test
53
43
*/
54
- static void amd_pstate_ut_acpi_cpc_valid (u32 index );
55
- static void amd_pstate_ut_check_enabled (u32 index );
56
- static void amd_pstate_ut_check_perf (u32 index );
57
- static void amd_pstate_ut_check_freq (u32 index );
58
- static void amd_pstate_ut_check_driver (u32 index );
44
+ static int amd_pstate_ut_acpi_cpc_valid (u32 index );
45
+ static int amd_pstate_ut_check_enabled (u32 index );
46
+ static int amd_pstate_ut_check_perf (u32 index );
47
+ static int amd_pstate_ut_check_freq (u32 index );
48
+ static int amd_pstate_ut_check_driver (u32 index );
59
49
60
50
static struct amd_pstate_ut_struct amd_pstate_ut_cases [] = {
61
51
{"amd_pstate_ut_acpi_cpc_valid" , amd_pstate_ut_acpi_cpc_valid },
@@ -78,51 +68,46 @@ static bool get_shared_mem(void)
78
68
/*
79
69
* check the _CPC object is present in SBIOS.
80
70
*/
81
- static void amd_pstate_ut_acpi_cpc_valid (u32 index )
71
+ static int amd_pstate_ut_acpi_cpc_valid (u32 index )
82
72
{
83
- if (acpi_cpc_valid ())
84
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_PASS ;
85
- else {
86
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
73
+ if (!acpi_cpc_valid ()) {
87
74
pr_err ("%s the _CPC object is not present in SBIOS!\n" , __func__ );
75
+ return - EINVAL ;
88
76
}
77
+
78
+ return 0 ;
89
79
}
90
80
91
- static void amd_pstate_ut_pstate_enable (u32 index )
81
+ /*
82
+ * check if amd pstate is enabled
83
+ */
84
+ static int amd_pstate_ut_check_enabled (u32 index )
92
85
{
93
- int ret = 0 ;
94
86
u64 cppc_enable = 0 ;
87
+ int ret ;
88
+
89
+ if (get_shared_mem ())
90
+ return 0 ;
95
91
96
92
ret = rdmsrl_safe (MSR_AMD_CPPC_ENABLE , & cppc_enable );
97
93
if (ret ) {
98
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
99
94
pr_err ("%s rdmsrl_safe MSR_AMD_CPPC_ENABLE ret=%d error!\n" , __func__ , ret );
100
- return ;
95
+ return ret ;
101
96
}
102
- if (cppc_enable )
103
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_PASS ;
104
- else {
105
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
97
+
98
+ if (!cppc_enable ) {
106
99
pr_err ("%s amd pstate must be enabled!\n" , __func__ );
100
+ return - EINVAL ;
107
101
}
108
- }
109
102
110
- /*
111
- * check if amd pstate is enabled
112
- */
113
- static void amd_pstate_ut_check_enabled (u32 index )
114
- {
115
- if (get_shared_mem ())
116
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_PASS ;
117
- else
118
- amd_pstate_ut_pstate_enable (index );
103
+ return 0 ;
119
104
}
120
105
121
106
/*
122
107
* check if performance values are reasonable.
123
108
* highest_perf >= nominal_perf > lowest_nonlinear_perf > lowest_perf > 0
124
109
*/
125
- static void amd_pstate_ut_check_perf (u32 index )
110
+ static int amd_pstate_ut_check_perf (u32 index )
126
111
{
127
112
int cpu = 0 , ret = 0 ;
128
113
u32 highest_perf = 0 , nominal_perf = 0 , lowest_nonlinear_perf = 0 , lowest_perf = 0 ;
@@ -142,9 +127,8 @@ static void amd_pstate_ut_check_perf(u32 index)
142
127
if (get_shared_mem ()) {
143
128
ret = cppc_get_perf_caps (cpu , & cppc_perf );
144
129
if (ret ) {
145
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
146
130
pr_err ("%s cppc_get_perf_caps ret=%d error!\n" , __func__ , ret );
147
- return ;
131
+ return ret ;
148
132
}
149
133
150
134
highest_perf = cppc_perf .highest_perf ;
@@ -154,9 +138,8 @@ static void amd_pstate_ut_check_perf(u32 index)
154
138
} else {
155
139
ret = rdmsrl_safe_on_cpu (cpu , MSR_AMD_CPPC_CAP1 , & cap1 );
156
140
if (ret ) {
157
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
158
141
pr_err ("%s read CPPC_CAP1 ret=%d error!\n" , __func__ , ret );
159
- return ;
142
+ return ret ;
160
143
}
161
144
162
145
highest_perf = AMD_CPPC_HIGHEST_PERF (cap1 );
@@ -169,40 +152,38 @@ static void amd_pstate_ut_check_perf(u32 index)
169
152
if (highest_perf != cur_perf .highest_perf && !cpudata -> hw_prefcore ) {
170
153
pr_err ("%s cpu%d highest=%d %d highest perf doesn't match\n" ,
171
154
__func__ , cpu , highest_perf , cur_perf .highest_perf );
172
- return ;
155
+ return - EINVAL ;
173
156
}
174
157
if (nominal_perf != cur_perf .nominal_perf ||
175
158
(lowest_nonlinear_perf != cur_perf .lowest_nonlinear_perf ) ||
176
159
(lowest_perf != cur_perf .lowest_perf )) {
177
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
178
160
pr_err ("%s cpu%d nominal=%d %d lowest_nonlinear=%d %d lowest=%d %d, they should be equal!\n" ,
179
161
__func__ , cpu , nominal_perf , cur_perf .nominal_perf ,
180
162
lowest_nonlinear_perf , cur_perf .lowest_nonlinear_perf ,
181
163
lowest_perf , cur_perf .lowest_perf );
182
- return ;
164
+ return - EINVAL ;
183
165
}
184
166
185
167
if (!((highest_perf >= nominal_perf ) &&
186
168
(nominal_perf > lowest_nonlinear_perf ) &&
187
169
(lowest_nonlinear_perf >= lowest_perf ) &&
188
170
(lowest_perf > 0 ))) {
189
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
190
171
pr_err ("%s cpu%d highest=%d >= nominal=%d > lowest_nonlinear=%d > lowest=%d > 0, the formula is incorrect!\n" ,
191
172
__func__ , cpu , highest_perf , nominal_perf ,
192
173
lowest_nonlinear_perf , lowest_perf );
193
- return ;
174
+ return - EINVAL ;
194
175
}
195
176
}
196
177
197
- amd_pstate_ut_cases [ index ]. result = AMD_PSTATE_UT_RESULT_PASS ;
178
+ return 0 ;
198
179
}
199
180
200
181
/*
201
182
* Check if frequency values are reasonable.
202
183
* max_freq >= nominal_freq > lowest_nonlinear_freq > min_freq > 0
203
184
* check max freq when set support boost mode.
204
185
*/
205
- static void amd_pstate_ut_check_freq (u32 index )
186
+ static int amd_pstate_ut_check_freq (u32 index )
206
187
{
207
188
int cpu = 0 ;
208
189
struct amd_cpudata * cpudata = NULL ;
@@ -219,39 +200,33 @@ static void amd_pstate_ut_check_freq(u32 index)
219
200
(cpudata -> nominal_freq > cpudata -> lowest_nonlinear_freq ) &&
220
201
(cpudata -> lowest_nonlinear_freq >= policy -> cpuinfo .min_freq ) &&
221
202
(policy -> cpuinfo .min_freq > 0 ))) {
222
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
223
203
pr_err ("%s cpu%d max=%d >= nominal=%d > lowest_nonlinear=%d > min=%d > 0, the formula is incorrect!\n" ,
224
204
__func__ , cpu , policy -> cpuinfo .max_freq , cpudata -> nominal_freq ,
225
205
cpudata -> lowest_nonlinear_freq , policy -> cpuinfo .min_freq );
226
- return ;
206
+ return - EINVAL ;
227
207
}
228
208
229
209
if (cpudata -> lowest_nonlinear_freq != policy -> min ) {
230
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
231
210
pr_err ("%s cpu%d cpudata_lowest_nonlinear_freq=%d policy_min=%d, they should be equal!\n" ,
232
211
__func__ , cpu , cpudata -> lowest_nonlinear_freq , policy -> min );
233
- return ;
212
+ return - EINVAL ;
234
213
}
235
214
236
215
if (cpudata -> boost_supported ) {
237
- if ((policy -> max == policy -> cpuinfo .max_freq ) ||
238
- (policy -> max == cpudata -> nominal_freq ))
239
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_PASS ;
240
- else {
241
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
216
+ if ((policy -> max != policy -> cpuinfo .max_freq ) &&
217
+ (policy -> max != cpudata -> nominal_freq )) {
242
218
pr_err ("%s cpu%d policy_max=%d should be equal cpu_max=%d or cpu_nominal=%d !\n" ,
243
219
__func__ , cpu , policy -> max , policy -> cpuinfo .max_freq ,
244
220
cpudata -> nominal_freq );
245
- return ;
221
+ return - EINVAL ;
246
222
}
247
223
} else {
248
- amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
249
224
pr_err ("%s cpu%d must support boost!\n" , __func__ , cpu );
250
- return ;
225
+ return - EINVAL ;
251
226
}
252
227
}
253
228
254
- amd_pstate_ut_cases [ index ]. result = AMD_PSTATE_UT_RESULT_PASS ;
229
+ return 0 ;
255
230
}
256
231
257
232
static int amd_pstate_set_mode (enum amd_pstate_mode mode )
@@ -263,49 +238,41 @@ static int amd_pstate_set_mode(enum amd_pstate_mode mode)
263
238
return amd_pstate_update_status (mode_str , strlen (mode_str ));
264
239
}
265
240
266
- static void amd_pstate_ut_check_driver (u32 index )
241
+ static int amd_pstate_ut_check_driver (u32 index )
267
242
{
268
243
enum amd_pstate_mode mode1 , mode2 = AMD_PSTATE_DISABLE ;
269
- int ret ;
270
244
271
245
for (mode1 = AMD_PSTATE_DISABLE ; mode1 < AMD_PSTATE_MAX ; mode1 ++ ) {
272
- ret = amd_pstate_set_mode (mode1 );
246
+ int ret = amd_pstate_set_mode (mode1 );
273
247
if (ret )
274
- goto out ;
248
+ return ret ;
275
249
for (mode2 = AMD_PSTATE_DISABLE ; mode2 < AMD_PSTATE_MAX ; mode2 ++ ) {
276
250
if (mode1 == mode2 )
277
251
continue ;
278
252
ret = amd_pstate_set_mode (mode2 );
279
- if (ret )
280
- goto out ;
253
+ if (ret ) {
254
+ pr_err ("%s: failed to update status for %s->%s\n" , __func__ ,
255
+ amd_pstate_get_mode_string (mode1 ),
256
+ amd_pstate_get_mode_string (mode2 ));
257
+ return ret ;
258
+ }
281
259
}
282
260
}
283
- out :
284
- if (ret )
285
- pr_warn ("%s: failed to update status for %s->%s: %d\n" , __func__ ,
286
- amd_pstate_get_mode_string (mode1 ),
287
- amd_pstate_get_mode_string (mode2 ), ret );
288
-
289
- amd_pstate_ut_cases [index ].result = ret ?
290
- AMD_PSTATE_UT_RESULT_FAIL :
291
- AMD_PSTATE_UT_RESULT_PASS ;
261
+
262
+ return 0 ;
292
263
}
293
264
294
265
static int __init amd_pstate_ut_init (void )
295
266
{
296
267
u32 i = 0 , arr_size = ARRAY_SIZE (amd_pstate_ut_cases );
297
268
298
269
for (i = 0 ; i < arr_size ; i ++ ) {
299
- amd_pstate_ut_cases [i ].func (i );
300
- switch (amd_pstate_ut_cases [i ].result ) {
301
- case AMD_PSTATE_UT_RESULT_PASS :
270
+ int ret = amd_pstate_ut_cases [i ].func (i );
271
+
272
+ if (ret )
273
+ pr_err ("%-4d %-20s\t fail: %d!\n" , i + 1 , amd_pstate_ut_cases [i ].name , ret );
274
+ else
302
275
pr_info ("%-4d %-20s\t success!\n" , i + 1 , amd_pstate_ut_cases [i ].name );
303
- break ;
304
- case AMD_PSTATE_UT_RESULT_FAIL :
305
- default :
306
- pr_info ("%-4d %-20s\t fail!\n" , i + 1 , amd_pstate_ut_cases [i ].name );
307
- break ;
308
- }
309
276
}
310
277
311
278
return 0 ;
0 commit comments