All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mike Leach <mike.leach@linaro.org>, Leo Yan <leo.yan@linaro.org>,
	John Garry <john.garry@huawei.com>, Will Deacon <will@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Kajol Jain <kjain@linux.ibm.com>,
	James Clark <james.clark@arm.com>,
	German Gomez <german.gomez@arm.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Riccardo Mancini <rickyman7@gmail.com>,
	Andi Kleen <ak@linux.intel.com>,
	Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>,
	Alexander Antonov <alexander.antonov@linux.intel.com>,
	linux-perf-users <linux-perf-users@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v5 1/6] perf cpumap: Switch to using perf_cpu_map API
Date: Thu, 5 May 2022 14:39:26 -0300	[thread overview]
Message-ID: <YnQLzvmuI2tG3bvj@kernel.org> (raw)
In-Reply-To: <CAM9d7cia6OT5Mk13R36CwZW8iwVWtsyQVBE7s1+NKhh+dT93Vg@mail.gmail.com>

Em Wed, May 04, 2022 at 10:44:42AM -0700, Namhyung Kim escreveu:
> Hi Ian,
> 
> On Mon, May 2, 2022 at 9:18 PM Ian Rogers <irogers@google.com> wrote:
> >
> > Switch some raw accesses to the cpu map to using the library API. This
> > can help with reference count checking. Some BPF cases switch from index
> > to CPU for consistency, this shouldn't matter as the CPU map is full.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks, applied.

