xref: /linux/tools/perf/util/mem-events.h (revision 8eca6fa643b8b0d2474ca0a7e722cfa0ba9a6156)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_MEM_EVENTS_H
3 #define __PERF_MEM_EVENTS_H
4 
5 #include <stdbool.h>
6 #include <linux/types.h>
7 
8 struct perf_mem_event {
9 	bool		supported;
10 	bool		ldlat;
11 	u32		aux_event;
12 	const char	*tag;
13 	const char	*name;
14 	const char	*event_name;
15 };
16 
17 enum {
18 	PERF_MEM_EVENTS__LOAD,
19 	PERF_MEM_EVENTS__STORE,
20 	PERF_MEM_EVENTS__LOAD_STORE,
21 	PERF_MEM_EVENTS__MAX,
22 };
23 
24 struct evsel;
25 struct mem_info;
26 struct perf_pmu;
27 struct perf_session;
28 
29 extern unsigned int perf_mem_events__loads_ldlat;
30 extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX];
31 extern bool perf_mem_record[PERF_MEM_EVENTS__MAX];
32 
33 int perf_pmu__mem_events_parse(struct perf_pmu *pmu, const char *str);
34 int perf_pmu__mem_events_init(void);
35 
36 struct perf_mem_event *perf_pmu__mem_events_ptr(struct perf_pmu *pmu, int i);
37 struct perf_pmu *perf_mem_events_find_pmu(void);
38 int perf_pmu__mem_events_num_mem_pmus(struct perf_pmu *pmu);
39 bool is_mem_loads_aux_event(struct evsel *leader);
40 
41 void perf_pmu__mem_events_list(struct perf_pmu *pmu);
42 int perf_mem_events__record_args(const char **rec_argv, int *argv_nr,
43 				 char **event_name_storage_out);
44 
45 int perf_mem__tlb_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
46 int perf_mem__lvl_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
47 int perf_mem__snp_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
48 int perf_mem__lck_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
49 int perf_mem__blk_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
50 
51 int perf_script__meminfo_scnprintf(char *bf, size_t size, const struct mem_info *mem_info,
52 				   struct perf_session *session);
53 
54 struct c2c_stats {
55 	u32	nr_entries;
56 
57 	u32	locks;               /* count of 'lock' transactions */
58 	u32	store;               /* count of all stores in trace */
59 	u32	st_uncache;          /* stores to uncacheable address */
60 	u32	st_noadrs;           /* cacheable store with no address */
61 	u32	st_l1hit;            /* count of stores that hit L1D */
62 	u32	st_l1miss;           /* count of stores that miss L1D */
63 	u32	st_na;               /* count of stores with memory level is not available */
64 	u32	load;                /* count of all loads in trace */
65 	u32	ld_excl;             /* exclusive loads, rmt/lcl DRAM - snp none/miss */
66 	u32	ld_shared;           /* shared loads, rmt/lcl DRAM - snp hit */
67 	u32	ld_uncache;          /* loads to uncacheable address */
68 	u32	ld_io;               /* loads to io address */
69 	u32	ld_miss;             /* loads miss */
70 	u32	ld_noadrs;           /* cacheable load with no address */
71 	u32	ld_fbhit;            /* count of loads hitting Fill Buffer */
72 	u32	ld_l1hit;            /* count of loads that hit L1D */
73 	u32	ld_l2hit;            /* count of loads that hit L2D */
74 	u32	ld_llchit;           /* count of loads that hit LLC */
75 	u32	lcl_hitm;            /* count of loads with local HITM  */
76 	u32	rmt_hitm;            /* count of loads with remote HITM */
77 	u32	tot_hitm;            /* count of loads with local and remote HITM */
78 	u32	lcl_peer;            /* count of loads with local peer cache */
79 	u32	rmt_peer;            /* count of loads with remote peer cache */
80 	u32	tot_peer;            /* count of loads with local and remote peer cache */
81 	u32	rmt_hit;             /* count of loads with remote hit clean; */
82 	u32	lcl_dram;            /* count of loads miss to local DRAM */
83 	u32	rmt_dram;            /* count of loads miss to remote DRAM */
84 	u32	blk_data;            /* count of loads blocked by data */
85 	u32	blk_addr;            /* count of loads blocked by address conflict */
86 	u32	nomap;               /* count of load/stores with no phys addrs */
87 	u32	noparse;             /* count of unparsable data sources */
88 };
89 
90 struct hist_entry;
91 int c2c_decode_stats(struct c2c_stats *stats, struct mem_info *mi);
92 void c2c_add_stats(struct c2c_stats *stats, struct c2c_stats *add);
93 
94 enum mem_stat_type {
95 	PERF_MEM_STAT_OP,
96 	PERF_MEM_STAT_CACHE,
97 	PERF_MEM_STAT_MEMORY,
98 	PERF_MEM_STAT_SNOOP,
99 	PERF_MEM_STAT_DTLB,
100 };
101 
102 #define MEM_STAT_PRINT_LEN  7  /* 1 space + 5 digits + 1 percent sign */
103 
104 enum mem_stat_op {
105 	MEM_STAT_OP_LOAD,
106 	MEM_STAT_OP_STORE,
107 	MEM_STAT_OP_LDST,
108 	MEM_STAT_OP_PFETCH,
109 	MEM_STAT_OP_EXEC,
110 	MEM_STAT_OP_OTHER,
111 };
112 
113 enum mem_stat_cache {
114 	MEM_STAT_CACHE_L0,
115 	MEM_STAT_CACHE_L1,
116 	MEM_STAT_CACHE_L2,
117 	MEM_STAT_CACHE_L3,
118 	MEM_STAT_CACHE_L4,
119 	MEM_STAT_CACHE_L1_BUF,
120 	MEM_STAT_CACHE_L2_BUF,
121 	MEM_STAT_CACHE_OTHER,
122 };
123 
124 enum mem_stat_memory {
125 	MEM_STAT_MEMORY_RAM,
126 	MEM_STAT_MEMORY_MSC,
127 	MEM_STAT_MEMORY_UNC,
128 	MEM_STAT_MEMORY_CXL,
129 	MEM_STAT_MEMORY_IO,
130 	MEM_STAT_MEMORY_PMEM,
131 	MEM_STAT_MEMORY_OTHER,
132 };
133 
134 enum mem_stat_snoop {
135 	MEM_STAT_SNOOP_HIT,
136 	MEM_STAT_SNOOP_HITM,
137 	MEM_STAT_SNOOP_MISS,
138 	MEM_STAT_SNOOP_OTHER,
139 };
140 
141 enum mem_stat_dtlb {
142 	MEM_STAT_DTLB_L1_HIT,
143 	MEM_STAT_DTLB_L2_HIT,
144 	MEM_STAT_DTLB_ANY_HIT,
145 	MEM_STAT_DTLB_MISS,
146 	MEM_STAT_DTLB_OTHER,
147 };
148 
149 int mem_stat_index(const enum mem_stat_type mst, const u64 data_src);
150 const char *mem_stat_name(const enum mem_stat_type mst, const int idx);
151 
152 #endif /* __PERF_MEM_EVENTS_H */
153