1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Data structures shared between BPF and tools. */
3 #ifndef UTIL_BPF_SKEL_LOCK_DATA_H
4 #define UTIL_BPF_SKEL_LOCK_DATA_H
5 
6 struct owner_tracing_data {
7 	u32 pid; // Who has the lock.
8 	u32 count; // How many waiters for this lock.
9 	u64 timestamp; // The time while the owner acquires lock and contention is going on.
10 	s32 stack_id; // Identifier for `owner_stat`, which stores as value in `owner_stacks`
11 };
12 
13 struct tstamp_data {
14 	u64 timestamp;
15 	u64 lock;
16 	u32 flags;
17 	s32 stack_id;
18 };
19 
20 struct contention_key {
21 	s32 stack_id;
22 	u32 pid;
23 	u64 lock_addr_or_cgroup;
24 };
25 
26 #define TASK_COMM_LEN  16
27 
28 struct contention_task_data {
29 	char comm[TASK_COMM_LEN];
30 };
31 
32 /* default buffer size */
33 #define MAX_ENTRIES  16384
34 
35 /*
36  * Upper bits of the flags in the contention_data are used to identify
37  * some well-known locks which do not have symbols (non-global locks).
38  */
39 #define LCD_F_MMAP_LOCK		(1U << 31)
40 #define LCD_F_SIGHAND_LOCK	(1U << 30)
41 
42 #define LCB_F_SLAB_ID_SHIFT	16
43 #define LCB_F_SLAB_ID_START	(1U << 16)
44 #define LCB_F_SLAB_ID_END	(1U << 26)
45 #define LCB_F_SLAB_ID_MASK	0x03FF0000U
46 
47 #define LCB_F_TYPE_MAX		(1U << 7)
48 #define LCB_F_TYPE_MASK		0x0000007FU
49 
50 #define SLAB_NAME_MAX  28
51 
52 struct contention_data {
53 	u64 total_time;
54 	u64 min_time;
55 	u64 max_time;
56 	u32 count;
57 	u32 flags;
58 };
59 
60 enum lock_aggr_mode {
61 	LOCK_AGGR_ADDR = 0,
62 	LOCK_AGGR_TASK,
63 	LOCK_AGGR_CALLER,
64 	LOCK_AGGR_CGROUP,
65 };
66 
67 enum lock_class_sym {
68 	LOCK_CLASS_NONE,
69 	LOCK_CLASS_RQLOCK,
70 };
71 
72 struct slab_cache_data {
73 	u32 id;
74 	char name[SLAB_NAME_MAX];
75 };
76 
77 #endif /* UTIL_BPF_SKEL_LOCK_DATA_H */
78