• Home
  • Annotate
  • current directory
Name Date Size #Lines LOC

..18-Mar-2022-

.gitignore A D18-Mar-2022810 6463

Makefile A D18-Mar-202215.3 KiB443361

Makefile.target A D18-Mar-20222.9 KiB8741

README.rst A D18-Mar-20223.4 KiB11277

asm_goto_workaround.h A D18-Mar-2022725 2913

bpf_insn.h A D18-Mar-20226.3 KiB234158

cookie_uid_helper_example.c A D18-Mar-20229.3 KiB329241

cpustat_kern.c A D18-Mar-20227 KiB282141

cpustat_user.c A D18-Mar-20225.7 KiB253180

do_hbm_test.sh A D18-Mar-202212 KiB439392

fds_example.c A D18-Mar-20224.2 KiB194163

hash_func01.h A D18-Mar-20221.3 KiB5639

hbm.c A D18-Mar-202213.4 KiB506403

hbm.h A D18-Mar-20221.2 KiB3926

hbm_edt_kern.c A D18-Mar-20225.3 KiB16984

hbm_kern.h A D18-Mar-20225.7 KiB216182

hbm_out_kern.c A D18-Mar-20225.5 KiB18094

ibumad_kern.c A D18-Mar-20222.9 KiB139100

ibumad_user.c A D18-Mar-20223.4 KiB160123

lathist_kern.c A D18-Mar-20222.1 KiB10068

lathist_user.c A D18-Mar-20222.6 KiB131101

lwt_len_hist.sh A D18-Mar-20221 KiB4130

lwt_len_hist_kern.c A D18-Mar-20221.9 KiB8359

lwt_len_hist_user.c A D18-Mar-20221.6 KiB7860

map_perf_test_kern.c A D18-Mar-20226.5 KiB292239

map_perf_test_user.c A D18-Mar-202211.5 KiB502404

offwaketime_kern.c A D18-Mar-20223.8 KiB159125

offwaketime_user.c A D18-Mar-20223.2 KiB155126

parse_ldabs.c A D18-Mar-20221.2 KiB4433

parse_simple.c A D18-Mar-20221.3 KiB5036

parse_varlen.c A D18-Mar-20223.4 KiB151122

run_cookie_uid_helper_example.sh A D18-Mar-2022341 1611

sampleip_kern.c A D18-Mar-2022915 3926

sampleip_user.c A D18-Mar-20224.8 KiB228180

sock_example.c A D18-Mar-20222.9 KiB10774

sock_example.h A D18-Mar-2022814 3630

sock_flags_kern.c A D18-Mar-20221.2 KiB5034

sockex1_kern.c A D18-Mar-2022661 3125

sockex1_user.c A D18-Mar-20221.1 KiB5540

sockex2_kern.c A D18-Mar-20224.8 KiB224190

sockex2_user.c A D18-Mar-20221.2 KiB5644

sockex3_kern.c A D18-Mar-20226.2 KiB294227

sockex3_user.c A D18-Mar-20222.4 KiB10585

spintest_kern.c A D18-Mar-20222.1 KiB7056

spintest_user.c A D18-Mar-20222.1 KiB9479

syscall_nrs.c A D18-Mar-2022337 2015

syscall_tp_kern.c A D18-Mar-20221.4 KiB7460

syscall_tp_user.c A D18-Mar-20223.2 KiB137105

task_fd_query_kern.c A D18-Mar-2022410 2016

task_fd_query_user.c A D18-Mar-202211.4 KiB425361

tc_l2_redirect.sh A D18-Mar-20224.9 KiB175135

tc_l2_redirect_kern.c A D18-Mar-20226 KiB238182

tc_l2_redirect_user.c A D18-Mar-20221.3 KiB7156

tcbpf1_kern.c A D18-Mar-20222.6 KiB9276

tcp_basertt_kern.c A D18-Mar-20221.7 KiB7249

tcp_bpf.readme A D18-Mar-20221.1 KiB2921

tcp_bufs_kern.c A D18-Mar-20222.1 KiB8252

tcp_clamp_kern.c A D18-Mar-20222.7 KiB9868

