linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v4 0/3] Make eBPF programs output data to perf event
@ 2015-07-10 10:03 He Kuang
  2015-07-10 10:03 ` [RFC PATCH v4 1/3] tracing/events: Fix wrong sample output by storing array length instead of size He Kuang
                   ` (2 more replies)
  0 siblings, 3 replies; 53+ messages in thread
From: He Kuang @ 2015-07-10 10:03 UTC (permalink / raw)
  To: rostedt, ast, masami.hiramatsu.pt, acme, a.p.zijlstra, mingo,
	namhyung, jolsa
  Cc: wangnan0, pi3orama, linux-kernel, hekuang

Hi,

Previous discussion url(patch v3):
http://thread.gmane.org/gmane.linux.kernel/1990197/focus=1991022

We found that creating new trace event for bpf subsystem is more
simple than adding new ftrace:bpf entry, the only thing we should do
for outputing bpf sample events is to call a predefined trace event
function. Then it is easy to extend new output formats and not
restricted to one fixed format like ftrace:function.

By using trace events, we can also benifit from the dynamic array
field type for outputing results by number of items we filled in, and
achieve the purpose of standardization of output format. Function for
getting number of items in dynamic array is added to libtraceevent and
a improper result of macro __get_dynamic_array_len is corrected.

eBPF sample code, tests outputing multiple items:

  SEC("generic_perform_write=generic_perform_write")
  int NODE_generic_perform_write(struct pt_regs *ctx)
  {
         char fmt[] = "generic_perform_write last=%lld, cur=%lld, del=%lld\n";
         u64 cur_time, del_time, result[3] = {0};
         int ind =0;
         struct time_table *last = bpf_map_lookup_elem(&global_time_table, &ind);
         struct time_table output;

         if (!last)
                 return 0;
  
         cur_time = bpf_ktime_get_ns();
  
         if (!last->last_time)
                 del_time = 0;
         else
                 del_time = cur_time - last->last_time;
  
         /* For debug */
         bpf_trace_printk(fmt, sizeof(fmt), last->last_time, cur_time, del_time);
         result[0] = last->last_time;
  
         /* Table update */
         output.last_time = cur_time;
         bpf_map_update_elem(&global_time_table, &ind, &output, BPF_ANY);
  
         /* This is a casual condition to show the funciton */
         if (del_time < 1000)
                 return 0;
  
         result[1] = cur_time;
         result[2] = del_time;
         bpf_output_trace_data(result, sizeof(result));
  
         return 0;
  }

Record bpf events:

  $ perf record -e bpf:bpf_output_data -e sample.o --
    dd if=/dev/zero of=test bs=4k count=3

Results in /sys/kernel/debug/tracing/trace:

  dd-984   [000] d...    60.894097: : generic_perform_write
           last=60560862578, cur=60654629075, del=93766497
  dd-984   [000] d...    60.896957: : generic_perform_write
           last=60654629075, cur=60657510709, del=2881634
  dd-984   [000] d...    60.897276: : generic_perform_write
           last=60657510709, cur=60657829953, del=319244
           
Results showed in perf-script:

  dd   984 [000]    60.655211: bpf:bpf_output_data: 60560862578 60654629075 93766497
  dd   984 [000]    60.657552: bpf:bpf_output_data: 60654629075 60657510709 2881634
  dd   984 [000]    60.657898: bpf:bpf_output_data: 60657510709 60657829953 319244  

Thank you.

He Kuang (3):
  tracing/events: Fix wrong sample output by storing array length
    instead of size
  tools lib traceevent: Add function to get dynamic arrays length
  bpf: Introduce function for outputing data to perf event

 include/trace/events/bpf.h                         | 30 +++++++++++++
 include/trace/trace_events.h                       |  5 ++-
 include/uapi/linux/bpf.h                           |  7 +++
 kernel/trace/bpf_trace.c                           | 23 ++++++++++
 samples/bpf/bpf_helpers.h                          |  2 +
 tools/lib/traceevent/event-parse.c                 | 52 ++++++++++++++++++++++
 tools/lib/traceevent/event-parse.h                 |  1 +
 .../util/scripting-engines/trace-event-python.c    |  1 +
 8 files changed, 119 insertions(+), 2 deletions(-)
 create mode 100644 include/trace/events/bpf.h

