@@ -206,6 +206,7 @@ struct core_data {
206206 unsigned int core_temp_c ;
207207 unsigned int core_energy ; /* MSR_CORE_ENERGY_STAT */
208208 unsigned int core_id ;
209+ unsigned long long core_throt_cnt ;
209210 unsigned long long counter [MAX_ADDED_COUNTERS ];
210211} * core_even , * core_odd ;
211212
@@ -611,6 +612,7 @@ struct msr_counter bic[] = {
611612 { 0x0 , "Die" },
612613 { 0x0 , "GFXAMHz" },
613614 { 0x0 , "IPC" },
615+ { 0x0 , "CoreThr" },
614616};
615617
616618#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
@@ -667,6 +669,7 @@ struct msr_counter bic[] = {
667669#define BIC_Die (1ULL << 50)
668670#define BIC_GFXACTMHz (1ULL << 51)
669671#define BIC_IPC (1ULL << 52)
672+ #define BIC_CORE_THROT_CNT (1ULL << 53)
670673
671674#define BIC_TOPOLOGY (BIC_Package | BIC_Node | BIC_CoreCnt | BIC_PkgCnt | BIC_Core | BIC_CPU | BIC_Die )
672675#define BIC_THERMAL_PWR ( BIC_CoreTmp | BIC_PkgTmp | BIC_PkgWatt | BIC_CorWatt | BIC_GFXWatt | BIC_RAMWatt | BIC_PKG__ | BIC_RAM__)
@@ -888,6 +891,9 @@ void print_header(char *delim)
888891 if (DO_BIC (BIC_CoreTmp ))
889892 outp += sprintf (outp , "%sCoreTmp" , (printed ++ ? delim : "" ));
890893
894+ if (DO_BIC (BIC_CORE_THROT_CNT ))
895+ outp += sprintf (outp , "%sCoreThr" , (printed ++ ? delim : "" ));
896+
891897 if (do_rapl && !rapl_joules ) {
892898 if (DO_BIC (BIC_CorWatt ) && (do_rapl & RAPL_PER_CORE_ENERGY ))
893899 outp += sprintf (outp , "%sCorWatt" , (printed ++ ? delim : "" ));
@@ -1027,6 +1033,7 @@ int dump_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p
10271033 outp += sprintf (outp , "c6: %016llX\n" , c -> c6 );
10281034 outp += sprintf (outp , "c7: %016llX\n" , c -> c7 );
10291035 outp += sprintf (outp , "DTS: %dC\n" , c -> core_temp_c );
1036+ outp += sprintf (outp , "cpu_throt_count: %016llX\n" , c -> core_throt_cnt );
10301037 outp += sprintf (outp , "Joules: %0X\n" , c -> core_energy );
10311038
10321039 for (i = 0 , mp = sys .cp ; mp ; i ++ , mp = mp -> next ) {
@@ -1241,6 +1248,10 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
12411248 if (DO_BIC (BIC_CoreTmp ))
12421249 outp += sprintf (outp , "%s%d" , (printed ++ ? delim : "" ), c -> core_temp_c );
12431250
1251+ /* Core throttle count */
1252+ if (DO_BIC (BIC_CORE_THROT_CNT ))
1253+ outp += sprintf (outp , "%s%lld" , (printed ++ ? delim : "" ), c -> core_throt_cnt );
1254+
12441255 for (i = 0 , mp = sys .cp ; mp ; i ++ , mp = mp -> next ) {
12451256 if (mp -> format == FORMAT_RAW ) {
12461257 if (mp -> width == 32 )
@@ -1327,6 +1338,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
13271338 if (DO_BIC (BIC_PkgWatt ))
13281339 outp +=
13291340 sprintf (outp , fmt8 , (printed ++ ? delim : "" ), p -> energy_pkg * rapl_energy_units / interval_float );
1341+
13301342 if (DO_BIC (BIC_CorWatt ) && !(do_rapl & RAPL_PER_CORE_ENERGY ))
13311343 outp +=
13321344 sprintf (outp , fmt8 , (printed ++ ? delim : "" ), p -> energy_cores * rapl_energy_units / interval_float );
@@ -1483,6 +1495,7 @@ void delta_core(struct core_data *new, struct core_data *old)
14831495 old -> c6 = new -> c6 - old -> c6 ;
14841496 old -> c7 = new -> c7 - old -> c7 ;
14851497 old -> core_temp_c = new -> core_temp_c ;
1498+ old -> core_throt_cnt = new -> core_throt_cnt ;
14861499 old -> mc6_us = new -> mc6_us - old -> mc6_us ;
14871500
14881501 DELTA_WRAP32 (new -> core_energy , old -> core_energy );
@@ -1642,6 +1655,7 @@ void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data
16421655 c -> mc6_us = 0 ;
16431656 c -> core_temp_c = 0 ;
16441657 c -> core_energy = 0 ;
1658+ c -> core_throt_cnt = 0 ;
16451659
16461660 p -> pkg_wtd_core_c0 = 0 ;
16471661 p -> pkg_any_core_c0 = 0 ;
@@ -1726,6 +1740,7 @@ int sum_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
17261740 average .cores .mc6_us += c -> mc6_us ;
17271741
17281742 average .cores .core_temp_c = MAX (average .cores .core_temp_c , c -> core_temp_c );
1743+ average .cores .core_throt_cnt = MAX (average .cores .core_throt_cnt , c -> core_throt_cnt );
17291744
17301745 average .cores .core_energy += c -> core_energy ;
17311746
@@ -2003,6 +2018,26 @@ void get_apic_id(struct thread_data *t)
20032018 fprintf (outf , "cpu%d: BIOS BUG: apic 0x%x x2apic 0x%x\n" , t -> cpu_id , t -> apic_id , t -> x2apic_id );
20042019}
20052020
2021+ int get_core_throt_cnt (int cpu , unsigned long long * cnt )
2022+ {
2023+ char path [128 + PATH_BYTES ];
2024+ unsigned long long tmp ;
2025+ FILE * fp ;
2026+ int ret ;
2027+
2028+ sprintf (path , "/sys/devices/system/cpu/cpu%d/thermal_throttle/core_throttle_count" , cpu );
2029+ fp = fopen (path , "r" );
2030+ if (!fp )
2031+ return -1 ;
2032+ ret = fscanf (fp , "%lld" , & tmp );
2033+ if (ret != 1 )
2034+ return -1 ;
2035+ fclose (fp );
2036+ * cnt = tmp ;
2037+
2038+ return 0 ;
2039+ }
2040+
20062041/*
20072042 * get_counters(...)
20082043 * migrate to cpu
@@ -2145,6 +2180,9 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
21452180 c -> core_temp_c = tj_max - ((msr >> 16 ) & 0x7F );
21462181 }
21472182
2183+ if (DO_BIC (BIC_CORE_THROT_CNT ))
2184+ get_core_throt_cnt (cpu , & c -> core_throt_cnt );
2185+
21482186 if (do_rapl & RAPL_AMD_F17H ) {
21492187 if (get_msr (cpu , MSR_CORE_ENERGY_STAT , & msr ))
21502188 return -14 ;
@@ -5597,6 +5635,11 @@ void process_cpuid()
55975635 else
55985636 BIC_NOT_PRESENT (BIC_CPU_LPI );
55995637
5638+ if (!access ("/sys/devices/system/cpu/cpu0/thermal_throttle/core_throttle_count" , R_OK ))
5639+ BIC_PRESENT (BIC_CORE_THROT_CNT );
5640+ else
5641+ BIC_NOT_PRESENT (BIC_CORE_THROT_CNT );
5642+
56005643 if (!access (sys_lpi_file_sysfs , R_OK )) {
56015644 sys_lpi_file = sys_lpi_file_sysfs ;
56025645 BIC_PRESENT (BIC_SYS_LPI );
0 commit comments