1 // SPDX-License-Identifier: GPL-2.0
2 #ifndef PERF_LOCK_CONTENTION_H
3 #define PERF_LOCK_CONTENTION_H
5 #include <linux/list.h>
6 #include <linux/rbtree.h>
18 struct hlist_node hash_entry;
19 struct rb_node rb; /* used for sorting */
21 u64 addr; /* address of lockdep_map, used as ID */
22 char *name; /* for strcpy(), we cannot use const */
25 unsigned int nr_acquire;
26 unsigned int nr_acquired;
27 unsigned int nr_contended;
28 unsigned int nr_release;
31 unsigned int nr_readlock;
34 unsigned int nr_trylock;
36 /* these times are in nano sec. */
42 int broken; /* flag of blacklist */
47 * States of lock_seq_stat
49 * UNINITIALIZED is required for detecting first event of acquire.
50 * As the nature of lock events, there is no guarantee
51 * that the first event for the locks are acquire,
52 * it can be acquired, contended or release.
54 #define SEQ_STATE_UNINITIALIZED 0 /* initial state */
55 #define SEQ_STATE_RELEASED 1
56 #define SEQ_STATE_ACQUIRING 2
57 #define SEQ_STATE_ACQUIRED 3
58 #define SEQ_STATE_READ_ACQUIRED 4
59 #define SEQ_STATE_CONTENDED 5
63 * Imported from include/linux/sched.h.
64 * Should this be synchronized?
66 #define MAX_LOCK_DEPTH 48
68 struct lock_stat *lock_stat_find(u64 addr);
69 struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags);
72 * struct lock_seq_stat:
73 * Place to put on state of one lock sequence
74 * 1) acquire -> acquired -> release
75 * 2) acquire -> contended -> acquired -> release
76 * 3) acquire (with read or try) -> release
77 * 4) Are there other patterns?
79 struct lock_seq_stat {
80 struct list_head list;
92 struct list_head seq_list;
96 * CONTENTION_STACK_DEPTH
97 * Number of stack trace entries to find callers
99 #define CONTENTION_STACK_DEPTH 8
102 * CONTENTION_STACK_SKIP
103 * Number of stack trace entries to skip when finding callers.
104 * The first few entries belong to the locking implementation itself.
106 #define CONTENTION_STACK_SKIP 4
109 * flags for lock:contention_begin
110 * Imported from include/trace/events/lock.h.
112 #define LCB_F_SPIN (1U << 0)
113 #define LCB_F_READ (1U << 1)
114 #define LCB_F_WRITE (1U << 2)
115 #define LCB_F_RT (1U << 3)
116 #define LCB_F_PERCPU (1U << 4)
117 #define LCB_F_MUTEX (1U << 5)
123 struct lock_contention {
124 struct evlist *evlist;
125 struct target *target;
126 struct machine *machine;
127 struct hlist_head *result;
128 struct lock_filter *filters;
129 unsigned long map_nr_entries;
139 int lock_contention_prepare(struct lock_contention *con);
140 int lock_contention_start(void);
141 int lock_contention_stop(void);
142 int lock_contention_read(struct lock_contention *con);
143 int lock_contention_finish(void);
145 #else /* !HAVE_BPF_SKEL */
147 static inline int lock_contention_prepare(struct lock_contention *con __maybe_unused)
152 static inline int lock_contention_start(void) { return 0; }
153 static inline int lock_contention_stop(void) { return 0; }
154 static inline int lock_contention_finish(void) { return 0; }
156 static inline int lock_contention_read(struct lock_contention *con __maybe_unused)
161 #endif /* HAVE_BPF_SKEL */
163 #endif /* PERF_LOCK_CONTENTION_H */