- Arnaldo

 
> Thanks,
> Namhyung
> 
> 
> > ---
> >  tools/perf/builtin-record.c          | 13 +++++----
> >  tools/perf/util/bpf_counter_cgroup.c | 42 +++++++++++++---------------
> >  2 files changed, 26 insertions(+), 29 deletions(-)
> >
> > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> > index 069825c48d40..a5cf6a99d67f 100644
> > --- a/tools/perf/builtin-record.c
> > +++ b/tools/perf/builtin-record.c
> > @@ -1011,7 +1011,7 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
> >
> >         for (m = 0, tm = 0; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) {
> >                 if (cpu_map__is_dummy(cpus) ||
> > -                   test_bit(cpus->map[m].cpu, thread_data->mask->maps.bits)) {
> > +                   test_bit(perf_cpu_map__cpu(cpus, m).cpu, thread_data->mask->maps.bits)) {
> >                         if (thread_data->maps) {
> >                                 thread_data->maps[tm] = &mmap[m];
> >                                 pr_debug2("thread_data[%p]: cpu%d: maps[%d] -> mmap[%d]\n",
> > @@ -3331,13 +3331,14 @@ struct option *record_options = __record_options;
> >
> >  static void record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cpu_map *cpus)
> >  {
> > -       int c;
> > +       struct perf_cpu cpu;
> > +       int idx;
> >
> >         if (cpu_map__is_dummy(cpus))
> >                 return;
> >
> > -       for (c = 0; c < cpus->nr; c++)
> > -               set_bit(cpus->map[c].cpu, mask->bits);
> > +       perf_cpu_map__for_each_cpu(cpu, idx, cpus)
> > +               set_bit(cpu.cpu, mask->bits);
> >  }
> >
> >  static int record__mmap_cpu_mask_init_spec(struct mmap_cpu_mask *mask, const char *mask_spec)
> > @@ -3404,8 +3405,8 @@ static int record__init_thread_cpu_masks(struct record *rec, struct perf_cpu_map
> >         pr_debug("nr_threads: %d\n", rec->nr_threads);
> >
> >         for (t = 0; t < rec->nr_threads; t++) {
> > -               set_bit(cpus->map[t].cpu, rec->thread_masks[t].maps.bits);
> > -               set_bit(cpus->map[t].cpu, rec->thread_masks[t].affinity.bits);
> > +               set_bit(perf_cpu_map__cpu(cpus, t).cpu, rec->thread_masks[t].maps.bits);
> > +               set_bit(perf_cpu_map__cpu(cpus, t).cpu, rec->thread_masks[t].affinity.bits);
> >                 if (verbose) {
> >                         pr_debug("thread_masks[%d]: ", t);
> >                         mmap_cpu_mask__scnprintf(&rec->thread_masks[t].maps, "maps");
> > diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c
> > index ac60c08e8e2a..63b9db657442 100644
> > --- a/tools/perf/util/bpf_counter_cgroup.c
> > +++ b/tools/perf/util/bpf_counter_cgroup.c
> > @@ -46,8 +46,8 @@ static int bperf_load_program(struct evlist *evlist)
> >         struct bpf_link *link;
> >         struct evsel *evsel;
> >         struct cgroup *cgrp, *leader_cgrp;
> > -       __u32 i, cpu;
> > -       __u32 nr_cpus = evlist->core.all_cpus->nr;
> > +       int i, j;
> > +       struct perf_cpu cpu;
> >         int total_cpus = cpu__max_cpu().cpu;
> >         int map_size, map_fd;
> >         int prog_fd, err;
> > @@ -93,9 +93,9 @@ static int bperf_load_program(struct evlist *evlist)
> >                 goto out;
> >         }
> >
> > -       for (i = 0; i < nr_cpus; i++) {
> > +       perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) {
> >                 link = bpf_program__attach_perf_event(skel->progs.on_cgrp_switch,
> > -                                                     FD(cgrp_switch, i));
> > +                                                     FD(cgrp_switch, cpu.cpu));
> >                 if (IS_ERR(link)) {
> >                         pr_err("Failed to attach cgroup program\n");
> >                         err = PTR_ERR(link);
> > @@ -122,10 +122,9 @@ static int bperf_load_program(struct evlist *evlist)
> >                         }
> >
> >                         map_fd = bpf_map__fd(skel->maps.events);
> > -                       for (cpu = 0; cpu < nr_cpus; cpu++) {
> > -                               int fd = FD(evsel, cpu);
> > -                               __u32 idx = evsel->core.idx * total_cpus +
> > -                                       evlist->core.all_cpus->map[cpu].cpu;
> > +                       perf_cpu_map__for_each_cpu(cpu, j, evlist->core.all_cpus) {
> > +                               int fd = FD(evsel, cpu.cpu);
> > +                               __u32 idx = evsel->core.idx * total_cpus + cpu.cpu;
> >
> >                                 err = bpf_map_update_elem(map_fd, &idx, &fd,
> >                                                           BPF_ANY);
> > @@ -207,14 +206,12 @@ static int bperf_cgrp__install_pe(struct evsel *evsel __maybe_unused,
> >   */
> >  static int bperf_cgrp__sync_counters(struct evlist *evlist)
> >  {
> > -       int i, cpu;
> > -       int nr_cpus = evlist->core.all_cpus->nr;
> > +       struct perf_cpu cpu;
> > +       int idx;
> >         int prog_fd = bpf_program__fd(skel->progs.trigger_read);
> >
> > -       for (i = 0; i < nr_cpus; i++) {
> > -               cpu = evlist->core.all_cpus->map[i].cpu;
> > -               bperf_trigger_reading(prog_fd, cpu);
> > -       }
> > +       perf_cpu_map__for_each_cpu(cpu, idx, evlist->core.all_cpus)
> > +               bperf_trigger_reading(prog_fd, cpu.cpu);
> >
> >         return 0;
> >  }
> > @@ -244,12 +241,10 @@ static int bperf_cgrp__disable(struct evsel *evsel)
> >  static int bperf_cgrp__read(struct evsel *evsel)
> >  {
> >         struct evlist *evlist = evsel->evlist;
> > -       int i, cpu, nr_cpus = evlist->core.all_cpus->nr;
> >         int total_cpus = cpu__max_cpu().cpu;
> >         struct perf_counts_values *counts;
> >         struct bpf_perf_event_value *values;
> >         int reading_map_fd, err = 0;
> > -       __u32 idx;
> >
> >         if (evsel->core.idx)
> >                 return 0;
> > @@ -263,7 +258,10 @@ static int bperf_cgrp__read(struct evsel *evsel)
> >         reading_map_fd = bpf_map__fd(skel->maps.cgrp_readings);
> >
> >         evlist__for_each_entry(evlist, evsel) {
> > -               idx = evsel->core.idx;
> > +               __u32 idx = evsel->core.idx;
> > +               int i;
> > +               struct perf_cpu cpu;
> > +
> >                 err = bpf_map_lookup_elem(reading_map_fd, &idx, values);
> >                 if (err) {
> >                         pr_err("bpf map lookup failed: idx=%u, event=%s, cgrp=%s\n",
> > @@ -271,13 +269,11 @@ static int bperf_cgrp__read(struct evsel *evsel)
> >                         goto out;
> >                 }
> >
> > -               for (i = 0; i < nr_cpus; i++) {
> > -                       cpu = evlist->core.all_cpus->map[i].cpu;
> > -
> > +               perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) {
> >                         counts = perf_counts(evsel->counts, i, 0);
> > -                       counts->val = values[cpu].counter;
> > -                       counts->ena = values[cpu].enabled;
> > -                       counts->run = values[cpu].running;
> > +                       counts->val = values[cpu.cpu].counter;
> > +                       counts->ena = values[cpu.cpu].enabled;
> > +                       counts->run = values[cpu.cpu].running;
> >                 }
> >         }
> >
> > --
> > 2.36.0.464.gb9c8b46e94-goog
> >

-- 

- Arnaldo

  reply	other threads:[~2022-05-05 17:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03  4:17 [PATCH v5 0/6] Make evlist CPUs more accurate Ian Rogers
2022-05-03  4:17 ` [PATCH v5 1/6] perf cpumap: Switch to using perf_cpu_map API Ian Rogers
2022-05-04 17:44   ` Namhyung Kim
2022-05-05 17:39     ` Arnaldo Carvalho de Melo [this message]
2022-05-03  4:17 ` [PATCH v5 2/6] perf evlist: Clear all_cpus before propagating Ian Rogers
2022-05-04 14:15   ` Adrian Hunter
2022-05-05 17:39     ` Arnaldo Carvalho de Melo
2022-05-03  4:17 ` [PATCH v5 3/6] perf stat: Avoid printing cpus with no counters Ian Rogers
2022-05-03 14:19   ` Arnaldo Carvalho de Melo
2022-05-03  4:17 ` [PATCH v5 4/6] perf cpumap: Handle dummy maps as empty in subset Ian Rogers
2022-05-03  7:43   ` Adrian Hunter
2022-05-03 14:03     ` Ian Rogers
2022-05-04 12:54       ` Adrian Hunter
2022-05-04 13:59         ` Ian Rogers
2022-05-04 16:33           ` Ian Rogers
2022-05-03  4:17 ` [PATCH v5 5/6] perf evlist: Add to user_requested_cpus documentation Ian Rogers
2022-05-03  4:17 ` [PATCH v5 6/6] perf evlist: Rename all_cpus Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YnQLzvmuI2tG3bvj@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.antonov@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.v.bayduraev@linux.intel.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eranian@google.com \
    --cc=german.gomez@arm.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=john.fastabend@gmail.com \
    --cc=john.garry@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kjain@linux.ibm.com \
    --cc=kpsingh@kernel.org \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rickyman7@gmail.com \
    --cc=songliubraving@fb.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.