Re: [PATCH v3 3/7] perf evsel: Add iterator to iterate over events ordered by CPU

Andi Kleen
2019-10-30T16:02:34Z

On Wed, Oct 30, 2019 at 11:06:06AM +0100, Jiri Olsa wrote:
> > +struct perf_cpu_map *evlist__cpu_iter_start(struct evlist *evlist)
> > +{
> > + struct perf_cpu_map *cpus;
> > + struct evsel *pos;
> > +
> > + /*
> > + * evlist->cpus is not necessarily a superset of all the
> > + * event's cpus, so compute our own super set. This
> > + * assume that there is a super set
> > + */
> > + cpus = evlist->core.cpus;
> > + evlist__for_each_entry(evlist, pos) {
> > + pos->cpu_index = 0;
> > + if (pos->core.cpus->nr > cpus->nr)
> > + cpus = pos->core.cpus;
> > + }
> > + return cpus;
>
> I might not understand the reason for cpu_index, but

This is just so that we can iterate each event's map
independently.

> imagine something like below should be enough, no?

Well it's more complicated because evlist->all_cpus doesn't exist.
The exists evlist->cpus cannot be used (I tried that)
I also don't think we have an existing function to merge
two maps, so that would need to be added to create it.
Just using ->cpu_index is a much simpler change.

-Andi