kernel/locking/ww_mutex.h
Source file repositories/reference/linux-study-clean/kernel/locking/ww_mutex.h
File Facts
- System
- Linux kernel
- Corpus path
kernel/locking/ww_mutex.h- Extension
.h- Size
- 16263 bytes
- Lines
- 636
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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
- No C-style include directives detected by the generator.
Detected Declarations
function __ww_waiter_firstfunction __ww_waiter_nextfunction __ww_waiter_prevfunction __ww_waiter_lastfunction __ww_waiter_addfunction __ww_mutex_ownerfunction __ww_mutex_has_waitersfunction lock_wait_lockfunction unlock_wait_lockfunction lockdep_assert_wait_lock_heldfunction __ww_waiter_firstfunction __ww_waiter_nextfunction __ww_waiter_prevfunction __ww_waiter_lastfunction __ww_waiter_addfunction __ww_mutex_has_waitersfunction lock_wait_lockfunction unlock_wait_lockfunction lockdep_assert_wait_lock_heldfunction Itfunction __ww_ctx_lessfunction alreadyfunction __ww_mutex_woundfunction wake_up_processfunction __ww_mutex_check_waitersfunction ww_mutex_set_context_fastpathfunction __ww_mutex_killfunction __ww_mutex_add_waiterfunction __ww_mutex_add_waiterfunction __ww_mutex_unlock
Annotated Snippet
if (dl_prio(a_prio)) {
if (dl_time_before(b->task->dl.deadline,
a->task->dl.deadline))
return true;
if (dl_time_before(a->task->dl.deadline,
b->task->dl.deadline))
return false;
}
/* equal prio */
}
#endif
/* FIFO order tie break -- bigger is younger */
return (signed long)(a->stamp - b->stamp) > 0;
}
/*
* Wait-Die; wake a lesser waiter context (when locks held) such that it can
* die.
*
* Among waiters with context, only the first one can have other locks acquired
* already (ctx->acquired > 0), because __ww_mutex_add_waiter() and
* __ww_mutex_check_kill() wake any but the earliest context.
*/
static bool
__ww_mutex_die(struct MUTEX *lock, struct MUTEX_WAITER *waiter,
struct ww_acquire_ctx *ww_ctx, struct wake_q_head *wake_q)
{
if (!ww_ctx->is_wait_die)
return false;
if (waiter->ww_ctx->acquired > 0 && __ww_ctx_less(waiter->ww_ctx, ww_ctx)) {
#ifndef WW_RT
debug_mutex_wake_waiter(lock, waiter);
#endif
/*
* When waking up the task to die, be sure to set the
* blocked_on to PROXY_WAKING. Otherwise we can see
* circular blocked_on relationships that can't resolve.
*/
clear_task_blocked_on(waiter->task, lock);
wake_q_add(wake_q, waiter->task);
}
return true;
}
/*
* Wound-Wait; wound a lesser @hold_ctx if it holds the lock.
*
* Wound the lock holder if there are waiters with more important transactions
* than the lock holders. Even if multiple waiters may wound the lock holder,
* it's sufficient that only one does.
*/
static bool __ww_mutex_wound(struct MUTEX *lock,
struct ww_acquire_ctx *ww_ctx,
struct ww_acquire_ctx *hold_ctx,
struct wake_q_head *wake_q)
__must_hold(&lock->WAIT_LOCK)
{
struct task_struct *owner = __ww_mutex_owner(lock);
lockdep_assert_wait_lock_held(lock);
/*
* Possible through __ww_mutex_add_waiter() when we race with
* ww_mutex_set_context_fastpath(). In that case we'll get here again
* through __ww_mutex_check_waiters().
*/
if (!hold_ctx)
return false;
/*
* Can have !owner because of __mutex_unlock_slowpath(), but if owner,
* it cannot go away because we'll have FLAG_WAITERS set and hold
* wait_lock.
*/
if (!owner)
return false;
if (ww_ctx->acquired > 0 && __ww_ctx_less(hold_ctx, ww_ctx)) {
hold_ctx->wounded = 1;
/*
* wake_up_process() paired with set_current_state()
* inserts sufficient barriers to make sure @owner either sees
* it's wounded in __ww_mutex_check_kill() or has a
* wakeup pending to re-read the wounded state.
Annotation
- Detected declarations: `function __ww_waiter_first`, `function __ww_waiter_next`, `function __ww_waiter_prev`, `function __ww_waiter_last`, `function __ww_waiter_add`, `function __ww_mutex_owner`, `function __ww_mutex_has_waiters`, `function lock_wait_lock`, `function unlock_wait_lock`, `function lockdep_assert_wait_lock_held`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.