tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.c- Extension
.c- Size
- 9703 bytes
- Lines
- 394
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched.hlinux/smp.hlinux/delay.hlinux/module.hlinux/prandom.hlinux/ktime.hasm/rqspinlock.hlinux/perf_event.hlinux/kthread.hlinux/atomic.hlinux/slab.h
Detected Declarations
struct rqsl_cpu_histstruct rqsl_lock_pairenum rqsl_contextenum rqsl_modefunction rqsl_get_lock_pairfunction rqsl_hist_bucket_idxfunction rqsl_record_lock_resultfunction rqspinlock_worker_fnfunction nmi_cbfunction free_rqsl_threadsfunction free_rqsl_evtsfunction bpf_test_rqspinlock_initfunction for_each_online_cpufunction rqsl_print_histogramsfunction for_each_online_cpufunction bpf_test_rqspinlock_exitmodule init bpf_test_rqspinlock_init
Annotated Snippet
module_init(bpf_test_rqspinlock_init);
static void rqsl_print_histograms(void)
{
int cpu, i;
pr_err("rqspinlock acquisition latency histogram (ms):\n");
for_each_online_cpu(cpu) {
struct rqsl_cpu_hist *hist = per_cpu_ptr(&rqsl_cpu_hists, cpu);
u64 norm_counts[RQSL_NR_HIST_BUCKETS];
u64 nmi_counts[RQSL_NR_HIST_BUCKETS];
u64 total_counts[RQSL_NR_HIST_BUCKETS];
u64 norm_success, nmi_success, success_total;
u64 norm_failure, nmi_failure, failure_total;
u64 norm_total = 0, nmi_total = 0, total = 0;
bool has_slow = false;
for (i = 0; i < RQSL_NR_HIST_BUCKETS; i++) {
norm_counts[i] = atomic64_read(&hist->hist[RQSL_CTX_NORMAL][i]);
nmi_counts[i] = atomic64_read(&hist->hist[RQSL_CTX_NMI][i]);
total_counts[i] = norm_counts[i] + nmi_counts[i];
norm_total += norm_counts[i];
nmi_total += nmi_counts[i];
total += total_counts[i];
if (rqsl_hist_ms[i] > RQSL_SLOW_THRESHOLD_MS &&
total_counts[i])
has_slow = true;
}
norm_success = atomic64_read(&hist->success[RQSL_CTX_NORMAL]);
nmi_success = atomic64_read(&hist->success[RQSL_CTX_NMI]);
norm_failure = atomic64_read(&hist->failure[RQSL_CTX_NORMAL]);
nmi_failure = atomic64_read(&hist->failure[RQSL_CTX_NMI]);
success_total = norm_success + nmi_success;
failure_total = norm_failure + nmi_failure;
if (!total)
continue;
if (!has_slow) {
pr_err(" cpu%d: total %llu (normal %llu, nmi %llu) | "
"success %llu (normal %llu, nmi %llu) | "
"failure %llu (normal %llu, nmi %llu), all within 0-%ums\n",
cpu, total, norm_total, nmi_total,
success_total, norm_success, nmi_success,
failure_total, norm_failure, nmi_failure,
RQSL_SLOW_THRESHOLD_MS);
continue;
}
pr_err(" cpu%d: total %llu (normal %llu, nmi %llu) | "
"success %llu (normal %llu, nmi %llu) | "
"failure %llu (normal %llu, nmi %llu)\n",
cpu, total, norm_total, nmi_total,
success_total, norm_success, nmi_success,
failure_total, norm_failure, nmi_failure);
for (i = 0; i < RQSL_NR_HIST_BUCKETS; i++) {
unsigned int start_ms;
if (!total_counts[i])
continue;
start_ms = i == 0 ? 0 : rqsl_hist_ms[i - 1] + 1;
if (i == RQSL_NR_HIST_BUCKETS - 1) {
pr_err(" >= %ums: total %llu (normal %llu, nmi %llu)\n",
start_ms, total_counts[i],
norm_counts[i], nmi_counts[i]);
} else {
pr_err(" %u-%ums: total %llu (normal %llu, nmi %llu)\n",
start_ms, rqsl_hist_ms[i],
total_counts[i],
norm_counts[i], nmi_counts[i]);
}
}
}
}
static void bpf_test_rqspinlock_exit(void)
{
WRITE_ONCE(pause, 1);
free_rqsl_threads();
free_rqsl_evts();
rqsl_print_histograms();
}
module_exit(bpf_test_rqspinlock_exit);
MODULE_AUTHOR("Kumar Kartikeya Dwivedi");
MODULE_DESCRIPTION("BPF rqspinlock stress test module");
Annotation
- Immediate include surface: `linux/sched.h`, `linux/smp.h`, `linux/delay.h`, `linux/module.h`, `linux/prandom.h`, `linux/ktime.h`, `asm/rqspinlock.h`, `linux/perf_event.h`.
- Detected declarations: `struct rqsl_cpu_hist`, `struct rqsl_lock_pair`, `enum rqsl_context`, `enum rqsl_mode`, `function rqsl_get_lock_pair`, `function rqsl_hist_bucket_idx`, `function rqsl_record_lock_result`, `function rqspinlock_worker_fn`, `function nmi_cb`, `function free_rqsl_threads`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.