Messages in this thread | | | Date | Fri, 27 Nov 2015 15:31:58 +0800 | From | "Wangnan (F)" <> | Subject | Re: [PATCH 12/16] perf tools: Support setting different slots in a BPF map separately |
| |
On 2015/11/24 21:36, Wang Nan wrote: > This patch introduces basic facilities to support config different > slots in a BPF map one by one. > > array.nr_ranges and array.ranges are introduced into 'struct > parse_events_term', where ranges is an array of indices range (start, > length) which will be configured by this config term. nr_ranges > is the size of the array. The array is passed to 'struct bpf_map_priv'. > To indicate the new type of configuration, BPF_MAP_KEY_RANGES is > added as a new key type. bpf_map_config_foreach_key() is extended to > iterate over those indices instead of all possible keys. > > Code in this commit will be enabled by following commit which enables > the indices syntax for array configuration. > > Signed-off-by: Wang Nan <wangnan0@huawei.com> > Cc: Alexei Starovoitov <ast@kernel.org> > Cc: Arnaldo Carvalho de Melo <acme@redhat.com> > Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> > Cc: Namhyung Kim <namhyung@kernel.org> > Cc: Zefan Li <lizefan@huawei.com> > Cc: pi3orama@163.com > --- > tools/perf/util/bpf-loader.c | 133 ++++++++++++++++++++++++++++++++++++++--- > tools/perf/util/bpf-loader.h | 1 + > tools/perf/util/parse-events.c | 33 +++++++++- > tools/perf/util/parse-events.h | 12 ++++ > 4 files changed, 171 insertions(+), 8 deletions(-) > > diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c > index a6e4bde..185d2cf 100644 > --- a/tools/perf/util/bpf-loader.c > +++ b/tools/perf/util/bpf-loader.c
[SNIP]
> +static int > +bpf_map_op_setkey(struct bpf_map_op *op, struct parse_events_term *term, > + const char *map_name) > +{ > + op->key_type = BPF_MAP_KEY_ALL; > + > + if (term->array.nr_ranges) { > + size_t memsz = term->array.nr_ranges * > + sizeof(op->k.array.ranges[0]); > + > + op->k.array.ranges = malloc(memsz); > + if (!op->k.array.ranges) { > + pr_debug("No enough memory to alloc indices for %s\n", > + map_name); > + return -ENOMEM; > + } > + memcpy(op->k.array.ranges, term->array.ranges, memsz);
Here can use memdup.
> + op->key_type = BPF_MAP_KEY_RANGES; > + op->k.array.nr_ranges = term->array.nr_ranges; > + } > + return 0; > +} > +
| |