kernel/torture.c
Source file repositories/reference/linux-study-clean/kernel/torture.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/torture.c- Extension
.c- Size
- 27217 bytes
- Lines
- 991
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/kernel.hlinux/init.hlinux/module.hlinux/kthread.hlinux/err.hlinux/spinlock.hlinux/smp.hlinux/interrupt.hlinux/sched.hlinux/sched/clock.hlinux/atomic.hlinux/bitops.hlinux/completion.hlinux/moduleparam.hlinux/percpu.hlinux/notifier.hlinux/reboot.hlinux/freezer.hlinux/cpu.hlinux/delay.hlinux/stat.hlinux/slab.hlinux/trace_clock.hlinux/ktime.hasm/byteorder.hlinux/torture.hlinux/sched/rt.hrcu/rcu.h
Detected Declarations
struct shuffle_taskfunction verbose_torout_sleepfunction torture_hrtimeout_nsfunction nanosecondfunction microsecondfunction schedule_timeout_interruptiblefunction millisecondfunction torture_num_online_cpusfunction torture_offlinefunction torture_onlinefunction torture_online_allfunction for_each_possible_cpufunction torture_onofffunction torture_onoff_initfunction torture_onoff_cleanupfunction torture_onoff_statsfunction torture_onoff_failuresfunction torture_randomfunction torture_shuffle_task_registerfunction torture_shuffle_task_unregister_allfunction torture_shuffle_tasksfunction torture_shufflefunction torture_shuffle_initfunction torture_shuffle_cleanupfunction torture_shutdown_absorbfunction torture_shutdownfunction torture_shutdown_initfunction torture_shutdown_notifyfunction torture_shutdown_cleanupfunction stutter_waitfunction torture_stutterfunction torture_stutter_initfunction torture_stutter_cleanupfunction torture_print_module_parmsfunction module_initfunction torture_init_endfunction torture_init_beginfunction module_exitfunction torture_cleanup_endfunction torture_must_stopfunction torture_must_stop_irqfunction kthread_should_stopfunction _torture_create_kthreadfunction _torture_stop_kthreadfunction torture_sched_set_normalexport verbose_torout_sleepexport torture_hrtimeout_nsexport torture_hrtimeout_us
Annotated Snippet
* the usual module_init() mechanism, but rather by an explicit call from
* the client torture module. This call must be paired with a later
* torture_init_end().
*
* The runnable parameter points to a flag that controls whether or not
* the test is currently runnable. If there is no such flag, pass in NULL.
*/
bool torture_init_begin(char *ttype, int v)
{
mutex_lock(&fullstop_mutex);
if (torture_type != NULL) {
pr_alert("%s: Refusing %s init: %s running.\n",
__func__, ttype, torture_type);
pr_alert("%s: One torture test at a time!\n", __func__);
mutex_unlock(&fullstop_mutex);
return false;
}
torture_type = ttype;
verbose = v;
fullstop = FULLSTOP_DONTSTOP;
WRITE_ONCE(torture_init_jiffies, jiffies); // Lockless reads.
torture_print_module_parms();
return true;
}
EXPORT_SYMBOL_GPL(torture_init_begin);
/*
* Tell the torture module that initialization is complete.
*/
void torture_init_end(void)
{
mutex_unlock(&fullstop_mutex);
register_reboot_notifier(&torture_shutdown_nb);
}
EXPORT_SYMBOL_GPL(torture_init_end);
/*
* Get the torture_init_begin()-time value of the jiffies counter.
*/
unsigned long get_torture_init_jiffies(void)
{
return READ_ONCE(torture_init_jiffies);
}
EXPORT_SYMBOL_GPL(get_torture_init_jiffies);
/*
* Clean up torture module. Please note that this is -not- invoked via
* the usual module_exit() mechanism, but rather by an explicit call from
* the client torture module. Returns true if a race with system shutdown
* is detected, otherwise, all kthreads started by functions in this file
* will be shut down.
*
* This must be called before the caller starts shutting down its own
* kthreads.
*
* Both torture_cleanup_begin() and torture_cleanup_end() must be paired,
* in order to correctly perform the cleanup. They are separated because
* threads can still need to reference the torture_type type, thus nullify
* only after completing all other relevant calls.
*/
bool torture_cleanup_begin(void)
{
mutex_lock(&fullstop_mutex);
if (READ_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
pr_warn("Concurrent rmmod and shutdown illegal!\n");
mutex_unlock(&fullstop_mutex);
schedule_timeout_uninterruptible(10);
return true;
}
WRITE_ONCE(fullstop, FULLSTOP_RMMOD);
mutex_unlock(&fullstop_mutex);
torture_shutdown_cleanup();
torture_shuffle_cleanup();
torture_stutter_cleanup();
torture_onoff_cleanup();
return false;
}
EXPORT_SYMBOL_GPL(torture_cleanup_begin);
void torture_cleanup_end(void)
{
mutex_lock(&fullstop_mutex);
torture_type = NULL;
mutex_unlock(&fullstop_mutex);
}
EXPORT_SYMBOL_GPL(torture_cleanup_end);
/*
* Is it time for the current torture test to stop?
*/
Annotation
- Immediate include surface: `linux/types.h`, `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/kthread.h`, `linux/err.h`, `linux/spinlock.h`, `linux/smp.h`.
- Detected declarations: `struct shuffle_task`, `function verbose_torout_sleep`, `function torture_hrtimeout_ns`, `function nanosecond`, `function microsecond`, `function schedule_timeout_interruptible`, `function millisecond`, `function torture_num_online_cpus`, `function torture_offline`, `function torture_online`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.