locking/lock_events: Add locking events for lockdep
authorWaiman Long <longman@redhat.com>
Fri, 7 Mar 2025 23:26:54 +0000 (15:26 -0800)
committerIngo Molnar <mingo@kernel.org>
Fri, 7 Mar 2025 23:55:03 +0000 (00:55 +0100)
Add some lock events to lockdep to profile its behavior.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250307232717.1759087-5-boqun.feng@gmail.com
kernel/locking/lock_events_list.h
kernel/locking/lockdep.c

index 80b11f194c9f7de749a7fdc64aaa4a5fc8fd8e3e..9ef9850aeebe67d9cc3f3361c32adeb4e7557263 100644 (file)
@@ -88,3 +88,10 @@ LOCK_EVENT(rtmutex_slow_acq3)        /* # of locks acquired in *block()      */
 LOCK_EVENT(rtmutex_slow_sleep) /* # of sleeps                          */
 LOCK_EVENT(rtmutex_slow_wake)  /* # of wakeup's                        */
 LOCK_EVENT(rtmutex_deadlock)   /* # of rt_mutex_handle_deadlock()'s    */
+
+/*
+ * Locking events for lockdep
+ */
+LOCK_EVENT(lockdep_acquire)
+LOCK_EVENT(lockdep_lock)
+LOCK_EVENT(lockdep_nocheck)
index 4470680f022697f85da14cb2d78462ac02bafd9b..8436f017c74d816be6b4ae9297c59b15492acd4f 100644 (file)
@@ -61,6 +61,7 @@
 #include <asm/sections.h>
 
 #include "lockdep_internals.h"
+#include "lock_events.h"
 
 #include <trace/events/lock.h>
 
@@ -170,6 +171,7 @@ static struct task_struct *lockdep_selftest_task_struct;
 static int graph_lock(void)
 {
        lockdep_lock();
+       lockevent_inc(lockdep_lock);
        /*
         * Make sure that if another CPU detected a bug while
         * walking the graph we dont change it (while the other
@@ -5091,8 +5093,12 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
        if (unlikely(lock->key == &__lockdep_no_track__))
                return 0;
 
-       if (!prove_locking || lock->key == &__lockdep_no_validate__)
+       lockevent_inc(lockdep_acquire);
+
+       if (!prove_locking || lock->key == &__lockdep_no_validate__) {
                check = 0;
+               lockevent_inc(lockdep_nocheck);
+       }
 
        if (subclass < NR_LOCKDEP_CACHING_CLASSES)
                class = lock->class_cache[subclass];