tcp_cong_kern.c A D18-Mar-20221.9 KiB7953

tcp_dumpstats_kern.c A D18-Mar-20221.3 KiB6951

tcp_iw_kern.c A D18-Mar-20222.2 KiB8455

tcp_rwnd_kern.c A D18-Mar-20221.7 KiB6536

tcp_synrto_kern.c A D18-Mar-20221.7 KiB6536

tcp_tos_reflect_kern.c A D18-Mar-20221.8 KiB8167

test_cgrp2_array_pin.c A D18-Mar-20222.1 KiB10791

test_cgrp2_attach.c A D18-Mar-20224.5 KiB174126

test_cgrp2_sock.c A D18-Mar-20226.2 KiB291224

test_cgrp2_sock.sh A D18-Mar-20222.9 KiB13686

test_cgrp2_sock2.c A D18-Mar-20222 KiB9670

test_cgrp2_sock2.sh A D18-Mar-20221.8 KiB9976

test_cgrp2_tc.sh A D18-Mar-20224.2 KiB186158

test_cgrp2_tc_kern.c A D18-Mar-20221.8 KiB7155

test_cls_bpf.sh A D18-Mar-2022915 3931

test_current_task_under_cgroup_kern.c A D18-Mar-20221.1 KiB4530

test_current_task_under_cgroup_user.c A D18-Mar-20222.4 KiB11481

test_lru_dist.c A D18-Mar-202211.9 KiB538419

test_lwt_bpf.c A D18-Mar-20226 KiB254194

test_lwt_bpf.sh A D18-Mar-20229 KiB401348

test_map_in_map_kern.c A D18-Mar-20223.9 KiB177131

test_map_in_map_user.c A D18-Mar-20224.3 KiB168131

test_overhead_kprobe_kern.c A D18-Mar-20221.3 KiB4936

test_overhead_raw_tp_kern.c A D18-Mar-2022361 1813

test_overhead_tp_kern.c A D18-Mar-2022832 3726

test_overhead_user.c A D18-Mar-20224.2 KiB217179

test_override_return.sh A D18-Mar-2022276 1714

test_probe_write_user_kern.c A D18-Mar-20221.8 KiB5736

test_probe_write_user_user.c A D18-Mar-20223.3 KiB10985

trace_common.h A D18-Mar-2022286 1410

trace_event_kern.c A D18-Mar-20222.3 KiB8062

trace_event_user.c A D18-Mar-20227.8 KiB353288

trace_output_kern.c A D18-Mar-2022660 3225

trace_output_user.c A D18-Mar-20222.3 KiB10887

tracex1_kern.c A D18-Mar-20221.8 KiB5531

tracex1_user.c A D18-Mar-20221.1 KiB5140

tracex2_kern.c A D18-Mar-20222.3 KiB10378

tracex2_user.c A D18-Mar-20224 KiB188154

tracex3_kern.c A D18-Mar-20222.1 KiB9159

tracex3_user.c A D18-Mar-20223.7 KiB185157

tracex4_kern.c A D18-Mar-20221.2 KiB5637

tracex4_user.c A D18-Mar-20222 KiB9877

tracex5_kern.c A D18-Mar-20222.2 KiB9470

tracex5_user.c A D18-Mar-20222.3 KiB9978

tracex6_kern.c A D18-Mar-20221.4 KiB7057

tracex6_user.c A D18-Mar-20225.5 KiB224189

tracex7_kern.c A D18-Mar-2022339 1713

tracex7_user.c A D18-Mar-20221.2 KiB5746

xdp1_kern.c A D18-Mar-20222.1 KiB9672

xdp1_user.c A D18-Mar-20223.3 KiB162131

xdp2_kern.c A D18-Mar-20222.4 KiB11790

xdp2skb_meta.sh A D18-Mar-20224.5 KiB221168

xdp2skb_meta_kern.c A D18-Mar-20223 KiB10636

xdp_adjust_tail_kern.c A D18-Mar-20223.8 KiB156120

xdp_adjust_tail_user.c A D18-Mar-20224.5 KiB193154

xdp_fwd_kern.c A D18-Mar-20224.5 KiB15998

