函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

函数名称:Wait until we successfully acquire the write lock

函数原型:static struct rw_semaphore *rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)

返回类型:struct rw_semaphore

参数:

类型参数名称
struct rw_semaphore *sem
intstate
1145  ret等于sem
1149  如果rwsem_can_spin_on_owner(sem, RWSEM_WR_NONSPINNABLE)且rwsem_optimistic_spin(sem, true)则
1152  返回:sem
1160  disable_rspin等于atomic_long_read( & Write owner or one of the read owners as well flags regarding* the current state of the rwsem. Can be used as a speculative* check to see if the write owner is running on the cpu.)按位与RWSEM_NONSPINNABLE
1166  task等于当前进程
1167  type等于RWSEM_WAITING_FOR_WRITE
1168  timeout等于jiffiesThe typical HZ value is either 250 or 1000. So set the minimum waiting* time to at least 4ms or 1 jiffy (if it is higher than 4ms) in the wait* queue before initiating the handoff protocol.
1170  关闭本地中断,获取所要保护的运行队列(runqueue)的自旋锁(spinlock),为查找可运行进程做准备。( & wait_lock)
1173  wstate等于如果链表为空 Writer is first in wait list 否则 Writer is not first in wait list
1175  添加链表项
1178  如果wstate恒等于 Writer is not first in wait list
1179  count等于atomic_long_read( & count)
1189  如果count按位与RWSEM_WRITER_MASK则转到:wait
1192  handle the lock release when processes blocked on it that can now run* - if we come here from up_xxxx(), then the RWSEM_FLAG_WAITERS bit must* have been set
1196  如果非wake_q_empty( & wake_q)则
1202  wake_up_q( & wake_q)
1203  wake_q_init( & wake_q)
1206  否则
1207  atomic_long_or(RWSEM_FLAG_WAITERS, & count)
1210  wait :
1212  set_current_state(state)
1213  循环
1216  退出
1219  raw_spin_unlock_irq( & wait_lock)
1229  如果wstate恒等于WRITER_HANDOFFrwsem_spin_on_owner(sem, RWSEM_NONSPINNABLE)恒等于OWNER_NULL则转到:trylock_again
1234  循环
1238  进程调度
1245  如果wstate恒等于WRITER_HANDOFF退出
1252  count等于atomic_long_read( & count)
1253  如果非count按位与RWSEM_LOCK_MASK的值则退出
1262  wstate等于WRITER_HANDOFF
1264  退出
1267  trylock_again :
1268  关闭本地中断,获取所要保护的运行队列(runqueue)的自旋锁(spinlock),为查找可运行进程做准备。( & wait_lock)
1270  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;* (就绪态)
1271  删除链表项
1272  This function is called by the a write lock owner. So the owner value* won't get changed by others.
1273  raw_spin_unlock_irq( & wait_lock)
1276  返回:ret
1278  out_nolock :
1279  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;* (就绪态)
1280  关闭本地中断,获取所要保护的运行队列(runqueue)的自旋锁(spinlock),为查找可运行进程做准备。( & wait_lock)
1281  删除链表项
1283  如果此条件成立可能性小(为编译器优化)(wstate == WRITER_HANDOFF)则atomic_long_add( - RWSEM_FLAG_HANDOFF, & count)
1286  如果链表为空atomic_long_andnot(RWSEM_FLAG_WAITERS, & count)
1288  否则handle the lock release when processes blocked on it that can now run* - if we come here from up_xxxx(), then the RWSEM_FLAG_WAITERS bit must* have been set
1290  raw_spin_unlock_irq( & wait_lock)
1291  wake_up_q( & wake_q)
1294  返回:错误号
调用者
名称描述
__down_writelock for writing
__down_write_killable