@@ -4017,15 +4017,55 @@ static unsigned int read_perf_type(const char *subsys)
4017
4017
return read_perf_counter_info_n (path , format );
4018
4018
}
4019
4019
4020
- static unsigned int read_rapl_config (const char * subsys , const char * event_name )
4020
+ static unsigned int read_perf_config (const char * subsys , const char * event_name )
4021
4021
{
4022
4022
const char * const path_format = "/sys/bus/event_source/devices/%s/events/%s" ;
4023
- const char * const format = "event=%x" ;
4023
+ FILE * fconfig = NULL ;
4024
4024
char path [128 ];
4025
+ char config_str [64 ];
4026
+ unsigned int config ;
4027
+ unsigned int umask ;
4028
+ bool has_config = false;
4029
+ bool has_umask = false;
4030
+ unsigned int ret = -1 ;
4025
4031
4026
4032
snprintf (path , sizeof (path ), path_format , subsys , event_name );
4027
4033
4028
- return read_perf_counter_info_n (path , format );
4034
+ fconfig = fopen (path , "r" );
4035
+ if (!fconfig )
4036
+ return -1 ;
4037
+
4038
+ if (fgets (config_str , ARRAY_SIZE (config_str ), fconfig ) != config_str )
4039
+ goto cleanup_and_exit ;
4040
+
4041
+ for (char * pconfig_str = & config_str [0 ]; pconfig_str ;) {
4042
+ if (sscanf (pconfig_str , "event=%x" , & config ) == 1 ) {
4043
+ has_config = true;
4044
+ goto next ;
4045
+ }
4046
+
4047
+ if (sscanf (pconfig_str , "umask=%x" , & umask ) == 1 ) {
4048
+ has_umask = true;
4049
+ goto next ;
4050
+ }
4051
+
4052
+ next :
4053
+ pconfig_str = strchr (pconfig_str , ',' );
4054
+ if (pconfig_str ) {
4055
+ * pconfig_str = '\0' ;
4056
+ ++ pconfig_str ;
4057
+ }
4058
+ }
4059
+
4060
+ if (!has_umask )
4061
+ umask = 0 ;
4062
+
4063
+ if (has_config )
4064
+ ret = (umask << 8 ) | config ;
4065
+
4066
+ cleanup_and_exit :
4067
+ fclose (fconfig );
4068
+ return ret ;
4029
4069
}
4030
4070
4031
4071
static unsigned int read_perf_rapl_unit (const char * subsys , const char * event_name )
@@ -4044,7 +4084,7 @@ static unsigned int read_perf_rapl_unit(const char *subsys, const char *event_na
4044
4084
return RAPL_UNIT_INVALID ;
4045
4085
}
4046
4086
4047
- static double read_perf_rapl_scale (const char * subsys , const char * event_name )
4087
+ static double read_perf_scale (const char * subsys , const char * event_name )
4048
4088
{
4049
4089
const char * const path_format = "/sys/bus/event_source/devices/%s/events/%s.scale" ;
4050
4090
const char * const format = "%lf" ;
@@ -7425,7 +7465,7 @@ int add_rapl_perf_counter_(int cpu, struct rapl_counter_info_t *rci, const struc
7425
7465
if (no_perf )
7426
7466
return -1 ;
7427
7467
7428
- const double scale = read_perf_rapl_scale (cai -> perf_subsys , cai -> perf_name );
7468
+ const double scale = read_perf_scale (cai -> perf_subsys , cai -> perf_name );
7429
7469
7430
7470
if (scale == 0.0 )
7431
7471
return -1 ;
@@ -7436,7 +7476,7 @@ int add_rapl_perf_counter_(int cpu, struct rapl_counter_info_t *rci, const struc
7436
7476
return -1 ;
7437
7477
7438
7478
const unsigned int rapl_type = read_perf_type (cai -> perf_subsys );
7439
- const unsigned int rapl_energy_pkg_config = read_rapl_config (cai -> perf_subsys , cai -> perf_name );
7479
+ const unsigned int rapl_energy_pkg_config = read_perf_config (cai -> perf_subsys , cai -> perf_name );
7440
7480
7441
7481
const int fd_counter =
7442
7482
open_perf_counter (cpu , rapl_type , rapl_energy_pkg_config , rci -> fd_perf , PERF_FORMAT_GROUP );
@@ -7598,7 +7638,7 @@ int add_cstate_perf_counter_(int cpu, struct cstate_counter_info_t *cci, const s
7598
7638
return -1 ;
7599
7639
7600
7640
const unsigned int type = read_perf_type (cai -> perf_subsys );
7601
- const unsigned int config = read_rapl_config (cai -> perf_subsys , cai -> perf_name );
7641
+ const unsigned int config = read_perf_config (cai -> perf_subsys , cai -> perf_name );
7602
7642
7603
7643
const int fd_counter = open_perf_counter (cpu , type , config , * pfd_group , PERF_FORMAT_GROUP );
7604
7644
@@ -7628,7 +7668,7 @@ int add_msr_perf_counter_(int cpu, struct msr_counter_info_t *cci, const struct
7628
7668
return -1 ;
7629
7669
7630
7670
const unsigned int type = read_perf_type (cai -> perf_subsys );
7631
- const unsigned int config = read_rapl_config (cai -> perf_subsys , cai -> perf_name );
7671
+ const unsigned int config = read_perf_config (cai -> perf_subsys , cai -> perf_name );
7632
7672
7633
7673
const int fd_counter = open_perf_counter (cpu , type , config , cci -> fd_perf , PERF_FORMAT_GROUP );
7634
7674
@@ -8571,15 +8611,15 @@ int added_perf_counters_init_(struct perf_counter_info *pinfo)
8571
8611
continue ;
8572
8612
}
8573
8613
8574
- perf_config = read_rapl_config (pinfo -> device , pinfo -> event );
8614
+ perf_config = read_perf_config (pinfo -> device , pinfo -> event );
8575
8615
if (perf_config == (unsigned int )-1 ) {
8576
8616
warnx ("%s: perf/%s/%s: failed to read %s" ,
8577
8617
__func__ , pinfo -> device , pinfo -> event , "config" );
8578
8618
continue ;
8579
8619
}
8580
8620
8581
8621
/* Scale is not required, some counters just don't have it. */
8582
- perf_scale = read_perf_rapl_scale (pinfo -> device , pinfo -> event );
8622
+ perf_scale = read_perf_scale (pinfo -> device , pinfo -> event );
8583
8623
if (perf_scale == 0.0 )
8584
8624
perf_scale = 1.0 ;
8585
8625
0 commit comments