Skip to content

Commit c5a26ea

Browse files
Jin Yaoacmel
authored andcommitted
perf pmu: Add hybrid helper functions
The functions perf_pmu__is_hybrid and perf_pmu__find_hybrid_pmu can be used to identify the hybrid platform and return the found hybrid cpu pmu. All the detected hybrid pmus have been saved in 'perf_pmu__hybrid_pmus' list. So we just need to search this list. perf_pmu__hybrid_type_to_pmu converts the user specified string to hybrid pmu name. This is used to support the '--cputype' option in next patches. perf_pmu__has_hybrid checks the existing of hybrid pmu. Note that, we have to define it in pmu.c (make pmu-hybrid.c no more symbol dependency), otherwise perf test python would be failed. Signed-off-by: Jin Yao <[email protected]> Reviewed-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4446243 commit c5a26ea

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

tools/perf/util/pmu-hybrid.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,43 @@ bool perf_pmu__hybrid_mounted(const char *name)
4747

4848
return true;
4949
}
50+
51+
struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name)
52+
{
53+
struct perf_pmu *pmu;
54+
55+
if (!name)
56+
return NULL;
57+
58+
perf_pmu__for_each_hybrid_pmu(pmu) {
59+
if (!strcmp(name, pmu->name))
60+
return pmu;
61+
}
62+
63+
return NULL;
64+
}
65+
66+
bool perf_pmu__is_hybrid(const char *name)
67+
{
68+
return perf_pmu__find_hybrid_pmu(name) != NULL;
69+
}
70+
71+
char *perf_pmu__hybrid_type_to_pmu(const char *type)
72+
{
73+
char *pmu_name = NULL;
74+
75+
if (asprintf(&pmu_name, "cpu_%s", type) < 0)
76+
return NULL;
77+
78+
if (perf_pmu__is_hybrid(pmu_name))
79+
return pmu_name;
80+
81+
/*
82+
* pmu may be not scanned, check the sysfs.
83+
*/
84+
if (perf_pmu__hybrid_mounted(pmu_name))
85+
return pmu_name;
86+
87+
free(pmu_name);
88+
return NULL;
89+
}

tools/perf/util/pmu-hybrid.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ extern struct list_head perf_pmu__hybrid_pmus;
1515

1616
bool perf_pmu__hybrid_mounted(const char *name);
1717

18+
struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name);
19+
bool perf_pmu__is_hybrid(const char *name);
20+
char *perf_pmu__hybrid_type_to_pmu(const char *type);
21+
1822
#endif /* __PMU_HYBRID_H */

tools/perf/util/pmu.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ int perf_pmu_parse(struct list_head *list, char *name);
4040
extern FILE *perf_pmu_in;
4141

4242
static LIST_HEAD(pmus);
43+
static bool hybrid_scanned;
4344

4445
/*
4546
* Parse & process all the sysfs attributes located under
@@ -1861,3 +1862,13 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
18611862
"'%llx' not supported by kernel)!\n",
18621863
name ?: "N/A", buf, config);
18631864
}
1865+
1866+
bool perf_pmu__has_hybrid(void)
1867+
{
1868+
if (!hybrid_scanned) {
1869+
hybrid_scanned = true;
1870+
perf_pmu__scan(NULL);
1871+
}
1872+
1873+
return !list_empty(&perf_pmu__hybrid_pmus);
1874+
}

tools/perf/util/pmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,6 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu);
132132
void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
133133
char *name);
134134

135+
bool perf_pmu__has_hybrid(void);
136+
135137
#endif /* __PMU_H */

0 commit comments

Comments
 (0)