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
5#if !defined(_TRACE_LOCK_H) || defined(TRACE_HEADER_MULTI_READ)5#if !defined(_TRACE_LOCK_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_LOCK_H6#define _TRACE_LOCK_H
7 7
8#include <linux/lockdep.h>8#include <linux/sched.h>
9#include <linux/tracepoint.h>9#include <linux/tracepoint.h>
10 10
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
11#ifdef CONFIG_LOCKDEP19#ifdef CONFIG_LOCKDEP
12 20
21#include <linux/lockdep.h>
22
13TRACE_EVENT(lock_acquire,23TRACE_EVENT(lock_acquire,
14 24
15 TP_PROTO(struct lockdep_map *lock, unsigned int subclass,25 TP_PROTO(struct lockdep_map *lock, unsigned int subclass,
@@ -78,8 +88,53 @@ DEFINE_EVENT(lock, lock_acquired, · 62 unmodified lines
78 TP_ARGS(lock, ip)88 TP_ARGS(lock, ip)
79);89);
80 90
81#endif91#endif /* CONFIG_LOCK_STAT */
82#endif92#endif /* CONFIG_LOCKDEP */
93
94TRACE_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
120TRACE_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);
83 138
84#endif /* _TRACE_LOCK_H */139#endif /* _TRACE_LOCK_H */
85 140
kernel/locking/lockdep.c+0−1
@@ -60,7 +60,6 @@ · 59 unmodified lines
60 60
61#include "lockdep_internals.h"61#include "lockdep_internals.h"
62 62
63#define CREATE_TRACE_POINTS
64#include <trace/events/lock.h>63#include <trace/events/lock.h>
65 64
66#ifdef CONFIG_PROVE_LOCKING65#ifdef CONFIG_PROVE_LOCKING
kernel/locking/mutex.c+3−0
@@ -30,6 +30,9 @@ · 29 unmodified lines
30#include <linux/debug_locks.h>30#include <linux/debug_locks.h>
31#include <linux/osq_lock.h>31#include <linux/osq_lock.h>
32 32
33#define CREATE_TRACE_POINTS
34#include <trace/events/lock.h>
35
33#ifndef CONFIG_PREEMPT_RT36#ifndef CONFIG_PREEMPT_RT
34#include "mutex.h"37#include "mutex.h"
35 38

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