Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754962AbbLKMrI (ORCPT ); Fri, 11 Dec 2015 07:47:08 -0500 Received: from mail.kernel.org ([198.145.29.136]:48254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751273AbbLKMrH (ORCPT ); Fri, 11 Dec 2015 07:47:07 -0500 Date: Fri, 11 Dec 2015 09:47:02 -0300 From: Arnaldo Carvalho de Melo To: pi3orama Cc: Wang Nan , namhyung@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, lizefan@huawei.com, Alexei Starovoitov , Masami Hiramatsu Subject: Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for BPF maps Message-ID: <20151211124702.GB6843@kernel.org> References: <1449541544-67621-1-git-send-email-wangnan0@huawei.com> <1449541544-67621-10-git-send-email-wangnan0@huawei.com> <20151211121145.GP17996@kernel.org> <20151211121521.GQ17996@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3461 Lines: 95 Em Fri, Dec 11, 2015 at 08:39:35PM +0800, pi3orama escreveu: > > > 发自我的 iPhone > > > 在 2015年12月11日,下午8:15,Arnaldo Carvalho de Melo 写道: > > > > Em Fri, Dec 11, 2015 at 09:11:45AM -0300, Arnaldo Carvalho de Melo escreveu: > >> Em Tue, Dec 08, 2015 at 02:25:37AM +0000, Wang Nan escreveu: > >>> This patch introduce a new syntax to perf event parser: > >>> > >>> # perf record -e bpf_file.c/maps.mymap.value[0,3...5,7]=1234/ ... > >> > >> Is the above example valid? Wouldn't this be "maps:mymap.value" ? > >> > >>> > >>> By utilizing the basic facilities in bpf-loader.c which allow setting > >>> different slots in a BPF map separately, the newly introduced syntax > >>> allows perf to control specific elements in a BPF map. > >>> > >>> Test result: > >>> > >>> # cat ./test_bpf_map_3.c > >>> /************************ BEGIN **************************/ > >>> #define SEC(NAME) __attribute__((section(NAME), used)) > >>> enum bpf_map_type { > >>> BPF_MAP_TYPE_ARRAY = 2, > >>> }; > >>> struct bpf_map_def { > >>> unsigned int type; > >>> unsigned int key_size; > >>> unsigned int value_size; > >>> unsigned int max_entries; > >>> }; > >>> static void *(*map_lookup_elem)(struct bpf_map_def *, void *) = > >>> (void *)1; > >>> static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) = > >>> (void *)6; > >> > >> Can you explain the above a bit more? What are the magic 1 and 6 values? > > > > So, from another patch: > > > > static u64 (*bpf_ktime_get_ns)(void) = > > (void *)5; > > static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) = > > (void *)6; > > static int (*bpf_get_smp_processor_id)(void) = > > (void *)8; > > static int (*bpf_perf_event_output)(void *, struct bpf_map_def *, int, > > void *, unsigned long) = > > (void *)23; > > > > Where can I get this magical mistery table? Could this be hidden away in > > some .h file automagically included in bpf scriptlets so that n00bies > > like me don't have to be wtf'ing? > > > > They are function numbers defined in bpf.h and bpf-common.h, but they are Linux > headers. Directly include them causes many error for llvm. Also, the function > prototypes are BPF specific and can't included in Linux source. We should have > a place holds those indices and prototypes together. Sure, just please don't assume whoever is reading your patches has this background, provide comments above such places, so that reviewing gets facilitated. I eventually figured this is some sort of trampoline to access kernel functions: /* integer value in 'imm' field of BPF_CALL instruction selects which * helper function eBPF program intends to call */ enum bpf_func_id { BPF_FUNC_unspec, BPF_FUNC_map_lookup_elem, /* void *map_lookup_elem(&map, &key) */ BPF_FUNC_map_update_elem, /* int map_update_elem(&map, &key, &value, flags) */ BPF_FUNC_map_delete_elem, /* int map_delete_elem(&map, &key) */ BPF_FUNC_probe_read, /* int bpf_probe_read(void *dst, int size, void *src) */ But if you had just: /* * See enum_bpf_func_id in ./include/uapi/linux/bpf.h */ That would've helped. - Arnaldo -- 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/