From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Muhammad Falak R Wani <falakreyaz@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Quentin Monnet <quentin@isovalent.com>,
Yu Kuai <yukuai3@huawei.com>,
"linux-perf-use." <linux-perf-users@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH] perflib: deprecate bpf_map__resize in favor of bpf_map_set_max_entries
Date: Wed, 15 Sep 2021 17:56:26 -0300 [thread overview]
Message-ID: <YUJd+jo1W+mdK0Fv@kernel.org> (raw)
In-Reply-To: <CAEf4BzZ+3hM9oPxdXsxXRKJD2TCmpXPnkWz1LPnP7mDagprdyA@mail.gmail.com>
Em Mon, Aug 16, 2021 at 12:28:14PM -0700, Andrii Nakryiko escreveu:
> On Sun, Aug 15, 2021 at 3:36 AM Muhammad Falak R Wani
> <falakreyaz@gmail.com> wrote:
> >
> > As a part of libbpf 1.0 plan[0], this patch deprecates use of
> > bpf_map__resize in favour of bpf_map__set_max_entries.
> >
> > Reference: https://github.com/libbpf/libbpf/issues/304
> > [0]: https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0#libbpfh-high-level-apis
> >
> > Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
> > ---
>
> All looks good, there is an opportunity to simplify the code a bit (see below).
>
> Arnaldo, I assume you'll take this through your tree or you'd like us
Yeah, I'll take the opportunity to try to improve that detection of
libbpf version, etc.
- Arnaldo
> to take it through bpf-next?
>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
>
> > tools/perf/util/bpf_counter.c | 8 ++++----
> > tools/perf/util/bpf_counter_cgroup.c | 8 ++++----
> > 2 files changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c
> > index ba0f20853651..ced2dac31dcf 100644
> > --- a/tools/perf/util/bpf_counter.c
> > +++ b/tools/perf/util/bpf_counter.c
> > @@ -127,9 +127,9 @@ static int bpf_program_profiler_load_one(struct evsel *evsel, u32 prog_id)
> >
> > skel->rodata->num_cpu = evsel__nr_cpus(evsel);
> >
> > - bpf_map__resize(skel->maps.events, evsel__nr_cpus(evsel));
> > - bpf_map__resize(skel->maps.fentry_readings, 1);
> > - bpf_map__resize(skel->maps.accum_readings, 1);
> > + bpf_map__set_max_entries(skel->maps.events, evsel__nr_cpus(evsel));
> > + bpf_map__set_max_entries(skel->maps.fentry_readings, 1);
> > + bpf_map__set_max_entries(skel->maps.accum_readings, 1);
> >
> > prog_name = bpf_target_prog_name(prog_fd);
> > if (!prog_name) {
> > @@ -399,7 +399,7 @@ static int bperf_reload_leader_program(struct evsel *evsel, int attr_map_fd,
> > return -1;
> > }
> >
> > - bpf_map__resize(skel->maps.events, libbpf_num_possible_cpus());
> > + bpf_map__set_max_entries(skel->maps.events, libbpf_num_possible_cpus());
>
> If you set max_entries to 0 (or just skip specifying it) for events
> map in util/bpf_skel/bperf_cgroup.bpf.c, you won't need to resize it,
> libbpf will automatically size it to number of possible CPUs.
>
> > err = bperf_leader_bpf__load(skel);
> > if (err) {
> > pr_err("Failed to load leader skeleton\n");
> > diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c
> > index 89aa5e71db1a..cbc6c2bca488 100644
> > --- a/tools/perf/util/bpf_counter_cgroup.c
> > +++ b/tools/perf/util/bpf_counter_cgroup.c
> > @@ -65,14 +65,14 @@ static int bperf_load_program(struct evlist *evlist)
> >
> > /* we need one copy of events per cpu for reading */
> > map_size = total_cpus * evlist->core.nr_entries / nr_cgroups;
> > - bpf_map__resize(skel->maps.events, map_size);
> > - bpf_map__resize(skel->maps.cgrp_idx, nr_cgroups);
> > + bpf_map__set_max_entries(skel->maps.events, map_size);
> > + bpf_map__set_max_entries(skel->maps.cgrp_idx, nr_cgroups);
> > /* previous result is saved in a per-cpu array */
> > map_size = evlist->core.nr_entries / nr_cgroups;
> > - bpf_map__resize(skel->maps.prev_readings, map_size);
> > + bpf_map__set_max_entries(skel->maps.prev_readings, map_size);
> > /* cgroup result needs all events (per-cpu) */
> > map_size = evlist->core.nr_entries;
> > - bpf_map__resize(skel->maps.cgrp_readings, map_size);
> > + bpf_map__set_max_entries(skel->maps.cgrp_readings, map_size);
> >
> > set_max_rlimit();
> >
> > --
> > 2.17.1
> >
--
- Arnaldo
prev parent reply other threads:[~2021-09-15 20:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-15 10:36 [PATCH] perflib: deprecate bpf_map__resize in favor of bpf_map_set_max_entries Muhammad Falak R Wani
2021-08-16 19:28 ` Andrii Nakryiko
2021-09-15 20:56 ` Arnaldo Carvalho de Melo [this message]
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=YUJd+jo1W+mdK0Fv@kernel.org \
--to=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=falakreyaz@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@redhat.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=quentin@isovalent.com \
--cc=songliubraving@fb.com \
--cc=yukuai3@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).