Re: [PATCH v5 11/13] perf stat: Use affinity for reading

From: Jiri Olsa
Date: Mon Nov 11 2019 - 08:31:09 EST


On Thu, Nov 07, 2019 at 10:16:44AM -0800, Andi Kleen wrote:

SNIP

> @@ -325,15 +318,34 @@ 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;
> + 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;
> + counter->err = read_counter(counter, rs, counter->cpu_iter - 1);

this will be overwritten by another cpu attempt,
so the check below won't get triggered properly

should we just break in case of error in here?

> + }
> + }
> + affinity__cleanup(&affinity);
>
> evlist__for_each_entry(evsel_list, counter) {
> - ret = read_counter(counter, rs);
> - if (ret)
> + if (counter->err)
> pr_debug("failed to read counter %s\n", counter->name);
> -
> - if (ret == 0 && perf_stat_process_counter(&stat_config, counter))
> + if (counter->err == 0 && perf_stat_process_counter(&stat_config, counter))
> pr_warning("failed to process counter %s\n", counter->name);
> + counter->err = 0;
> }
> }
>

SNIP