On Mon, Mar 03, 2025 at 05:36:41PM +0530, Malladi, Meghana wrote: > > > +static int emac_run_xdp(struct prueth_emac *emac, struct xdp_buff *xdp, > > > + struct page *page) > > > +{ > > > + struct net_device *ndev = emac->ndev; > > > + int err, result = ICSSG_XDP_PASS; > > > + struct bpf_prog *xdp_prog; > > > + struct xdp_frame *xdpf; > > > + int q_idx; > > > + u32 act; > > > + > > > + xdp_prog = READ_ONCE(emac->xdp_prog); > > > + act = bpf_prog_run_xdp(xdp_prog, xdp); > > > + switch (act) { > > > + case XDP_PASS: > > > + break; > > > + case XDP_TX: > > > + /* Send packet to TX ring for immediate transmission */ > > > + xdpf = xdp_convert_buff_to_frame(xdp); > > > + if (unlikely(!xdpf)) > > > > This is the second unlikely() macro which is added in this patchset. > > The rule with likely/unlikely() is that it should only be added if it > > likely makes a difference in benchmarking. Quite often the compiler > > is able to predict that valid pointers are more likely than NULL > > pointers so often these types of annotations don't make any difference > > at all to the compiled code. But it depends on the compiler and the -O2 > > options. > > > > Do correct me if I am wrong, but from my understanding, XDP feature depends > alot of performance and benchmarking and having unlikely does make a > difference. Atleast in all the other drivers I see this being used for XDP. > Which compiler are you on when you say that "having unlikely does make a difference"? I'm on gcc version 14.2.0 (Debian 14.2.0-16) and it doesn't make a difference to the compiled code. This matches what one would expect from a compiler. Valid pointers are fast path and NULL pointers are slow path. Adding an unlikely() is a micro optimization. There are so many other things you can do to speed up the code. I wouldn't start with that. regards, dan