linux-perf-users.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
Subject: Re: [PATCH bpf-next 2/2] perf: stop using deprecated bpf__object_next() API
Date: Tue, 21 Dec 2021 09:22:51 +0100	[thread overview]
Message-ID: <YcGO271nDvfMeSlK@krava> (raw)
In-Reply-To: <20211216222108.110518-3-christylee@fb.com>

On Thu, Dec 16, 2021 at 02:21:08PM -0800, Christy Lee wrote:
> bpf__object_next is deprecated, track bpf_objects directly in
> perf instead.
> 
> Signed-off-by: Christy Lee <christylee@fb.com>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  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 528aeb0ab79d..9e3988fd719a 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, so this duplicates libbpf's bpf_objects_list,
how do objects get on this list?

could you please put more comments in changelog
and share how you tested this?

thanks,
jirka

> +
> +struct bpf_perf_object *bpf_perf_object__next(struct bpf_perf_object *prev)
> +{
> +	struct bpf_perf_object *next;
> +
> +	if (!prev)
> +		next = list_first_entry(&bpf_objects_list,
> +					struct bpf_perf_object, list);
> +	else
> +		next = list_next_entry(prev, list);
> +
> +	/* Empty list is noticed here so don't need checking on entry. */
> +	if (&next->list == &bpf_objects_list)
> +		return NULL;
> +
> +	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)
> +
>  static bool libbpf_initialized;
>  
>  struct bpf_object *
> @@ -113,9 +140,10 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
>  
>  void bpf__clear(void)
>  {
> -	struct bpf_object *obj, *tmp;
> +	struct bpf_perf_object *perf_obj, *tmp;
> +	struct bpf_object *obj;
>  
> -	bpf_object__for_each_safe(obj, tmp) {
> +	bpf_perf_object__for_each(perf_obj, tmp, obj) {
>  		bpf__unprobe(obj);
>  		bpf_object__close(obj);
>  	}
> @@ -621,8 +649,12 @@ static int hook_load_preprocessor(struct bpf_program *prog)
>  	if (err)
>  		return err;
>  
> +/* temporarily disable libbpf deprecation warnings */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
>  	err = bpf_program__set_prep(prog, priv->nr_types,
>  				    preproc_gen_prologue);
> +#pragma GCC diagnostic pop
>  	return err;
>  }
>  
> @@ -776,7 +808,11 @@ int bpf__foreach_event(struct bpf_object *obj,
>  			if (priv->need_prologue) {
>  				int type = priv->type_mapping[i];
>  
> +/* temporarily disable libbpf deprecation warnings */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
>  				fd = bpf_program__nth_fd(prog, type);
> +#pragma GCC diagnostic pop
>  			} else {
>  				fd = bpf_program__fd(prog);
>  			}
> @@ -1498,10 +1534,11 @@ apply_obj_config_object(struct bpf_object *obj)
>  
>  int bpf__apply_obj_config(void)
>  {
> -	struct bpf_object *obj, *tmp;
> +	struct bpf_perf_object *perf_obj, *tmp;
> +	struct bpf_object *obj;
>  	int err;
>  
> -	bpf_object__for_each_safe(obj, tmp) {
> +	bpf_perf_object__for_each(perf_obj, tmp, obj) {
>  		err = apply_obj_config_object(obj);
>  		if (err)
>  			return err;
> @@ -1510,26 +1547,25 @@ int bpf__apply_obj_config(void)
>  	return 0;
>  }
>  
> -#define bpf__for_each_map(pos, obj, objtmp)	\
> -	bpf_object__for_each_safe(obj, objtmp)	\
> -		bpf_object__for_each_map(pos, obj)
> +#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__for_each_map_named(pos, obj, objtmp, name)	\
> -	bpf__for_each_map(pos, obj, objtmp) 		\
> -		if (bpf_map__name(pos) && 		\
> -			(strcmp(name, 			\
> -				bpf_map__name(pos)) == 0))
> +#define bpf__perf_for_each_map_named(perf_obj, tmp, obj, map, name)            \
> +	bpf__perf_for_each_map(perf_obj, tmp, obj, 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_object *obj, *tmp;
> +	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__for_each_map_named(map, obj, tmp, name) {
> +	bpf__perf_for_each_map_named(perf_obj, tmp, obj, map, name) {
>  		struct bpf_map_priv *priv = bpf_map__priv(map);
>  
>  		if (IS_ERR(priv))
> @@ -1565,7 +1601,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name)
>  		evsel = evlist__last(evlist);
>  	}
>  
> -	bpf__for_each_map_named(map, obj, tmp, name) {
> +	bpf__perf_for_each_map_named(perf_obj, tmp, obj, 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 5d1c725cea29..95262b7e936f 100644
> --- a/tools/perf/util/bpf-loader.h
> +++ b/tools/perf/util/bpf-loader.h
> @@ -53,6 +53,7 @@ typedef int (*bpf_prog_iter_callback_t)(const char *group, const char *event,
>  
>  #ifdef HAVE_LIBBPF_SUPPORT
>  struct bpf_object *bpf__prepare_load(const char *filename, bool source);
> +struct bpf_perf_object *bpf_perf_object__next(struct bpf_perf_object *prev);
>  int bpf__strerror_prepare_load(const char *filename, bool source,
>  			       int err, char *buf, size_t size);
>  
> -- 
> 2.30.2
> 


  reply	other threads:[~2021-12-21  8:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 22:21 [PATCH bpf-next 0/2] perf: stop using deprecated bpf APIs Christy Lee
2021-12-16 22:21 ` [PATCH bpf-next 1/2] perf: stop using deprecated bpf_prog_load() API Christy Lee
2021-12-16 22:21 ` [PATCH bpf-next 2/2] perf: stop using deprecated bpf__object_next() API Christy Lee
2021-12-21  8:22   ` Jiri Olsa [this message]
2021-12-21 21:58     ` Andrii Nakryiko
2021-12-22 13:44       ` Jiri Olsa
2021-12-22 22:17         ` Andrii Nakryiko
2021-12-29 19:01           ` Christy Lee
2022-01-04 14:40             ` Jiri Olsa
2022-01-05 13:49               ` Jiri Olsa
2022-01-06 17:54                 ` Christy Lee
2022-01-06 22:41                   ` Jiri Olsa
2022-01-13 15:14                   ` Jiri Olsa
2022-01-14 21:00                     ` Andrii Nakryiko
2022-01-17  9:25                       ` Jiri Olsa
2022-01-18 23:05                         ` Andrii Nakryiko
2022-01-22 20:29                         ` Arnaldo Carvalho de Melo
2022-01-06 20:25                 ` 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=YcGO271nDvfMeSlK@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=andrii@kernel.org \
    --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 \
    /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).