xref: /openbmc/linux/include/trace/events/lock.h (revision f052febd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM lock
4 
5 #if !defined(_TRACE_LOCK_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_LOCK_H
7 
8 #include <linux/sched.h>
9 #include <linux/tracepoint.h>
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 #define LCB_F_MUTEX	(1U << 5)
18 
19 
20 #ifdef CONFIG_LOCKDEP
21 
22 #include <linux/lockdep.h>
23 
24 TRACE_EVENT(lock_acquire,
25 
26 	TP_PROTO(struct lockdep_map *lock, unsigned int subclass,
27 		int trylock, int read, int check,
28 		struct lockdep_map *next_lock, unsigned long ip),
29 
30 	TP_ARGS(lock, subclass, trylock, read, check, next_lock, ip),
31 
32 	TP_STRUCT__entry(
33 		__field(unsigned int, flags)
34 		__string(name, lock->name)
35 		__field(void *, lockdep_addr)
36 	),
37 
38 	TP_fast_assign(
39 		__entry->flags = (trylock ? 1 : 0) | (read ? 2 : 0);
40 		__assign_str(name, lock->name);
41 		__entry->lockdep_addr = lock;
42 	),
43 
44 	TP_printk("%p %s%s%s", __entry->lockdep_addr,
45 		  (__entry->flags & 1) ? "try " : "",
46 		  (__entry->flags & 2) ? "read " : "",
47 		  __get_str(name))
48 );
49 
50 DECLARE_EVENT_CLASS(lock,
51 
52 	TP_PROTO(struct lockdep_map *lock, unsigned long ip),
53 
54 	TP_ARGS(lock, ip),
55 
56 	TP_STRUCT__entry(
57 		__string(	name, 	lock->name	)
58 		__field(	void *, lockdep_addr	)
59 	),
60 
61 	TP_fast_assign(
62 		__assign_str(name, lock->name);
63 		__entry->lockdep_addr = lock;
64 	),
65 
66 	TP_printk("%p %s",  __entry->lockdep_addr, __get_str(name))
67 );
68 
69 DEFINE_EVENT(lock, lock_release,
70 
71 	TP_PROTO(struct lockdep_map *lock, unsigned long ip),
72 
73 	TP_ARGS(lock, ip)
74 );
75 
76 #ifdef CONFIG_LOCK_STAT
77 
78 DEFINE_EVENT(lock, lock_contended,
79 
80 	TP_PROTO(struct lockdep_map *lock, unsigned long ip),
81 
82 	TP_ARGS(lock, ip)
83 );
84 
85 DEFINE_EVENT(lock, lock_acquired,
86 
87 	TP_PROTO(struct lockdep_map *lock, unsigned long ip),
88 
89 	TP_ARGS(lock, ip)
90 );
91 
92 #endif /* CONFIG_LOCK_STAT */
93 #endif /* CONFIG_LOCKDEP */
94 
95 TRACE_EVENT(contention_begin,
96 
97 	TP_PROTO(void *lock, unsigned int flags),
98 
99 	TP_ARGS(lock, flags),
100 
101 	TP_STRUCT__entry(
102 		__field(void *, lock_addr)
103 		__field(unsigned int, flags)
104 	),
105 
106 	TP_fast_assign(
107 		__entry->lock_addr = lock;
108 		__entry->flags = flags;
109 	),
110 
111 	TP_printk("%p (flags=%s)", __entry->lock_addr,
112 		  __print_flags(__entry->flags, "|",
113 				{ LCB_F_SPIN,		"SPIN" },
114 				{ LCB_F_READ,		"READ" },
115 				{ LCB_F_WRITE,		"WRITE" },
116 				{ LCB_F_RT,		"RT" },
117 				{ LCB_F_PERCPU,		"PERCPU" },
118 				{ LCB_F_MUTEX,		"MUTEX" }
119 			  ))
120 );
121 
122 TRACE_EVENT(contention_end,
123 
124 	TP_PROTO(void *lock, int ret),
125 
126 	TP_ARGS(lock, ret),
127 
128 	TP_STRUCT__entry(
129 		__field(void *, lock_addr)
130 		__field(int, ret)
131 	),
132 
133 	TP_fast_assign(
134 		__entry->lock_addr = lock;
135 		__entry->ret = ret;
136 	),
137 
138 	TP_printk("%p (ret=%d)", __entry->lock_addr, __entry->ret)
139 );
140 
141 #endif /* _TRACE_LOCK_H */
142 
143 /* This part must be outside protection */
144 #include <trace/define_trace.h>
145