OSDN Git Service

selftest/bpf/benchs: Enhance argp parsing
authorAnton Protopopov <aspsk@isovalent.com>
Mon, 13 Feb 2023 09:15:15 +0000 (09:15 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 16 Feb 2023 00:29:31 +0000 (16:29 -0800)
commit22ff7aeaa9e3d0533df613da3500db1ecf452253
tree97b5eb2f97e7278a98697a51a512e6ff8cb814e7
parent2f1c59637fb17dbb2a725c3bd48e4d9d3809df89
selftest/bpf/benchs: Enhance argp parsing

To parse command line the bench utility uses the argp_parse() function. This
function takes as an argument a parent 'struct argp' structure which defines
common command line options and an array of children 'struct argp' structures
which defines additional command line options for particular benchmarks. This
implementation doesn't allow benchmarks to share option names, e.g., if two
benchmarks want to use, say, the --option option, then only one of them will
succeed (the first one encountered in the array).  This will be convenient if
same option names could be used in different benchmarks (with the same
semantics, e.g., --nr_loops=N).

Fix this by calling the argp_parse() function twice. The first call is the same
as it was before, with all children argps, and helps to find the benchmark name
and to print a combined help message if anything is wrong.  Given the name, we
can call the argp_parse the second time, but now the children array points only
to a correct benchmark thus always calling the correct parsers. (If there's no
a specific list of arguments, then only one call to argp_parse will be done.)

Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230213091519.1202813-4-aspsk@isovalent.com
tools/testing/selftests/bpf/bench.c
tools/testing/selftests/bpf/bench.h
tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
tools/testing/selftests/bpf/benchs/bench_bpf_loop.c
tools/testing/selftests/bpf/benchs/bench_local_storage.c
tools/testing/selftests/bpf/benchs/bench_local_storage_rcu_tasks_trace.c
tools/testing/selftests/bpf/benchs/bench_ringbufs.c
tools/testing/selftests/bpf/benchs/bench_strncmp.c