History

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.

Namhyung Kim committed 4 years ago

Commit 16edd9b1 parent 1ee32613 files · +61 −4Browse files

Unified · Split

3 files
  1. include/trace/events/lock.h +58 −3
  2. kernel/locking/lockdep.c +0 −1
  3. kernel/locking/mutex.c +3 −0
include/trace/events/lock.h+58−3
@@ -5,11 +5,21 @@ · 4 unmodified lines
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, · 62 unmodified lines
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+0−1
@@ -60,7 +60,6 @@ · 59 unmodified lines
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+3−0
@@ -30,6 +30,9 @@ · 29 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t