BPF Trace
BPF Trace
High level tracing language
eBPF based
static and dynamic tracing
kernel and user namespace
Tracing
- Ability to interrupt flow of running program. at configurable location.
- execution of code to obtain some data
- For visibility
It affects performance.
Perf sample all data and then you filter. it is different.
Static Tracing
hard coded instrumentation points in code
Dynamic Tracing
Can instrument any software event. E.g. function call, return
live modification of instruction set
it needs symbol table
E.g. gdb
Probe Providers
They provides probe point. At probe point we can execute some code.
1. BEGIN/END : built-in events. BEGIN to initialize data structure END to aggregate counters.
2. hardware: processor level events
3. interval: built-in timers
4. kprobe / kretprobe : Kernel function tracing
5. profile: timed sampling
6. rawtracepoint: Kernel static trace point with raw argument
7. software: kernel software event
8. tracepoint: kernel static tracepoint
9. uprobe / uretprobe : user-level function start / return
sudo bpftrace -l | wc -l
153620
Most of them are kernel level. static trace points.
e.g. 1 openat syscall using tracepoint:syscall:sys_enter_openat
Here
(1) "comm" is built-in variable having process name
(2) "args" is struct containing all tracepoint arguments
for more details about "args" struct, use below command
bpftrace -vl tracepoint:syscall:sys_enter_openat
To execute
sudo bpftrace -e 'tracepoint:syscall:sys_enter_openat {printf();}
sudo bpftrace <file name>
It has buil-in histagram
in the command we can specify filter
/pid == 32184/
/comm == "<name of process>"/
Reference
github.com/bpftrace
https://media.ccc.de/v/osmodevcon2024-204-introduction-to-xdp-ebpf-and-afxdp
eBPF, XDP and AF_XDP
eBPF, XDP and AF_XDP are Kernel Feature for high speed packet processing
* [eBPF](https://ebpf.io/what-is-ebpf/) (extended Berkeley Packet Filter) is a kind of virtual machine that runs sandboxed programs inside the Linux kernel.
- TCP Dump uses BPF.
- Not tied specifically to networking
- in kernel verifiers. No endless loop. no access to invalid memory.
Instructions
- RFC by IETF defines instruction set
- VM + limited instruction set
- JIT
Program Types
1. XDP
2. socket filtering, kprobe, tc schedular (action, classifiers), performance events
3. tracing: function entry, function exit, modify return value
4. cgroups, light weight tunnels
5. TCP stream parsing ( kernel assisted TLS and KCM = kernel connection machine. IP multiplex)
$ bpftool prog
$ clang target bpf
eBPF maps
1. K-v store
2. hash, array, radix-tree, bloom filter
3. _per_cpu variants for multi-processor efficiency
Use cases
1. device driver for DPDK, VPP and related user plane frameworks
2. load balancer (e.g. dnsdist)
3. software switch (e.g. vSwitch)
4. DoS protection filter
5. Intrusion Detection Systems (e.g. Suricata)
6. eupf = eBPF + AF_XDP for accelerated 5G UPF
* [XDP](https://docs.cilium.io/en/latest/bpf/progtypes/#xdp) (eXpress Data Path) is a framework for eBPF that enables high-performance programmable packet processing in the Linux kernel* [AF_XDP](https://www.kernel.org/doc/html/next/networking/af_xdp.html) is an *address family* that is optimized for high-performance packet processing. It allows in-kernel XDP eBPF programs to efficiently pass packets to userspace via memory-mapped ring buffers.