-- 
1.8.5.2


^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2015-08-13  6:24 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 10:03 [RFC PATCH v4 0/3] Make eBPF programs output data to perf event He Kuang
2015-07-10 10:03 ` [RFC PATCH v4 1/3] tracing/events: Fix wrong sample output by storing array length instead of size He Kuang
2015-07-17 14:32   ` Steven Rostedt
2015-07-17 17:24     ` Sara Rostedt
2015-07-17 18:13     ` Steven Rostedt
2015-07-23 19:36       ` Alex Bennée
2015-07-10 10:03 ` [RFC PATCH v4 2/3] tools lib traceevent: Add function to get dynamic arrays length He Kuang
2015-07-10 10:03 ` [RFC PATCH v4 3/3] bpf: Introduce function for outputing data to perf event He Kuang
2015-07-10 22:10   ` Alexei Starovoitov
2015-07-13  4:36     ` He Kuang
2015-07-13 13:52       ` Namhyung Kim
2015-07-13 14:01         ` pi3orama
2015-07-13 14:09           ` Namhyung Kim
2015-07-13 14:29             ` pi3orama
2015-07-14  1:43               ` Alexei Starovoitov
2015-07-14 11:54                 ` He Kuang
2015-07-17  4:11                   ` Alexei Starovoitov
2015-07-17  4:14                     ` Wangnan (F)
2015-07-17  4:27                       ` Alexei Starovoitov
2015-07-23 11:54                         ` He Kuang
2015-07-23 20:49                           ` llvm bpf debug info. " Alexei Starovoitov
2015-07-24  3:20                             ` Alexei Starovoitov
2015-07-24  4:16                               ` He Kuang
2015-07-25 10:04                                 ` He Kuang
2015-07-28  2:18                                   ` Alexei Starovoitov
2015-07-29  9:38                                     ` He Kuang
2015-07-29 17:13                                       ` Alexei Starovoitov
2015-07-29 20:00                                         ` pi3orama
2015-07-29 22:20                                           ` Alexei Starovoitov
2015-07-31 10:18                                         ` Wangnan (F)
2015-07-31 10:20                                           ` [LLVM PATCH] BPF: add FRAMEADDR support Wang Nan
2015-07-31 10:21                                           ` [LLVM CLANG PATCH] BPF: add __builtin_bpf_typeid() Wang Nan
2015-07-31 10:48                                           ` llvm bpf debug info. Re: [RFC PATCH v4 3/3] bpf: Introduce function for outputing data to perf event pi3orama
2015-08-03 19:44                                           ` Alexei Starovoitov
2015-08-04  9:01                                             ` Cc llvmdev: " Wangnan (F)
2015-08-05  1:58                                               ` Wangnan (F)
2015-08-05  2:05                                                 ` Wangnan (F)
2015-08-05  6:51                                                   ` [LLVMdev] " Wangnan (F)
2015-08-05  7:11                                                     ` Alexei Starovoitov
2015-08-05  8:28                                                       ` Wangnan (F)
2015-08-06  3:22                                                         ` [llvm-dev] " Alexei Starovoitov
2015-08-06  4:35                                                           ` Wangnan (F)
2015-08-06  6:55                                                             ` Alexei Starovoitov
2015-08-12  2:34                                             ` Wangnan (F)
2015-08-12  4:57                                               ` [llvm-dev] " Alexei Starovoitov
2015-08-12  5:28                                                 ` Wangnan (F)
2015-08-12 13:15                                                   ` Brenden Blanco
2015-08-13  6:24                                                     ` Wangnan (F)
2015-08-05  8:59                                         ` [LLVMdev] Cc llvmdev: " He Kuang
2015-08-06  3:41                                           ` [llvm-dev] " Alexei Starovoitov
2015-08-06  4:31                                             ` Wangnan (F)
2015-08-06  6:50                                               ` Alexei Starovoitov
2015-07-13  8:29   ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).