• Home
Name Date Size #Lines LOC

..--

.gitignoreD08-May-2024704 5554

MakefileD08-May-202410.8 KiB330275

Makefile.targetD08-May-20242.5 KiB7633

README.rstD08-May-20243.1 KiB10672

asm_goto_workaround.hD08-May-2024725 2913

bpf_insn.hD08-May-20245.4 KiB218157

bpf_load.cD08-May-202416 KiB668534

bpf_load.hD08-May-20241.5 KiB5832

cookie_uid_helper_example.cD08-May-20249.2 KiB324236

cpustat_kern.cD08-May-20247 KiB282141

cpustat_user.cD08-May-20245.7 KiB253180

do_hbm_test.shD08-May-202412.1 KiB443397

fds_example.cD08-May-20244.2 KiB194163

hash_func01.hD08-May-20241.3 KiB5639

hbm.cD08-May-202413.2 KiB501404

hbm.hD08-May-20241.2 KiB3926

hbm_edt_kern.cD08-May-20245.3 KiB16984

hbm_kern.hD08-May-20245.7 KiB218184

hbm_out_kern.cD08-May-20245.5 KiB18094

ibumad_kern.cD08-May-20243 KiB139100

ibumad_user.cD08-May-20242.5 KiB12391

lathist_kern.cD08-May-20242.1 KiB10068

lathist_user.cD08-May-20242.6 KiB131101

lwt_len_hist.shD08-May-20241 KiB4130

lwt_len_hist_kern.cD08-May-20241.9 KiB8359

lwt_len_hist_user.cD08-May-20241.6 KiB7860

map_perf_test_kern.cD08-May-20246.5 KiB292239

map_perf_test_user.cD08-May-202411.6 KiB508409

offwaketime_kern.cD08-May-20243.8 KiB158124

offwaketime_user.cD08-May-20243.3 KiB161131

parse_ldabs.cD08-May-20241.2 KiB4433

parse_simple.cD08-May-20241.3 KiB5036

parse_varlen.cD08-May-20243.4 KiB151122

run_cookie_uid_helper_example.shD08-May-2024341 1611

sampleip_kern.cD08-May-2024942 4027

sampleip_user.cD08-May-20244.8 KiB228180

sock_example.cD08-May-20242.9 KiB10774

sock_example.hD08-May-2024814 3630

sock_flags_kern.cD08-May-20241.2 KiB5034

sockex1_kern.cD08-May-2024661 3125

sockex1_user.cD08-May-20241.1 KiB5540

sockex2_kern.cD08-May-20244.8 KiB224190

sockex2_user.cD08-May-20241.2 KiB5846

sockex3_kern.cD08-May-20246.2 KiB294227

sockex3_user.cD08-May-20242.5 KiB10787

spintest_kern.cD08-May-20242.1 KiB7056

spintest_user.cD08-May-20242.2 KiB10084

syscall_nrs.cD08-May-2024337 2015

syscall_tp_kern.cD08-May-20241.4 KiB7460

syscall_tp_user.cD08-May-20243.2 KiB139107

task_fd_query_kern.cD08-May-2024410 2016

task_fd_query_user.cD08-May-202410.5 KiB384325

tc_l2_redirect.shD08-May-20244.9 KiB175135

tc_l2_redirect_kern.cD08-May-20246 KiB238182

tc_l2_redirect_user.cD08-May-20241.3 KiB7156

tcbpf1_kern.cD08-May-20242.6 KiB9276

tcp_basertt_kern.cD08-May-20241.7 KiB7249

tcp_bpf.readmeD08-May-20241.1 KiB2921

tcp_bufs_kern.cD08-May-20242.1 KiB8252

tcp_clamp_kern.cD08-May-20242.7 KiB9868

tcp_cong_kern.cD08-May-20241.9 KiB7953

tcp_dumpstats_kern.cD08-May-20241.3 KiB6951

tcp_iw_kern.cD08-May-20242.2 KiB8455

tcp_rwnd_kern.cD08-May-20241.7 KiB6536

tcp_synrto_kern.cD08-May-20241.7 KiB6536

tcp_tos_reflect_kern.cD08-May-20241.8 KiB8167

test_cgrp2_array_pin.cD08-May-20242.1 KiB10791

test_cgrp2_attach.cD08-May-20244.6 KiB173126

test_cgrp2_sock.cD08-May-20246.2 KiB291224

test_cgrp2_sock.shD08-May-20242.9 KiB13686

test_cgrp2_sock2.cD08-May-20241.4 KiB6947

test_cgrp2_sock2.shD08-May-20241.5 KiB8665

