Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: bpftool: Document and add bash completion for -L, -B options

The -L|--use-loader option for using loader programs when loading, or
when generating a skeleton, did not have any documentation or bash
completion. Same thing goes for -B|--base-btf, used to pass a path to a
base BTF object for split BTF such as BTF for kernel modules.

This patch documents and adds bash completion for those options.

Fixes: 75fa1777694c ("tools/bpftool: Add bpftool support for split BTF")
Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210730215435.7095-7-quentin@isovalent.com

authored by

Quentin Monnet and committed by
Andrii Nakryiko
8cc8c635 da87772f

+96 -10
+47 -1
tools/bpf/bpftool/Documentation/bpftool-btf.rst
··· 12 12 13 13 **bpftool** [*OPTIONS*] **btf** *COMMAND* 14 14 15 - *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | {**-d** | **--debug** } } 15 + *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | {**-d** | **--debug** } | 16 + { **-B** | **--base-btf** } } 16 17 17 18 *COMMANDS* := { **dump** | **help** } 18 19 ··· 73 72 OPTIONS 74 73 ======= 75 74 .. include:: common_options.rst 75 + 76 + -B, --base-btf *FILE* 77 + Pass a base BTF object. Base BTF objects are typically used 78 + with BTF objects for kernel modules. To avoid duplicating 79 + all kernel symbols required by modules, BTF objects for 80 + modules are "split", they are built incrementally on top of 81 + the kernel (vmlinux) BTF object. So the base BTF reference 82 + should usually point to the kernel BTF. 83 + 84 + When the main BTF object to process (for example, the 85 + module BTF to dump) is passed as a *FILE*, bpftool attempts 86 + to autodetect the path for the base object, and passing 87 + this option is optional. When the main BTF object is passed 88 + through other handles, this option becomes necessary. 76 89 77 90 EXAMPLES 78 91 ======== ··· 232 217 **# bpftool btf dump prog tag b88e0a09b1d9759d** 233 218 234 219 **# bpftool btf dump prog pinned /sys/fs/bpf/prog_name** 220 + 221 + | 222 + | **# bpftool btf dump file /sys/kernel/btf/i2c_smbus** 223 + | (or) 224 + | **# I2C_SMBUS_ID=$(bpftool btf show -p | jq '.[] | select(.name=="i2c_smbus").id')** 225 + | **# bpftool btf dump id ${I2C_SMBUS_ID} -B /sys/kernel/btf/vmlinux** 226 + 227 + :: 228 + 229 + [104848] STRUCT 'i2c_smbus_alert' size=40 vlen=2 230 + 'alert' type_id=393 bits_offset=0 231 + 'ara' type_id=56050 bits_offset=256 232 + [104849] STRUCT 'alert_data' size=12 vlen=3 233 + 'addr' type_id=16 bits_offset=0 234 + 'type' type_id=56053 bits_offset=32 235 + 'data' type_id=7 bits_offset=64 236 + [104850] PTR '(anon)' type_id=104848 237 + [104851] PTR '(anon)' type_id=104849 238 + [104852] FUNC 'i2c_register_spd' type_id=84745 linkage=static 239 + [104853] FUNC 'smbalert_driver_init' type_id=1213 linkage=static 240 + [104854] FUNC_PROTO '(anon)' ret_type_id=18 vlen=1 241 + 'ara' type_id=56050 242 + [104855] FUNC 'i2c_handle_smbus_alert' type_id=104854 linkage=static 243 + [104856] FUNC 'smbalert_remove' type_id=104854 linkage=static 244 + [104857] FUNC_PROTO '(anon)' ret_type_id=18 vlen=2 245 + 'ara' type_id=56050 246 + 'id' type_id=56056 247 + [104858] FUNC 'smbalert_probe' type_id=104857 linkage=static 248 + [104859] FUNC 'smbalert_work' type_id=9695 linkage=static 249 + [104860] FUNC 'smbus_alert' type_id=71367 linkage=static 250 + [104861] FUNC 'smbus_do_alert' type_id=84827 linkage=static
+8 -1
tools/bpf/bpftool/Documentation/bpftool-gen.rst
··· 12 12 13 13 **bpftool** [*OPTIONS*] **gen** *COMMAND* 14 14 15 - *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } } 15 + *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } | 16 + { **-L** | **--use-loader** } } 16 17 17 18 *COMMAND* := { **object** | **skeleton** | **help** } 18 19 ··· 152 151 OPTIONS 153 152 ======= 154 153 .. include:: common_options.rst 154 + 155 + -L, --use-loader 156 + For skeletons, generate a "light" skeleton (also known as "loader" 157 + skeleton). A light skeleton contains a loader eBPF program. It does 158 + not use the majority of the libbpf infrastructure, and does not need 159 + libelf. 155 160 156 161 EXAMPLES 157 162 ========
+29 -1
tools/bpf/bpftool/Documentation/bpftool-prog.rst
··· 13 13 **bpftool** [*OPTIONS*] **prog** *COMMAND* 14 14 15 15 *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } | 16 - { **-f** | **--bpffs** } | { **-m** | **--mapcompat** } | { **-n** | **--nomount** } } 16 + { **-f** | **--bpffs** } | { **-m** | **--mapcompat** } | { **-n** | **--nomount** } | 17 + { **-L** | **--use-loader** } } 17 18 18 19 *COMMANDS* := 19 20 { **show** | **list** | **dump xlated** | **dump jited** | **pin** | **load** ··· 225 224 Do not automatically attempt to mount any virtual file system 226 225 (such as tracefs or BPF virtual file system) when necessary. 227 226 227 + -L, --use-loader 228 + Load program as a "loader" program. This is useful to debug 229 + the generation of such programs. When this option is in 230 + use, bpftool attempts to load the programs from the object 231 + file into the kernel, but does not pin them (therefore, the 232 + *PATH* must not be provided). 233 + 234 + When combined with the **-d**\ \|\ **--debug** option, 235 + additional debug messages are generated, and the execution 236 + of the loader program will use the **bpf_trace_printk**\ () 237 + helper to log each step of loading BTF, creating the maps, 238 + and loading the programs (see **bpftool prog tracelog** as 239 + a way to dump those messages). 240 + 228 241 EXAMPLES 229 242 ======== 230 243 **# bpftool prog show** ··· 342 327 40176203 cycles (83.05%) 343 328 42518139 instructions # 1.06 insns per cycle (83.39%) 344 329 123 llc_misses # 2.89 LLC misses per million insns (83.15%) 330 + 331 + | 332 + | Output below is for the trace logs. 333 + | Run in separate terminals: 334 + | **# bpftool prog tracelog** 335 + | **# bpftool prog load -L -d file.o** 336 + 337 + :: 338 + 339 + bpftool-620059 [004] d... 2634685.517903: bpf_trace_printk: btf_load size 665 r=5 340 + bpftool-620059 [004] d... 2634685.517912: bpf_trace_printk: map_create sample_map idx 0 type 2 value_size 4 value_btf_id 0 r=6 341 + bpftool-620059 [004] d... 2634685.517997: bpf_trace_printk: prog_load sample insn_cnt 13 r=7 342 + bpftool-620059 [004] d... 2634685.517999: bpf_trace_printk: close(5) = 0
+5 -3
tools/bpf/bpftool/bash-completion/bpftool
··· 260 260 261 261 # Deal with options 262 262 if [[ ${words[cword]} == -* ]]; then 263 - local c='--version --json --pretty --bpffs --mapcompat --debug' 263 + local c='--version --json --pretty --bpffs --mapcompat --debug \ 264 + --use-loader --base-btf' 264 265 COMPREPLY=( $( compgen -W "$c" -- "$cur" ) ) 265 266 return 0 266 267 fi ··· 279 278 _sysfs_get_netdevs 280 279 return 0 281 280 ;; 282 - file|pinned) 281 + file|pinned|-B|--base-btf) 283 282 _filedir 284 283 return 0 285 284 ;; ··· 292 291 # Remove all options so completions don't have to deal with them. 293 292 local i 294 293 for (( i=1; i < ${#words[@]}; )); do 295 - if [[ ${words[i]::1} == - ]]; then 294 + if [[ ${words[i]::1} == - ]] && 295 + [[ ${words[i]} != "-B" ]] && [[ ${words[i]} != "--base-btf" ]]; then 296 296 words=( "${words[@]:0:i}" "${words[@]:i+1}" ) 297 297 [[ $i -le $cword ]] && cword=$(( cword - 1 )) 298 298 else
+2 -1
tools/bpf/bpftool/btf.c
··· 981 981 " FORMAT := { raw | c }\n" 982 982 " " HELP_SPEC_MAP "\n" 983 983 " " HELP_SPEC_PROGRAM "\n" 984 - " " HELP_SPEC_OPTIONS " }\n" 984 + " " HELP_SPEC_OPTIONS " |\n" 985 + " {-B|--base-btf} }\n" 985 986 "", 986 987 bin_name, "btf"); 987 988
+1 -1
tools/bpf/bpftool/cgroup.c
··· 502 502 " " HELP_SPEC_ATTACH_FLAGS "\n" 503 503 " " HELP_SPEC_PROGRAM "\n" 504 504 " " HELP_SPEC_OPTIONS " |\n" 505 - " {-f|--bpffs} } 505 + " {-f|--bpffs} }\n" 506 506 "", 507 507 bin_name, argv[-2]); 508 508
+2 -1
tools/bpf/bpftool/gen.c
··· 1026 1026 " %1$s %2$s skeleton FILE [name OBJECT_NAME]\n" 1027 1027 " %1$s %2$s help\n" 1028 1028 "\n" 1029 - " " HELP_SPEC_OPTIONS " }\n" 1029 + " " HELP_SPEC_OPTIONS " |\n" 1030 + " {-L|--use-loader} }\n" 1030 1031 "", 1031 1032 bin_name, "gen"); 1032 1033
+2 -1
tools/bpf/bpftool/prog.c
··· 2260 2260 " stream_parser | flow_dissector }\n" 2261 2261 " METRIC := { cycles | instructions | l1d_loads | llc_misses | itlb_misses | dtlb_misses }\n" 2262 2262 " " HELP_SPEC_OPTIONS " |\n" 2263 - " {-f|--bpffs} | {-m|--mapcompat} | {-n|--nomount} }\n" 2263 + " {-f|--bpffs} | {-m|--mapcompat} | {-n|--nomount} |\n" 2264 + " {-L|--use-loader} }\n" 2264 2265 "", 2265 2266 bin_name, argv[-2]); 2266 2267