Skip to content

Commit 1ba3752

Browse files
captain5050acmel
authored andcommitted
perf pmu-events: Hide the pmu_events
Hide that the pmu_event structs are an array with a new wrapper struct. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mike Leach <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Will Deacon <[email protected]> Cc: Xing Zhengjun <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 660842e commit 1ba3752

File tree

12 files changed

+101
-91
lines changed

12 files changed

+101
-91
lines changed

tools/perf/arch/arm64/util/pmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "../../../util/cpumap.h"
44
#include "../../../util/pmu.h"
55

6-
const struct pmu_event *pmu_events_table__find(void)
6+
const struct pmu_events_table *pmu_events_table__find(void)
77
{
88
struct perf_pmu *pmu = NULL;
99

tools/perf/pmu-events/empty-pmu-events.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ static const struct pmu_event pme_test_soc_cpu[] = {
176176
},
177177
};
178178

179+
/* Struct used to make the PMU event table implementation opaque to callers. */
180+
struct pmu_events_table {
181+
const struct pmu_event *entries;
182+
};
179183

180184
/*
181185
* Map a CPU to its table of PMU events. The CPU is identified by the
@@ -188,7 +192,7 @@ static const struct pmu_event pme_test_soc_cpu[] = {
188192
struct pmu_events_map {
189193
const char *arch;
190194
const char *cpuid;
191-
const struct pmu_event *table;
195+
const struct pmu_events_table table;
192196
};
193197

194198
/*
@@ -199,12 +203,12 @@ static const struct pmu_events_map pmu_events_map[] = {
199203
{
200204
.arch = "testarch",
201205
.cpuid = "testcpu",
202-
.table = pme_test_soc_cpu,
206+
.table = { pme_test_soc_cpu },
203207
},
204208
{
205209
.arch = 0,
206210
.cpuid = 0,
207-
.table = 0,
211+
.table = { 0 },
208212
},
209213
};
210214

@@ -234,23 +238,23 @@ static const struct pmu_event pme_test_soc_sys[] = {
234238

235239
struct pmu_sys_events {
236240
const char *name;
237-
const struct pmu_event *table;
241+
const struct pmu_events_table table;
238242
};
239243

240244
static const struct pmu_sys_events pmu_sys_event_tables[] = {
241245
{
242-
.table = pme_test_soc_sys,
246+
.table = { pme_test_soc_sys },
243247
.name = "pme_test_soc_sys",
244248
},
245249
{
246-
.table = 0
250+
.table = { 0 }
247251
},
248252
};
249253

250-
int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
254+
int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
251255
void *data)
252256
{
253-
for (const struct pmu_event *pe = &table[0];
257+
for (const struct pmu_event *pe = &table->entries[0];
254258
pe->name || pe->metric_group || pe->metric_name;
255259
pe++) {
256260
int ret = fn(pe, table, data);
@@ -261,9 +265,9 @@ int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_ite
261265
return 0;
262266
}
263267

264-
const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
268+
const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
265269
{
266-
const struct pmu_event *table = NULL;
270+
const struct pmu_events_table *table = NULL;
267271
char *cpuid = perf_pmu__getcpuid(pmu);
268272
int i;
269273

@@ -277,49 +281,49 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
277281
for (;;) {
278282
const struct pmu_events_map *map = &pmu_events_map[i++];
279283

280-
if (!map->table)
284+
if (!map->cpuid)
281285
break;
282286

283287
if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
284-
table = map->table;
288+
table = &map->table;
285289
break;
286290
}
287291
}
288292
free(cpuid);
289293
return table;
290294
}
291295

292-
const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid)
296+
const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid)
293297
{
294298
for (const struct pmu_events_map *tables = &pmu_events_map[0];
295-
tables->table;
299+
tables->arch;
296300
tables++) {
297301
if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
298-
return tables->table;
302+
return &tables->table;
299303
}
300304
return NULL;
301305
}
302306

303307
int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
304308
{
305309
for (const struct pmu_events_map *tables = &pmu_events_map[0];
306-
tables->table;
310+
tables->arch;
307311
tables++) {
308-
int ret = pmu_events_table_for_each_event(tables->table, fn, data);
312+
int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
309313

310314
if (ret)
311315
return ret;
312316
}
313317
return 0;
314318
}
315319

316-
const struct pmu_event *find_sys_events_table(const char *name)
320+
const struct pmu_events_table *find_sys_events_table(const char *name)
317321
{
318322
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
319323
tables->name;
320324
tables++) {
321325
if (!strcmp(tables->name, name))
322-
return tables->table;
326+
return &tables->table;
323327
}
324328
return NULL;
325329
}
@@ -329,7 +333,7 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
329333
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
330334
tables->name;
331335
tables++) {
332-
int ret = pmu_events_table_for_each_event(tables->table, fn, data);
336+
int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
333337

334338
if (ret)
335339
return ret;

tools/perf/pmu-events/jevents.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ def is_leaf_dir(path: str) -> bool:
335335
def print_mapping_table(archs: Sequence[str]) -> None:
336336
"""Read the mapfile and generate the struct from cpuid string to event table."""
337337
_args.output_file.write("""
338+
/* Struct used to make the PMU event table implementation opaque to callers. */
339+
struct pmu_events_table {
340+
const struct pmu_event *entries;
341+
};
342+
338343
/*
339344
* Map a CPU to its table of PMU events. The CPU is identified by the
340345
* cpuid field, which is an arch-specific identifier for the CPU.
@@ -346,7 +351,7 @@ def print_mapping_table(archs: Sequence[str]) -> None:
346351
struct pmu_events_map {
347352
const char *arch;
348353
const char *cpuid;
349-
const struct pmu_event *table;
354+
struct pmu_events_table table;
350355
};
351356
352357
/*
@@ -360,7 +365,7 @@ def print_mapping_table(archs: Sequence[str]) -> None:
360365
_args.output_file.write("""{
361366
\t.arch = "testarch",
362367
\t.cpuid = "testcpu",
363-
\t.table = pme_test_soc_cpu,
368+
\t.table = { pme_test_soc_cpu },
364369
},
365370
""")
366371
else:
@@ -375,15 +380,15 @@ def print_mapping_table(archs: Sequence[str]) -> None:
375380
_args.output_file.write(f"""{{
376381
\t.arch = "{arch}",
377382
\t.cpuid = "{cpuid}",
378-
\t.table = {tblname}
383+
\t.table = {{ {tblname} }}
379384
}},
380385
""")
381386
first = False
382387

383388
_args.output_file.write("""{
384389
\t.arch = 0,
385390
\t.cpuid = 0,
386-
\t.table = 0,
391+
\t.table = { 0 },
387392
}
388393
};
389394
""")
@@ -394,26 +399,26 @@ def print_system_mapping_table() -> None:
394399
_args.output_file.write("""
395400
struct pmu_sys_events {
396401
\tconst char *name;
397-
\tconst struct pmu_event *table;
402+
\tstruct pmu_events_table table;
398403
};
399404
400405
static const struct pmu_sys_events pmu_sys_event_tables[] = {
401406
""")
402407
for tblname in _sys_event_tables:
403408
_args.output_file.write(f"""\t{{
404-
\t\t.table = {tblname},
409+
\t\t.table = {{ {tblname} }},
405410
\t\t.name = \"{tblname}\",
406411
\t}},
407412
""")
408413
_args.output_file.write("""\t{
409-
\t\t.table = 0
414+
\t\t.table = { 0 }
410415
\t},
411416
};
412417
413-
int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
418+
int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
414419
void *data)
415420
{
416-
for (const struct pmu_event *pe = &table[0];
421+
for (const struct pmu_event *pe = &table->entries[0];
417422
pe->name || pe->metric_group || pe->metric_name;
418423
pe++) {
419424
int ret = fn(pe, table, data);
@@ -424,9 +429,9 @@ def print_system_mapping_table() -> None:
424429
return 0;
425430
}
426431
427-
const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
432+
const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
428433
{
429-
const struct pmu_event *table = NULL;
434+
const struct pmu_events_table *table = NULL;
430435
char *cpuid = perf_pmu__getcpuid(pmu);
431436
int i;
432437
@@ -439,49 +444,49 @@ def print_system_mapping_table() -> None:
439444
i = 0;
440445
for (;;) {
441446
const struct pmu_events_map *map = &pmu_events_map[i++];
442-
if (!map->table)
447+
if (!map->arch)
443448
break;
444449
445450
if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
446-
table = map->table;
451+
table = &map->table;
447452
break;
448453
}
449454
}
450455
free(cpuid);
451456
return table;
452457
}
453458
454-
const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid)
459+
const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid)
455460
{
456461
for (const struct pmu_events_map *tables = &pmu_events_map[0];
457-
tables->table;
462+
tables->arch;
458463
tables++) {
459464
if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
460-
return tables->table;
465+
return &tables->table;
461466
}
462467
return NULL;
463468
}
464469
465470
int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
466471
{
467472
for (const struct pmu_events_map *tables = &pmu_events_map[0];
468-
tables->table;
473+
tables->arch;
469474
tables++) {
470-
int ret = pmu_events_table_for_each_event(tables->table, fn, data);
475+
int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
471476
472477
if (ret)
473478
return ret;
474479
}
475480
return 0;
476481
}
477482
478-
const struct pmu_event *find_sys_events_table(const char *name)
483+
const struct pmu_events_table *find_sys_events_table(const char *name)
479484
{
480485
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
481486
tables->name;
482487
tables++) {
483488
if (!strcmp(tables->name, name))
484-
return tables->table;
489+
return &tables->table;
485490
}
486491
return NULL;
487492
}
@@ -491,7 +496,7 @@ def print_system_mapping_table() -> None:
491496
for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
492497
tables->name;
493498
tables++) {
494-
int ret = pmu_events_table_for_each_event(tables->table, fn, data);
499+
int ret = pmu_events_table_for_each_event(&tables->table, fn, data);
495500
496501
if (ret)
497502
return ret;

tools/perf/pmu-events/pmu-events.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@ struct pmu_event {
3030
const char *metric_constraint;
3131
};
3232

33+
struct pmu_events_table;
34+
3335
typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe,
34-
const struct pmu_event *table,
36+
const struct pmu_events_table *table,
3537
void *data);
3638

37-
int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
39+
int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
3840
void *data);
3941

40-
const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu);
41-
const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid);
42+
const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu);
43+
const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid);
4244
int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data);
4345

44-
const struct pmu_event *find_sys_events_table(const char *name);
46+
const struct pmu_events_table *find_sys_events_table(const char *name);
4547
int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data);
4648

4749
#endif

tools/perf/tests/expand-cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static int expand_metric_events(void)
180180
struct evlist *evlist;
181181
struct rblist metric_events;
182182
const char metric_str[] = "CPI";
183-
const struct pmu_event *pme_test;
183+
const struct pmu_events_table *pme_test;
184184

185185
evlist = evlist__new();
186186
TEST_ASSERT_VAL("failed to get evlist", evlist);

tools/perf/tests/parse-metric.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int __compute_metric(const char *name, struct value *vals,
7272
struct rblist metric_events = {
7373
.nr_entries = 0,
7474
};
75-
const struct pmu_event *pme_test;
75+
const struct pmu_events_table *pme_test;
7676
struct perf_cpu_map *cpus;
7777
struct runtime_stat st;
7878
struct evlist *evlist;

0 commit comments

Comments
 (0)