Add a preliminary set of mutex locking event counters. Signed-off-by: Waiman Long <longman@xxxxxxxxxx> --- kernel/locking/lock_events_list.h | 9 +++++++++ kernel/locking/mutex.c | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/kernel/locking/lock_events_list.h b/kernel/locking/lock_events_list.h index 239039d0ce21..90db996f0608 100644 --- a/kernel/locking/lock_events_list.h +++ b/kernel/locking/lock_events_list.h @@ -69,3 +69,12 @@ LOCK_EVENT(rwsem_rlock_handoff) /* # of read lock handoffs */ LOCK_EVENT(rwsem_wlock) /* # of write locks acquired */ LOCK_EVENT(rwsem_wlock_fail) /* # of failed write lock acquisitions */ LOCK_EVENT(rwsem_wlock_handoff) /* # of write lock handoffs */ + +/* + * Locking events for mutex + */ +LOCK_EVENT(mutex_slowpath) /* # of mutex sleeping slowpaths */ +LOCK_EVENT(mutex_optspin) /* # of successful optimistic spinnings */ +LOCK_EVENT(mutex_timeout) /* # of mutex timeouts */ +LOCK_EVENT(mutex_sleep) /* # of mutex sleeps */ +LOCK_EVENT(mutex_handoff) /* # of mutex lock handoffs */ diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 976179a4ed9e..1c5c252ce6fb 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -36,6 +36,7 @@ #else # include "mutex.h" #endif +#include "lock_events.h" void __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) @@ -996,10 +997,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, lock_acquired(&lock->dep_map, ip); if (use_ww_ctx && ww_ctx) ww_mutex_set_context_fastpath(ww, ww_ctx); + lockevent_inc(mutex_optspin); preempt_enable(); return 0; } + lockevent_inc(mutex_slowpath); spin_lock(&lock->wait_lock); /* * After waiting to acquire the wait_lock, try again. @@ -1069,12 +1072,14 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, to = mutex_setup_hrtimer(&timer_sleeper, timeout); if (!to || !to->task) { + lockevent_inc(mutex_timeout); ret = -ETIMEDOUT; goto err; } } spin_unlock(&lock->wait_lock); + lockevent_inc(mutex_sleep); schedule_preempt_disabled(); /* @@ -1083,8 +1088,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, */ if ((use_ww_ctx && ww_ctx) || !first) { first = __mutex_waiter_is_first(lock, &waiter); - if (first) + if (first) { __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); + lockevent_inc(mutex_handoff); + } } set_current_state(state); -- 2.18.1