tools/testing/selftests/bpf/prog_tests/lru_lock_nmi.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/lru_lock_nmi.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/lru_lock_nmi.c- Extension
.c- Size
- 5986 bytes
- Lines
- 244
- 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
pthread.hsched.hsys/syscall.hlinux/perf_event.htest_progs.htesting_helpers.hlru_lock_nmi.skel.h
Detected Declarations
struct hammer_argstruct refill_argfunction pin_to_cpufunction drain_then_verify_capacityfunction run_variantfunction serial_test_lru_lock_nmi
Annotated Snippet
struct hammer_arg {
int map_fd;
int cpu;
__u64 deadline_ns;
};
struct refill_arg {
int map_fd;
int cpu;
int per_cpu_quota;
int update_errors;
};
/*
* Pin the calling thread to @cpu. Uses dynamically-allocated CPU sets so
* we stay correct on hosts with @cpu >= CPU_SETSIZE (default 1024).
*/
static int pin_to_cpu(int cpu)
{
cpu_set_t *cs;
size_t cs_size;
int err;
cs = CPU_ALLOC(cpu + 1);
if (!cs)
return -ENOMEM;
cs_size = CPU_ALLOC_SIZE(cpu + 1);
CPU_ZERO_S(cs_size, cs);
CPU_SET_S(cpu, cs_size, cs);
err = pthread_setaffinity_np(pthread_self(), cs_size, cs);
CPU_FREE(cs);
return err;
}
static void *hammer_thread(void *p)
{
struct hammer_arg *a = p;
int nr_possible_cpus = libbpf_num_possible_cpus();
__u64 val[nr_possible_cpus];
unsigned int seed;
__u32 key;
memset(val, 0, sizeof(val));
pin_to_cpu(a->cpu);
seed = (unsigned int)a->cpu ^ (unsigned int)(uintptr_t)pthread_self();
while (get_time_ns() < a->deadline_ns) {
bool do_update = rand_r(&seed) & 1;
key = rand_r(&seed) % KEY_RANGE;
if (do_update)
bpf_map_update_elem(a->map_fd, &key, val, BPF_ANY);
else
bpf_map_delete_elem(a->map_fd, &key);
}
return NULL;
}
static void *refill_thread(void *p)
{
struct refill_arg *a = p;
int nr_possible_cpus = libbpf_num_possible_cpus();
__u64 val[nr_possible_cpus];
__u32 start, end, key;
memset(val, 0, sizeof(val));
pin_to_cpu(a->cpu);
start = (__u32)a->cpu * (__u32)a->per_cpu_quota;
end = start + (__u32)a->per_cpu_quota;
for (key = start; key < end; key++)
if (bpf_map_update_elem(a->map_fd, &key, val, BPF_ANY))
a->update_errors++;
return NULL;
}
/*
* Drain the map, then refill it with each CPU inserting only its own
* quota of keys.
* After refill, lookup every key we inserted - a stranded node on any
* CPU's pool would have forced eviction.
*/
static int drain_then_verify_capacity(int map_fd, int nr_cpus)
{
int per_cpu_quota = MAP_ENTRIES / nr_cpus;
int total = per_cpu_quota * nr_cpus;
int nr_possible_cpus = libbpf_num_possible_cpus();
pthread_t threads[nr_cpus];
Annotation
- Immediate include surface: `pthread.h`, `sched.h`, `sys/syscall.h`, `linux/perf_event.h`, `test_progs.h`, `testing_helpers.h`, `lru_lock_nmi.skel.h`.
- Detected declarations: `struct hammer_arg`, `struct refill_arg`, `function pin_to_cpu`, `function drain_then_verify_capacity`, `function run_variant`, `function serial_test_lru_lock_nmi`.
- 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.