Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
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;     /* used for sorting */
0011 
0012     u64         addr;       /* address of lockdep_map, used as ID */
0013     char            *name;      /* for strcpy(), we cannot use const */
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     /* these times are in nano sec. */
0027     u64                     avg_wait_time;
0028     u64         wait_time_total;
0029     u64         wait_time_min;
0030     u64         wait_time_max;
0031 
0032     int         broken; /* flag of blacklist */
0033     int         combined;
0034 };
0035 
0036 /*
0037  * States of lock_seq_stat
0038  *
0039  * UNINITIALIZED is required for detecting first event of acquire.
0040  * As the nature of lock events, there is no guarantee
0041  * that the first event for the locks are acquire,
0042  * it can be acquired, contended or release.
0043  */
0044 #define SEQ_STATE_UNINITIALIZED      0         /* initial state */
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  * MAX_LOCK_DEPTH
0053  * Imported from include/linux/sched.h.
0054  * Should this be synchronized?
0055  */
0056 #define MAX_LOCK_DEPTH 48
0057 
0058 /*
0059  * struct lock_seq_stat:
0060  * Place to put on state of one lock sequence
0061  * 1) acquire -> acquired -> release
0062  * 2) acquire -> contended -> acquired -> release
0063  * 3) acquire (with read or try) -> release
0064  * 4) Are there other patterns?
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  * CONTENTION_STACK_DEPTH
0084  * Number of stack trace entries to find callers
0085  */
0086 #define CONTENTION_STACK_DEPTH  8
0087 
0088 /*
0089  * CONTENTION_STACK_SKIP
0090  * Number of stack trace entries to skip when finding callers.
0091  * The first few entries belong to the locking implementation itself.
0092  */
0093 #define CONTENTION_STACK_SKIP  3
0094 
0095 /*
0096  * flags for lock:contention_begin
0097  * Imported from include/trace/events/lock.h.
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  /* !HAVE_BPF_SKEL */
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  /* HAVE_BPF_SKEL */
0144 
0145 bool is_lock_function(struct machine *machine, u64 addr);
0146 
0147 #endif  /* PERF_LOCK_CONTENTION_H */