[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
<PAXPR04MB85108330035756EDEE55D943888CA@PAXPR04MB8510.eurprd04.prod.outlook.com>
Date: Thu, 15 Jan 2026 02:27:14 +0000
From: Wei Fang <wei.fang@....com>
To: David Laight <david.laight.linux@...il.com>
CC: Shenwei Wang <shenwei.wang@....com>, Clark Wang <xiaoning.wang@....com>,
Frank Li <frank.li@....com>, "andrew+netdev@...n.ch" <andrew+netdev@...n.ch>,
"davem@...emloft.net" <davem@...emloft.net>, "edumazet@...gle.com"
<edumazet@...gle.com>, "kuba@...nel.org" <kuba@...nel.org>,
"pabeni@...hat.com" <pabeni@...hat.com>, "ast@...nel.org" <ast@...nel.org>,
"daniel@...earbox.net" <daniel@...earbox.net>, "hawk@...nel.org"
<hawk@...nel.org>, "john.fastabend@...il.com" <john.fastabend@...il.com>,
"sdf@...ichev.me" <sdf@...ichev.me>, "netdev@...r.kernel.org"
<netdev@...r.kernel.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "imx@...ts.linux.dev" <imx@...ts.linux.dev>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>
Subject: RE: [PATCH net-next 07/11] net: fec: use switch statement to check
the type of tx_buf
> > 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
Powered by blists - more mailing lists