[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211106132822.1396621-1-houtao1@huawei.com>
Date: Sat, 6 Nov 2021 21:28:20 +0800
From: Hou Tao <houtao1@...wei.com>
To: Alexei Starovoitov <ast@...nel.org>
CC: Martin KaFai Lau <kafai@...com>, Yonghong Song <yhs@...com>,
Song Liu <songliubraving@...com>,
Daniel Borkmann <daniel@...earbox.net>,
"Andrii Nakryiko" <andrii@...nel.org>, <netdev@...r.kernel.org>,
<bpf@...r.kernel.org>, <houtao1@...wei.com>
Subject: [RFC PATCH bpf-next 0/2] introduce bpf_strncmp() helper
Hi,
The motivation for introducing bpf_strncmp() helper comes from
two aspects:
(1) clang doesn't always replace strncmp() automatically
(and don't known why)
In tracing program, sometimes we need to using a home-made
strncmp() to check whether or not the file name is expected.
(2) the performance of home-made strncmp is not so good
As shown in the benchmark of patch #2, the performance of
bpf_strncmp helper is 80% better than home-made strncmp under
x86-64, and 600% better under arm64 thanks to its arch-optimized
strncmp().
But i'm concernt about whether the API of bpf_strncmp() is OK.
Now the first argument must be a read-only null-terminated
string, it is enough for our file-name comparsion case because
the target file name is const and read-only, but may be not
usable for comparsion of two strings stored in writable-maps.
Any comments are welcome.
Regards,
Tao
Hou Tao (2):
bpf: add bpf_strncmp helper
selftests/bpf: add benchmark bpf_strcmp
include/linux/bpf.h | 1 +
include/uapi/linux/bpf.h | 11 ++
kernel/bpf/helpers.c | 14 +++
kernel/trace/bpf_trace.c | 2 +
tools/include/uapi/linux/bpf.h | 11 ++
.../bpf/prog_tests/test_strncmp_helper.c | 75 ++++++++++++
.../selftests/bpf/progs/strncmp_helper.c | 109 ++++++++++++++++++
7 files changed, 223 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/test_strncmp_helper.c
create mode 100644 tools/testing/selftests/bpf/progs/strncmp_helper.c
--
2.29.2
Powered by blists - more mailing lists