bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Christy Lee <christylee@fb.com>
Cc: andrii@kernel.org, acme@kernel.org, christyc.y.lee@gmail.com,
	bpf@vger.kernel.org, linux-perf-users@vger.kernel.org,
	kernel-team@fb.com, wangnan0@huawei.com,
	bobo.shaobowang@huawei.com, yuehaibing@huawei.com
Subject: Re: [PATCH bpf-next v4 2/2] perf: stop using deprecated bpf_object__next() API
Date: Wed, 2 Feb 2022 18:00:19 +0100	[thread overview]
Message-ID: <Yfq4o0Op4eYvFKIp@krava> (raw)
In-Reply-To: <Ye2LAEiXaBoj2n8Z@krava>

hi,
just checking, do you plan to send new version for this?

thanks,
jirka

On Sun, Jan 23, 2022 at 06:06:08PM +0100, Jiri Olsa wrote:
> On Wed, Jan 19, 2022 at 03:06:36PM -0800, Christy Lee wrote:
> 
> SNIP
> 
> > ---
> >  tools/perf/util/bpf-loader.c | 72 +++++++++++++++++++++++++++---------
> >  tools/perf/util/bpf-loader.h |  1 +
> >  2 files changed, 55 insertions(+), 18 deletions(-)
> > 
> > diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
> > index 4631cac3957f..b1822f8af2bb 100644
> > --- a/tools/perf/util/bpf-loader.c
> > +++ b/tools/perf/util/bpf-loader.c
> > @@ -29,9 +29,6 @@
> >  
> >  #include <internal/xyarray.h>
> >  
> > -/* temporarily disable libbpf deprecation warnings */
> > -#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> > -
> >  static int libbpf_perf_print(enum libbpf_print_level level __attribute__((unused)),
> >  			      const char *fmt, va_list args)
> >  {
> > @@ -49,6 +46,36 @@ struct bpf_prog_priv {
> >  	int *type_mapping;
> >  };
> >  
> > +struct bpf_perf_object {
> > +	struct bpf_object *obj;
> > +	struct list_head list;
> > +};
> > +
> > +static LIST_HEAD(bpf_objects_list);
> 
> hum.. I still can't see any code adding/removing bpf_perf_object
> objects to this list, and that's why the code is failing to remove
> probes
> 
> because there are no objects to iterate on, so added probes stay
> configured and screw following tests
> 
> you need something like below to add and del objects from
> bpf_objects_list list
> 
> it also simplifies for_each macros to work just over perf_obj,
> because I wasn't patient enough to make it work with the extra
> bpf_object ;-) I don't mind if you fix that, but this way looks
> simpler to me
> 
> tests are working for me with this fix, please feel free to
> squash it into your change
> 
> thanks,
> jirka
> 
> 
> ---
> diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
> index 57b9591f7cbb..d09d25707f1e 100644
> --- a/tools/perf/tests/bpf.c
> +++ b/tools/perf/tests/bpf.c
> @@ -210,6 +210,11 @@ prepare_bpf(void *obj_buf, size_t obj_buf_sz, const char *name)
>  		pr_debug("Compile BPF program failed.\n");
>  		return NULL;
>  	}
> +
> +	if (bpf_perf_object__add(obj)) {
> +		bpf_object__close(obj);
> +		return NULL;
> +	}
>  	return obj;
>  }
>  
> diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
> index 89e584ac267c..a7a8ad32c847 100644
> --- a/tools/perf/util/bpf-loader.c
> +++ b/tools/perf/util/bpf-loader.c
> @@ -70,11 +70,11 @@ struct bpf_perf_object *bpf_perf_object__next(struct bpf_perf_object *prev)
>  	return next;
>  }
>  
> -#define bpf_perf_object__for_each(perf_obj, tmp, obj)                          \
> -	for ((perf_obj) = bpf_perf_object__next(NULL),                         \
> -	    (tmp) = bpf_perf_object__next(perf_obj), (obj) = NULL;             \
> -	     (perf_obj) != NULL; (perf_obj) = (tmp),                           \
> -	    (tmp) = bpf_perf_object__next(tmp), (obj) = (perf_obj)->obj)
> +#define bpf_perf_object__for_each(perf_obj, tmp)         \
> +	for ((perf_obj) = bpf_perf_object__next(NULL),   \
> +	     (tmp) = bpf_perf_object__next(perf_obj);    \
> +	     (perf_obj) != NULL; (perf_obj) = (tmp),     \
> +	    (tmp) = bpf_perf_object__next(tmp) )
>  
>  static bool libbpf_initialized;
>  
> @@ -97,6 +97,24 @@ bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name)
>  	return obj;
>  }
>  
> +int bpf_perf_object__add(struct bpf_object *obj)
> +{
> +	struct bpf_perf_object *perf_obj = zalloc(sizeof(*perf_obj));
> +
> +	if (perf_obj) {
> +		perf_obj->obj = obj;
> +		list_add_tail(&perf_obj->list, &bpf_objects_list);
> +	}
> +	return perf_obj ? 0 : -ENOMEM;
> +}
> +
> +static void bpf_perf_object__close(struct bpf_perf_object *perf_obj)
> +{
> +	list_del(&perf_obj->list);
> +	bpf_object__close(perf_obj->obj);
> +	free(perf_obj);
> +}
> +
>  struct bpf_object *bpf__prepare_load(const char *filename, bool source)
>  {
>  	struct bpf_object *obj;
> @@ -135,17 +153,20 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
>  		return obj;
>  	}
>  
> +	if (bpf_perf_object__add(obj)) {
> +		bpf_object__close(obj);
> +		return ERR_PTR(-BPF_LOADER_ERRNO__COMPILE);
> +	}
>  	return obj;
>  }
>  
>  void bpf__clear(void)
>  {
>  	struct bpf_perf_object *perf_obj, *tmp;
> -	struct bpf_object *obj;
>  
> -	bpf_perf_object__for_each(perf_obj, tmp, obj) {
> -		bpf__unprobe(obj);
> -		bpf_object__close(obj);
> +	bpf_perf_object__for_each(perf_obj, tmp) {
> +		bpf__unprobe(perf_obj->obj);
> +		bpf_perf_object__close(perf_obj);
>  	}
>  }
>  
> @@ -1538,11 +1559,10 @@ apply_obj_config_object(struct bpf_object *obj)
>  int bpf__apply_obj_config(void)
>  {
>  	struct bpf_perf_object *perf_obj, *tmp;
> -	struct bpf_object *obj;
>  	int err;
>  
> -	bpf_perf_object__for_each(perf_obj, tmp, obj) {
> -		err = apply_obj_config_object(obj);
> +	bpf_perf_object__for_each(perf_obj, tmp) {
> +		err = apply_obj_config_object(perf_obj->obj);
>  		if (err)
>  			return err;
>  	}
> @@ -1550,25 +1570,24 @@ int bpf__apply_obj_config(void)
>  	return 0;
>  }
>  
> -#define bpf__perf_for_each_map(perf_obj, tmp, obj, map)                        \
> -	bpf_perf_object__for_each(perf_obj, tmp, obj)                          \
> -		bpf_object__for_each_map(map, obj)
> +#define bpf__perf_for_each_map(perf_obj, tmp, map)                   \
> +	bpf_perf_object__for_each(perf_obj, tmp)                     \
> +		bpf_object__for_each_map(map, perf_obj->obj)
>  
> -#define bpf__perf_for_each_map_named(perf_obj, tmp, obj, map, name)            \
> -	bpf__perf_for_each_map(perf_obj, tmp, obj, map)                        \
> +#define bpf__perf_for_each_map_named(perf_obj, tmp, map, name)            \
> +	bpf__perf_for_each_map(perf_obj, tmp, map)                        \
>  		if (bpf_map__name(map) && (strcmp(name, bpf_map__name(map)) == 0))
>  
>  struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name)
>  {
>  	struct bpf_map_priv *tmpl_priv = NULL;
>  	struct bpf_perf_object *perf_obj, *tmp;
> -	struct bpf_object *obj;
>  	struct evsel *evsel = NULL;
>  	struct bpf_map *map;
>  	int err;
>  	bool need_init = false;
>  
> -	bpf__perf_for_each_map_named(perf_obj, tmp, obj, map, name) {
> +	bpf__perf_for_each_map_named(perf_obj, tmp, map, name) {
>  		struct bpf_map_priv *priv = bpf_map__priv(map);
>  
>  		if (IS_ERR(priv))
> @@ -1604,7 +1623,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name)
>  		evsel = evlist__last(evlist);
>  	}
>  
> -	bpf__perf_for_each_map_named(perf_obj, tmp, obj, map, name) {
> +	bpf__perf_for_each_map_named(perf_obj, tmp, map, name) {
>  		struct bpf_map_priv *priv = bpf_map__priv(map);
>  
>  		if (IS_ERR(priv))
> diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
> index 95262b7e936f..78c7d3662910 100644
> --- a/tools/perf/util/bpf-loader.h
> +++ b/tools/perf/util/bpf-loader.h
> @@ -83,6 +83,8 @@ int bpf__strerror_config_obj(struct bpf_object *obj,
>  int bpf__apply_obj_config(void);
>  int bpf__strerror_apply_obj_config(int err, char *buf, size_t size);
>  
> +int bpf_perf_object__add(struct bpf_object *obj);
> +
>  int bpf__setup_stdout(struct evlist *evlist);
>  struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name);
>  int bpf__strerror_setup_output_event(struct evlist *evlist, int err, char *buf, size_t size);


  reply	other threads:[~2022-02-02 17:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19 23:06 [PATCH bpf-next v4 0/2] perf: stop using deprecated bpf APIs Christy Lee
2022-01-19 23:06 ` [PATCH bpf-next v4 1/2] perf: stop using deprecated bpf_load_program() API Christy Lee
2022-01-19 23:25   ` Andrii Nakryiko
     [not found]   ` <C02B00A0-5760-44CE-B727-90CF601A8437@fb.com>
2022-01-19 23:26     ` Andrii Nakryiko
     [not found]       ` <D753C41C-A70A-4316-8201-9F8369D1E627@fb.com>
2022-01-20  1:01         ` Andrii Nakryiko
2022-01-19 23:06 ` [PATCH bpf-next v4 2/2] perf: stop using deprecated bpf_object__next() API Christy Lee
2022-01-19 23:23   ` Song Liu
2022-01-23 17:06   ` Jiri Olsa
2022-02-02 17:00     ` Jiri Olsa [this message]
2022-02-02 17:24       ` Christy Lee
2022-02-09 16:11         ` Andrii Nakryiko
2022-02-12  7:31     ` Andrii Nakryiko
2022-01-20 22:58 ` [PATCH bpf-next v4 0/2] perf: stop using deprecated bpf APIs Andrii Nakryiko
2022-01-22 20:01   ` Arnaldo Carvalho de Melo
2022-01-22 20:38     ` Arnaldo Carvalho de Melo
2022-01-22 21:07       ` 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=Yfq4o0Op4eYvFKIp@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=andrii@kernel.org \
    --cc=bobo.shaobowang@huawei.com \
    --cc=bpf@vger.kernel.org \
    --cc=christyc.y.lee@gmail.com \
    --cc=christylee@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=wangnan0@huawei.com \
    --cc=yuehaibing@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).