Re: [PATCH v6 10/12] perf stat: Use affinity for reading

From: Jiri Olsa
Date: Fri Nov 15 2019 - 09:55:50 EST


On Mon, Nov 11, 2019 at 04:59:39PM -0800, Andi Kleen wrote:

SNIP

>
> return 0;
> @@ -325,15 +318,35 @@ static int read_counter(struct evsel *counter, struct timespec *rs)
> static void read_counters(struct timespec *rs)
> {
> struct evsel *counter;
> - int ret;
> + struct affinity affinity;
> + int i, ncpus, cpu;
> +
> + if (affinity__setup(&affinity) < 0)
> + return;
> +
> + ncpus = evsel_list->core.all_cpus->nr;
> + if (!(target__has_cpu(&target) && !target__has_per_thread(&target)))
> + ncpus = 1;

hum, could we propagate the negation inside amke this more readable?

if (!target__has_cpu(&target) || target__has_per_thread(&target))

jirka

> + evlist__for_each_cpu (evsel_list, i, cpu) {
> + if (i >= ncpus)
> + break;
> + affinity__set(&affinity, cpu);
> +
> + evlist__for_each_entry(evsel_list, counter) {
> + if (evsel__cpu_iter_skip(counter, cpu))
> + continue;
> + if (!counter->err)
> + counter->err = read_counter(counter, rs, counter->cpu_iter - 1);
> + }
> + }
> + affinity__cleanup(&affinity);

SNIP