samples/bpf: Add xdp_stat sample program
Subsystems (4)
PATCH v4 1/1 samples/bpf: Add xdp_stat sample program
At Facebook we use tail calls to jump between our firewall filters and our L4LB. This is a program I wrote to estimate per program performance by swapping out the entries in the program array with interceptors that take measurements and then jump to the original entries.
I found the sample programs to be invaluable in understanding how to use the libbpf API (as well as the test env from the xdp-tutorial repo for testing), and want to return the favor. I am currently working on my next iteration that uses fentry/fexit to be less invasive, but I thought it was an interesting PoC of what you can do with program arrays.
v4:
- rebase
v3:
- Fixed typos in xdp_stat_kern.c
- Switch to using key_size, value_size for prog arrays
--- samples/bpf/Makefile | 3 + samples/bpf/xdp_stat | Bin 0 -> 200488 bytes samples/bpf/xdp_stat_common.h | 28 ++ samples/bpf/xdp_stat_kern.c | 192 +++++++++ samples/bpf/xdp_stat_user.c | 748 ++++++++++++++++++++++++++++++++++ 5 files changed, 971 insertions(+) create mode 100755 samples/bpf/xdp_stat create mode 100644 samples/bpf/xdp_stat_common.h create mode 100644 samples/bpf/xdp_stat_kern.c create mode 100644 samples/bpf/xdp_stat_user.c
samples/bpf/Makefile +3 -0
@@ -53,6 +53,7 @@ tprogs-y += task_fd_query tprogs-y += xdp_sample_pkts tprogs-y += ibumad tprogs-y += hbm +tprogs-y += xdp_stat # Libbpf dependencies LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
@@ -109,6 +110,7 @@ task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS) xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS) ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS) hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS) +xdp_stat-objs := xdp_stat_user.o # Tell kbuild to always build the programs always-y := $(tprogs-y)
@@ -170,6 +172,7 @@ always-y += ibumad_kern.o always-y += hbm_out_kern.o always-y += hbm_edt_kern.o always-y += xdpsock_kern.o +always-y += xdp_stat_kern.o ifeq ($(ARCH), arm) # Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux
samples/bpf/xdp_stat new file binary +0 -0
samples/bpf/xdp_stat_common.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 +* Copyright (c) 2019 Facebook +*/ + +#ifndef __XDP_STAT_COMMON_HEADER_H +#define __XDP_STAT_COMMON_HEADER_H + +/* WARNING: Must match the number of interceptors generated in +* xdp_stat_kern.c including xdp/interceptor_0. +*/ +#define MAX_INTERCEPTORS 10 + +/* prog_stats_rec contains stats specific to an intercepted BPF program. +*/ +struct prog_stats_rec { +__u64 nr_terminal_runs; +__u64 nr_chained_runs; +__u64 ns_chained_runtime; +}; + +/* interception_info_rec contains global to all interceptors on a single CPU. +*/ +struct interception_info_rec { +__u32 prev_interceptor_nr; +__u64 prev_ns_start; +}; + +#endif /* __XDP_STAT_COMMON_HEADER_H */
samples/bpf/xdp_stat_kern.c new file +192 -0
192 lines not on this page · raw message
samples/bpf/xdp_stat_user.c new file +748 -0
748 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 19 lines · Eric Sage
At Facebook we use tail calls to jump between our firewall filters and our L4LB. This is a program I wrote to estimate per program performance by swapping out the entries in the program array with interceptors that take measurements and then jump to the original entries.
I found the sample programs to be invaluable in understanding how to use the libbpf API (as well as the test env from the xdp-tutorial repo for testing), and want to return the favor. I am currently working on my next iteration that uses fentry/fexit to be less invasive, but I thought it was an interesting PoC of what you can do with program arrays.
v4:
- rebase
v3:
- Fixed typos inxdp_stat_kern.c
- Switch to usingkey_size,value_sizefor prog arrays
Quoted 5 lines
Signed-off-by Eric Sage <[email protected]>Acked-by Andrii Nakryiko <[email protected]>--- samples/bpf/Makefile | 3 + samples/bpf/xdp_stat | Bin 0 -> 200488 bytes
Add xdp_stat to .gitignore?
Quoted 9 lines
samples/bpf/xdp_stat_common.h | 28 ++ samples/bpf/xdp_stat_kern.c | 192 +++++++++ samples/bpf/xdp_stat_user.c | 748 ++++++++++++++++++++++++++++++++++ 5 files changed, 971 insertions(+) create mode 100755 samples/bpf/xdp_stat create mode 100644 samples/bpf/xdp_stat_common.h create mode 100644 samples/bpf/xdp_stat_kern.c create mode 100644 samples/bpf/xdp_stat_user.c
On Sun, 29 Mar 2020 16:16:30 -0700
Eric Sage <[email protected]> wrote:
[...]
Quoted 3 lines
--- samples/bpf/Makefile | 3 + samples/bpf/xdp_stat | Bin 0 -> 200488 bytes
No binary files please.
Quoted 9 lines
samples/bpf/xdp_stat_common.h | 28 ++ samples/bpf/xdp_stat_kern.c | 192 +++++++++ samples/bpf/xdp_stat_user.c | 748 ++++++++++++++++++++++++++++++++++ 5 files changed, 971 insertions(+) create mode 100755 samples/bpf/xdp_stat create mode 100644 samples/bpf/xdp_stat_common.h create mode 100644 samples/bpf/xdp_stat_kern.c create mode 100644 samples/bpf/xdp_stat_user.c
[...]
Quoted 8 lines
samples/bpf/xdp_stat new file binary +0
-0zu2ZL~PMtb+>YP(momu|i;0%{bN&aLgmnlru<rhnk^;=OUbjy@!{wh
qmG1as&b0b
Quoted 8 lines
z6=}DGF^74@hdd
_$fS~dW?4yvwXxhHJAY9|F;Ywy^P%*SzdN5v3i)KY&YxoY)p{1% z1(Q!D+sbCSE_}9FZ|>d%SZC*f5d7bE-_(?ZvHpCGNG#+0VtRtYq@(EJxl{*ION| ze)tNBn0ywhR=G#*XR;izS#EdCD!2QeR=L#ECS$k#O!AX7^8Z?^7@oyQF<s1u;*-BS zpTy-)*>|CFd@t)~6)fv#wU>MbyGt}BAn9(7Uf9i|JxsX7?kVm_R{gC;Yh2-<kRk^ za{lCrw_JSD`IE=>n>=x9xVB$y;l=$fzUaJ~Y3E%a``ru0C{shO9<H46_opwvV6!Ld z#dVX5&-MIzPFB@tpOJ3T!1{>8AL85WlFv${nJ@b#g~gpgSQY-i_H_F(ML!!!u>|DM zpHd``ITR#QZ>NFJL*svj&vE@T_zh{`Z=wT#hJR6-cK@5Ep6k-U{b}H2#Gkc$R2uwa z)6n@#ntFasQ_t8m@X|DJk*3|XY1;i)8vHxbj8~sD_+8TAf0u^N9%<@1FAe;qH1*t@
No binary files please.
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer