From bc97d5019afdfa2a26cd39d6556ace0e55269919 Mon Sep 17 00:00:00 2001 From: xieliujie Date: Mon, 25 Dec 2023 14:28:51 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks for rt_mutex steal Add hooks at rt_mutex_steal function so that oems can decide whether tasks with the same priority steal the rt_mutex or not. We did experiments and found that rt_mutex throughput can benefit a lot when threads with the same priority can steal the rt_mutex lock. Bug: 317670024 Change-Id: Id60a7a41c6c77a67808982d3667946cabe4acc8f Signed-off-by: xeiliujie --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/dtask.h | 3 +++ kernel/locking/rtmutex.c | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 43eb748c1103..ee68032b1918 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -95,6 +95,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_task_blocks_on_rtmutex); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rtmutex_waiter_prio); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rtmutex_wait_start); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rtmutex_wait_finish); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rt_mutex_steal); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_opt_spin_start); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_opt_spin_finish); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_can_spin_on_owner); diff --git a/include/trace/hooks/dtask.h b/include/trace/hooks/dtask.h index a63a2868e626..b51147089b2d 100644 --- a/include/trace/hooks/dtask.h +++ b/include/trace/hooks/dtask.h @@ -42,6 +42,9 @@ DECLARE_HOOK(android_vh_rtmutex_wait_start, DECLARE_HOOK(android_vh_rtmutex_wait_finish, TP_PROTO(struct rt_mutex_base *lock), TP_ARGS(lock)); +DECLARE_HOOK(android_vh_rt_mutex_steal, + TP_PROTO(int waiter_prio, int top_waiter_prio, bool *ret), + TP_ARGS(waiter_prio, top_waiter_prio, ret)); DECLARE_HOOK(android_vh_rwsem_read_wait_start, TP_PROTO(struct rw_semaphore *sem), diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 351716fe9138..8207fdade4a8 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -391,9 +391,15 @@ static __always_inline int rt_mutex_waiter_equal(struct rt_mutex_waiter *left, static inline bool rt_mutex_steal(struct rt_mutex_waiter *waiter, struct rt_mutex_waiter *top_waiter) { + bool ret = false; + if (rt_mutex_waiter_less(waiter, top_waiter)) return true; + trace_android_vh_rt_mutex_steal(waiter->prio, top_waiter->prio, &ret); + if (ret) + return true; + #ifdef RT_MUTEX_BUILD_SPINLOCKS /* * Note that RT tasks are excluded from same priority (lateral)