Re: [RFC PATCH v1 04/37] perf util: add mmap_cpu_mask__duplicate function

From: Arnaldo Carvalho de Melo
Date: Tue Aug 31 2021 - 15:21:09 EST


Em Sat, Aug 21, 2021 at 11:19:10AM +0200, Riccardo Mancini escreveu:
> This patch adds a new function in util/mmap.c to duplicate a mmap_cpu_mask.
>
> This new function will be used in the following patches.
>
> Signed-off-by: Riccardo Mancini <rickyman7@xxxxxxxxx>
> ---
> tools/perf/util/mmap.c | 12 ++++++++++++
> tools/perf/util/mmap.h | 3 +++
> 2 files changed, 15 insertions(+)
>
> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index ab7108d22428b527..9e9a447682cc962c 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -350,3 +350,15 @@ int perf_mmap__push(struct mmap *md, void *to,
> out:
> return rc;
> }
> +
> +int mmap_cpu_mask__duplicate(struct mmap_cpu_mask *original,
> + struct mmap_cpu_mask *clone)
> +{
> + clone->nbits = original->nbits;
> + clone->bits = bitmap_alloc(original->nbits);
> + if (!clone->bits)
> + return -ENOMEM;
> +
> + memcpy(clone->bits, original->bits, MMAP_CPU_MASK_BYTES(original));
> + return 0;
> +}
> diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
> index 9d5f589f02ae70e1..b4923e587fd7749c 100644
> --- a/tools/perf/util/mmap.h
> +++ b/tools/perf/util/mmap.h
> @@ -63,4 +63,7 @@ size_t mmap__mmap_len(struct mmap *map);
>
> void mmap_cpu_mask__scnprintf(struct mmap_cpu_mask *mask, const char *tag);
>
> +int mmap_cpu_mask__duplicate(struct mmap_cpu_mask *original,
> + struct mmap_cpu_mask *clone);
> +
> #endif /*__PERF_MMAP_H */

The jargon here is class__clone():

⬢[acme@toolbox perf]$ find tools/perf -name "*.[ch]" | xargs grep __clone
tools/perf/util/bpf-loader.c:bpf_map_op__clone(struct bpf_map_op *op)
tools/perf/util/bpf-loader.c:bpf_map_priv__clone(struct bpf_map_priv *priv)
tools/perf/util/bpf-loader.c: newop = bpf_map_op__clone(pos);
tools/perf/util/bpf-loader.c: priv = bpf_map_priv__clone(tmpl_priv);
tools/perf/util/cgroup.c: evsel = evsel__clone(pos);
tools/perf/util/evsel.c: * evsel__clone - create a new evsel copied from @orig
tools/perf/util/evsel.c:struct evsel *evsel__clone(struct evsel *orig)
tools/perf/util/evsel.h: * Please check evsel__clone() to copy them properly so that
tools/perf/util/evsel.h:struct evsel *evsel__clone(struct evsel *orig);
tools/perf/util/map.h:struct map *map__clone(struct map *map);
tools/perf/util/maps.h:int maps__clone(struct thread *thread, struct maps *parent);
tools/perf/util/parse-events.c:int parse_events_term__clone(struct parse_events_term **new,
tools/perf/util/parse-events.c: ret = parse_events_term__clone(&n, term);
tools/perf/util/parse-events.h:int parse_events_term__clone(struct parse_events_term **new,
tools/perf/util/symbol.c: struct map *m = map__clone(new_map);
tools/perf/util/thread.c:static int thread__clone_maps(struct thread *thread, struct thread *parent, bool do_maps_clone)
tools/perf/util/thread.c: return do_maps_clone ? maps__clone(thread, parent->maps) : 0;
tools/perf/util/thread.c: return thread__clone_maps(thread, parent, do_maps_clone);
tools/perf/util/map.c:struct map *map__clone(struct map *from)
tools/perf/util/map.c: struct map *before = map__clone(pos);
tools/perf/util/map.c: struct map *after = map__clone(pos);
tools/perf/util/map.c:int maps__clone(struct thread *thread, struct maps *parent)
tools/perf/util/map.c: struct map *new = map__clone(map);
tools/perf/util/pmu.c: ret = parse_events_term__clone(&cloned, term);
⬢[acme@toolbox perf]$ find tools/perf -name "*.[ch]" | xargs grep __duplicate
⬢[acme@toolbox perf]$