tools/testing/selftests/bpf/progs/strncmp_bench.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/strncmp_bench.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/strncmp_bench.c- Extension
.c- Size
- 1144 bytes
- Lines
- 54
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
linux/types.hlinux/bpf.hbpf/bpf_helpers.hbpf/bpf_tracing.h
Detected Declarations
function local_strncmpfunction strncmp_no_helperfunction strncmp_helper
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2021. Huawei Technologies Co., Ltd */
#include <linux/types.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#define STRNCMP_STR_SZ 4096
/* Will be updated by benchmark before program loading */
const volatile unsigned int cmp_str_len = 1;
const char target[STRNCMP_STR_SZ];
long hits = 0;
char str[STRNCMP_STR_SZ];
char _license[] SEC("license") = "GPL";
static __always_inline int local_strncmp(const char *s1, unsigned int sz,
const char *s2)
{
int ret = 0;
unsigned int i;
for (i = 0; i < sz; i++) {
/* E.g. 0xff > 0x31 */
ret = (unsigned char)s1[i] - (unsigned char)s2[i];
if (ret || !s1[i])
break;
}
return ret;
}
SEC("tp/syscalls/sys_enter_getpgid")
int strncmp_no_helper(void *ctx)
{
const char *target_str = target;
barrier_var(target_str);
if (local_strncmp(str, cmp_str_len + 1, target_str) < 0)
__sync_add_and_fetch(&hits, 1);
return 0;
}
SEC("tp/syscalls/sys_enter_getpgid")
int strncmp_helper(void *ctx)
{
if (bpf_strncmp(str, cmp_str_len + 1, target) < 0)
__sync_add_and_fetch(&hits, 1);
return 0;
}
Annotation
- Immediate include surface: `linux/types.h`, `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `function local_strncmp`, `function strncmp_no_helper`, `function strncmp_helper`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.