0001
0002 #ifndef PERF_LOCK_CONTENTION_H
0003 #define PERF_LOCK_CONTENTION_H
0004
0005 #include <linux/list.h>
0006 #include <linux/rbtree.h>
0007
0008 struct lock_stat {
0009 struct hlist_node hash_entry;
0010 struct rb_node rb;
0011
0012 u64 addr;
0013 char *name;
0014
0015 unsigned int nr_acquire;
0016 unsigned int nr_acquired;
0017 unsigned int nr_contended;
0018 unsigned int nr_release;
0019
0020 union {
0021 unsigned int nr_readlock;
0022 unsigned int flags;
0023 };
0024 unsigned int nr_trylock;
0025
0026
0027 u64 avg_wait_time;
0028 u64 wait_time_total;
0029 u64 wait_time_min;
0030 u64 wait_time_max;
0031
0032 int broken;
0033 int combined;
0034 };
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #define SEQ_STATE_UNINITIALIZED 0
0045 #define SEQ_STATE_RELEASED 1
0046 #define SEQ_STATE_ACQUIRING 2
0047 #define SEQ_STATE_ACQUIRED 3
0048 #define SEQ_STATE_READ_ACQUIRED 4
0049 #define SEQ_STATE_CONTENDED 5
0050
0051
0052
0053
0054
0055
0056 #define MAX_LOCK_DEPTH 48
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 struct lock_seq_stat {
0067 struct list_head list;
0068 int state;
0069 u64 prev_event_time;
0070 u64 addr;
0071
0072 int read_count;
0073 };
0074
0075 struct thread_stat {
0076 struct rb_node rb;
0077
0078 u32 tid;
0079 struct list_head seq_list;
0080 };
0081
0082
0083
0084
0085
0086 #define CONTENTION_STACK_DEPTH 8
0087
0088
0089
0090
0091
0092
0093 #define CONTENTION_STACK_SKIP 3
0094
0095
0096
0097
0098
0099 #define LCB_F_SPIN (1U << 0)
0100 #define LCB_F_READ (1U << 1)
0101 #define LCB_F_WRITE (1U << 2)
0102 #define LCB_F_RT (1U << 3)
0103 #define LCB_F_PERCPU (1U << 4)
0104 #define LCB_F_MUTEX (1U << 5)
0105
0106 struct evlist;
0107 struct machine;
0108 struct target;
0109
0110 struct lock_contention {
0111 struct evlist *evlist;
0112 struct target *target;
0113 struct machine *machine;
0114 struct hlist_head *result;
0115 unsigned long map_nr_entries;
0116 unsigned long lost;
0117 };
0118
0119 #ifdef HAVE_BPF_SKEL
0120
0121 int lock_contention_prepare(struct lock_contention *con);
0122 int lock_contention_start(void);
0123 int lock_contention_stop(void);
0124 int lock_contention_read(struct lock_contention *con);
0125 int lock_contention_finish(void);
0126
0127 #else
0128
0129 static inline int lock_contention_prepare(struct lock_contention *con __maybe_unused)
0130 {
0131 return 0;
0132 }
0133
0134 static inline int lock_contention_start(void) { return 0; }
0135 static inline int lock_contention_stop(void) { return 0; }
0136 static inline int lock_contention_finish(void) { return 0; }
0137
0138 static inline int lock_contention_read(struct lock_contention *con __maybe_unused)
0139 {
0140 return 0;
0141 }
0142
0143 #endif
0144
0145 bool is_lock_function(struct machine *machine, u64 addr);
0146
0147 #endif