xref: /linux/tools/perf/util/c2c.h (revision 83684c4e4d62cb02b2e4d0d18963d1035439278e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_UTIL_C2C_H
3 #define __PERF_UTIL_C2C_H
4 
5 #include <stdbool.h>
6 #include <stdint.h>
7 #include <linux/types.h>
8 #include "hist.h"
9 #include "mem-events.h"
10 #include "stat.h"
11 
12 struct sort_entry;
13 
14 struct c2c_hists {
15 	struct hists		hists;
16 	struct perf_hpp_list	list;
17 	struct c2c_stats	stats;
18 };
19 
20 struct compute_stats {
21 	struct stats		 lcl_hitm;
22 	struct stats		 rmt_hitm;
23 	struct stats		 lcl_peer;
24 	struct stats		 rmt_peer;
25 	struct stats		 load;
26 };
27 
28 struct c2c_hist_entry {
29 	struct c2c_hists	*hists;
30 	struct evsel		*evsel;
31 	struct c2c_stats	 stats;
32 	unsigned long		*cpuset;
33 	unsigned long		*nodeset;
34 	struct c2c_stats	*node_stats;
35 	unsigned int		 cacheline_idx;
36 
37 	struct compute_stats	 cstats;
38 
39 	unsigned long		 paddr;
40 	unsigned long		 paddr_cnt;
41 	bool			 paddr_zero;
42 	char			*nodestr;
43 
44 	/*
45 	 * must be at the end,
46 	 * because of its callchain dynamic entry
47 	 */
48 	struct hist_entry	he;
49 };
50 
51 #define C2C_HEADER_MAX 2
52 
53 struct c2c_header {
54 	struct {
55 		const char *text;
56 		int	    span;
57 	} line[C2C_HEADER_MAX];
58 };
59 
60 struct c2c_dimension {
61 	struct c2c_header	 header;
62 	const char		*name;
63 	int			 width;
64 	struct sort_entry	*se;
65 
66 	int64_t (*cmp)(struct perf_hpp_fmt *fmt,
67 		       struct hist_entry *left, struct hist_entry *right);
68 	int   (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
69 		       struct hist_entry *he);
70 	int   (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
71 		       struct hist_entry *he);
72 };
73 
74 struct c2c_fmt {
75 	struct perf_hpp_fmt	 fmt;
76 	struct c2c_dimension	*dim;
77 };
78 
79 #define SYMBOL_WIDTH 30
80 
81 #define HEADER_LOW(__h)			\
82 	{				\
83 		.line[1] = {		\
84 			.text = __h,	\
85 		},			\
86 	}
87 
88 #define HEADER_BOTH(__h0, __h1)		\
89 	{				\
90 		.line[0] = {		\
91 			.text = __h0,	\
92 		},			\
93 		.line[1] = {		\
94 			.text = __h1,	\
95 		},			\
96 	}
97 
98 void c2c_fmt_free(struct perf_hpp_fmt *fmt);
99 bool c2c_fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);
100 
101 /*
102  * Build the function-view hierarchy. Returns -EOPNOTSUPP when @cl_sort lacks
103  * iaddr. On success, *@hists remains valid until the next
104  * c2c_function__build() or c2c_function__reset(). On failure, *@hists is
105  * NULL.
106  */
107 int c2c_function__build(struct c2c_hists *cl_hists, const char *cl_sort,
108 			bool symbol_full, struct hists **hists);
109 void c2c_function__reset(void);
110 /* Valid only between a successful build and c2c_function__reset(). */
111 struct hist_entry *c2c_function__find_cacheline(struct hist_entry *he);
112 
113 /* Inputs and TUI callback supplied by the c2c command. */
114 struct c2c_function_view_args {
115 	/* Source cacheline histograms used by the common model. */
116 	struct c2c_hists	*cl_hists;
117 	/* --coalesce field list, used to require iaddr. */
118 	const char		*cl_sort;
119 	/* Do not cap long symbol names. */
120 	bool			 symbol_full;
121 	/* Open the cacheline detail view for @he. */
122 	int			(*browse_cacheline)(struct hist_entry *he);
123 };
124 
125 #ifdef HAVE_SLANG_SUPPORT
126 int perf_c2c__browse_function_view(struct c2c_function_view_args *args);
127 #else
128 static inline int
129 perf_c2c__browse_function_view(struct c2c_function_view_args *args __maybe_unused)
130 {
131 	return 0;
132 }
133 #endif
134 
135 #endif /* __PERF_UTIL_C2C_H */
136