kernel/locking/lockdep.c
Source file repositories/reference/linux-study-clean/kernel/locking/lockdep.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/locking/lockdep.c- Extension
.c- Size
- 180070 bytes
- Lines
- 6881
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mutex.hlinux/sched.hlinux/sched/clock.hlinux/sched/task.hlinux/sched/mm.hlinux/delay.hlinux/module.hlinux/proc_fs.hlinux/seq_file.hlinux/spinlock.hlinux/kallsyms.hlinux/interrupt.hlinux/stacktrace.hlinux/debug_locks.hlinux/irqflags.hlinux/utsname.hlinux/hash.hlinux/ftrace.hlinux/stringify.hlinux/bitmap.hlinux/bitops.hlinux/gfp.hlinux/random.hlinux/jhash.hlinux/nmi.hlinux/rcupdate.hlinux/kprobes.hlinux/lockdep.hlinux/context_tracking.hlinux/console.hlinux/kasan.hasm/sections.h
Detected Declarations
struct pending_freestruct lock_tracestruct circular_queueenum bfs_resultfunction kernel_lockdep_sysctls_initfunction lockdep_enabledfunction lockdep_lockfunction lockdep_unlockfunction lockdep_assert_lockedfunction graph_lockfunction itfunction graph_unlockfunction debug_locks_off_graph_unlockfunction lockstat_clockfunction lock_pointfunction lock_time_incfunction lock_time_addfunction lock_statsfunction clear_lock_statsfunction for_each_possible_cpufunction lock_release_holdtimefunction lock_release_holdtimefunction hlock_idfunction chain_hlock_class_idxfunction iterate_chain_keyfunction lockdep_init_taskfunction lockdep_recursion_incfunction lockdep_recursion_finishfunction lockdep_set_selftest_taskfunction class_filterfunction verbosefunction print_lockdep_offfunction traces_identicalfunction lockdep_stack_trace_countfunction hlist_for_each_entryfunction lockdep_stack_hash_countfunction lock_flagfunction get_usage_charfunction get_usage_charsfunction __print_lock_namefunction print_lock_namefunction print_lockdep_cachefunction print_lockfunction lockdep_print_held_locksfunction print_kernel_identfunction very_verbosefunction static_objfunction count_matching_names
Annotated Snippet
struct pending_free {
struct list_head zapped;
DECLARE_BITMAP(lock_chains_being_freed, MAX_LOCKDEP_CHAINS);
};
/**
* struct delayed_free - data structures used for delayed freeing
*
* A data structure for delayed freeing of data structures that may be
* accessed by RCU readers at the time these were freed.
*
* @rcu_head: Used to schedule an RCU callback for freeing data structures.
* @index: Index of @pf to which freed data structures are added.
* @scheduled: Whether or not an RCU callback has been scheduled.
* @pf: Array with information about data structures about to be freed.
*/
static struct delayed_free {
struct rcu_head rcu_head;
int index;
int scheduled;
struct pending_free pf[2];
} delayed_free;
/*
* The lockdep classes are in a hash-table as well, for fast lookup:
*/
#define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
#define CLASSHASH_SIZE (1UL << CLASSHASH_BITS)
#define __classhashfn(key) hash_long((unsigned long)key, CLASSHASH_BITS)
#define classhashentry(key) (classhash_table + __classhashfn((key)))
static struct hlist_head classhash_table[CLASSHASH_SIZE];
/*
* We put the lock dependency chains into a hash-table as well, to cache
* their existence:
*/
#define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
#define CHAINHASH_SIZE (1UL << CHAINHASH_BITS)
#define __chainhashfn(chain) hash_long(chain, CHAINHASH_BITS)
#define chainhashentry(chain) (chainhash_table + __chainhashfn((chain)))
static struct hlist_head chainhash_table[CHAINHASH_SIZE];
/*
* the id of held_lock
*/
static inline u16 hlock_id(struct held_lock *hlock)
{
BUILD_BUG_ON(MAX_LOCKDEP_KEYS_BITS + 2 > 16);
return (hlock->class_idx | (hlock->read << MAX_LOCKDEP_KEYS_BITS));
}
static inline __maybe_unused unsigned int chain_hlock_class_idx(u16 hlock_id)
{
return hlock_id & (MAX_LOCKDEP_KEYS - 1);
}
/*
* The hash key of the lock dependency chains is a hash itself too:
* it's a hash of all locks taken up to that lock, including that lock.
* It's a 64-bit hash, because it's important for the keys to be
* unique.
*/
static inline u64 iterate_chain_key(u64 key, u32 idx)
{
u32 k0 = key, k1 = key >> 32;
__jhash_mix(idx, k0, k1); /* Macro that modifies arguments! */
return k0 | (u64)k1 << 32;
}
void lockdep_init_task(struct task_struct *task)
{
task->lockdep_depth = 0; /* no locks held yet */
task->curr_chain_key = INITIAL_CHAIN_KEY;
task->lockdep_recursion = 0;
}
static __always_inline void lockdep_recursion_inc(void)
{
__this_cpu_inc(lockdep_recursion);
}
static __always_inline void lockdep_recursion_finish(void)
{
if (WARN_ON_ONCE(__this_cpu_dec_return(lockdep_recursion)))
__this_cpu_write(lockdep_recursion, 0);
Annotation
- Immediate include surface: `linux/mutex.h`, `linux/sched.h`, `linux/sched/clock.h`, `linux/sched/task.h`, `linux/sched/mm.h`, `linux/delay.h`, `linux/module.h`, `linux/proc_fs.h`.
- Detected declarations: `struct pending_free`, `struct lock_trace`, `struct circular_queue`, `enum bfs_result`, `function kernel_lockdep_sysctls_init`, `function lockdep_enabled`, `function lockdep_lock`, `function lockdep_unlock`, `function lockdep_assert_locked`, `function graph_lock`.
- 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.