@@ -2409,7 +2409,7 @@ struct topo_params {
24092409 int max_l3_id ;
24102410 int max_node_num ;
24112411 int nodes_per_pkg ;
2412- int cores_per_node ;
2412+ int cores_per_pkg ;
24132413 int threads_per_core ;
24142414} topo ;
24152415
@@ -2835,32 +2835,38 @@ void bic_lookup(cpu_set_t *ret_set, char *name_list, enum show_hide_mode mode)
28352835static inline int print_name (int width , int * printed , char * delim , char * name , enum counter_type type , enum counter_format format )
28362836{
28372837 UNUSED (type );
2838+ char * sep = (* printed )++ ? delim : "" ;
28382839
28392840 if (format == FORMAT_RAW && width >= 64 )
2840- return ( sprintf (outp , "%s%-8s" , ( * printed ++ ? delim : "" ) , name ) );
2841+ return sprintf (outp , "%s%-8s" , sep , name );
28412842 else
2842- return ( sprintf (outp , "%s%s" , ( * printed ++ ? delim : "" ) , name ) );
2843+ return sprintf (outp , "%s%s" , sep , name );
28432844}
28442845
28452846static inline int print_hex_value (int width , int * printed , char * delim , unsigned long long value )
28462847{
2848+ char * sep = (* printed )++ ? delim : "" ;
2849+
28472850 if (width <= 32 )
2848- return (sprintf (outp , "%s%08x " , ( * printed ++ ? delim : "" ), ( unsigned int ) value ));
2851+ return (sprintf (outp , "%s%08llx " , sep , value ));
28492852 else
2850- return (sprintf (outp , "%s%016llx" , ( * printed ++ ? delim : "" ) , value ));
2853+ return (sprintf (outp , "%s%016llx" , sep , value ));
28512854}
28522855
28532856static inline int print_decimal_value (int width , int * printed , char * delim , unsigned long long value )
28542857{
2855- if (width <= 32 )
2856- return (sprintf (outp , "%s%d" , (* printed ++ ? delim : "" ), (unsigned int )value ));
2857- else
2858- return (sprintf (outp , "%s%-8lld" , (* printed ++ ? delim : "" ), value ));
2858+ char * sep = (* printed )++ ? delim : "" ;
2859+
2860+ UNUSED (width );
2861+
2862+ return (sprintf (outp , "%s%lld" , sep , value ));
28592863}
28602864
28612865static inline int print_float_value (int * printed , char * delim , double value )
28622866{
2863- return (sprintf (outp , "%s%0.2f" , (* printed ++ ? delim : "" ), value ));
2867+ char * sep = (* printed )++ ? delim : "" ;
2868+
2869+ return (sprintf (outp , "%s%0.2f" , sep , value ));
28642870}
28652871
28662872void print_header (char * delim )
@@ -3469,7 +3475,7 @@ int format_counters(PER_THREAD_PARAMS)
34693475 for (i = 0 , pp = sys .perf_tp ; pp ; ++ i , pp = pp -> next ) {
34703476 if (pp -> format == FORMAT_RAW )
34713477 outp += print_hex_value (pp -> width , & printed , delim , t -> perf_counter [i ]);
3472- else if (pp -> format == FORMAT_DELTA || mp -> format == FORMAT_AVERAGE )
3478+ else if (pp -> format == FORMAT_DELTA || pp -> format == FORMAT_AVERAGE )
34733479 outp += print_decimal_value (pp -> width , & printed , delim , t -> perf_counter [i ]);
34743480 else if (pp -> format == FORMAT_PERCENT ) {
34753481 if (pp -> type == COUNTER_USEC )
@@ -3490,12 +3496,12 @@ int format_counters(PER_THREAD_PARAMS)
34903496
34913497 case PMT_TYPE_XTAL_TIME :
34923498 value_converted = pct (value_raw / crystal_hz , interval_float );
3493- outp += sprintf ( outp , "%s%.2f" , ( printed ++ ? delim : "" ) , value_converted );
3499+ outp += print_float_value ( & printed , delim , value_converted );
34943500 break ;
34953501
34963502 case PMT_TYPE_TCORE_CLOCK :
34973503 value_converted = pct (value_raw / tcore_clock_freq_hz , interval_float );
3498- outp += sprintf ( outp , "%s%.2f" , ( printed ++ ? delim : "" ) , value_converted );
3504+ outp += print_float_value ( & printed , delim , value_converted );
34993505 }
35003506 }
35013507
@@ -3539,7 +3545,7 @@ int format_counters(PER_THREAD_PARAMS)
35393545 for (i = 0 , pp = sys .perf_cp ; pp ; i ++ , pp = pp -> next ) {
35403546 if (pp -> format == FORMAT_RAW )
35413547 outp += print_hex_value (pp -> width , & printed , delim , c -> perf_counter [i ]);
3542- else if (pp -> format == FORMAT_DELTA || mp -> format == FORMAT_AVERAGE )
3548+ else if (pp -> format == FORMAT_DELTA || pp -> format == FORMAT_AVERAGE )
35433549 outp += print_decimal_value (pp -> width , & printed , delim , c -> perf_counter [i ]);
35443550 else if (pp -> format == FORMAT_PERCENT )
35453551 outp += print_float_value (& printed , delim , pct (c -> perf_counter [i ], tsc ));
@@ -3695,7 +3701,7 @@ int format_counters(PER_THREAD_PARAMS)
36953701 outp += print_hex_value (pp -> width , & printed , delim , p -> perf_counter [i ]);
36963702 else if (pp -> type == COUNTER_K2M )
36973703 outp += sprintf (outp , "%s%d" , (printed ++ ? delim : "" ), (unsigned int )p -> perf_counter [i ] / 1000 );
3698- else if (pp -> format == FORMAT_DELTA || mp -> format == FORMAT_AVERAGE )
3704+ else if (pp -> format == FORMAT_DELTA || pp -> format == FORMAT_AVERAGE )
36993705 outp += print_decimal_value (pp -> width , & printed , delim , p -> perf_counter [i ]);
37003706 else if (pp -> format == FORMAT_PERCENT )
37013707 outp += print_float_value (& printed , delim , pct (p -> perf_counter [i ], tsc ));
@@ -9122,10 +9128,13 @@ void process_cpuid()
91229128 cpuid_has_hv = ecx_flags & (1 << 31 );
91239129
91249130 if (!no_msr ) {
9125- if (get_msr (sched_getcpu (), MSR_IA32_UCODE_REV , & ucode_patch ))
9131+ if (get_msr (sched_getcpu (), MSR_IA32_UCODE_REV , & ucode_patch )) {
91269132 warnx ("get_msr(UCODE)" );
9127- else
9133+ } else {
91289134 ucode_patch_valid = true;
9135+ if (!authentic_amd && !hygon_genuine )
9136+ ucode_patch >>= 32 ;
9137+ }
91299138 }
91309139
91319140 /*
@@ -9139,7 +9148,7 @@ void process_cpuid()
91399148 if (!quiet ) {
91409149 fprintf (outf , "CPUID(1): family:model:stepping 0x%x:%x:%x (%d:%d:%d)" , family , model , stepping , family , model , stepping );
91419150 if (ucode_patch_valid )
9142- fprintf (outf , " microcode 0x%x" , (unsigned int )(( ucode_patch >> 32 ) & 0xFFFFFFFF ) );
9151+ fprintf (outf , " microcode 0x%x" , (unsigned int )ucode_patch );
91439152 fputc ('\n' , outf );
91449153
91459154 fprintf (outf , "CPUID(0x80000000): max_extended_levels: 0x%x\n" , max_extended_level );
@@ -9634,9 +9643,9 @@ void topology_probe(bool startup)
96349643 topo .max_core_id = max_core_id ; /* within a package */
96359644 topo .max_package_id = max_package_id ;
96369645
9637- topo .cores_per_node = max_core_id + 1 ;
9646+ topo .cores_per_pkg = max_core_id + 1 ;
96389647 if (debug > 1 )
9639- fprintf (outf , "max_core_id %d, sizing for %d cores per package\n" , max_core_id , topo .cores_per_node );
9648+ fprintf (outf , "max_core_id %d, sizing for %d cores per package\n" , max_core_id , topo .cores_per_pkg );
96409649 if (!summary_only )
96419650 BIC_PRESENT (BIC_Core );
96429651
@@ -9701,14 +9710,13 @@ void allocate_counters_1(struct counters *counters)
97019710void allocate_counters (struct counters * counters )
97029711{
97039712 int i ;
9704- int num_cores = topo .cores_per_node * topo .nodes_per_pkg * topo .num_packages ;
9705- int num_threads = topo .threads_per_core * num_cores ;
9713+ int num_cores = topo .cores_per_pkg * topo .num_packages ;
97069714
9707- counters -> threads = calloc (num_threads , sizeof (struct thread_data ));
9715+ counters -> threads = calloc (topo . max_cpu_num + 1 , sizeof (struct thread_data ));
97089716 if (counters -> threads == NULL )
97099717 goto error ;
97109718
9711- for (i = 0 ; i < num_threads ; i ++ )
9719+ for (i = 0 ; i < topo . max_cpu_num + 1 ; i ++ )
97129720 (counters -> threads )[i ].cpu_id = -1 ;
97139721
97149722 counters -> cores = calloc (num_cores , sizeof (struct core_data ));
@@ -11284,6 +11292,14 @@ void probe_cpuidle_residency(void)
1128411292 }
1128511293}
1128611294
11295+ static bool cpuidle_counter_wanted (char * name )
11296+ {
11297+ if (is_deferred_skip (name ))
11298+ return false;
11299+
11300+ return DO_BIC (BIC_cpuidle ) || is_deferred_add (name );
11301+ }
11302+
1128711303void probe_cpuidle_counts (void )
1128811304{
1128911305 char path [64 ];
@@ -11293,7 +11309,7 @@ void probe_cpuidle_counts(void)
1129311309 int min_state = 1024 , max_state = 0 ;
1129411310 char * sp ;
1129511311
11296- if (!DO_BIC (BIC_cpuidle ))
11312+ if (!DO_BIC (BIC_cpuidle ) && ! deferred_add_index )
1129711313 return ;
1129811314
1129911315 for (state = 10 ; state >= 0 ; -- state ) {
@@ -11308,12 +11324,6 @@ void probe_cpuidle_counts(void)
1130811324
1130911325 remove_underbar (name_buf );
1131011326
11311- if (!DO_BIC (BIC_cpuidle ) && !is_deferred_add (name_buf ))
11312- continue ;
11313-
11314- if (is_deferred_skip (name_buf ))
11315- continue ;
11316-
1131711327 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */
1131811328 sp = strchr (name_buf , '-' );
1131911329 if (!sp )
@@ -11328,16 +11338,19 @@ void probe_cpuidle_counts(void)
1132811338 * Add 'C1+' for C1, and so on. The 'below' sysfs file always contains 0 for
1132911339 * the last state, so do not add it.
1133011340 */
11331-
1133211341 * sp = '+' ;
1133311342 * (sp + 1 ) = '\0' ;
11334- sprintf (path , "cpuidle/state%d/below" , state );
11335- add_counter (0 , path , name_buf , 64 , SCOPE_CPU , COUNTER_ITEMS , FORMAT_DELTA , SYSFS_PERCPU , 0 );
11343+ if (cpuidle_counter_wanted (name_buf )) {
11344+ sprintf (path , "cpuidle/state%d/below" , state );
11345+ add_counter (0 , path , name_buf , 64 , SCOPE_CPU , COUNTER_ITEMS , FORMAT_DELTA , SYSFS_PERCPU , 0 );
11346+ }
1133611347 }
1133711348
1133811349 * sp = '\0' ;
11339- sprintf (path , "cpuidle/state%d/usage" , state );
11340- add_counter (0 , path , name_buf , 64 , SCOPE_CPU , COUNTER_ITEMS , FORMAT_DELTA , SYSFS_PERCPU , 0 );
11350+ if (cpuidle_counter_wanted (name_buf )) {
11351+ sprintf (path , "cpuidle/state%d/usage" , state );
11352+ add_counter (0 , path , name_buf , 64 , SCOPE_CPU , COUNTER_ITEMS , FORMAT_DELTA , SYSFS_PERCPU , 0 );
11353+ }
1134111354
1134211355 /*
1134311356 * The 'above' sysfs file always contains 0 for the shallowest state (smallest
@@ -11346,8 +11359,10 @@ void probe_cpuidle_counts(void)
1134611359 if (state != min_state ) {
1134711360 * sp = '-' ;
1134811361 * (sp + 1 ) = '\0' ;
11349- sprintf (path , "cpuidle/state%d/above" , state );
11350- add_counter (0 , path , name_buf , 64 , SCOPE_CPU , COUNTER_ITEMS , FORMAT_DELTA , SYSFS_PERCPU , 0 );
11362+ if (cpuidle_counter_wanted (name_buf )) {
11363+ sprintf (path , "cpuidle/state%d/above" , state );
11364+ add_counter (0 , path , name_buf , 64 , SCOPE_CPU , COUNTER_ITEMS , FORMAT_DELTA , SYSFS_PERCPU , 0 );
11365+ }
1135111366 }
1135211367 }
1135311368}
0 commit comments