Skip to content

Commit

Permalink
perf evsel: Add iterator to iterate over events ordered by CPU
Browse files Browse the repository at this point in the history
Add some common code that is needed to iterate over all events
in CPU order. Used in followon patches

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lore.kernel.org/lkml/20191121001522.180827-6-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Andi Kleen authored and Arnaldo Carvalho de Melo committed Nov 29, 2019
1 parent a2408a7 commit a8cbe40
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/perf/util/cpumap.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,

int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);

#endif /* __PERF_CPUMAP_H */
32 changes: 32 additions & 0 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,38 @@ static int perf_evlist__nr_threads(struct evlist *evlist,
return perf_thread_map__nr(evlist->core.threads);
}

void evlist__cpu_iter_start(struct evlist *evlist)
{
struct evsel *pos;

/*
* Reset the per evsel cpu_iter. This is needed because
* each evsel's cpumap may have a different index space,
* and some operations need the index to modify
* the FD xyarray (e.g. open, close)
*/
evlist__for_each_entry(evlist, pos)
pos->cpu_iter = 0;
}

bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu)
{
if (ev->cpu_iter >= ev->core.cpus->nr)
return true;
if (cpu >= 0 && ev->core.cpus->map[ev->cpu_iter] != cpu)
return true;
return false;
}

bool evsel__cpu_iter_skip(struct evsel *ev, int cpu)
{
if (!evsel__cpu_iter_skip_no_inc(ev, cpu)) {
ev->cpu_iter++;
return false;
}
return true;
}

void evlist__disable(struct evlist *evlist)
{
struct evsel *pos;
Expand Down
8 changes: 8 additions & 0 deletions tools/perf/util/evlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,17 @@ void perf_evlist__to_front(struct evlist *evlist,
#define evlist__for_each_entry_safe(evlist, tmp, evsel) \
__evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)

#define evlist__for_each_cpu(evlist, index, cpu) \
evlist__cpu_iter_start(evlist); \
perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)

void perf_evlist__set_tracking_event(struct evlist *evlist,
struct evsel *tracking_evsel);

void evlist__cpu_iter_start(struct evlist *evlist);
bool evsel__cpu_iter_skip(struct evsel *ev, int cpu);
bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu);

struct evsel *
perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);

Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/evsel.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct evsel {
bool collect_stat;
bool weak_group;
bool percore;
int cpu_iter;
const char *pmu_name;
struct {
perf_evsel__sb_cb_t *cb;
Expand Down

0 comments on commit a8cbe40

Please sign in to comment.