test_cgrp2_tc.shD08-May-20244.2 KiB186158

test_cgrp2_tc_kern.cD08-May-20241.8 KiB7155

test_cls_bpf.shD08-May-2024915 3931

test_current_task_under_cgroup_kern.cD08-May-20241.1 KiB4530

test_current_task_under_cgroup_user.cD08-May-20242.4 KiB11481

test_ipip.shD08-May-20245.6 KiB180147

test_lru_dist.cD08-May-202412 KiB541421

test_lwt_bpf.cD08-May-20246 KiB254194

test_lwt_bpf.shD08-May-20249 KiB401348

test_map_in_map_kern.cD08-May-20243.9 KiB177131

test_map_in_map_user.cD08-May-20244.4 KiB174136

test_overhead_kprobe_kern.cD08-May-20241.3 KiB4936

test_overhead_raw_tp_kern.cD08-May-2024361 1813

test_overhead_tp_kern.cD08-May-2024832 3726

test_overhead_user.cD08-May-20243.6 KiB183157

test_override_return.shD08-May-2024276 1714

test_probe_write_user_kern.cD08-May-20241.8 KiB5736

test_probe_write_user_user.cD08-May-20243.3 KiB10985

trace_common.hD08-May-2024286 1410

trace_event_kern.cD08-May-20242.3 KiB8163

trace_event_user.cD08-May-20247.9 KiB355290

trace_output_kern.cD08-May-2024660 3225

trace_output_user.cD08-May-20242.3 KiB10887

tracex1_kern.cD08-May-20241.8 KiB5531

tracex1_user.cD08-May-20241.1 KiB5140

tracex2_kern.cD08-May-20242.3 KiB10378

tracex2_user.cD08-May-20244.2 KiB194159

tracex3_kern.cD08-May-20242.1 KiB9159

tracex3_user.cD08-May-20243.8 KiB191162

tracex4_kern.cD08-May-20241.2 KiB5637

tracex4_user.cD08-May-20242.2 KiB10482

tracex5_kern.cD08-May-20242.2 KiB9470

tracex5_user.cD08-May-20242.4 KiB10280

tracex6_kern.cD08-May-20241.9 KiB8363

tracex6_user.cD08-May-20245.6 KiB227191

tracex7_kern.cD08-May-2024339 1713

tracex7_user.cD08-May-20241.2 KiB5746

xdp1_kern.cD08-May-20242.1 KiB9472

xdp1_user.cD08-May-20243.4 KiB168136

xdp2_kern.cD08-May-20242.4 KiB11590

xdp2skb_meta.shD08-May-20244.5 KiB221168

xdp2skb_meta_kern.cD08-May-20243 KiB10636

xdp_adjust_tail_kern.cD08-May-20243.8 KiB156120

xdp_adjust_tail_user.cD08-May-20244.7 KiB199159

xdp_fwd_kern.cD08-May-20244.5 KiB15998

xdp_fwd_user.cD08-May-20243.8 KiB171129

xdp_monitor_kern.cD08-May-20246.6 KiB258182

xdp_monitor_user.cD08-May-202418.6 KiB793632

xdp_redirect_cpu_kern.cD08-May-202417.2 KiB731549

xdp_redirect_cpu_user.cD08-May-202424 KiB984806

xdp_redirect_kern.cD08-May-20242.1 KiB9164

xdp_redirect_map_kern.cD08-May-20242.2 KiB9362

xdp_redirect_map_user.cD08-May-20245.4 KiB223182

xdp_redirect_user.cD08-May-20245.4 KiB224182

xdp_router_ipv4_kern.cD08-May-20244.4 KiB187151

xdp_router_ipv4_user.cD08-May-202418.4 KiB742663

xdp_rxq_info_kern.cD08-May-20243.2 KiB14194

xdp_rxq_info_user.cD08-May-202414 KiB606502

xdp_sample_pkts_kern.cD08-May-20241.5 KiB5836

xdp_sample_pkts_user.cD08-May-20244.1 KiB203171

xdp_tx_iptunnel_common.hD08-May-2024485 3526

xdp_tx_iptunnel_kern.cD08-May-20245.6 KiB238180

xdp_tx_iptunnel_user.cD08-May-20247.5 KiB315268

xdpsock.hD08-May-2024167 124

xdpsock_kern.cD08-May-2024593 2515

xdpsock_user.cD08-May-202438.3 KiB1,5511,263

xsk_fwd.cD08-May-202425.1 KiB1,086768

README.rst

