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