ANDROID: vendor_hooks: Add hooks for mutex and rwsem optimistic spin
These hooks help us do the following things: a) Record the number of mutex and rwsem optimistic spin. b) Monitor the time of mutex and rwsem optimistic spin. c) Make it possible if oems don't want mutex and rwsem to optimistic spin for a long time. Bug: 267565260 Change-Id: I2bee30fb17946be85e026213b481aeaeaee2459f Signed-off-by: xieliujie <xieliujie@oppo.com>
This commit is contained in:
committed by
Treehugger Robot
parent
f8cc197cb1
commit
501e135ecf
@@ -77,12 +77,18 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_restore_priority);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_wait_start);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_wait_finish);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_init);
|
||||
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);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rtmutex_wait_start);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rtmutex_wait_finish);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_read_wait_start);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_read_wait_finish);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_write_wait_start);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_write_wait_finish);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_opt_spin_start);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_opt_spin_finish);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_can_spin_on_owner);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpu_idle_enter);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpu_idle_exit);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mpam_set);
|
||||
|
||||
@@ -27,6 +27,16 @@ DECLARE_HOOK(android_vh_mutex_wait_finish,
|
||||
DECLARE_HOOK(android_vh_mutex_init,
|
||||
TP_PROTO(struct mutex *lock),
|
||||
TP_ARGS(lock));
|
||||
DECLARE_HOOK(android_vh_mutex_opt_spin_start,
|
||||
TP_PROTO(struct mutex *lock, bool *time_out, int *cnt),
|
||||
TP_ARGS(lock, time_out, cnt));
|
||||
DECLARE_HOOK(android_vh_mutex_opt_spin_finish,
|
||||
TP_PROTO(struct mutex *lock, bool taken),
|
||||
TP_ARGS(lock, taken));
|
||||
DECLARE_HOOK(android_vh_mutex_can_spin_on_owner,
|
||||
TP_PROTO(struct mutex *lock, int *retval),
|
||||
TP_ARGS(lock, retval));
|
||||
|
||||
DECLARE_HOOK(android_vh_rtmutex_wait_start,
|
||||
TP_PROTO(struct rt_mutex_base *lock),
|
||||
TP_ARGS(lock));
|
||||
@@ -46,6 +56,15 @@ DECLARE_HOOK(android_vh_rwsem_write_wait_start,
|
||||
DECLARE_HOOK(android_vh_rwsem_write_wait_finish,
|
||||
TP_PROTO(struct rw_semaphore *sem),
|
||||
TP_ARGS(sem));
|
||||
DECLARE_HOOK(android_vh_rwsem_opt_spin_start,
|
||||
TP_PROTO(struct rw_semaphore *sem, bool *time_out, int *cnt, bool chk_only),
|
||||
TP_ARGS(sem, time_out, cnt, chk_only));
|
||||
DECLARE_HOOK(android_vh_rwsem_opt_spin_finish,
|
||||
TP_PROTO(struct rw_semaphore *sem, bool taken),
|
||||
TP_ARGS(sem, taken));
|
||||
DECLARE_HOOK(android_vh_rwsem_can_spin_on_owner,
|
||||
TP_PROTO(struct rw_semaphore *sem, bool *ret),
|
||||
TP_ARGS(sem, ret));
|
||||
|
||||
struct device;
|
||||
DECLARE_HOOK(android_vh_dpm_wait_start,
|
||||
|
||||
@@ -335,10 +335,17 @@ bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner,
|
||||
struct ww_acquire_ctx *ww_ctx, struct mutex_waiter *waiter)
|
||||
{
|
||||
bool ret = true;
|
||||
int cnt = 0;
|
||||
bool time_out = false;
|
||||
|
||||
lockdep_assert_preemption_disabled();
|
||||
|
||||
while (__mutex_owner(lock) == owner) {
|
||||
trace_android_vh_mutex_opt_spin_start(lock, &time_out, &cnt);
|
||||
if (time_out) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Ensure we emit the owner->on_cpu, dereference _after_
|
||||
* checking lock->owner still matches owner. And we already
|
||||
@@ -389,6 +396,7 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock)
|
||||
owner = __mutex_owner(lock);
|
||||
if (owner)
|
||||
retval = owner_on_cpu(owner);
|
||||
trace_android_vh_mutex_can_spin_on_owner(lock, &retval);
|
||||
|
||||
/*
|
||||
* If lock->owner is not set, the mutex has been released. Return true
|
||||
@@ -470,6 +478,7 @@ mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx,
|
||||
if (!waiter)
|
||||
osq_unlock(&lock->osq);
|
||||
|
||||
trace_android_vh_mutex_opt_spin_finish(lock, true);
|
||||
return true;
|
||||
|
||||
|
||||
@@ -478,6 +487,7 @@ fail_unlock:
|
||||
osq_unlock(&lock->osq);
|
||||
|
||||
fail:
|
||||
trace_android_vh_mutex_opt_spin_finish(lock, false);
|
||||
/*
|
||||
* If we fell out of the spin path because of need_resched(),
|
||||
* reschedule now, before we try-lock the mutex. This avoids getting
|
||||
|
||||
@@ -725,6 +725,7 @@ static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
|
||||
if ((flags & RWSEM_NONSPINNABLE) ||
|
||||
(owner && !(flags & RWSEM_READER_OWNED) && !owner_on_cpu(owner)))
|
||||
ret = false;
|
||||
trace_android_vh_rwsem_can_spin_on_owner(sem, &ret);
|
||||
|
||||
lockevent_cond_inc(rwsem_opt_fail, !ret);
|
||||
return ret;
|
||||
@@ -750,6 +751,8 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)
|
||||
struct task_struct *new, *owner;
|
||||
unsigned long flags, new_flags;
|
||||
enum owner_state state;
|
||||
int cnt = 0;
|
||||
bool time_out = false;
|
||||
|
||||
lockdep_assert_preemption_disabled();
|
||||
|
||||
@@ -759,6 +762,9 @@ rwsem_spin_on_owner(struct rw_semaphore *sem)
|
||||
return state;
|
||||
|
||||
for (;;) {
|
||||
trace_android_vh_rwsem_opt_spin_start(sem, &time_out, &cnt, true);
|
||||
if (time_out)
|
||||
break;
|
||||
/*
|
||||
* When a waiting writer set the handoff flag, it may spin
|
||||
* on the owner as well. Once that writer acquires the lock,
|
||||
@@ -823,6 +829,8 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem)
|
||||
int prev_owner_state = OWNER_NULL;
|
||||
int loop = 0;
|
||||
u64 rspin_threshold = 0;
|
||||
int cnt = 0;
|
||||
bool time_out = false;
|
||||
|
||||
/* sem->wait_lock should not be held when doing optimistic spinning */
|
||||
if (!osq_lock(&sem->osq))
|
||||
@@ -837,6 +845,9 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem)
|
||||
for (;;) {
|
||||
enum owner_state owner_state;
|
||||
|
||||
trace_android_vh_rwsem_opt_spin_start(sem, &time_out, &cnt, false);
|
||||
if (time_out)
|
||||
break;
|
||||
owner_state = rwsem_spin_on_owner(sem);
|
||||
if (!(owner_state & OWNER_SPINNABLE))
|
||||
break;
|
||||
@@ -930,6 +941,7 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem)
|
||||
cpu_relax();
|
||||
}
|
||||
osq_unlock(&sem->osq);
|
||||
trace_android_vh_rwsem_opt_spin_finish(sem, taken);
|
||||
done:
|
||||
lockevent_cond_inc(rwsem_opt_fail, !taken);
|
||||
return taken;
|
||||
|
||||
Reference in New Issue
Block a user