public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Ian Rogers <irogers@google.com>,
	"linux-perf-use." <linux-perf-users@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH 2/2] perf tools: Remove bpf_map__set_priv/bpf_map__priv usage
Date: Tue, 1 Mar 2022 09:49:30 +0100	[thread overview]
Message-ID: <Yh3eGjZj7aY1kuIY@krava> (raw)
In-Reply-To: <CAEf4BzbqbHDzGJJu8Zp1QPa-bxT_usespzs=rEj2UX0A-k0gPA@mail.gmail.com>

On Mon, Feb 28, 2022 at 05:49:32PM -0800, Andrii Nakryiko wrote:
> On Thu, Feb 24, 2022 at 7:53 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Both bpf_map__set_priv/bpf_map__priv are deprecated
> > and will be eventually removed.
> >
> > Using hashmap to replace that functionality.
> >
> > Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/perf/util/bpf-loader.c | 66 ++++++++++++++++++++++++++++++++----
> >  1 file changed, 59 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
> > index b9d4278895ec..4f6173756a9d 100644
> > --- a/tools/perf/util/bpf-loader.c
> > +++ b/tools/perf/util/bpf-loader.c
> > @@ -27,6 +27,7 @@
> >  #include "llvm-utils.h"
> >  #include "c++/clang-c.h"
> >  #include "hashmap.h"
> > +#include "asm/bug.h"
> >
> >  #include <internal/xyarray.h>
> >
> > @@ -57,6 +58,7 @@ struct bpf_perf_object {
> >
> >  static LIST_HEAD(bpf_objects_list);
> >  static struct hashmap *bpf_program_hash;
> > +static struct hashmap *bpf_map_hash;
> >
> >  static struct bpf_perf_object *
> >  bpf_perf_object__next(struct bpf_perf_object *prev)
> > @@ -204,6 +206,8 @@ static void bpf_program_hash_free(void)
> >         bpf_program_hash = NULL;
> >  }
> >
> > +static void bpf_map_hash_free(void);
> > +
> >  void bpf__clear(void)
> >  {
> >         struct bpf_perf_object *perf_obj, *tmp;
> > @@ -214,6 +218,7 @@ void bpf__clear(void)
> >         }
> >
> >         bpf_program_hash_free();
> > +       bpf_map_hash_free();
> >  }
> >
> >  static size_t ptr_hash(const void *__key, void *ctx __maybe_unused)
> > @@ -976,7 +981,7 @@ bpf_map_priv__purge(struct bpf_map_priv *priv)
> >  }
> >
> >  static void
> > -bpf_map_priv__clear(struct bpf_map *map __maybe_unused,
> > +bpf_map_priv__clear(const struct bpf_map *map __maybe_unused,
> >                     void *_priv)
> >  {
> >         struct bpf_map_priv *priv = _priv;
> > @@ -985,6 +990,53 @@ bpf_map_priv__clear(struct bpf_map *map __maybe_unused,
> >         free(priv);
> >  }
> >
> > +static void *map_priv(const struct bpf_map *map)
> > +{
> > +       void *priv;
> > +
> > +       if (IS_ERR_OR_NULL(bpf_map_hash))
> > +               return NULL;
> > +       if (!hashmap__find(bpf_map_hash, map, &priv))
> > +               return NULL;
> > +       return priv;
> > +}
> > +
> > +static void bpf_map_hash_free(void)
> > +{
> > +       struct hashmap_entry *cur;
> > +       size_t bkt;
> > +
> > +       if (IS_ERR_OR_NULL(bpf_map_hash))
> > +               return;
> > +
> > +       hashmap__for_each_entry(bpf_map_hash, cur, bkt)
> > +               bpf_map_priv__clear(cur->key, cur->value);
> > +
> > +       hashmap__free(bpf_map_hash);
> > +       bpf_map_hash = NULL;
> > +}
> > +
> > +static int map_set_priv(struct bpf_map *map, void *priv)
> > +{
> > +       void *old_priv;
> > +
> > +       if (WARN_ON_ONCE(IS_ERR(bpf_map_hash)))
> > +               return PTR_ERR(bpf_program_hash);
> > +
> 
> you didn't warn for this in the previous patch. I have no preference,
> just pointing out assymetry.

there's already message from the caller when program_set_priv fails,
so I don't think we need another one

jirka

> 
> > +       if (!bpf_map_hash) {
> > +               bpf_map_hash = hashmap__new(ptr_hash, ptr_equal, NULL);
> > +               if (IS_ERR(bpf_map_hash))
> > +                       return PTR_ERR(bpf_map_hash);
> > +       }
> > +
> > +       old_priv = map_priv(map);
> > +       if (old_priv) {
> > +               bpf_map_priv__clear(map, old_priv);
> > +               return hashmap__set(bpf_map_hash, map, priv, NULL, NULL);
> > +       }
> > +       return hashmap__add(bpf_map_hash, map, priv);
> > +}
> > +
> 
> [...]

  reply	other threads:[~2022-03-01  8:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 15:52 [PATCHv3 0/2] perf/bpf: Replace deprecated code Jiri Olsa
2022-02-24 15:52 ` [PATCH 1/2] perf tools: Remove bpf_program__set_priv/bpf_program__priv usage Jiri Olsa
2022-02-24 15:52 ` [PATCH 2/2] perf tools: Remove bpf_map__set_priv/bpf_map__priv usage Jiri Olsa
2022-03-01  1:49   ` Andrii Nakryiko
2022-03-01  8:49     ` Jiri Olsa [this message]
2022-03-01  1:49 ` [PATCHv3 0/2] perf/bpf: Replace deprecated code Andrii Nakryiko
2022-03-05 19:13   ` Arnaldo Carvalho de Melo

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=Yh3eGjZj7aY1kuIY@krava \
    --to=olsajiri@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /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