tools/testing/selftests/membarrier/membarrier_rseq_stress.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/membarrier/membarrier_rseq_stress.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/membarrier/membarrier_rseq_stress.c- Extension
.c- Size
- 25054 bytes
- Lines
- 952
- 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.
- 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
stdio.hstdlib.hstring.hunistd.hpthread.hsyscall.hsys/stat.hsys/types.hsys/wait.hfcntl.hstdint.herrno.hsched.htime.hsignal.hstdatomic.hdirent.hsys/prctl.hsys/mman.h../kselftest.hlinux/compiler.h
Detected Declarations
struct rseq_abistruct leaf_infofunction write_filefunction monotonic_usfunction update_max_latencyfunction init_stress_cpusfunction rseq_register_threadfunction rseq_register_thread_atfunction membarrier_register_rseq_mmfunction rm_cgroup_recursivefunction cgroup_setupfunction cgroup_add_pid_to_pathfunction cgroup_teardownfunction cgroup_unthrottlefunction burner_thread_fn_wrapperfunction leaf_child_fnfunction run_throttle_childfunction main
Annotated Snippet
struct rseq_abi {
__u32 cpu_id_start;
__u32 cpu_id;
__u64 rseq_cs;
__u32 flags;
__u32 node_id;
__u32 mm_cid;
char end[0];
} __aligned(32);
/* -- membarrier constants (not in all distro headers) -- */
#ifndef MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ
# define MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ (1 << 7)
#endif
#ifndef MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ
# define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ (1 << 8)
#endif
#ifndef MEMBARRIER_CMD_FLAG_CPU
# define MEMBARRIER_CMD_FLAG_CPU (1 << 0)
#endif
/* -- Test parameters -- */
#define N_SIBLINGS 2000
#define NEST_DEPTH 5
static char g_cgroup_path[4096];
static int use_cgroup_v2;
#define CFS_QUOTA_US 1000
#define CFS_PERIOD_US 5000
#define N_HAMMER_PER_CPU 25
#define N_BURNER_PER_CPU 50
#define MAX_STRESS_CPUS 1024
#define TEST_DURATION_SEC 20
/* Latency thresholds for the sentinel */
#define LATENCY_WARN_MS 50
#define LATENCY_CRITICAL_MS 200
/* Sentinel sampling interval */
#define SENTINEL_INTERVAL_US 500
/* -- Shared globals -- */
static atomic_int g_stop;
static atomic_int g_stop_sentinel;
static atomic_long g_max_latency_us;
static atomic_long g_interval_max_latency_us;
static atomic_long g_mb_ok;
static atomic_long g_mb_err;
static int g_ncpus_stress;
static int *g_stress_cpus;
static atomic_int g_test_ready;
/* Per-thread rseq ABI block registered with the kernel */
static __thread struct rseq_abi tls_rseq
__attribute__((tls_model("initial-exec"))) __aligned(32) = {
.cpu_id = RSEQ_CPU_ID_UNINITIALIZED,
};
/* -- Utility -- */
static int write_file(const char *path, const char *val)
{
int fd = open(path, O_WRONLY | O_CLOEXEC);
if (fd < 0)
return -errno;
size_t len = strlen(val);
ssize_t r = write(fd, val, len);
close(fd);
if (r < 0)
return -errno;
if ((size_t)r != len)
return -EIO;
return 0;
}
static uint64_t monotonic_us(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000ULL;
}
static void update_max_latency(long lat)
{
long old = atomic_load_explicit(&g_max_latency_us, memory_order_relaxed);
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `pthread.h`, `syscall.h`, `sys/stat.h`, `sys/types.h`.
- Detected declarations: `struct rseq_abi`, `struct leaf_info`, `function write_file`, `function monotonic_us`, `function update_max_latency`, `function init_stress_cpus`, `function rseq_register_thread`, `function rseq_register_thread_at`, `function membarrier_register_rseq_mm`, `function rm_cgroup_recursive`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.