Message ID | 20240823113306.2310957-6-leo.yan@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | perf auxtrace: Support multiple AUX events | expand |
On 23/08/24 14:33, Leo Yan wrote: > This commit splits the evlist__enable_event_idx() function into two > steps. The first step uses a new function evlist__find_cpu_map_idx() to > find the CPU map index, based on the found CPU map index or a thread map > index, it continues to call evlist__enable_event_idx() for enabling the > corresponding event. > > Signed-off-by: Leo Yan <leo.yan@arm.com> > --- > tools/perf/util/auxtrace.c | 42 +++++++++++++++++++++++++++++--------- > 1 file changed, 32 insertions(+), 10 deletions(-) > > diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c > index 87e4f21b6edf..e7b582d92811 100644 > --- a/tools/perf/util/auxtrace.c > +++ b/tools/perf/util/auxtrace.c > @@ -651,20 +651,30 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr, > return -EINVAL; > } > > -static int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, int idx) > +static int evlist__find_cpu_map_idx(struct evlist *evlist, struct evsel *evsel, > + int idx) > { > bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); > + struct perf_cpu evlist_cpu; > + int cpu_map_idx; > > - if (per_cpu_mmaps) { > - struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); > - int cpu_map_idx = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu); > + if (!per_cpu_mmaps) > + return -EINVAL; > > - if (cpu_map_idx == -1) > - return -EINVAL; > - return perf_evsel__enable_cpu(&evsel->core, cpu_map_idx); > - } > + evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); > + cpu_map_idx = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu); > + if (cpu_map_idx == -1) > + return -ENOENT; > + > + return cpu_map_idx; > +} > > - return perf_evsel__enable_thread(&evsel->core, idx); > +static int evlist__enable_event_idx(struct evsel *evsel, int cpu_mode, int idx) > +{ > + if (cpu_mode) > + return perf_evsel__enable_cpu(&evsel->core, idx); > + else > + return perf_evsel__enable_thread(&evsel->core, idx); > } > > int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx) > @@ -676,9 +686,21 @@ int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx) > > evlist__for_each_entry(itr->evlist, evsel) { > if (evsel__is_aux_event(evsel)) { > + int cpu_map_idx; > + > if (evsel->disabled) > return 0; > - return evlist__enable_event_idx(itr->evlist, evsel, idx); > + > + cpu_map_idx = evlist__find_cpu_map_idx(itr->evlist, > + evsel, idx); > + /* No map is found in per CPU mmap */ > + if (cpu_map_idx == -ENOENT) > + return cpu_map_idx; > + > + if (cpu_map_idx >= 0) > + return evlist__enable_event_idx(evsel, 1, cpu_map_idx); > + else > + return evlist__enable_event_idx(evsel, 0, idx); > } > } > return -EINVAL; What about keeping per_cpu_mmaps in auxtrace_record__read_finish() e.g. static int evlist__find_evsel_cpu_idx(struct evlist *evlist, struct evsel *evsel, int idx) { struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); return perf_cpu_map__idx(evsel->core.cpus, evlist_cpu); } int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx) { bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); struct evsel *evsel; int evsel_cpu_idx; if (!itr->evlist) return -EINVAL; evlist__for_each_entry(itr->evlist, evsel) { if (!evsel__is_aux_event(evsel)) continue; if (per_cpu_mmaps) { evsel_cpu_idx = evlist__find_evsel_cpu_idx(itr->evlist, evsel, idx); /* No map is found in per CPU mmap */ if (evsel_cpu_idx < 0) return -EINVAL; } if (evsel->disabled) return 0; if (per_cpu_mmaps) return perf_evsel__enable_cpu(&evsel->core, evsel_cpu_idx); return perf_evsel__enable_thread(&evsel->core, idx); } return -EINVAL; }
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 87e4f21b6edf..e7b582d92811 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -651,20 +651,30 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr, return -EINVAL; } -static int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, int idx) +static int evlist__find_cpu_map_idx(struct evlist *evlist, struct evsel *evsel, + int idx) { bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); + struct perf_cpu evlist_cpu; + int cpu_map_idx; - if (per_cpu_mmaps) { - struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); - int cpu_map_idx = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu); + if (!per_cpu_mmaps) + return -EINVAL; - if (cpu_map_idx == -1) - return -EINVAL; - return perf_evsel__enable_cpu(&evsel->core, cpu_map_idx); - } + evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); + cpu_map_idx = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu); + if (cpu_map_idx == -1) + return -ENOENT; + + return cpu_map_idx; +} - return perf_evsel__enable_thread(&evsel->core, idx); +static int evlist__enable_event_idx(struct evsel *evsel, int cpu_mode, int idx) +{ + if (cpu_mode) + return perf_evsel__enable_cpu(&evsel->core, idx); + else + return perf_evsel__enable_thread(&evsel->core, idx); } int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx) @@ -676,9 +686,21 @@ int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx) evlist__for_each_entry(itr->evlist, evsel) { if (evsel__is_aux_event(evsel)) { + int cpu_map_idx; + if (evsel->disabled) return 0; - return evlist__enable_event_idx(itr->evlist, evsel, idx); + + cpu_map_idx = evlist__find_cpu_map_idx(itr->evlist, + evsel, idx); + /* No map is found in per CPU mmap */ + if (cpu_map_idx == -ENOENT) + return cpu_map_idx; + + if (cpu_map_idx >= 0) + return evlist__enable_event_idx(evsel, 1, cpu_map_idx); + else + return evlist__enable_event_idx(evsel, 0, idx); } } return -EINVAL;
This commit splits the evlist__enable_event_idx() function into two steps. The first step uses a new function evlist__find_cpu_map_idx() to find the CPU map index, based on the found CPU map index or a thread map index, it continues to call evlist__enable_event_idx() for enabling the corresponding event. Signed-off-by: Leo Yan <leo.yan@arm.com> --- tools/perf/util/auxtrace.c | 42 +++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-)