@@ -205,6 +205,7 @@ struct msr_counter bic[] = {
205205 { 0x0 , "SysWatt" , NULL , 0 , 0 , 0 , NULL , 0 },
206206 { 0x0 , "Sys_J" , NULL , 0 , 0 , 0 , NULL , 0 },
207207 { 0x0 , "NMI" , NULL , 0 , 0 , 0 , NULL , 0 },
208+ { 0x0 , "CPU%c1e" , NULL , 0 , 0 , 0 , NULL , 0 },
208209};
209210
210211#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
@@ -270,6 +271,7 @@ struct msr_counter bic[] = {
270271#define BIC_SysWatt (1ULL << 59)
271272#define BIC_Sys_J (1ULL << 60)
272273#define BIC_NMI (1ULL << 61)
274+ #define BIC_CPU_c1e (1ULL << 62)
273275
274276#define BIC_TOPOLOGY (BIC_Package | BIC_Node | BIC_CoreCnt | BIC_PkgCnt | BIC_Core | BIC_CPU | BIC_Die)
275277#define BIC_THERMAL_PWR (BIC_CoreTmp | BIC_PkgTmp | BIC_PkgWatt | BIC_CorWatt | BIC_GFXWatt | BIC_RAMWatt | BIC_PKG__ | BIC_RAM__ | BIC_SysWatt)
@@ -1538,6 +1540,14 @@ static struct msr_counter_arch_info msr_counter_arch_infos[] = {
15381540#define PMT_MTL_DC6_GUID 0x1a067102
15391541#define PMT_MTL_DC6_SEQ 0
15401542
1543+ #define PMT_COUNTER_CWF_MC1E_OFFSET_BASE 20936
1544+ #define PMT_COUNTER_CWF_MC1E_OFFSET_INCREMENT 24
1545+ #define PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE 12
1546+ #define PMT_COUNTER_CWF_CPUS_PER_MODULE 4
1547+ #define PMT_COUNTER_CWF_MC1E_LSB 0
1548+ #define PMT_COUNTER_CWF_MC1E_MSB 63
1549+ #define PMT_CWF_MC1E_GUID 0x14421519
1550+
15411551unsigned long long tcore_clock_freq_hz = 800000000 ;
15421552
15431553#define PMT_COUNTER_NAME_SIZE_BYTES 16
@@ -9367,11 +9377,69 @@ int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum
93679377
93689378void pmt_init (void )
93699379{
9380+ int cpu_num ;
9381+ unsigned long seq , offset , mod_num ;
9382+
93709383 if (BIC_IS_ENABLED (BIC_Diec6 )) {
93719384 pmt_add_counter (PMT_MTL_DC6_GUID , PMT_MTL_DC6_SEQ , "Die%c6" , PMT_TYPE_XTAL_TIME ,
93729385 PMT_COUNTER_MTL_DC6_LSB , PMT_COUNTER_MTL_DC6_MSB , PMT_COUNTER_MTL_DC6_OFFSET ,
93739386 SCOPE_PACKAGE , FORMAT_DELTA , 0 , PMT_OPEN_TRY );
93749387 }
9388+
9389+ if (BIC_IS_ENABLED (BIC_CPU_c1e )) {
9390+ seq = 0 ;
9391+ offset = PMT_COUNTER_CWF_MC1E_OFFSET_BASE ;
9392+ mod_num = 0 ; /* Relative module number for current PMT file. */
9393+
9394+ /* Open the counter for each CPU. */
9395+ for (cpu_num = 0 ; cpu_num < topo .max_cpu_num ;) {
9396+
9397+ if (cpu_is_not_allowed (cpu_num ))
9398+ goto next_loop_iter ;
9399+
9400+ /*
9401+ * Set the scope to CPU, even though CWF report the counter per module.
9402+ * CPUs inside the same module will read from the same location, instead of reporting zeros.
9403+ *
9404+ * CWF with newer firmware might require a PMT_TYPE_XTAL_TIME intead of PMT_TYPE_TCORE_CLOCK.
9405+ */
9406+ pmt_add_counter (PMT_CWF_MC1E_GUID , seq , "CPU%c1e" , PMT_TYPE_TCORE_CLOCK ,
9407+ PMT_COUNTER_CWF_MC1E_LSB , PMT_COUNTER_CWF_MC1E_MSB , offset , SCOPE_CPU ,
9408+ FORMAT_DELTA , cpu_num , PMT_OPEN_TRY );
9409+
9410+ /*
9411+ * Rather complex logic for each time we go to the next loop iteration,
9412+ * so keep it as a label.
9413+ */
9414+ next_loop_iter :
9415+ /*
9416+ * Advance the cpu number and check if we should also advance offset to
9417+ * the next counter inside the PMT file.
9418+ *
9419+ * On Clearwater Forest platform, the counter is reported per module,
9420+ * so open the same counter for all of the CPUs inside the module.
9421+ * That way, reported table show the correct value for all of the CPUs inside the module,
9422+ * instead of zeros.
9423+ */
9424+ ++ cpu_num ;
9425+ if (cpu_num % PMT_COUNTER_CWF_CPUS_PER_MODULE == 0 ) {
9426+ offset += PMT_COUNTER_CWF_MC1E_OFFSET_INCREMENT ;
9427+ ++ mod_num ;
9428+ }
9429+
9430+ /*
9431+ * There are PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE in each PMT file.
9432+ *
9433+ * If that number is reached, seq must be incremented to advance to the next file in a sequence.
9434+ * Offset inside that file and a module counter has to be reset.
9435+ */
9436+ if (mod_num == PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE ) {
9437+ ++ seq ;
9438+ offset = PMT_COUNTER_CWF_MC1E_OFFSET_BASE ;
9439+ mod_num = 0 ;
9440+ }
9441+ }
9442+ }
93759443}
93769444
93779445void turbostat_init ()
0 commit comments