@@ -228,9 +228,10 @@ static u8 shmem_get_epp(struct amd_cpudata *cpudata)
228
228
return FIELD_GET (AMD_CPPC_EPP_PERF_MASK , epp );
229
229
}
230
230
231
- static int msr_update_perf (struct amd_cpudata * cpudata , u8 min_perf ,
231
+ static int msr_update_perf (struct cpufreq_policy * policy , u8 min_perf ,
232
232
u8 des_perf , u8 max_perf , u8 epp , bool fast_switch )
233
233
{
234
+ struct amd_cpudata * cpudata = policy -> driver_data ;
234
235
u64 value , prev ;
235
236
236
237
value = prev = READ_ONCE (cpudata -> cppc_req_cached );
@@ -242,6 +243,18 @@ static int msr_update_perf(struct amd_cpudata *cpudata, u8 min_perf,
242
243
value |= FIELD_PREP (AMD_CPPC_MIN_PERF_MASK , min_perf );
243
244
value |= FIELD_PREP (AMD_CPPC_EPP_PERF_MASK , epp );
244
245
246
+ if (trace_amd_pstate_epp_perf_enabled ()) {
247
+ union perf_cached perf = READ_ONCE (cpudata -> perf );
248
+
249
+ trace_amd_pstate_epp_perf (cpudata -> cpu ,
250
+ perf .highest_perf ,
251
+ epp ,
252
+ min_perf ,
253
+ max_perf ,
254
+ policy -> boost_enabled ,
255
+ value != prev );
256
+ }
257
+
245
258
if (value == prev )
246
259
return 0 ;
247
260
@@ -256,31 +269,46 @@ static int msr_update_perf(struct amd_cpudata *cpudata, u8 min_perf,
256
269
}
257
270
258
271
WRITE_ONCE (cpudata -> cppc_req_cached , value );
259
- WRITE_ONCE (cpudata -> epp_cached , epp );
272
+ if (epp != cpudata -> epp_cached )
273
+ WRITE_ONCE (cpudata -> epp_cached , epp );
260
274
261
275
return 0 ;
262
276
}
263
277
264
278
DEFINE_STATIC_CALL (amd_pstate_update_perf , msr_update_perf );
265
279
266
- static inline int amd_pstate_update_perf (struct amd_cpudata * cpudata ,
280
+ static inline int amd_pstate_update_perf (struct cpufreq_policy * policy ,
267
281
u8 min_perf , u8 des_perf ,
268
282
u8 max_perf , u8 epp ,
269
283
bool fast_switch )
270
284
{
271
- return static_call (amd_pstate_update_perf )(cpudata , min_perf , des_perf ,
285
+ return static_call (amd_pstate_update_perf )(policy , min_perf , des_perf ,
272
286
max_perf , epp , fast_switch );
273
287
}
274
288
275
- static int msr_set_epp (struct amd_cpudata * cpudata , u8 epp )
289
+ static int msr_set_epp (struct cpufreq_policy * policy , u8 epp )
276
290
{
291
+ struct amd_cpudata * cpudata = policy -> driver_data ;
277
292
u64 value , prev ;
278
293
int ret ;
279
294
280
295
value = prev = READ_ONCE (cpudata -> cppc_req_cached );
281
296
value &= ~AMD_CPPC_EPP_PERF_MASK ;
282
297
value |= FIELD_PREP (AMD_CPPC_EPP_PERF_MASK , epp );
283
298
299
+ if (trace_amd_pstate_epp_perf_enabled ()) {
300
+ union perf_cached perf = cpudata -> perf ;
301
+
302
+ trace_amd_pstate_epp_perf (cpudata -> cpu , perf .highest_perf ,
303
+ epp ,
304
+ FIELD_GET (AMD_CPPC_MIN_PERF_MASK ,
305
+ cpudata -> cppc_req_cached ),
306
+ FIELD_GET (AMD_CPPC_MAX_PERF_MASK ,
307
+ cpudata -> cppc_req_cached ),
308
+ policy -> boost_enabled ,
309
+ value != prev );
310
+ }
311
+
284
312
if (value == prev )
285
313
return 0 ;
286
314
@@ -299,15 +327,29 @@ static int msr_set_epp(struct amd_cpudata *cpudata, u8 epp)
299
327
300
328
DEFINE_STATIC_CALL (amd_pstate_set_epp , msr_set_epp );
301
329
302
- static inline int amd_pstate_set_epp (struct amd_cpudata * cpudata , u8 epp )
330
+ static inline int amd_pstate_set_epp (struct cpufreq_policy * policy , u8 epp )
303
331
{
304
- return static_call (amd_pstate_set_epp )(cpudata , epp );
332
+ return static_call (amd_pstate_set_epp )(policy , epp );
305
333
}
306
334
307
- static int shmem_set_epp (struct amd_cpudata * cpudata , u8 epp )
335
+ static int shmem_set_epp (struct cpufreq_policy * policy , u8 epp )
308
336
{
309
- int ret ;
337
+ struct amd_cpudata * cpudata = policy -> driver_data ;
310
338
struct cppc_perf_ctrls perf_ctrls ;
339
+ int ret ;
340
+
341
+ if (trace_amd_pstate_epp_perf_enabled ()) {
342
+ union perf_cached perf = cpudata -> perf ;
343
+
344
+ trace_amd_pstate_epp_perf (cpudata -> cpu , perf .highest_perf ,
345
+ epp ,
346
+ FIELD_GET (AMD_CPPC_MIN_PERF_MASK ,
347
+ cpudata -> cppc_req_cached ),
348
+ FIELD_GET (AMD_CPPC_MAX_PERF_MASK ,
349
+ cpudata -> cppc_req_cached ),
350
+ policy -> boost_enabled ,
351
+ epp != cpudata -> epp_cached );
352
+ }
311
353
312
354
if (epp == cpudata -> epp_cached )
313
355
return 0 ;
@@ -339,17 +381,7 @@ static int amd_pstate_set_energy_pref_index(struct cpufreq_policy *policy,
339
381
return - EBUSY ;
340
382
}
341
383
342
- if (trace_amd_pstate_epp_perf_enabled ()) {
343
- union perf_cached perf = READ_ONCE (cpudata -> perf );
344
-
345
- trace_amd_pstate_epp_perf (cpudata -> cpu , perf .highest_perf ,
346
- epp ,
347
- FIELD_GET (AMD_CPPC_MIN_PERF_MASK , cpudata -> cppc_req_cached ),
348
- FIELD_GET (AMD_CPPC_MAX_PERF_MASK , cpudata -> cppc_req_cached ),
349
- policy -> boost_enabled );
350
- }
351
-
352
- return amd_pstate_set_epp (cpudata , epp );
384
+ return amd_pstate_set_epp (policy , epp );
353
385
}
354
386
355
387
static inline int msr_cppc_enable (bool enable )
@@ -492,15 +524,16 @@ static inline int amd_pstate_init_perf(struct amd_cpudata *cpudata)
492
524
return static_call (amd_pstate_init_perf )(cpudata );
493
525
}
494
526
495
- static int shmem_update_perf (struct amd_cpudata * cpudata , u8 min_perf ,
527
+ static int shmem_update_perf (struct cpufreq_policy * policy , u8 min_perf ,
496
528
u8 des_perf , u8 max_perf , u8 epp , bool fast_switch )
497
529
{
530
+ struct amd_cpudata * cpudata = policy -> driver_data ;
498
531
struct cppc_perf_ctrls perf_ctrls ;
499
532
u64 value , prev ;
500
533
int ret ;
501
534
502
535
if (cppc_state == AMD_PSTATE_ACTIVE ) {
503
- int ret = shmem_set_epp (cpudata , epp );
536
+ int ret = shmem_set_epp (policy , epp );
504
537
505
538
if (ret )
506
539
return ret ;
@@ -515,6 +548,18 @@ static int shmem_update_perf(struct amd_cpudata *cpudata, u8 min_perf,
515
548
value |= FIELD_PREP (AMD_CPPC_MIN_PERF_MASK , min_perf );
516
549
value |= FIELD_PREP (AMD_CPPC_EPP_PERF_MASK , epp );
517
550
551
+ if (trace_amd_pstate_epp_perf_enabled ()) {
552
+ union perf_cached perf = READ_ONCE (cpudata -> perf );
553
+
554
+ trace_amd_pstate_epp_perf (cpudata -> cpu ,
555
+ perf .highest_perf ,
556
+ epp ,
557
+ min_perf ,
558
+ max_perf ,
559
+ policy -> boost_enabled ,
560
+ value != prev );
561
+ }
562
+
518
563
if (value == prev )
519
564
return 0 ;
520
565
@@ -592,7 +637,7 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u8 min_perf,
592
637
cpudata -> cpu , fast_switch );
593
638
}
594
639
595
- amd_pstate_update_perf (cpudata , min_perf , des_perf , max_perf , 0 , fast_switch );
640
+ amd_pstate_update_perf (policy , min_perf , des_perf , max_perf , 0 , fast_switch );
596
641
}
597
642
598
643
static int amd_pstate_verify (struct cpufreq_policy_data * policy_data )
@@ -1525,7 +1570,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
1525
1570
return ret ;
1526
1571
WRITE_ONCE (cpudata -> cppc_req_cached , value );
1527
1572
}
1528
- ret = amd_pstate_set_epp (cpudata , cpudata -> epp_default );
1573
+ ret = amd_pstate_set_epp (policy , cpudata -> epp_default );
1529
1574
if (ret )
1530
1575
return ret ;
1531
1576
@@ -1566,14 +1611,8 @@ static int amd_pstate_epp_update_limit(struct cpufreq_policy *policy)
1566
1611
epp = READ_ONCE (cpudata -> epp_cached );
1567
1612
1568
1613
perf = READ_ONCE (cpudata -> perf );
1569
- if (trace_amd_pstate_epp_perf_enabled ()) {
1570
- trace_amd_pstate_epp_perf (cpudata -> cpu , perf .highest_perf , epp ,
1571
- perf .min_limit_perf ,
1572
- perf .max_limit_perf ,
1573
- policy -> boost_enabled );
1574
- }
1575
1614
1576
- return amd_pstate_update_perf (cpudata , perf .min_limit_perf , 0U ,
1615
+ return amd_pstate_update_perf (policy , perf .min_limit_perf , 0U ,
1577
1616
perf .max_limit_perf , epp , false);
1578
1617
}
1579
1618
@@ -1605,20 +1644,12 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
1605
1644
1606
1645
static int amd_pstate_epp_reenable (struct cpufreq_policy * policy )
1607
1646
{
1608
- struct amd_cpudata * cpudata = policy -> driver_data ;
1609
- union perf_cached perf = READ_ONCE (cpudata -> perf );
1610
1647
int ret ;
1611
1648
1612
1649
ret = amd_pstate_cppc_enable (true);
1613
1650
if (ret )
1614
1651
pr_err ("failed to enable amd pstate during resume, return %d\n" , ret );
1615
1652
1616
- if (trace_amd_pstate_epp_perf_enabled ()) {
1617
- trace_amd_pstate_epp_perf (cpudata -> cpu , perf .highest_perf ,
1618
- cpudata -> epp_cached ,
1619
- FIELD_GET (AMD_CPPC_MIN_PERF_MASK , cpudata -> cppc_req_cached ),
1620
- perf .highest_perf , policy -> boost_enabled );
1621
- }
1622
1653
1623
1654
return amd_pstate_epp_update_limit (policy );
1624
1655
}
@@ -1646,14 +1677,7 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
1646
1677
if (cpudata -> suspended )
1647
1678
return 0 ;
1648
1679
1649
- if (trace_amd_pstate_epp_perf_enabled ()) {
1650
- trace_amd_pstate_epp_perf (cpudata -> cpu , perf .highest_perf ,
1651
- AMD_CPPC_EPP_BALANCE_POWERSAVE ,
1652
- perf .lowest_perf , perf .lowest_perf ,
1653
- policy -> boost_enabled );
1654
- }
1655
-
1656
- return amd_pstate_update_perf (cpudata , perf .lowest_perf , 0 , perf .lowest_perf ,
1680
+ return amd_pstate_update_perf (policy , perf .lowest_perf , 0 , perf .lowest_perf ,
1657
1681
AMD_CPPC_EPP_BALANCE_POWERSAVE , false);
1658
1682
}
1659
1683
0 commit comments