1eBPF sample programs
2====================
3
4This directory contains a test stubs, verifier test-suite and examples
5for using eBPF. The examples use libbpf from tools/lib/bpf.
6
7Build dependencies
8==================
9
10Compiling requires having installed:
11 * clang >= version 3.4.0
12 * llvm >= version 3.7.1
13
14Note that LLVM's tool 'llc' must support target 'bpf', list version
15and supported targets with command: ``llc --version``
16
17Clean and configuration
18-----------------------
19
20It can be needed to clean tools, samples or kernel before trying new arch or
21after some changes (on demand)::
22
23 make -C tools clean
24 make -C samples/bpf clean
25 make clean
26
27Configure kernel, defconfig for instance::
28
29 make defconfig
30
31Kernel headers
32--------------
33
34There are usually dependencies to header files of the current kernel.
35To avoid installing devel kernel headers system wide, as a normal
36user, simply call::
37
38 make headers_install
39
40This will creates a local "usr/include" directory in the git/build top
41level directory, that the make system automatically pickup first.
42
43Compiling
44=========
45
46For building the BPF samples, issue the below command from the kernel
47top level directory::
48
49 make M=samples/bpf
50
51It is also possible to call make from this directory.  This will just
52hide the invocation of make as above.
53
54Manually compiling LLVM with 'bpf' support
55------------------------------------------
56
57Since version 3.7.0, LLVM adds a proper LLVM backend target for the
58BPF bytecode architecture.
59
60By default llvm will build all non-experimental backends including bpf.
61To generate a smaller llc binary one can use::
62
63 -DLLVM_TARGETS_TO_BUILD="BPF"
64
65Quick sniplet for manually compiling LLVM and clang
66(build dependencies are cmake and gcc-c++)::
67
68 $ git clone http://llvm.org/git/llvm.git
69 $ cd llvm/tools
70 $ git clone --depth 1 http://llvm.org/git/clang.git
71 $ cd ..; mkdir build; cd build
72 $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86"
73 $ make -j $(getconf _NPROCESSORS_ONLN)
74
75It is also possible to point make to the newly compiled 'llc' or
76'clang' command via redefining LLC or CLANG on the make command line::
77
78 make M=samples/bpf LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
79
80Cross compiling samples
81-----------------------
82In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
83environment variables before calling make. But do this before clean,
84cofiguration and header install steps described above. This will direct make to
85build samples for the cross target::
86
87 export ARCH=arm64
88 export CROSS_COMPILE="aarch64-linux-gnu-"
89
90Headers can be also installed on RFS of target board if need to keep them in
91sync (not necessarily and it creates a local "usr/include" directory also)::
92
93 make INSTALL_HDR_PATH=~/some_sysroot/usr headers_install
94
95Pointing LLC and CLANG is not necessarily if it's installed on HOST and have
96in its targets appropriate arm64 arch (usually it has several arches).
97Build samples::
98
99 make M=samples/bpf
100
101Or build samples with SYSROOT if some header or library is absent in toolchain,
102say libelf, providing address to file system containing headers and libs,
103can be RFS of target board::
104
105 make M=samples/bpf SYSROOT=~/some_sysroot
106

tcp_bpf.readme

1This file describes how to run the tcp_*_kern.o tcp_bpf (or socket_ops)
2programs. These programs attach to a cgroupv2. The following commands create
3a cgroupv2 and attach a bash shell to the group.
4
5  mkdir -p /tmp/cgroupv2
6  mount -t cgroup2 none /tmp/cgroupv2
7  mkdir -p /tmp/cgroupv2/foo
8  bash
9  echo $$ >> /tmp/cgroupv2/foo/cgroup.procs
10
11Anything that runs under this shell belongs to the foo cgroupv2. To load
12(attach) one of the tcp_*_kern.o programs:
13
14  bpftool prog load tcp_basertt_kern.o /sys/fs/bpf/tcp_prog
15  bpftool cgroup attach /tmp/cgroupv2/foo sock_ops pinned /sys/fs/bpf/tcp_prog
16  bpftool prog tracelog
17
18"bpftool prog tracelog" will continue to run printing the BPF log buffer.
19The tcp_*_kern.o programs use special print functions to print logging
20information (if enabled by the ifdef).
21
22If using netperf/netserver to create traffic, you need to run them under the
23cgroupv2 to which the BPF programs are attached (i.e. under bash shell
24attached to the cgroupv2).
25
26To remove (unattach) a socket_ops BPF program from a cgroupv2:
27
28  bpftool cgroup detach /tmp/cgroupv2/foo sock_ops pinned /sys/fs/bpf/tcp_prog
29