xref: /linux/include/trace/events/xdp.h (revision 83a37b3292f4aca799b355179ad6fbdd78a08e10)
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM xdp
3 
4 #if !defined(_TRACE_XDP_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_XDP_H
6 
7 #include <linux/netdevice.h>
8 #include <linux/filter.h>
9 #include <linux/tracepoint.h>
10 
11 #define __XDP_ACT_MAP(FN)	\
12 	FN(ABORTED)		\
13 	FN(DROP)		\
14 	FN(PASS)		\
15 	FN(TX)			\
16 	FN(REDIRECT)
17 
18 #define __XDP_ACT_TP_FN(x)	\
19 	TRACE_DEFINE_ENUM(XDP_##x);
20 #define __XDP_ACT_SYM_FN(x)	\
21 	{ XDP_##x, #x },
22 #define __XDP_ACT_SYM_TAB	\
23 	__XDP_ACT_MAP(__XDP_ACT_SYM_FN) { -1, 0 }
24 __XDP_ACT_MAP(__XDP_ACT_TP_FN)
25 
26 TRACE_EVENT(xdp_exception,
27 
28 	TP_PROTO(const struct net_device *dev,
29 		 const struct bpf_prog *xdp, u32 act),
30 
31 	TP_ARGS(dev, xdp, act),
32 
33 	TP_STRUCT__entry(
34 		__field(int, prog_id)
35 		__field(u32, act)
36 		__field(int, ifindex)
37 	),
38 
39 	TP_fast_assign(
40 		__entry->prog_id	= xdp->aux->id;
41 		__entry->act		= act;
42 		__entry->ifindex	= dev->ifindex;
43 	),
44 
45 	TP_printk("prog_id=%d action=%s ifindex=%d",
46 		  __entry->prog_id,
47 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
48 		  __entry->ifindex)
49 );
50 
51 DECLARE_EVENT_CLASS(xdp_redirect_template,
52 
53 	TP_PROTO(const struct net_device *dev,
54 		 const struct bpf_prog *xdp,
55 		 int to_ifindex, int err,
56 		 const struct bpf_map *map, u32 map_index),
57 
58 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
59 
60 	TP_STRUCT__entry(
61 		__field(int, prog_id)
62 		__field(u32, act)
63 		__field(int, ifindex)
64 		__field(int, err)
65 		__field(int, to_ifindex)
66 		__field(u32, map_id)
67 		__field(int, map_index)
68 	),
69 
70 	TP_fast_assign(
71 		__entry->prog_id	= xdp->aux->id;
72 		__entry->act		= XDP_REDIRECT;
73 		__entry->ifindex	= dev->ifindex;
74 		__entry->err		= err;
75 		__entry->to_ifindex	= to_ifindex;
76 		__entry->map_id		= map ? map->id : 0;
77 		__entry->map_index	= map_index;
78 	),
79 
80 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d",
81 		  __entry->prog_id,
82 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
83 		  __entry->ifindex, __entry->to_ifindex,
84 		  __entry->err)
85 );
86 
87 DEFINE_EVENT(xdp_redirect_template, xdp_redirect,
88 	TP_PROTO(const struct net_device *dev,
89 		 const struct bpf_prog *xdp,
90 		 int to_ifindex, int err,
91 		 const struct bpf_map *map, u32 map_index),
92 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
93 );
94 
95 DEFINE_EVENT(xdp_redirect_template, xdp_redirect_err,
96 	TP_PROTO(const struct net_device *dev,
97 		 const struct bpf_prog *xdp,
98 		 int to_ifindex, int err,
99 		 const struct bpf_map *map, u32 map_index),
100 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
101 );
102 
103 #define _trace_xdp_redirect(dev, xdp, to)		\
104 	 trace_xdp_redirect(dev, xdp, to, 0, NULL, 0);
105 
106 #define _trace_xdp_redirect_err(dev, xdp, to, err)	\
107 	 trace_xdp_redirect_err(dev, xdp, to, err, NULL, 0);
108 
109 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map,
110 	TP_PROTO(const struct net_device *dev,
111 		 const struct bpf_prog *xdp,
112 		 int to_ifindex, int err,
113 		 const struct bpf_map *map, u32 map_index),
114 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
115 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
116 		  " map_id=%d map_index=%d",
117 		  __entry->prog_id,
118 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
119 		  __entry->ifindex, __entry->to_ifindex,
120 		  __entry->err,
121 		  __entry->map_id, __entry->map_index)
122 );
123 
124 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map_err,
125 	TP_PROTO(const struct net_device *dev,
126 		 const struct bpf_prog *xdp,
127 		 int to_ifindex, int err,
128 		 const struct bpf_map *map, u32 map_index),
129 	TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
130 	TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
131 		  " map_id=%d map_index=%d",
132 		  __entry->prog_id,
133 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
134 		  __entry->ifindex, __entry->to_ifindex,
135 		  __entry->err,
136 		  __entry->map_id, __entry->map_index)
137 );
138 
139 #define devmap_ifindex(fwd, map)				\
140 	(!fwd ? 0 :						\
141 	 (!map ? 0 :						\
142 	  ((map->map_type == BPF_MAP_TYPE_DEVMAP) ?		\
143 	   ((struct net_device *)fwd)->ifindex : 0)))
144 
145 #define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx)		\
146 	 trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map),	\
147 				0, map, idx)
148 
149 #define _trace_xdp_redirect_map_err(dev, xdp, fwd, map, idx, err)	\
150 	 trace_xdp_redirect_map_err(dev, xdp, devmap_ifindex(fwd, map),	\
151 				    err, map, idx)
152 
153 TRACE_EVENT(xdp_cpumap_kthread,
154 
155 	TP_PROTO(int map_id, unsigned int processed,  unsigned int drops,
156 		 int sched),
157 
158 	TP_ARGS(map_id, processed, drops, sched),
159 
160 	TP_STRUCT__entry(
161 		__field(int, map_id)
162 		__field(u32, act)
163 		__field(int, cpu)
164 		__field(unsigned int, drops)
165 		__field(unsigned int, processed)
166 		__field(int, sched)
167 	),
168 
169 	TP_fast_assign(
170 		__entry->map_id		= map_id;
171 		__entry->act		= XDP_REDIRECT;
172 		__entry->cpu		= smp_processor_id();
173 		__entry->drops		= drops;
174 		__entry->processed	= processed;
175 		__entry->sched	= sched;
176 	),
177 
178 	TP_printk("kthread"
179 		  " cpu=%d map_id=%d action=%s"
180 		  " processed=%u drops=%u"
181 		  " sched=%d",
182 		  __entry->cpu, __entry->map_id,
183 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
184 		  __entry->processed, __entry->drops,
185 		  __entry->sched)
186 );
187 
188 TRACE_EVENT(xdp_cpumap_enqueue,
189 
190 	TP_PROTO(int map_id, unsigned int processed,  unsigned int drops,
191 		 int to_cpu),
192 
193 	TP_ARGS(map_id, processed, drops, to_cpu),
194 
195 	TP_STRUCT__entry(
196 		__field(int, map_id)
197 		__field(u32, act)
198 		__field(int, cpu)
199 		__field(unsigned int, drops)
200 		__field(unsigned int, processed)
201 		__field(int, to_cpu)
202 	),
203 
204 	TP_fast_assign(
205 		__entry->map_id		= map_id;
206 		__entry->act		= XDP_REDIRECT;
207 		__entry->cpu		= smp_processor_id();
208 		__entry->drops		= drops;
209 		__entry->processed	= processed;
210 		__entry->to_cpu		= to_cpu;
211 	),
212 
213 	TP_printk("enqueue"
214 		  " cpu=%d map_id=%d action=%s"
215 		  " processed=%u drops=%u"
216 		  " to_cpu=%d",
217 		  __entry->cpu, __entry->map_id,
218 		  __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
219 		  __entry->processed, __entry->drops,
220 		  __entry->to_cpu)
221 );
222 
223 #endif /* _TRACE_XDP_H */
224 
225 #include <trace/define_trace.h>
226