Skip to content

Commit 15c57a8

Browse files
captain5050acmel
authored andcommitted
perf pmus: Split pmus list into core and other
Split the pmus list into core and other. This will later allow for the core and other pmus to be populated separately. Reviewed-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ali Saidi <alisaidi@amazon.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Dmitrii Dolgov <9erthalion6@gmail.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kang Minchul <tegongkang@gmail.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Ming Wang <wangming01@loongson.cn> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Rob Herring <robh@kernel.org> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Will Deacon <will@kernel.org> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20230527072210.2900565-29-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 1eaf496 commit 15c57a8

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

tools/perf/util/pmus.c

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
#include "pmu.h"
1313
#include "print-events.h"
1414

15-
static LIST_HEAD(pmus);
15+
static LIST_HEAD(core_pmus);
16+
static LIST_HEAD(other_pmus);
1617

1718
void perf_pmus__destroy(void)
1819
{
1920
struct perf_pmu *pmu, *tmp;
2021

21-
list_for_each_entry_safe(pmu, tmp, &pmus, list) {
22+
list_for_each_entry_safe(pmu, tmp, &core_pmus, list) {
23+
list_del(&pmu->list);
24+
25+
perf_pmu__delete(pmu);
26+
}
27+
list_for_each_entry_safe(pmu, tmp, &other_pmus, list) {
2228
list_del(&pmu->list);
2329

2430
perf_pmu__delete(pmu);
@@ -29,7 +35,12 @@ static struct perf_pmu *pmu_find(const char *name)
2935
{
3036
struct perf_pmu *pmu;
3137

32-
list_for_each_entry(pmu, &pmus, list) {
38+
list_for_each_entry(pmu, &core_pmus, list) {
39+
if (!strcmp(pmu->name, name) ||
40+
(pmu->alias_name && !strcmp(pmu->alias_name, name)))
41+
return pmu;
42+
}
43+
list_for_each_entry(pmu, &other_pmus, list) {
3344
if (!strcmp(pmu->name, name) ||
3445
(pmu->alias_name && !strcmp(pmu->alias_name, name)))
3546
return pmu;
@@ -53,7 +64,7 @@ struct perf_pmu *perf_pmus__find(const char *name)
5364
return pmu;
5465

5566
dirfd = perf_pmu__event_source_devices_fd();
56-
pmu = perf_pmu__lookup(&pmus, dirfd, name);
67+
pmu = perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dirfd, name);
5768
close(dirfd);
5869

5970
return pmu;
@@ -72,7 +83,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name)
7283
if (pmu)
7384
return pmu;
7485

75-
return perf_pmu__lookup(&pmus, dirfd, name);
86+
return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dirfd, name);
7687
}
7788

7889
/* Add all pmus in sysfs to pmu list: */
@@ -93,7 +104,7 @@ static void pmu_read_sysfs(void)
93104
while ((dent = readdir(dir))) {
94105
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
95106
continue;
96-
/* add to static LIST_HEAD(pmus): */
107+
/* add to static LIST_HEAD(core_pmus) or LIST_HEAD(other_pmus): */
97108
perf_pmu__find2(fd, dent->d_name);
98109
}
99110

@@ -104,24 +115,37 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int type)
104115
{
105116
struct perf_pmu *pmu;
106117

107-
list_for_each_entry(pmu, &pmus, list)
118+
list_for_each_entry(pmu, &core_pmus, list) {
108119
if (pmu->type == type)
109120
return pmu;
110-
121+
}
122+
list_for_each_entry(pmu, &other_pmus, list) {
123+
if (pmu->type == type)
124+
return pmu;
125+
}
111126
return NULL;
112127
}
113128

129+
/*
130+
* pmu iterator: If pmu is NULL, we start at the begin, otherwise return the
131+
* next pmu. Returns NULL on end.
132+
*/
114133
struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu)
115134
{
116-
/*
117-
* pmu iterator: If pmu is NULL, we start at the begin,
118-
* otherwise return the next pmu. Returns NULL on end.
119-
*/
135+
bool use_core_pmus = !pmu || pmu->is_core;
136+
120137
if (!pmu) {
121138
pmu_read_sysfs();
122-
pmu = list_prepare_entry(pmu, &pmus, list);
139+
pmu = list_prepare_entry(pmu, &core_pmus, list);
140+
}
141+
if (use_core_pmus) {
142+
list_for_each_entry_continue(pmu, &core_pmus, list)
143+
return pmu;
144+
145+
pmu = NULL;
146+
pmu = list_prepare_entry(pmu, &other_pmus, list);
123147
}
124-
list_for_each_entry_continue(pmu, &pmus, list)
148+
list_for_each_entry_continue(pmu, &other_pmus, list)
125149
return pmu;
126150
return NULL;
127151
}

0 commit comments

Comments
 (0)