History log of /linux-master/tools/testing/selftests/bpf/benchs/bench_strncmp.c
Revision Date Author Comments
# 970308a7 13-Jun-2023 Hou Tao <houtao1@huawei.com>

selftests/bpf: Set the default value of consumer_cnt as 0

Considering that only bench_ringbufs.c supports consumer, just set the
default value of consumer_cnt as 0. After that, update the validity
check of consumer_cnt, remove unused consumer_thread code snippets and
set consumer_cnt as 1 in run_bench_ringbufs.sh accordingly.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20230613080921.1623219-5-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>


# 22ff7aea 13-Feb-2023 Anton Protopopov <aspsk@isovalent.com>

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


# 9c42652f 10-Dec-2021 Hou Tao <houtao1@huawei.com>

selftests/bpf: Add benchmark for bpf_strncmp() helper

Add benchmark to compare the performance between home-made strncmp()
in bpf program and bpf_strncmp() helper. In summary, the performance
win of bpf_strncmp() under x86-64 is greater than 18% when the compared
string length is greater than 64, and is 179% when the length is 4095.
Under arm64 the performance win is even bigger: 33% when the length
is greater than 64 and 600% when the length is 4095.

The following is the details:

no-helper-X: use home-made strncmp() to compare X-sized string
helper-Y: use bpf_strncmp() to compare Y-sized string

Under x86-64:

no-helper-1 3.504 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-1 3.347 ± 0.001M/s (drops 0.000 ± 0.000M/s)

no-helper-8 3.357 ± 0.001M/s (drops 0.000 ± 0.000M/s)
helper-8 3.307 ± 0.001M/s (drops 0.000 ± 0.000M/s)

no-helper-32 3.064 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-32 3.253 ± 0.001M/s (drops 0.000 ± 0.000M/s)

no-helper-64 2.563 ± 0.001M/s (drops 0.000 ± 0.000M/s)
helper-64 3.040 ± 0.001M/s (drops 0.000 ± 0.000M/s)

no-helper-128 1.975 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-128 2.641 ± 0.000M/s (drops 0.000 ± 0.000M/s)

no-helper-512 0.759 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-512 1.574 ± 0.000M/s (drops 0.000 ± 0.000M/s)

no-helper-2048 0.329 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-2048 0.602 ± 0.000M/s (drops 0.000 ± 0.000M/s)

no-helper-4095 0.117 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-4095 0.327 ± 0.000M/s (drops 0.000 ± 0.000M/s)

Under arm64:

no-helper-1 2.806 ± 0.004M/s (drops 0.000 ± 0.000M/s)
helper-1 2.819 ± 0.002M/s (drops 0.000 ± 0.000M/s)

no-helper-8 2.797 ± 0.109M/s (drops 0.000 ± 0.000M/s)
helper-8 2.786 ± 0.025M/s (drops 0.000 ± 0.000M/s)

no-helper-32 2.399 ± 0.011M/s (drops 0.000 ± 0.000M/s)
helper-32 2.703 ± 0.002M/s (drops 0.000 ± 0.000M/s)

no-helper-64 2.020 ± 0.015M/s (drops 0.000 ± 0.000M/s)
helper-64 2.702 ± 0.073M/s (drops 0.000 ± 0.000M/s)

no-helper-128 1.604 ± 0.001M/s (drops 0.000 ± 0.000M/s)
helper-128 2.516 ± 0.002M/s (drops 0.000 ± 0.000M/s)

no-helper-512 0.699 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-512 2.106 ± 0.003M/s (drops 0.000 ± 0.000M/s)

no-helper-2048 0.215 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-2048 1.223 ± 0.003M/s (drops 0.000 ± 0.000M/s)

no-helper-4095 0.112 ± 0.000M/s (drops 0.000 ± 0.000M/s)
helper-4095 0.796 ± 0.000M/s (drops 0.000 ± 0.000M/s)

Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211210141652.877186-4-houtao1@huawei.com