xref: /OK3568_Linux_fs/kernel/tools/bpf/bpftool/Documentation/bpftool-iter.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun============
2*4882a593Smuzhiyunbpftool-iter
3*4882a593Smuzhiyun============
4*4882a593Smuzhiyun-------------------------------------------------------------------------------
5*4882a593Smuzhiyuntool to create BPF iterators
6*4882a593Smuzhiyun-------------------------------------------------------------------------------
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun:Manual section: 8
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunSYNOPSIS
11*4882a593Smuzhiyun========
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun	**bpftool** [*OPTIONS*] **iter** *COMMAND*
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun	*COMMANDS* := { **pin** | **help** }
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunITER COMMANDS
18*4882a593Smuzhiyun===================
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun|	**bpftool** **iter pin** *OBJ* *PATH* [**map** *MAP*]
21*4882a593Smuzhiyun|	**bpftool** **iter help**
22*4882a593Smuzhiyun|
23*4882a593Smuzhiyun|	*OBJ* := /a/file/of/bpf_iter_target.o
24*4882a593Smuzhiyun|	*MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunDESCRIPTION
27*4882a593Smuzhiyun===========
28*4882a593Smuzhiyun	**bpftool iter pin** *OBJ* *PATH* [**map** *MAP*]
29*4882a593Smuzhiyun		  A bpf iterator combines a kernel iterating of
30*4882a593Smuzhiyun		  particular kernel data (e.g., tasks, bpf_maps, etc.)
31*4882a593Smuzhiyun		  and a bpf program called for each kernel data object
32*4882a593Smuzhiyun		  (e.g., one task, one bpf_map, etc.). User space can
33*4882a593Smuzhiyun		  *read* kernel iterator output through *read()* syscall.
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun		  The *pin* command creates a bpf iterator from *OBJ*,
36*4882a593Smuzhiyun		  and pin it to *PATH*. The *PATH* should be located
37*4882a593Smuzhiyun		  in *bpffs* mount. It must not contain a dot
38*4882a593Smuzhiyun		  character ('.'), which is reserved for future extensions
39*4882a593Smuzhiyun		  of *bpffs*.
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun		  Map element bpf iterator requires an additional parameter
42*4882a593Smuzhiyun		  *MAP* so bpf program can iterate over map elements for
43*4882a593Smuzhiyun		  that map. User can have a bpf program in kernel to run
44*4882a593Smuzhiyun		  with each map element, do checking, filtering, aggregation,
45*4882a593Smuzhiyun		  etc. without copying data to user space.
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun		  User can then *cat PATH* to see the bpf iterator output.
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun	**bpftool iter help**
50*4882a593Smuzhiyun		  Print short help message.
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunOPTIONS
53*4882a593Smuzhiyun=======
54*4882a593Smuzhiyun	.. include:: common_options.rst
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunEXAMPLES
57*4882a593Smuzhiyun========
58*4882a593Smuzhiyun**# bpftool iter pin bpf_iter_netlink.o /sys/fs/bpf/my_netlink**
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun::
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun   Create a file-based bpf iterator from bpf_iter_netlink.o and pin it
63*4882a593Smuzhiyun   to /sys/fs/bpf/my_netlink
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun**# bpftool iter pin bpf_iter_hashmap.o /sys/fs/bpf/my_hashmap map id 20**
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun::
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun   Create a file-based bpf iterator from bpf_iter_hashmap.o and map with
70*4882a593Smuzhiyun   id 20, and pin it to /sys/fs/bpf/my_hashmap
71