14
14
#define MIDR_REVISION_MASK GENMASK(3, 0)
15
15
#define MIDR_VARIANT_MASK GENMASK(23, 20)
16
16
17
- static int _get_cpuid (char * buf , size_t sz , struct perf_cpu_map * cpus )
17
+ static int _get_cpuid (char * buf , size_t sz , struct perf_cpu cpu )
18
18
{
19
+ char path [PATH_MAX ];
20
+ FILE * file ;
19
21
const char * sysfs = sysfs__mountpoint ();
20
- struct perf_cpu cpu ;
21
- int idx , ret = EINVAL ;
22
22
23
+ assert (cpu .cpu != -1 );
23
24
if (!sysfs || sz < MIDR_SIZE )
24
25
return EINVAL ;
25
26
26
- perf_cpu_map__for_each_cpu (cpu , idx , cpus ) {
27
- char path [PATH_MAX ];
28
- FILE * file ;
29
-
30
- scnprintf (path , PATH_MAX , "%s/devices/system/cpu/cpu%d" MIDR ,
31
- sysfs , cpu .cpu );
32
-
33
- file = fopen (path , "r" );
34
- if (!file ) {
35
- pr_debug ("fopen failed for file %s\n" , path );
36
- continue ;
37
- }
38
-
39
- if (!fgets (buf , MIDR_SIZE , file )) {
40
- fclose (file );
41
- continue ;
42
- }
43
- fclose (file );
27
+ scnprintf (path , PATH_MAX , "%s/devices/system/cpu/cpu%d" MIDR , sysfs , cpu .cpu );
44
28
45
- /* got midr break loop */
46
- ret = 0 ;
47
- break ;
29
+ file = fopen (path , "r" );
30
+ if (!file ) {
31
+ pr_debug ("fopen failed for file %s\n" , path );
32
+ return EINVAL ;
48
33
}
49
34
50
- return ret ;
35
+ if (!fgets (buf , MIDR_SIZE , file )) {
36
+ pr_debug ("Failed to read file %s\n" , path );
37
+ fclose (file );
38
+ return EINVAL ;
39
+ }
40
+ fclose (file );
41
+ return 0 ;
51
42
}
52
43
53
- int get_cpuid (char * buf , size_t sz , struct perf_cpu cpu __maybe_unused )
44
+ int get_cpuid (char * buf , size_t sz , struct perf_cpu cpu )
54
45
{
55
- struct perf_cpu_map * cpus = perf_cpu_map__new_online_cpus ();
56
- int ret ;
46
+ struct perf_cpu_map * cpus ;
47
+ int idx ;
48
+
49
+ if (cpu .cpu != -1 )
50
+ return _get_cpuid (buf , sz , cpu );
57
51
52
+ cpus = perf_cpu_map__new_online_cpus ();
58
53
if (!cpus )
59
54
return EINVAL ;
60
55
61
- ret = _get_cpuid (buf , sz , cpus );
62
-
63
- perf_cpu_map__put (cpus );
56
+ perf_cpu_map__for_each_cpu (cpu , idx , cpus ) {
57
+ int ret = _get_cpuid (buf , sz , cpu );
64
58
65
- return ret ;
59
+ if (ret == 0 )
60
+ return 0 ;
61
+ }
62
+ return EINVAL ;
66
63
}
67
64
68
65
char * get_cpuid_str (struct perf_pmu * pmu )
@@ -78,7 +75,7 @@ char *get_cpuid_str(struct perf_pmu *pmu)
78
75
return NULL ;
79
76
80
77
/* read midr from list of cpus mapped to this pmu */
81
- res = _get_cpuid (buf , MIDR_SIZE , pmu -> cpus );
78
+ res = get_cpuid (buf , MIDR_SIZE , perf_cpu_map__min ( pmu -> cpus ) );
82
79
if (res ) {
83
80
pr_err ("failed to get cpuid string for PMU %s\n" , pmu -> name );
84
81
free (buf );
0 commit comments