Thread (25 messages) flat view 25 messages, 4 authors, 2026-01-15

RE: [PATCH net-next 07/11] net: fec: use switch statement to check the type of tx_buf

From: Wei Fang <wei.fang@nxp.com>
Date: 2026-01-15 02:27:18
Also in: bpf, imx, lkml

quoted
The tx_buf has three types: FEC_TXBUF_T_SKB, FEC_TXBUF_T_XDP_NDO and
FEC_TXBUF_T_XDP_TX. Currently, the driver uses 'if...else...' statements
to check the type and perform the corresponding processing. This is very
detrimental to future expansion. For example, if new types are added to
support XDP zero copy in the future, continuing to use 'if...else...'
would be a very bad coding style. So the 'if...else...' statements in
the current driver are replaced with switch statements to support XDP
zero copy in the future.
The if...else... sequence has the advantage that the common 'cases'
can be put first.
Yes, you are right. But for the current situation, we cannot determine which
is the common case. When XDP is not enabled, there is no doubt that TX
packets come from the traditional kernel network stack, so FEC_TXBUF_T_SKB
is the common case. However, the situation may be different when XDP copy
mode or XDP zero-copy mode is enabled. With AF_XDP support, there will be
five types of tx_buf. So there will be five branches, thus I think using a switch
statement is clearer and more readable.
The compiler will use a branch tree for a switch statement (jumps tables
are pretty much not allowed because of speculative execution issues) and
limit the maximum number of branches.
That is likely to be pessimal in many cases - especially if it generates
mispredicted branches for the common cases.

So not clear cut at all.

	David
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help