Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162755AbbKTN3K (ORCPT ); Fri, 20 Nov 2015 08:29:10 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:14856 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162687AbbKTN3J (ORCPT ); Fri, 20 Nov 2015 08:29:09 -0500 Message-ID: <564F1F50.9000807@huawei.com> Date: Fri, 20 Nov 2015 21:25:36 +0800 From: "Wangnan (F)" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: , , CC: , , , , , , , , , , , , Arnaldo Carvalho de Melo Subject: Re: [RFC PATCH 5/7] perf tools: Support setting different slots in a BPF map separately References: <1445078910-73699-1-git-send-email-wangnan0@huawei.com> <1445078910-73699-6-git-send-email-wangnan0@huawei.com> In-Reply-To: <1445078910-73699-6-git-send-email-wangnan0@huawei.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.66.109] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.564F1F5D.025A,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 93984bb842b88adcd9e8cab17c54b7ef Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3687 Lines: 110 On 2015/10/17 18:48, Wang Nan wrote: > This patch introduces basic facilities to support config different > slots in a BPF map one by one. > > nr_indics and indics are introduced into 'struct parse_events_term', > where indics is an array of indics which will be configured by this > config term, nr_indics is the size of the array. The array is passed > to 'struct bpf_map_priv'. To indicate the new type of configuration, > BPF_MAP_PRIV_KEY_INDICS is added as a new key type. > bpf_map_config_foreach_key() is extended to iterate over those indics > instead of all possible keys. > > Signed-off-by: Wang Nan > Cc: Arnaldo Carvalho de Melo > Cc: Alexei Starovoitov > Cc: Brendan Gregg > Cc: Daniel Borkmann > Cc: David Ahern > Cc: He Kuang > Cc: Jiri Olsa > Cc: Kaixu Xia > Cc: Masami Hiramatsu > Cc: Namhyung Kim > Cc: Paul Mackerras > Cc: Peter Zijlstra > Cc: Zefan Li > Cc: pi3orama@163.com > --- > tools/perf/util/bpf-loader.c | 68 +++++++++++++++++++++++++++++++++++++++++- > tools/perf/util/parse-events.c | 4 ++- > tools/perf/util/parse-events.h | 2 ++ > 3 files changed, 72 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c > index 15cf27a..023fc12 100644 > --- a/tools/perf/util/bpf-loader.c > +++ b/tools/perf/util/bpf-loader.c > @@ -638,6 +638,7 @@ int bpf__foreach_tev(struct bpf_object *obj, > > enum bpf_map_priv_key_type { > BPF_MAP_PRIV_KEY_ALL, > + BPF_MAP_PRIV_KEY_INDICS, > }; > > enum bpf_map_priv_value_type { > @@ -647,6 +648,12 @@ enum bpf_map_priv_value_type { > struct bpf_map_priv { > struct { > enum bpf_map_priv_key_type type; > + union { > + struct { > + size_t nr_indics; > + u64 *indics; > + } indics; > + }; > } key; > > struct { > @@ -663,6 +670,8 @@ bpf_map_priv__clear(struct bpf_map *map __maybe_unused, > { > struct bpf_map_priv *priv = _priv; > > + if (priv->key.type == BPF_MAP_PRIV_KEY_INDICS) > + zfree(&priv->key.indics.indics); > free(priv); > } > > @@ -718,6 +727,20 @@ bpf_map_config_foreach_key(struct bpf_map *map, > } > } > return 0; > + case BPF_MAP_PRIV_KEY_INDICS: > + for (i = 0; i < priv->key.indics.nr_indics; i++) { > + u64 _idx = priv->key.indics.indics[i]; > + unsigned int idx = (unsigned int)(_idx); > + > + err = (*func)(name, map_fd, &def, > + priv, &idx, arg); > + if (err) { > + pr_debug("ERROR: failed to insert value to %s[%u]\n", > + name, idx); > + return err; > + } > + } This for-loop has a potential problem that, if perf's user want to set a very big array using indices, for example: # perf record -e mybpf.c/maps:mymap:values[1,2,3,10-100000,200000-400000]=3/ mybpf.c/maps:mymap:values[100000-200000]=3/ ... Perf would alloc nearly 300000 slots for indices array, consume too much memory. I will fix this problem by reinterprete indices array, makes negative value represent range start and use next slot to store range size. For example, the above perf cmdline can be converted to: {1,2,3,-10, 99991,-200000,200001} and {-100000,100001}. Thank you. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/