kernel/rcu/srcutree.c
Source file repositories/reference/linux-study-clean/kernel/rcu/srcutree.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/rcu/srcutree.c- Extension
.c- Size
- 78978 bytes
- Lines
- 2204
- 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/export.hlinux/mutex.hlinux/percpu.hlinux/preempt.hlinux/irq_work.hlinux/rcupdate_wait.hlinux/sched.hlinux/smp.hlinux/delay.hlinux/module.hlinux/slab.hlinux/srcu.hrcu.hrcu_segcblist.h
Detected Declarations
function srcu_read_lockfunction srcu_invl_snp_seqfunction init_srcu_struct_nodesfunction init_srcu_struct_fieldsfunction __init_srcu_struct_commonfunction __init_srcu_structfunction __init_srcu_struct_fastfunction __init_srcu_struct_fast_updownfunction DEFINE_SRCUfunction DEFINE_SRCU_FASTfunction DEFINE_SRCU_FAST_UPDOWNfunction __srcu_transition_to_bigfunction srcu_transition_to_bigfunction raw_spin_lock_irqsave_check_contentionfunction raw_spin_lock_irqsave_sdp_contentionfunction raw_spin_lock_irqsave_ssp_contentionfunction check_init_srcu_structfunction srcu_gp_is_expeditedfunction barrierfunction for_each_possible_cpufunction srcu_readers_unlock_idxfunction for_each_possible_cpufunction srcu_readers_active_idx_checkfunction srcu_readers_activefunction for_each_possible_cpufunction srcu_get_delayfunction init_srcu_structfunction WARN_ONfunction __srcu_check_read_flavorfunction __srcu_read_unlockfunction srcu_read_lockfunction srcu_read_unlockfunction srcu_read_lockfunction srcu_gp_startfunction srcu_delay_timerfunction srcu_queue_delayed_work_onfunction srcu_schedule_cbs_sdpfunction srcu_schedule_cbs_snpfunction srcu_gp_endfunction srcu_for_each_node_breadth_firstfunction for_each_possible_cpufunction ULONG_CMP_LTfunction srcu_funnel_exp_startfunction srcu_funnel_exp_startfunction rcu_seq_statefunction try_check_zerofunction srcu_flipfunction _lite
Annotated Snippet
if (snp == &ssp->srcu_sup->node[0]) {
/* Root node, special case. */
snp->srcu_parent = NULL;
continue;
}
/* Non-root node. */
if (snp == ssp->srcu_sup->level[level + 1])
level++;
snp->srcu_parent = ssp->srcu_sup->level[level - 1] +
(snp - ssp->srcu_sup->level[level]) /
levelspread[level - 1];
}
/*
* Initialize the per-CPU srcu_data array, which feeds into the
* leaves of the srcu_node tree.
*/
level = rcu_num_lvls - 1;
snp_first = ssp->srcu_sup->level[level];
for_each_possible_cpu(cpu) {
sdp = per_cpu_ptr(ssp->sda, cpu);
sdp->mynode = &snp_first[cpu / levelspread[level]];
for (snp = sdp->mynode; snp != NULL; snp = snp->srcu_parent) {
if (snp->grplo < 0)
snp->grplo = cpu;
snp->grphi = cpu;
}
sdp->grpmask = 1UL << (cpu - sdp->mynode->grplo);
}
smp_store_release(&ssp->srcu_sup->srcu_size_state, SRCU_SIZE_WAIT_BARRIER);
return true;
}
/*
* Initialize non-compile-time initialized fields, including the
* associated srcu_node and srcu_data structures. The is_static parameter
* tells us that ->sda has already been wired up to srcu_data.
*/
static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
{
if (!is_static)
ssp->srcu_sup = kzalloc_obj(*ssp->srcu_sup);
if (!ssp->srcu_sup)
return -ENOMEM;
if (!is_static)
raw_spin_lock_init(&ACCESS_PRIVATE(ssp->srcu_sup, lock));
ssp->srcu_sup->srcu_size_state = SRCU_SIZE_SMALL;
ssp->srcu_sup->node = NULL;
mutex_init(&ssp->srcu_sup->srcu_cb_mutex);
mutex_init(&ssp->srcu_sup->srcu_gp_mutex);
ssp->srcu_sup->srcu_gp_seq = SRCU_GP_SEQ_INITIAL_VAL;
ssp->srcu_sup->srcu_barrier_seq = 0;
mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
ssp->srcu_sup->sda_is_static = is_static;
if (!is_static) {
ssp->sda = alloc_percpu(struct srcu_data);
ssp->srcu_ctrp = &ssp->sda->srcu_ctrs[0];
}
if (!ssp->sda)
goto err_free_sup;
init_srcu_struct_data(ssp);
ssp->srcu_sup->srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL;
ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
if (READ_ONCE(ssp->srcu_sup->srcu_size_state) == SRCU_SIZE_SMALL && SRCU_SIZING_IS_INIT()) {
if (!preemptible())
WRITE_ONCE(ssp->srcu_sup->srcu_size_state, SRCU_SIZE_ALLOC);
else if (init_srcu_struct_nodes(ssp, GFP_KERNEL))
WRITE_ONCE(ssp->srcu_sup->srcu_size_state, SRCU_SIZE_BIG);
else
goto err_free_sda;
}
ssp->srcu_sup->srcu_ssp = ssp;
smp_store_release(&ssp->srcu_sup->srcu_gp_seq_needed,
SRCU_GP_SEQ_INITIAL_VAL); /* Init done. */
return 0;
err_free_sda:
if (!is_static) {
free_percpu(ssp->sda);
ssp->sda = NULL;
}
err_free_sup:
if (!is_static) {
kfree(ssp->srcu_sup);
ssp->srcu_sup = NULL;
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/mutex.h`, `linux/percpu.h`, `linux/preempt.h`, `linux/irq_work.h`, `linux/rcupdate_wait.h`, `linux/sched.h`, `linux/smp.h`.
- Detected declarations: `function srcu_read_lock`, `function srcu_invl_snp_seq`, `function init_srcu_struct_nodes`, `function init_srcu_struct_fields`, `function __init_srcu_struct_common`, `function __init_srcu_struct`, `function __init_srcu_struct_fast`, `function __init_srcu_struct_fast_updown`, `function DEFINE_SRCU`, `function DEFINE_SRCU_FAST`.
- 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.