Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <yao.jin@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210427070139.25256-7-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jin Yao and committed by
Arnaldo Carvalho de Melo
c5a26ea4 44462430

+57
+40
tools/perf/util/pmu-hybrid.c
··· 47 47 48 48 return true; 49 49 } 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 + }
+4
tools/perf/util/pmu-hybrid.h
··· 15 15 16 16 bool perf_pmu__hybrid_mounted(const char *name); 17 17 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 + 18 22 #endif /* __PMU_HYBRID_H */
+11
tools/perf/util/pmu.c
··· 40 40 extern FILE *perf_pmu_in; 41 41 42 42 static LIST_HEAD(pmus); 43 + static bool hybrid_scanned; 43 44 44 45 /* 45 46 * Parse & process all the sysfs attributes located under ··· 1861 1860 pr_warning("WARNING: event '%s' not valid (bits %s of config " 1862 1861 "'%llx' not supported by kernel)!\n", 1863 1862 name ?: "N/A", buf, config); 1863 + } 1864 + 1865 + bool perf_pmu__has_hybrid(void) 1866 + { 1867 + if (!hybrid_scanned) { 1868 + hybrid_scanned = true; 1869 + perf_pmu__scan(NULL); 1870 + } 1871 + 1872 + return !list_empty(&perf_pmu__hybrid_pmus); 1864 1873 }
+2
tools/perf/util/pmu.h
··· 132 132 void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, 133 133 char *name); 134 134 135 + bool perf_pmu__has_hybrid(void); 136 + 135 137 #endif /* __PMU_H */