1a67edbf4SDaniel Borkmann #undef TRACE_SYSTEM 2a67edbf4SDaniel Borkmann #define TRACE_SYSTEM xdp 3a67edbf4SDaniel Borkmann 4a67edbf4SDaniel Borkmann #if !defined(_TRACE_XDP_H) || defined(TRACE_HEADER_MULTI_READ) 5a67edbf4SDaniel Borkmann #define _TRACE_XDP_H 6a67edbf4SDaniel Borkmann 7a67edbf4SDaniel Borkmann #include <linux/netdevice.h> 8a67edbf4SDaniel Borkmann #include <linux/filter.h> 9a67edbf4SDaniel Borkmann #include <linux/tracepoint.h> 10a67edbf4SDaniel Borkmann 11a67edbf4SDaniel Borkmann #define __XDP_ACT_MAP(FN) \ 12a67edbf4SDaniel Borkmann FN(ABORTED) \ 13a67edbf4SDaniel Borkmann FN(DROP) \ 14a67edbf4SDaniel Borkmann FN(PASS) \ 155acaee0aSJohn Fastabend FN(TX) \ 165acaee0aSJohn Fastabend FN(REDIRECT) 17a67edbf4SDaniel Borkmann 18a67edbf4SDaniel Borkmann #define __XDP_ACT_TP_FN(x) \ 19a67edbf4SDaniel Borkmann TRACE_DEFINE_ENUM(XDP_##x); 20a67edbf4SDaniel Borkmann #define __XDP_ACT_SYM_FN(x) \ 21a67edbf4SDaniel Borkmann { XDP_##x, #x }, 22a67edbf4SDaniel Borkmann #define __XDP_ACT_SYM_TAB \ 23a67edbf4SDaniel Borkmann __XDP_ACT_MAP(__XDP_ACT_SYM_FN) { -1, 0 } 24a67edbf4SDaniel Borkmann __XDP_ACT_MAP(__XDP_ACT_TP_FN) 25a67edbf4SDaniel Borkmann 26a67edbf4SDaniel Borkmann TRACE_EVENT(xdp_exception, 27a67edbf4SDaniel Borkmann 28a67edbf4SDaniel Borkmann TP_PROTO(const struct net_device *dev, 29a67edbf4SDaniel Borkmann const struct bpf_prog *xdp, u32 act), 30a67edbf4SDaniel Borkmann 31a67edbf4SDaniel Borkmann TP_ARGS(dev, xdp, act), 32a67edbf4SDaniel Borkmann 33a67edbf4SDaniel Borkmann TP_STRUCT__entry( 34b06337dfSJesper Dangaard Brouer __field(int, prog_id) 35a67edbf4SDaniel Borkmann __field(u32, act) 36315ec399SJesper Dangaard Brouer __field(int, ifindex) 37a67edbf4SDaniel Borkmann ), 38a67edbf4SDaniel Borkmann 39a67edbf4SDaniel Borkmann TP_fast_assign( 40b06337dfSJesper Dangaard Brouer __entry->prog_id = xdp->aux->id; 41a67edbf4SDaniel Borkmann __entry->act = act; 42315ec399SJesper Dangaard Brouer __entry->ifindex = dev->ifindex; 43a67edbf4SDaniel Borkmann ), 44a67edbf4SDaniel Borkmann 45b06337dfSJesper Dangaard Brouer TP_printk("prog_id=%d action=%s ifindex=%d", 46b06337dfSJesper Dangaard Brouer __entry->prog_id, 47315ec399SJesper Dangaard Brouer __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB), 48315ec399SJesper Dangaard Brouer __entry->ifindex) 49a67edbf4SDaniel Borkmann ); 50a67edbf4SDaniel Borkmann 518d3b778fSJesper Dangaard Brouer DECLARE_EVENT_CLASS(xdp_redirect_template, 525acaee0aSJohn Fastabend 53a8735855SJesper Dangaard Brouer TP_PROTO(const struct net_device *dev, 54c31e5a48SJesper Dangaard Brouer const struct bpf_prog *xdp, 558d3b778fSJesper Dangaard Brouer int to_ifindex, int err, 568d3b778fSJesper Dangaard Brouer const struct bpf_map *map, u32 map_index), 575acaee0aSJohn Fastabend 588d3b778fSJesper Dangaard Brouer TP_ARGS(dev, xdp, to_ifindex, err, map, map_index), 595acaee0aSJohn Fastabend 605acaee0aSJohn Fastabend TP_STRUCT__entry( 61b06337dfSJesper Dangaard Brouer __field(int, prog_id) 625acaee0aSJohn Fastabend __field(u32, act) 63a8735855SJesper Dangaard Brouer __field(int, ifindex) 644c03bdd7SJesper Dangaard Brouer __field(int, err) 658d3b778fSJesper Dangaard Brouer __field(int, to_ifindex) 668d3b778fSJesper Dangaard Brouer __field(u32, map_id) 678d3b778fSJesper Dangaard Brouer __field(int, map_index) 685acaee0aSJohn Fastabend ), 695acaee0aSJohn Fastabend 705acaee0aSJohn Fastabend TP_fast_assign( 71b06337dfSJesper Dangaard Brouer __entry->prog_id = xdp->aux->id; 72c31e5a48SJesper Dangaard Brouer __entry->act = XDP_REDIRECT; 73a8735855SJesper Dangaard Brouer __entry->ifindex = dev->ifindex; 744c03bdd7SJesper Dangaard Brouer __entry->err = err; 758d3b778fSJesper Dangaard Brouer __entry->to_ifindex = to_ifindex; 768d3b778fSJesper Dangaard Brouer __entry->map_id = map ? map->id : 0; 778d3b778fSJesper Dangaard Brouer __entry->map_index = map_index; 785acaee0aSJohn Fastabend ), 795acaee0aSJohn Fastabend 8059a30896SJesper Dangaard Brouer TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d", 81b06337dfSJesper Dangaard Brouer __entry->prog_id, 824c03bdd7SJesper Dangaard Brouer __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB), 838d3b778fSJesper Dangaard Brouer __entry->ifindex, __entry->to_ifindex, 8459a30896SJesper Dangaard Brouer __entry->err) 855acaee0aSJohn Fastabend ); 868d3b778fSJesper Dangaard Brouer 878d3b778fSJesper Dangaard Brouer DEFINE_EVENT(xdp_redirect_template, xdp_redirect, 888d3b778fSJesper Dangaard Brouer TP_PROTO(const struct net_device *dev, 898d3b778fSJesper Dangaard Brouer const struct bpf_prog *xdp, 908d3b778fSJesper Dangaard Brouer int to_ifindex, int err, 918d3b778fSJesper Dangaard Brouer const struct bpf_map *map, u32 map_index), 928d3b778fSJesper Dangaard Brouer TP_ARGS(dev, xdp, to_ifindex, err, map, map_index) 938d3b778fSJesper Dangaard Brouer ); 948d3b778fSJesper Dangaard Brouer 95f5836ca5SJesper Dangaard Brouer DEFINE_EVENT(xdp_redirect_template, xdp_redirect_err, 96f5836ca5SJesper Dangaard Brouer TP_PROTO(const struct net_device *dev, 97f5836ca5SJesper Dangaard Brouer const struct bpf_prog *xdp, 98f5836ca5SJesper Dangaard Brouer int to_ifindex, int err, 99f5836ca5SJesper Dangaard Brouer const struct bpf_map *map, u32 map_index), 100f5836ca5SJesper Dangaard Brouer TP_ARGS(dev, xdp, to_ifindex, err, map, map_index) 101f5836ca5SJesper Dangaard Brouer ); 1028d3b778fSJesper Dangaard Brouer 103f5836ca5SJesper Dangaard Brouer #define _trace_xdp_redirect(dev, xdp, to) \ 104f5836ca5SJesper Dangaard Brouer trace_xdp_redirect(dev, xdp, to, 0, NULL, 0); 105f5836ca5SJesper Dangaard Brouer 106f5836ca5SJesper Dangaard Brouer #define _trace_xdp_redirect_err(dev, xdp, to, err) \ 107f5836ca5SJesper Dangaard Brouer trace_xdp_redirect_err(dev, xdp, to, err, NULL, 0); 108f5836ca5SJesper Dangaard Brouer 10959a30896SJesper Dangaard Brouer DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map, 11059a30896SJesper Dangaard Brouer TP_PROTO(const struct net_device *dev, 11159a30896SJesper Dangaard Brouer const struct bpf_prog *xdp, 11259a30896SJesper Dangaard Brouer int to_ifindex, int err, 11359a30896SJesper Dangaard Brouer const struct bpf_map *map, u32 map_index), 11459a30896SJesper Dangaard Brouer TP_ARGS(dev, xdp, to_ifindex, err, map, map_index), 11559a30896SJesper Dangaard Brouer TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d" 11659a30896SJesper Dangaard Brouer " map_id=%d map_index=%d", 11759a30896SJesper Dangaard Brouer __entry->prog_id, 11859a30896SJesper Dangaard Brouer __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB), 11959a30896SJesper Dangaard Brouer __entry->ifindex, __entry->to_ifindex, 12059a30896SJesper Dangaard Brouer __entry->err, 12159a30896SJesper Dangaard Brouer __entry->map_id, __entry->map_index) 12259a30896SJesper Dangaard Brouer ); 123f5836ca5SJesper Dangaard Brouer 12459a30896SJesper Dangaard Brouer DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map_err, 12559a30896SJesper Dangaard Brouer TP_PROTO(const struct net_device *dev, 12659a30896SJesper Dangaard Brouer const struct bpf_prog *xdp, 12759a30896SJesper Dangaard Brouer int to_ifindex, int err, 12859a30896SJesper Dangaard Brouer const struct bpf_map *map, u32 map_index), 12959a30896SJesper Dangaard Brouer TP_ARGS(dev, xdp, to_ifindex, err, map, map_index), 13059a30896SJesper Dangaard Brouer TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d" 13159a30896SJesper Dangaard Brouer " map_id=%d map_index=%d", 13259a30896SJesper Dangaard Brouer __entry->prog_id, 13359a30896SJesper Dangaard Brouer __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB), 13459a30896SJesper Dangaard Brouer __entry->ifindex, __entry->to_ifindex, 13559a30896SJesper Dangaard Brouer __entry->err, 13659a30896SJesper Dangaard Brouer __entry->map_id, __entry->map_index) 13759a30896SJesper Dangaard Brouer ); 13859a30896SJesper Dangaard Brouer 1399c270af3SJesper Dangaard Brouer #define devmap_ifindex(fwd, map) \ 1409c270af3SJesper Dangaard Brouer (!fwd ? 0 : \ 1419c270af3SJesper Dangaard Brouer (!map ? 0 : \ 1429c270af3SJesper Dangaard Brouer ((map->map_type == BPF_MAP_TYPE_DEVMAP) ? \ 1439c270af3SJesper Dangaard Brouer ((struct net_device *)fwd)->ifindex : 0))) 1449c270af3SJesper Dangaard Brouer 14559a30896SJesper Dangaard Brouer #define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx) \ 1469c270af3SJesper Dangaard Brouer trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map), \ 14796c5508eSJesper Dangaard Brouer 0, map, idx) 14859a30896SJesper Dangaard Brouer 14959a30896SJesper Dangaard Brouer #define _trace_xdp_redirect_map_err(dev, xdp, fwd, map, idx, err) \ 1509c270af3SJesper Dangaard Brouer trace_xdp_redirect_map_err(dev, xdp, devmap_ifindex(fwd, map), \ 15196c5508eSJesper Dangaard Brouer err, map, idx) 1528d3b778fSJesper Dangaard Brouer 153*f9419f7bSJesper Dangaard Brouer TRACE_EVENT(xdp_cpumap_kthread, 154*f9419f7bSJesper Dangaard Brouer 155*f9419f7bSJesper Dangaard Brouer TP_PROTO(int map_id, unsigned int processed, unsigned int drops, 156*f9419f7bSJesper Dangaard Brouer int sched), 157*f9419f7bSJesper Dangaard Brouer 158*f9419f7bSJesper Dangaard Brouer TP_ARGS(map_id, processed, drops, sched), 159*f9419f7bSJesper Dangaard Brouer 160*f9419f7bSJesper Dangaard Brouer TP_STRUCT__entry( 161*f9419f7bSJesper Dangaard Brouer __field(int, map_id) 162*f9419f7bSJesper Dangaard Brouer __field(u32, act) 163*f9419f7bSJesper Dangaard Brouer __field(int, cpu) 164*f9419f7bSJesper Dangaard Brouer __field(unsigned int, drops) 165*f9419f7bSJesper Dangaard Brouer __field(unsigned int, processed) 166*f9419f7bSJesper Dangaard Brouer __field(int, sched) 167*f9419f7bSJesper Dangaard Brouer ), 168*f9419f7bSJesper Dangaard Brouer 169*f9419f7bSJesper Dangaard Brouer TP_fast_assign( 170*f9419f7bSJesper Dangaard Brouer __entry->map_id = map_id; 171*f9419f7bSJesper Dangaard Brouer __entry->act = XDP_REDIRECT; 172*f9419f7bSJesper Dangaard Brouer __entry->cpu = smp_processor_id(); 173*f9419f7bSJesper Dangaard Brouer __entry->drops = drops; 174*f9419f7bSJesper Dangaard Brouer __entry->processed = processed; 175*f9419f7bSJesper Dangaard Brouer __entry->sched = sched; 176*f9419f7bSJesper Dangaard Brouer ), 177*f9419f7bSJesper Dangaard Brouer 178*f9419f7bSJesper Dangaard Brouer TP_printk("kthread" 179*f9419f7bSJesper Dangaard Brouer " cpu=%d map_id=%d action=%s" 180*f9419f7bSJesper Dangaard Brouer " processed=%u drops=%u" 181*f9419f7bSJesper Dangaard Brouer " sched=%d", 182*f9419f7bSJesper Dangaard Brouer __entry->cpu, __entry->map_id, 183*f9419f7bSJesper Dangaard Brouer __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB), 184*f9419f7bSJesper Dangaard Brouer __entry->processed, __entry->drops, 185*f9419f7bSJesper Dangaard Brouer __entry->sched) 186*f9419f7bSJesper Dangaard Brouer ); 187*f9419f7bSJesper Dangaard Brouer 188*f9419f7bSJesper Dangaard Brouer TRACE_EVENT(xdp_cpumap_enqueue, 189*f9419f7bSJesper Dangaard Brouer 190*f9419f7bSJesper Dangaard Brouer TP_PROTO(int map_id, unsigned int processed, unsigned int drops, 191*f9419f7bSJesper Dangaard Brouer int to_cpu), 192*f9419f7bSJesper Dangaard Brouer 193*f9419f7bSJesper Dangaard Brouer TP_ARGS(map_id, processed, drops, to_cpu), 194*f9419f7bSJesper Dangaard Brouer 195*f9419f7bSJesper Dangaard Brouer TP_STRUCT__entry( 196*f9419f7bSJesper Dangaard Brouer __field(int, map_id) 197*f9419f7bSJesper Dangaard Brouer __field(u32, act) 198*f9419f7bSJesper Dangaard Brouer __field(int, cpu) 199*f9419f7bSJesper Dangaard Brouer __field(unsigned int, drops) 200*f9419f7bSJesper Dangaard Brouer __field(unsigned int, processed) 201*f9419f7bSJesper Dangaard Brouer __field(int, to_cpu) 202*f9419f7bSJesper Dangaard Brouer ), 203*f9419f7bSJesper Dangaard Brouer 204*f9419f7bSJesper Dangaard Brouer TP_fast_assign( 205*f9419f7bSJesper Dangaard Brouer __entry->map_id = map_id; 206*f9419f7bSJesper Dangaard Brouer __entry->act = XDP_REDIRECT; 207*f9419f7bSJesper Dangaard Brouer __entry->cpu = smp_processor_id(); 208*f9419f7bSJesper Dangaard Brouer __entry->drops = drops; 209*f9419f7bSJesper Dangaard Brouer __entry->processed = processed; 210*f9419f7bSJesper Dangaard Brouer __entry->to_cpu = to_cpu; 211*f9419f7bSJesper Dangaard Brouer ), 212*f9419f7bSJesper Dangaard Brouer 213*f9419f7bSJesper Dangaard Brouer TP_printk("enqueue" 214*f9419f7bSJesper Dangaard Brouer " cpu=%d map_id=%d action=%s" 215*f9419f7bSJesper Dangaard Brouer " processed=%u drops=%u" 216*f9419f7bSJesper Dangaard Brouer " to_cpu=%d", 217*f9419f7bSJesper Dangaard Brouer __entry->cpu, __entry->map_id, 218*f9419f7bSJesper Dangaard Brouer __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB), 219*f9419f7bSJesper Dangaard Brouer __entry->processed, __entry->drops, 220*f9419f7bSJesper Dangaard Brouer __entry->to_cpu) 221*f9419f7bSJesper Dangaard Brouer ); 222*f9419f7bSJesper Dangaard Brouer 223a67edbf4SDaniel Borkmann #endif /* _TRACE_XDP_H */ 224a67edbf4SDaniel Borkmann 225a67edbf4SDaniel Borkmann #include <trace/define_trace.h> 226