Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1289543

Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for BPF maps

From pi3orama <pi3orama@163.com>
Newsgroups linux.kernel
Subject Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for BPF maps
Date 2015-12-11 14:00 +0100
Message-ID <qEvsL-4sJ-35@gated-at.bofh.it> (permalink)
References (1 earlier) <qDgcq-4Bz-31@gated-at.bofh.it> <qEuQ2-486-11@gated-at.bofh.it> <qEuQ3-486-31@gated-at.bofh.it> <qEvj4-4o4-11@gated-at.bofh.it> <qEvj4-4o4-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



发自我的 iPhone

> 在 2015年12月11日,下午8:47,Arnaldo Carvalho de Melo <acme@kernel.org> 写道:
> 
> Em Fri, Dec 11, 2015 at 08:39:35PM +0800, pi3orama escreveu:
>> 
>> 
>> 发自我的 iPhone
>> 
>>> 在 2015年12月11日,下午8:15,Arnaldo Carvalho de Melo <acme@kernel.org> 写道:
>>> 
>>> 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.
> 

Thank you, but I think this is a good chance to setup the policy about the header
files for BPF. I suggested to put BPF specific headers into Linux kernel include dir,
but we must find a way to avoid Linux includes them. Another useful structure is
pt_regs, however which is not as important as before because we have prologue
now.

I'd like to have a try next week.

Thank you.

> - 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/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/16] perf tools: BPF related update and other improvements Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:30 +0100
  [PATCH v4 01/16] tools lib bpf: Check return value of strdup when reading map names Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:30 +0100
    [tip:perf/core] tools lib bpf:   Check return value of strdup when reading map names tip-bot for Wang Nan <tipbot@zytor.com> - 2015-12-14 09:40 +0100
  [PATCH v4 07/16] perf tools: Enable passing event to BPF object Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:30 +0100
  [PATCH v4 12/16] perf data: Support converting data from bpf_perf_event_output() Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:30 +0100
  [PATCH v4 14/16] perf record: Support custom vmlinux path Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:30 +0100
  [PATCH v4 09/16] perf tools: Enable indices setting syntax for BPF maps Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:30 +0100
    Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-11 13:20 +0100
      Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-11 13:20 +0100
        Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-11 13:50 +0100
          Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for BPF maps pi3orama <pi3orama@163.com> - 2015-12-11 14:00 +0100
        Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for BPF maps pi3orama <pi3orama@163.com> - 2015-12-11 13:50 +0100
          Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-12-11 19:30 +0100
            Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps "Wangnan (F)" <wangnan0@huawei.com> - 2015-12-14 04:30 +0100
              Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-12-14 05:30 +0100
                Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps "Wangnan (F)" <wangnan0@huawei.com> - 2015-12-14 05:50 +0100
                Re: [PATCH v4 09/16] perf tools: Enable indices setting syntax for  BPF maps Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2015-12-14 07:00 +0100
  [PATCH v4 13/16] perf tools: Always give options even it not compiled Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:30 +0100
    Re: [PATCH v4 13/16] perf tools: Always give options even it not  compiled Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-11 13:50 +0100
  [PATCH v4 15/16] perf script: Add support for PERF_TYPE_BREAKPOINT Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:40 +0100
    [tip:perf/core] perf script: Add support for PERF_TYPE_BREAKPOINT tip-bot for Wang Nan <tipbot@zytor.com> - 2015-12-14 09:40 +0100
  [PATCH v4 06/16] perf tools: Support perf event alias name Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:40 +0100
    Re: [PATCH v4 06/16] perf tools: Support perf event alias name Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-12-11 13:10 +0100
      Re: [PATCH v4 06/16] perf tools: Support perf event alias name pi3orama <pi3orama@163.com> - 2015-12-11 13:20 +0100
  [PATCH v4 02/16] tools lib bpf: Fetch map names from correct strtab Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:40 +0100
    [tip:perf/core] tools lib bpf:   Fetch map names from correct strtab tip-bot for Wang Nan <tipbot@zytor.com> - 2015-12-14 09:40 +0100
  [PATCH v4 05/16] perf record: Apply config to BPF objects before recording Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:40 +0100
  [PATCH v4 04/16] perf tools: Enable BPF object configure syntax Wang Nan <wangnan0@huawei.com> - 2015-12-08 03:40 +0100

csiph-web