xdp_fwd_user.c A D18-Mar-20223.9 KiB173131

xdp_monitor.bpf.c A D18-Mar-2022218 92

xdp_monitor_user.c A D18-Mar-20222.8 KiB120103

xdp_redirect.bpf.c A D18-Mar-20221.3 KiB5029

xdp_redirect_cpu.bpf.c A D18-Mar-202212 KiB542431

xdp_redirect_cpu_user.c A D18-Mar-202214.9 KiB561463

xdp_redirect_map.bpf.c A D18-Mar-20222.4 KiB9664

xdp_redirect_map_multi.bpf.c A D18-Mar-20221.7 KiB7861

xdp_redirect_map_multi_user.c A D18-Mar-20225.8 KiB234201

xdp_redirect_map_user.c A D18-Mar-20225.7 KiB220187

xdp_redirect_user.c A D18-Mar-20224.3 KiB174148

xdp_router_ipv4_kern.c A D18-Mar-20224.4 KiB187151

xdp_router_ipv4_user.c A D18-Mar-202218.6 KiB751667

xdp_rxq_info_kern.c A D18-Mar-20223.2 KiB14194

xdp_rxq_info_user.c A D18-Mar-202213.8 KiB600497

xdp_sample.bpf.c A D18-Mar-20227.1 KiB267207

xdp_sample.bpf.h A D18-Mar-20223.9 KiB142105

xdp_sample_pkts_kern.c A D18-Mar-20221.5 KiB5836

xdp_sample_pkts_user.c A D18-Mar-20224 KiB198167

xdp_sample_shared.h A D18-Mar-2022295 1814

xdp_sample_user.c A D18-Mar-202242.4 KiB1,6761,418

xdp_sample_user.h A D18-Mar-20224.4 KiB10994

xdp_tx_iptunnel_common.h A D18-Mar-2022485 3526

xdp_tx_iptunnel_kern.c A D18-Mar-20225.6 KiB238180

xdp_tx_iptunnel_user.c A D18-Mar-20227.3 KiB309263

xdpsock.h A D18-Mar-2022298 209

xdpsock_ctrl_proc.c A D18-Mar-20223.7 KiB188153

xdpsock_kern.c A D18-Mar-2022593 2515

xdpsock_user.c A D18-Mar-202242.1 KiB1,7031,390

xsk_fwd.c A D18-Mar-202225.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
65We recommend that developers who want the fastest incremental builds
66use the Ninja build system, you can find it in your system's package
67manager, usually the package is ninja or ninja-build.
68
69Quick sniplet for manually compiling LLVM and clang
70(build dependencies are ninja, cmake and gcc-c++)::
71
72 $ git clone https://github.com/llvm/llvm-project.git
73 $ mkdir -p llvm-project/llvm/build
74 $ cd llvm-project/llvm/build
75 $ cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
76            -DLLVM_ENABLE_PROJECTS="clang"    \
77            -DCMAKE_BUILD_TYPE=Release        \
78            -DLLVM_BUILD_RUNTIME=OFF
79 $ ninja
80
81It is also possible to point make to the newly compiled 'llc' or
82'clang' command via redefining LLC or CLANG on the make command line::
83
84 make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang
85
86Cross compiling samples
87-----------------------
88In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
89environment variables before calling make. But do this before clean,
90cofiguration and header install steps described above. This will direct make to
91build samples for the cross target::
92
93 export ARCH=arm64
94 export CROSS_COMPILE="aarch64-linux-gnu-"
95
96Headers can be also installed on RFS of target board if need to keep them in
97sync (not necessarily and it creates a local "usr/include" directory also)::
98
99 make INSTALL_HDR_PATH=~/some_sysroot/usr headers_install
100
101Pointing LLC and CLANG is not necessarily if it's installed on HOST and have
102in its targets appropriate arm64 arch (usually it has several arches).
103Build samples::
104
105 make M=samples/bpf
106
107Or build samples with SYSROOT if some header or library is absent in toolchain,
108say libelf, providing address to file system containing headers and libs,
109can be RFS of target board::
110
111 make M=samples/bpf SYSROOT=~/some_sysroot
112

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