• Anton Protopopov's avatar
    selftest/bpf/benchs: Enhance argp parsing · 22ff7aea
    Anton Protopopov authored
    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: default avatarAnton Protopopov <aspsk@isovalent.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20230213091519.1202813-4-aspsk@isovalent.com
    22ff7aea
bench_bpf_loop.c 1.85 KB