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