tools/testing/selftests/bpf/benchs/bench_bpf_hashmap_full_update.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/benchs/bench_bpf_hashmap_full_update.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/benchs/bench_bpf_hashmap_full_update.c- Extension
.c- Size
- 2612 bytes
- Lines
- 120
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
bench.hbpf_hashmap_full_update_bench.skel.hbpf_util.h
Detected Declarations
function validatefunction measurefunction setupfunction rhash_setupfunction hashmap_report_final
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Bytedance */
#include "bench.h"
#include "bpf_hashmap_full_update_bench.skel.h"
#include "bpf_util.h"
/* BPF triggering benchmarks */
static struct ctx {
struct bpf_hashmap_full_update_bench *skel;
} ctx;
#define MAX_LOOP_NUM 10000
static void validate(void)
{
if (env.consumer_cnt != 0) {
fprintf(stderr, "benchmark doesn't support consumer!\n");
exit(1);
}
}
static void *producer(void *input)
{
while (true) {
/* trigger the bpf program */
syscall(__NR_getpgid);
}
return NULL;
}
static void measure(struct bench_res *res)
{
}
static void hashmap_full_update_setup(enum bpf_map_type map_type)
{
struct bpf_link *link;
int map_fd, i, max_entries;
setup_libbpf();
ctx.skel = bpf_hashmap_full_update_bench__open();
if (!ctx.skel) {
fprintf(stderr, "failed to open skeleton\n");
exit(1);
}
bpf_map__set_type(ctx.skel->maps.hash_map_bench, map_type);
if (map_type == BPF_MAP_TYPE_RHASH)
bpf_map__set_map_flags(ctx.skel->maps.hash_map_bench,
BPF_F_NO_PREALLOC);
if (bpf_hashmap_full_update_bench__load(ctx.skel)) {
fprintf(stderr, "failed to load skeleton\n");
exit(1);
}
ctx.skel->bss->nr_loops = MAX_LOOP_NUM;
link = bpf_program__attach(ctx.skel->progs.benchmark);
if (!link) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
/* fill hash_map */
map_fd = bpf_map__fd(ctx.skel->maps.hash_map_bench);
max_entries = bpf_map__max_entries(ctx.skel->maps.hash_map_bench);
for (i = 0; i < max_entries; i++)
bpf_map_update_elem(map_fd, &i, &i, BPF_ANY);
}
static void setup(void)
{
hashmap_full_update_setup(BPF_MAP_TYPE_HASH);
}
static void rhash_setup(void)
{
hashmap_full_update_setup(BPF_MAP_TYPE_RHASH);
}
static void hashmap_report_final(struct bench_res res[], int res_cnt)
{
unsigned int nr_cpus = bpf_num_possible_cpus();
int i;
for (i = 0; i < nr_cpus; i++) {
Annotation
- Immediate include surface: `bench.h`, `bpf_hashmap_full_update_bench.skel.h`, `bpf_util.h`.
- Detected declarations: `function validate`, `function measure`, `function setup`, `function rhash_setup`, `function hashmap_report_final`.
- 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.