tools/power turbostat: Add CPU%c1e BIC for CWF

Intel Clearwater Forest report PMT telemetry with GUID 0x14421519, which
can be used to obtain module c1e residency counter of type tcore clock.

Add early support for the counter by using heuristic that should work
for the Clearwater Forest platforms.

Signed-off-by: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>

authored by Patryk Wlazlyn and committed by Len Brown 5ce1e9bb 5499b5ac

Changed files
+68
tools
power
x86
turbostat
+68
tools/power/x86/turbostat/turbostat.c
··· 205 205 { 0x0, "SysWatt", NULL, 0, 0, 0, NULL, 0 }, 206 206 { 0x0, "Sys_J", NULL, 0, 0, 0, NULL, 0 }, 207 207 { 0x0, "NMI", NULL, 0, 0, 0, NULL, 0 }, 208 + { 0x0, "CPU%c1e", NULL, 0, 0, 0, NULL, 0 }, 208 209 }; 209 210 210 211 #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) ··· 271 270 #define BIC_SysWatt (1ULL << 59) 272 271 #define BIC_Sys_J (1ULL << 60) 273 272 #define BIC_NMI (1ULL << 61) 273 + #define BIC_CPU_c1e (1ULL << 62) 274 274 275 275 #define BIC_TOPOLOGY (BIC_Package | BIC_Node | BIC_CoreCnt | BIC_PkgCnt | BIC_Core | BIC_CPU | BIC_Die) 276 276 #define BIC_THERMAL_PWR (BIC_CoreTmp | BIC_PkgTmp | BIC_PkgWatt | BIC_CorWatt | BIC_GFXWatt | BIC_RAMWatt | BIC_PKG__ | BIC_RAM__ | BIC_SysWatt) ··· 1539 1537 #define PMT_COUNTER_MTL_DC6_MSB 63 1540 1538 #define PMT_MTL_DC6_GUID 0x1a067102 1541 1539 #define PMT_MTL_DC6_SEQ 0 1540 + 1541 + #define PMT_COUNTER_CWF_MC1E_OFFSET_BASE 20936 1542 + #define PMT_COUNTER_CWF_MC1E_OFFSET_INCREMENT 24 1543 + #define PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE 12 1544 + #define PMT_COUNTER_CWF_CPUS_PER_MODULE 4 1545 + #define PMT_COUNTER_CWF_MC1E_LSB 0 1546 + #define PMT_COUNTER_CWF_MC1E_MSB 63 1547 + #define PMT_CWF_MC1E_GUID 0x14421519 1542 1548 1543 1549 unsigned long long tcore_clock_freq_hz = 800000000; 1544 1550 ··· 9377 9367 9378 9368 void pmt_init(void) 9379 9369 { 9370 + int cpu_num; 9371 + unsigned long seq, offset, mod_num; 9372 + 9380 9373 if (BIC_IS_ENABLED(BIC_Diec6)) { 9381 9374 pmt_add_counter(PMT_MTL_DC6_GUID, PMT_MTL_DC6_SEQ, "Die%c6", PMT_TYPE_XTAL_TIME, 9382 9375 PMT_COUNTER_MTL_DC6_LSB, PMT_COUNTER_MTL_DC6_MSB, PMT_COUNTER_MTL_DC6_OFFSET, 9383 9376 SCOPE_PACKAGE, FORMAT_DELTA, 0, PMT_OPEN_TRY); 9377 + } 9378 + 9379 + if (BIC_IS_ENABLED(BIC_CPU_c1e)) { 9380 + seq = 0; 9381 + offset = PMT_COUNTER_CWF_MC1E_OFFSET_BASE; 9382 + mod_num = 0; /* Relative module number for current PMT file. */ 9383 + 9384 + /* Open the counter for each CPU. */ 9385 + for (cpu_num = 0; cpu_num < topo.max_cpu_num;) { 9386 + 9387 + if (cpu_is_not_allowed(cpu_num)) 9388 + goto next_loop_iter; 9389 + 9390 + /* 9391 + * Set the scope to CPU, even though CWF report the counter per module. 9392 + * CPUs inside the same module will read from the same location, instead of reporting zeros. 9393 + * 9394 + * CWF with newer firmware might require a PMT_TYPE_XTAL_TIME intead of PMT_TYPE_TCORE_CLOCK. 9395 + */ 9396 + pmt_add_counter(PMT_CWF_MC1E_GUID, seq, "CPU%c1e", PMT_TYPE_TCORE_CLOCK, 9397 + PMT_COUNTER_CWF_MC1E_LSB, PMT_COUNTER_CWF_MC1E_MSB, offset, SCOPE_CPU, 9398 + FORMAT_DELTA, cpu_num, PMT_OPEN_TRY); 9399 + 9400 + /* 9401 + * Rather complex logic for each time we go to the next loop iteration, 9402 + * so keep it as a label. 9403 + */ 9404 + next_loop_iter: 9405 + /* 9406 + * Advance the cpu number and check if we should also advance offset to 9407 + * the next counter inside the PMT file. 9408 + * 9409 + * On Clearwater Forest platform, the counter is reported per module, 9410 + * so open the same counter for all of the CPUs inside the module. 9411 + * That way, reported table show the correct value for all of the CPUs inside the module, 9412 + * instead of zeros. 9413 + */ 9414 + ++cpu_num; 9415 + if (cpu_num % PMT_COUNTER_CWF_CPUS_PER_MODULE == 0) { 9416 + offset += PMT_COUNTER_CWF_MC1E_OFFSET_INCREMENT; 9417 + ++mod_num; 9418 + } 9419 + 9420 + /* 9421 + * There are PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE in each PMT file. 9422 + * 9423 + * If that number is reached, seq must be incremented to advance to the next file in a sequence. 9424 + * Offset inside that file and a module counter has to be reset. 9425 + */ 9426 + if (mod_num == PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE) { 9427 + ++seq; 9428 + offset = PMT_COUNTER_CWF_MC1E_OFFSET_BASE; 9429 + mod_num = 0; 9430 + } 9431 + } 9384 9432 } 9385 9433 } 9386 9434