函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\locking\mutex.c Create Date:2022-07-27 10:47:51
Last Modify:2020-03-12 14:18:49 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:Lock a mutex (possibly interruptible), slowpath:

函数原型:static __always_inline int __sched __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, struct lockdep_map *nest_lock, unsigned long ip, struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)

返回类型:int

参数:

类型参数名称
struct mutex *lock
longstate
unsigned intsubclass
struct lockdep_map *nest_lock
unsigned longip
struct ww_acquire_ctx *ww_ctx
const booluse_ww_ctx
931  bool first = false
935  might_sleep()
941  ww等于container_of - cast a member of a structure out to the containing structure*@ptr: the pointer to the member.*@type: the type of the container struct this is embedded in.*@member: the name of the member within the struct.(lock, structww_mutex, base)
942  如果use_ww_ctxww_ctx
943  如果此条件成立可能性小(为编译器优化)(ww_ctx == READ_ONCE(ctx))则返回:负EALREADY
951  如果acquired恒等于0则wounded等于0
955  禁止抢占()
956  mutex_acquire_nest( & dep_map, subclass, 0, nest_lock, ip)
958  如果Actual trylock that will work on any unlocked state.mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, NULL)则
961  lock_acquired( & dep_map, ip)
962  如果use_ww_ctxww_ctxAfter acquiring lock with fastpath, where we do not hold wait_lock, set ctx* and wake up any waiters so they can recheck.
964  禁用抢占和中断()
965  返回:0
968  加自旋锁
972  如果Actual trylock that will work on any unlocked state.
973  如果use_ww_ctxww_ctxWe just acquired @lock under @ww_ctx, if there are later contexts waiting* behind us on the wait-list, check if they need to die, or wound us.* See __ww_mutex_add_waiter() for the list-order construction; basically the
976  转到:skip_wait
979  debug_mutex_lock_common(lock, & waiter)
981  lock_contended( & dep_map, ip)
983  如果非use_ww_ctx
985  Add @waiter to a given location in the lock wait_list and set the* FLAG_WAITERS flag if it's the first waiter.
991  否则
996  ret等于Add @waiter to the wait-list, keep the wait-list ordered by stamp, smallest* first
997  如果ret则转到:err_early_kill
1000  ww_ctx等于ww_ctx
1003  task等于当前进程
1005  set_current_state(state)
1006  循环
1013  如果Actual trylock that will work on any unlocked state.则转到:acquired
1022  ret等于负EINTR
1023  转到:err
1026  如果use_ww_ctxww_ctx
1028  如果ret则转到:err
1032  自旋锁解锁
1033  schedule_preempt_disabled - called with preemption disabled* Returns with preemption disabled. Note: preempt_count must be 1
1039  如果use_ww_ctxww_ctx或非first
1045  set_current_state(state)
1051  如果Actual trylock that will work on any unlocked state.firstmutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, & waiter)则退出
1055  加自旋锁
1057  加自旋锁
1058  acquired :
1059  set_current_state() includes a barrier so that the write of current->state* is correctly serialised wrt the caller's subsequent test of whether to* actually sleep:* for (;;) {* set_current_state(TASK_UNINTERRUPTIBLE);* if (!need_sleep)* break;* (就绪态)
1061  如果use_ww_ctxww_ctx
1066  如果非is_wait_die且非__mutex_waiter_is_first(lock, & waiter)则We just acquired @lock under @ww_ctx, if there are later contexts waiting* behind us on the wait-list, check if they need to die, or wound us.* See __ww_mutex_add_waiter() for the list-order construction; basically the
1071  Mutexes: blocking mutual exclusion locks* started by Ingo Molnar:* Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar * This file contains mutex debugging related internal prototypes, for the* !CONFIG_DEBUG_MUTEXES case(lock, & waiter, 当前进程)
1072  如果此条件成立可能性大(为编译器优化)(链表为空)则__mutex_clear_flag(lock, MUTEX_FLAGS)
1075  debug_mutex_free_waiter( & waiter)
1077  skip_wait :
1079  lock_acquired( & dep_map, ip)
1081  如果use_ww_ctxww_ctxAssociate the ww_mutex @ww with the context @ww_ctx under which we acquired* it.
1084  自旋锁解锁
1085  禁用抢占和中断()
1086  返回:0
1088  err :
1089  set_current_state() includes a barrier so that the write of current->state* is correctly serialised wrt the caller's subsequent test of whether to* actually sleep:* for (;;) {* set_current_state(TASK_UNINTERRUPTIBLE);* if (!need_sleep)* break;* (就绪态)
1090  Mutexes: blocking mutual exclusion locks* started by Ingo Molnar:* Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar * This file contains mutex debugging related internal prototypes, for the* !CONFIG_DEBUG_MUTEXES case(lock, & waiter, 当前进程)
1091  err_early_kill :
1092  自旋锁解锁
1093  debug_mutex_free_waiter( & waiter)
1094  mutex_release( & dep_map, ip)
1095  禁用抢占和中断()
1096  返回:ret
调用者
名称描述
__mutex_lock
__ww_mutex_lock
mutex_lock_io_nested