Skip to content

Commit 4e9bdcd

Browse files
committed
Adding tracing02-xdp-monitor example
In this lesson we will show how to attach to and monitor all xdp related raw tracepoints and some related info to user space stat application. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 6e5eebf commit 4e9bdcd

4 files changed

Lines changed: 1199 additions & 0 deletions

File tree

tracing02-xdp-monitor/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
3+
# Departing from the implicit _user.c scheme
4+
XDP_TARGETS := trace_prog_kern
5+
USER_TARGETS := trace_load_and_stats
6+
7+
LIBBPF_DIR = ../libbpf/src/
8+
COMMON_DIR = ../common/
9+
10+
include $(COMMON_DIR)/common.mk
11+

tracing02-xdp-monitor/README.org

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# -*- fill-column: 76; -*-
2+
#+TITLE: Tutorial: Tracing02 - monitor xdp raw tracepoints
3+
#+OPTIONS: ^:nil
4+
5+
In this lesson we will show how to attach to and monitor all
6+
xdp related raw tracepoints and some related info to user space
7+
stat application.
8+
9+
* Table of Contents :TOC:
10+
- [[#raw-tracepoint][RAW tracepoints]]
11+
- [[#todo][TODO]]
12+
- [[#assignments][Assignments]]
13+
- [[#assignment-1][Assignment 1: Monitor all xdp tracepoints]]
14+
15+
* RAW tracepoints
16+
17+
The RAW tracepoint is eBPF alternative to standard tracepoint,
18+
which allows attaching eBPF program to tracepoint without the
19+
perf layer being involved/executed.
20+
21+
The bpf library expects the raw tracepoint eBPF program to be stored
22+
in a section with following name:
23+
24+
#+begin_example sh
25+
raw_tracepoint/tracepoint/sys/tracepoint
26+
#+end_example
27+
28+
where 'sys' is the tracepoint subsystem and 'tracepoint' is
29+
the tracepoint name, which can be done with following construct:
30+
31+
#+begin_example sh
32+
SEC("raw_tracepoint/xdp/xdp_exception")
33+
int trace_xdp_exception(struct xdp_exception_ctx *ctx)
34+
#+end_example
35+
36+
The libbpf library exports interface to load and attach raw tracepoint
37+
programs, following call will load every program in the cfg->filename
38+
object as raw tracepoint programs:
39+
40+
#+begin_example sh
41+
err = bpf_prog_load(cfg->filename, BPF_PROG_TYPE_RAW_TRACEPOINT, &obj, &bpf_fd));
42+
#+end_example
43+
44+
You can then iterate through all the programs and attach
45+
every program to the raw tracepoint:
46+
47+
#+begin_example sh
48+
bpf_object__for_each_program(prog, obj) {
49+
...
50+
bpf_fd = bpf_program__fd(prog);
51+
...
52+
err = bpf_raw_tracepoint_open(tp, bpf_fd);
53+
...
54+
}
55+
#+end_example
56+
57+
for more details please check load_bpf_and_trace_attach function
58+
in trace_load_and_stats.c object.
59+
60+
* Assignments
61+
62+
** Assignment 1: Monitor all xdp tracepoints
63+
64+
#+begin_example sh
65+
$ sudo ./trace_load_and_stats
66+
XDP-event CPU:to pps drop-pps extra-info
67+
XDP_REDIRECT total 0 0 Success
68+
XDP_REDIRECT total 0 0 Error
69+
Exception 0 0 11 XDP_UNKNOWN
70+
Exception 1 0 2 XDP_UNKNOWN
71+
Exception 2 0 36 XDP_UNKNOWN
72+
Exception 3 0 29 XDP_UNKNOWN
73+
Exception 4 0 3 XDP_UNKNOWN
74+
Exception 5 0 8 XDP_UNKNOWN
75+
Exception total 0 91 XDP_UNKNOWN
76+
cpumap-kthread total 0 0 0
77+
devmap-xmit total 0 0 0.00
78+
#+end_example

0 commit comments

Comments
 (0)