hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/locking/rtmutex.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * RT-Mutexes: simple blocking mutual exclusion locks with PI support
34 *
....@@ -8,7 +9,7 @@
89 * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
910 * Copyright (C) 2006 Esben Nielsen
1011 *
11
- * See Documentation/locking/rt-mutex-design.txt for details.
12
+ * See Documentation/locking/rt-mutex-design.rst for details.
1213 */
1314 #include <linux/spinlock.h>
1415 #include <linux/export.h>
....@@ -18,6 +19,7 @@
1819 #include <linux/sched/wake_q.h>
1920 #include <linux/sched/debug.h>
2021 #include <linux/timer.h>
22
+#include <trace/hooks/dtask.h>
2123
2224 #include "rtmutex_common.h"
2325
....@@ -56,7 +58,7 @@
5658 if (rt_mutex_has_waiters(lock))
5759 val |= RT_MUTEX_HAS_WAITERS;
5860
59
- lock->owner = (struct task_struct *)val;
61
+ WRITE_ONCE(lock->owner, (struct task_struct *)val);
6062 }
6163
6264 static inline void clear_rt_mutex_waiters(struct rt_mutex *lock)
....@@ -140,7 +142,6 @@
140142 * set up.
141143 */
142144 #ifndef CONFIG_DEBUG_RT_MUTEXES
143
-# define rt_mutex_cmpxchg_relaxed(l,c,n) (cmpxchg_relaxed(&l->owner, c, n) == c)
144145 # define rt_mutex_cmpxchg_acquire(l,c,n) (cmpxchg_acquire(&l->owner, c, n) == c)
145146 # define rt_mutex_cmpxchg_release(l,c,n) (cmpxchg_release(&l->owner, c, n) == c)
146147
....@@ -201,7 +202,6 @@
201202 }
202203
203204 #else
204
-# define rt_mutex_cmpxchg_relaxed(l,c,n) (0)
205205 # define rt_mutex_cmpxchg_acquire(l,c,n) (0)
206206 # define rt_mutex_cmpxchg_release(l,c,n) (0)
207207
....@@ -627,8 +627,7 @@
627627 }
628628
629629 /* [10] Grab the next task, i.e. owner of @lock */
630
- task = rt_mutex_owner(lock);
631
- get_task_struct(task);
630
+ task = get_task_struct(rt_mutex_owner(lock));
632631 raw_spin_lock(&task->pi_lock);
633632
634633 /*
....@@ -708,8 +707,7 @@
708707 }
709708
710709 /* [10] Grab the next task, i.e. the owner of @lock */
711
- task = rt_mutex_owner(lock);
712
- get_task_struct(task);
710
+ task = get_task_struct(rt_mutex_owner(lock));
713711 raw_spin_lock(&task->pi_lock);
714712
715713 /* [11] requeue the pi waiters if necessary */
....@@ -1171,6 +1169,7 @@
11711169 {
11721170 int ret = 0;
11731171
1172
+ trace_android_vh_rtmutex_wait_start(lock);
11741173 for (;;) {
11751174 /* Try to acquire the lock: */
11761175 if (try_to_take_rt_mutex(lock, current, waiter))
....@@ -1200,6 +1199,7 @@
12001199 set_current_state(state);
12011200 }
12021201
1202
+ trace_android_vh_rtmutex_wait_finish(lock);
12031203 __set_current_state(TASK_RUNNING);
12041204 return ret;
12051205 }
....@@ -1441,7 +1441,7 @@
14411441 }
14421442
14431443 /*
1444
- * Performs the wakeup of the the top-waiter and re-enables preemption.
1444
+ * Performs the wakeup of the top-waiter and re-enables preemption.
14451445 */
14461446 void rt_mutex_postunlock(struct wake_q_head *wake_q)
14471447 {
....@@ -1471,6 +1471,7 @@
14711471
14721472 mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
14731473 rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
1474
+ trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
14741475 }
14751476
14761477 #ifdef CONFIG_DEBUG_LOCK_ALLOC
....@@ -1485,9 +1486,9 @@
14851486 __rt_mutex_lock(lock, subclass);
14861487 }
14871488 EXPORT_SYMBOL_GPL(rt_mutex_lock_nested);
1488
-#endif
14891489
1490
-#ifndef CONFIG_DEBUG_LOCK_ALLOC
1490
+#else /* !CONFIG_DEBUG_LOCK_ALLOC */
1491
+
14911492 /**
14921493 * rt_mutex_lock - lock a rt_mutex
14931494 *
....@@ -1518,7 +1519,9 @@
15181519 mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
15191520 ret = rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
15201521 if (ret)
1521
- mutex_release(&lock->dep_map, 1, _RET_IP_);
1522
+ mutex_release(&lock->dep_map, _RET_IP_);
1523
+ else
1524
+ trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
15221525
15231526 return ret;
15241527 }
....@@ -1562,7 +1565,9 @@
15621565 RT_MUTEX_MIN_CHAINWALK,
15631566 rt_mutex_slowlock);
15641567 if (ret)
1565
- mutex_release(&lock->dep_map, 1, _RET_IP_);
1568
+ mutex_release(&lock->dep_map, _RET_IP_);
1569
+ else
1570
+ trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
15661571
15671572 return ret;
15681573 }
....@@ -1589,6 +1594,8 @@
15891594 ret = rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
15901595 if (ret)
15911596 mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
1597
+ else
1598
+ trace_android_vh_record_rtmutex_lock_starttime(current, jiffies);
15921599
15931600 return ret;
15941601 }
....@@ -1601,8 +1608,9 @@
16011608 */
16021609 void __sched rt_mutex_unlock(struct rt_mutex *lock)
16031610 {
1604
- mutex_release(&lock->dep_map, 1, _RET_IP_);
1611
+ mutex_release(&lock->dep_map, _RET_IP_);
16051612 rt_mutex_fastunlock(lock, rt_mutex_slowunlock);
1613
+ trace_android_vh_record_rtmutex_lock_starttime(current, 0);
16061614 }
16071615 EXPORT_SYMBOL_GPL(rt_mutex_unlock);
16081616
....@@ -1835,7 +1843,7 @@
18351843 * been started.
18361844 * @waiter: the pre-initialized rt_mutex_waiter
18371845 *
1838
- * Wait for the the lock acquisition started on our behalf by
1846
+ * Wait for the lock acquisition started on our behalf by
18391847 * rt_mutex_start_proxy_lock(). Upon failure, the caller must call
18401848 * rt_mutex_cleanup_proxy_lock().
18411849 *