Skip to content

Commit 16edd9b

Browse files
namhyungPeter Zijlstra
authored andcommitted
locking: Add lock contention tracepoints
This adds two new lock contention tracepoints like below: * lock:contention_begin * lock:contention_end The lock:contention_begin takes a flags argument to classify locks. I found it useful to identify what kind of locks it's tracing like if it's spinning or sleeping, reader-writer lock, real-time, and per-cpu. Move tracepoint definitions into mutex.c so that we can use them without lockdep. Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Hyeonggon Yoo <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 1ee3261 commit 16edd9b

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

include/trace/events/lock.h

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55
#if !defined(_TRACE_LOCK_H) || defined(TRACE_HEADER_MULTI_READ)
66
#define _TRACE_LOCK_H
77

8-
#include <linux/lockdep.h>
8+
#include <linux/sched.h>
99
#include <linux/tracepoint.h>
1010

11+
/* flags for lock:contention_begin */
12+
#define LCB_F_SPIN (1U << 0)
13+
#define LCB_F_READ (1U << 1)
14+
#define LCB_F_WRITE (1U << 2)
15+
#define LCB_F_RT (1U << 3)
16+
#define LCB_F_PERCPU (1U << 4)
17+
18+
1119
#ifdef CONFIG_LOCKDEP
1220

21+
#include <linux/lockdep.h>
22+
1323
TRACE_EVENT(lock_acquire,
1424

1525
TP_PROTO(struct lockdep_map *lock, unsigned int subclass,
@@ -78,8 +88,53 @@ DEFINE_EVENT(lock, lock_acquired,
7888
TP_ARGS(lock, ip)
7989
);
8090

81-
#endif
82-
#endif
91+
#endif /* CONFIG_LOCK_STAT */
92+
#endif /* CONFIG_LOCKDEP */
93+
94+
TRACE_EVENT(contention_begin,
95+
96+
TP_PROTO(void *lock, unsigned int flags),
97+
98+
TP_ARGS(lock, flags),
99+
100+
TP_STRUCT__entry(
101+
__field(void *, lock_addr)
102+
__field(unsigned int, flags)
103+
),
104+
105+
TP_fast_assign(
106+
__entry->lock_addr = lock;
107+
__entry->flags = flags;
108+
),
109+
110+
TP_printk("%p (flags=%s)", __entry->lock_addr,
111+
__print_flags(__entry->flags, "|",
112+
{ LCB_F_SPIN, "SPIN" },
113+
{ LCB_F_READ, "READ" },
114+
{ LCB_F_WRITE, "WRITE" },
115+
{ LCB_F_RT, "RT" },
116+
{ LCB_F_PERCPU, "PERCPU" }
117+
))
118+
);
119+
120+
TRACE_EVENT(contention_end,
121+
122+
TP_PROTO(void *lock, int ret),
123+
124+
TP_ARGS(lock, ret),
125+
126+
TP_STRUCT__entry(
127+
__field(void *, lock_addr)
128+
__field(int, ret)
129+
),
130+
131+
TP_fast_assign(
132+
__entry->lock_addr = lock;
133+
__entry->ret = ret;
134+
),
135+
136+
TP_printk("%p (ret=%d)", __entry->lock_addr, __entry->ret)
137+
);
83138

84139
#endif /* _TRACE_LOCK_H */
85140

kernel/locking/lockdep.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060

6161
#include "lockdep_internals.h"
6262

63-
#define CREATE_TRACE_POINTS
6463
#include <trace/events/lock.h>
6564

6665
#ifdef CONFIG_PROVE_LOCKING

kernel/locking/mutex.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include <linux/debug_locks.h>
3131
#include <linux/osq_lock.h>
3232

33+
#define CREATE_TRACE_POINTS
34+
#include <trace/events/lock.h>
35+
3336
#ifndef CONFIG_PREEMPT_RT
3437
#include "mutex.h"
3538

0 commit comments

Comments
 (0)