netdevsim: support ETS offload
Subsystems (5)
cover netdevsim: support ETS offload
- patch 1 and 2 generalize taprio offload code so that we can re-use it to offload most of the existing qdiscs on netdevsim
- patch 3 enables ETS offload on netdevsim
- patch 4 is a tdc test for ets offload on netdevsim
Davide Caratti (4):
netdevsim: move TC offload code to a dedicated file
netdevsim: generalize taprio offload
netdevsim: support ETS qdisc offload
tc-testing: add a test case for ETS offload
drivers/net/netdevsim/Makefile | 2 +- drivers/net/netdevsim/netdev.c | 51 -------------- drivers/net/netdevsim/netdevsim.h | 3 + drivers/net/netdevsim/tc.c | 70 +++++++++++++++++++ .../tc-testing/tc-tests/qdiscs/ets.json | 23 ++++++ 5 files changed, 97 insertions(+), 52 deletions(-) create mode 100644 drivers/net/netdevsim/tc.c
Signature · 1 line
2.52.0
PATCH 1/4 netdevsim: move TC offload code to a dedicated file
This commit has no functional change.
--- drivers/net/netdevsim/Makefile | 2 +- drivers/net/netdevsim/netdev.c | 51 --------------------------- drivers/net/netdevsim/netdevsim.h | 3 ++ drivers/net/netdevsim/tc.c | 57 +++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 drivers/net/netdevsim/tc.c
drivers/net/netdevsim/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o netdevsim-objs := \ - netdev.o dev.o ethtool.o fib.o bus.o health.o hwstats.o udp_tunnels.o + netdev.o dev.o ethtool.o fib.o bus.o health.o hwstats.o udp_tunnels.o tc.o ifeq ($(CONFIG_BPF_SYSCALL),y) netdevsim-objs += \
drivers/net/netdevsim/netdev.c +0 -51
63 lines not on this page · raw message
drivers/net/netdevsim/netdevsim.h +3 -0
@@ -470,3 +470,6 @@ struct nsim_bus_dev {int nsim_bus_init (void );void nsim_bus_exit (void ); + +int nsim_setup_tc (struct net_device *dev,enum tc_setup_type type, +void *type_data);
drivers/net/netdevsim/tc.c new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH 2/4 netdevsim: generalize taprio offload
In reply to Davide CarattiCurrently, netdevsim supports TC offloads only for filter blocks and the 'taprio' qdisc. This improves coverage for situations where
.ndo_setup_tc(dev, TC_SETUP_QDISC_TAPRIO, ...)
returns 0, but the code can be generalized for offloading most of the Linux qdiscs we have at the moment. Generalize netdevsim qdisc offload, by providing:
- a function that returns 0 on 'setup'/'destroy'/'get_stats' commands read from qdisc-specific offload parameters, and returns -EOPNOTSUPP otherwise, namely "handle_<qdisc_name>()"
- a case label handling TC_SETUP_QDISC_<qdisc_name> in nsim_setup_tc().
This commit has no functional change.
--- drivers/net/netdevsim/tc.c | 57 ++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 24 deletions(-)
drivers/net/netdevsim/tc.c +33 -24
@@ -11,32 +11,31 @@ nsim_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)return nsim_bpf_setup_tc_block_cb (type, type_data, cb_priv); } -static void nsim_taprio_stats (struct tc_taprio_qopt_stats *stats) -{ - stats->window_drops =0 ; - stats->tx_overruns =0 ; -} +static LIST_HEAD (nsim_block_cb_list); -static int nsim_setup_tc_taprio (struct net_device *dev, -struct tc_taprio_qopt_offload *offload) -{ -int err =0 ; - -switch (offload->cmd) { -case TAPRIO_CMD_REPLACE : -case TAPRIO_CMD_DESTROY : -break ; -case TAPRIO_CMD_STATS : -nsim_taprio_stats (&offload->stats); -break ; -default : - err = -EOPNOTSUPP ; - } +#define QDISC_OFFLOAD_HANDLERS (X ) \ + X(taprio, tc_taprio_qopt_offload, cmd, TAPRIO_CMD_REPLACE, \ + TAPRIO_CMD_DESTROY, TAPRIO_CMD_STATS, stats) \ -return err; +#define QH (NAME ,OL_TYPE ,CMD_FLD ,O_REPLACE ,O_DESTROY ,O_STATS ,STATS_FLD ) \ +static int handle_##NAME(struct net_device *dev, struct OL_TYPE *offload) \ +{ \ + switch (offload->CMD_FLD) { \ + case O_REPLACE: \ + case O_DESTROY: \ +/* Do nothing, accept offload */ \ +return 0 ; \ +case O_STATS : \ +/* Zero out the requested stats block */ \ +memset (&offload->STATS_FLD,0 ,sizeof (offload->STATS_FLD)); \ +return 0 ; \ +default : \ +return -EOPNOTSUPP ; \ + } \ } -static LIST_HEAD (nsim_block_cb_list); +QDISC_OFFLOAD_HANDLERS(QH) +#undef QHint nsim_setup_tc (struct net_device *dev,enum tc_setup_type type,void *type_data)
@@ -44,8 +43,18 @@ nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data)struct netdevsim *ns =netdev_priv (dev);switch (type) { -case TC_SETUP_QDISC_TAPRIO : -return nsim_setup_tc_taprio (dev, type_data); +#define TC_QDISC_SETUP_CASES (X ) \ + X(TC_SETUP_QDISC_TAPRIO, tc_taprio_qopt_offload, taprio) \ + +#define SC (SETUP_LABEL ,OL_TYPE ,NAME ) \ + case SETUP_LABEL: \ + { \ + return handle_##NAME(dev, (struct OL_TYPE *)type_data); \ + } + + TC_QDISC_SETUP_CASES(SC) +#undef SC +case TC_SETUP_BLOCK : return flow_block_cb_setup_simple(type_data, &nsim_block_cb_list,
Signature · 1 line
2.52.0
Jakub Kicinski
maintainerRe: [PATCH net-next 2/4] netdevsim: generalize taprio offload
Quoted 37 lines · On Tue, 10 Mar 2026 19:06:29 +0100 Davide Caratti wrote:
drivers/net/netdevsim/tc.c +14
-21-static void nsim_taprio_stats (struct tc_taprio_qopt_stats *stats) -{ - stats->window_drops =0 ; - stats->tx_overruns =0 ; -} +static LIST_HEAD (nsim_block_cb_list); -static int nsim_setup_tc_taprio (struct net_device *dev, -struct tc_taprio_qopt_offload *offload) -{ -int err =0 ; - -switch (offload->cmd) { -case TAPRIO_CMD_REPLACE : -case TAPRIO_CMD_DESTROY : -break ; -case TAPRIO_CMD_STATS : -nsim_taprio_stats (&offload->stats); -break ; -default : - err = -EOPNOTSUPP ; - } +#define QDISC_OFFLOAD_HANDLERS (X ) \ + X(taprio, tc_taprio_qopt_offload, cmd, TAPRIO_CMD_REPLACE, \ + TAPRIO_CMD_DESTROY, TAPRIO_CMD_STATS, stats) \ -return err; +#define QH (NAME ,OL_TYPE ,CMD_FLD ,O_REPLACE ,O_DESTROY ,O_STATS ,STATS_FLD ) \ +static int handle_##NAME(struct net_device *dev, struct OL_TYPE *offload) \ +{ \ + switch (offload->CMD_FLD) { \ + case O_REPLACE: \ + case O_DESTROY: \ +/* Do nothing, accept offload */ \ +return 0 ; \ +case O_STATS : \ +/* Zero out the requested stats block */ \
drivers/net/netdevsim/tc.c nsim_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv) · line 38
Quoted 10 lines
drivers/net/netdevsim/tc.c +7
-1+memset (&offload->STATS_FLD,0 ,sizeof (offload->STATS_FLD)); \ +return 0 ; \ +default : \ +return -EOPNOTSUPP ; \ + } \ } -static LIST_HEAD (nsim_block_cb_list); +QDISC_OFFLOAD_HANDLERS (QH) +#undef QH
Please just type the code in. These sort of macros are too ugly to live in code I directly maintain, sorry.
Signature · 1 line
pw-bot: cr
PATCH 3/4 netdevsim: support ETS qdisc offload
In reply to Davide CarattiExtend QDISC_OFFLOAD_HANDLERS() and TC_QDISC_SETUP_CASES() to add "fake" offload for the 'ets' qdisc.
--- drivers/net/netdevsim/tc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/netdevsim/tc.c +4 -0
@@ -2,6 +2,7 @@#include <linux/netdevice.h> #include <net/pkt_sched.h> +#include <net/pkt_cls.h> #include "netdevsim.h"
@@ -16,6 +17,8 @@ static LIST_HEAD(nsim_block_cb_list);#define QDISC_OFFLOAD_HANDLERS (X ) \ X(taprio, tc_taprio_qopt_offload, cmd, TAPRIO_CMD_REPLACE, \ TAPRIO_CMD_DESTROY, TAPRIO_CMD_STATS, stats) \ + X(ets, tc_ets_qopt_offload, command, TC_ETS_REPLACE, TC_ETS_DESTROY, \ + TC_ETS_STATS, stats) \#define QH (NAME ,OL_TYPE ,CMD_FLD ,O_REPLACE ,O_DESTROY ,O_STATS ,STATS_FLD ) \ static int handle_##NAME(struct net_device *dev, struct OL_TYPE *offload) \
@@ -45,6 +48,7 @@ nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data)switch (type) {#define TC_QDISC_SETUP_CASES (X ) \ X(TC_SETUP_QDISC_TAPRIO, tc_taprio_qopt_offload, taprio) \ + X(TC_SETUP_QDISC_ETS, tc_ets_qopt_offload, ets) \#define SC (SETUP_LABEL ,OL_TYPE ,NAME ) \ case SETUP_LABEL: \
Signature · 1 line
2.52.0
PATCH 4/4 tc-testing: add a test case for ETS offload
In reply to Davide CarattiWhile reviewing the fix for unintentional u32 overflows in ets offload code, Jamal said:
[...]
Quoted 2 lines
otherwise a tdc test should cover it fine (when you get to the netdevsim change perhaps)
Add a test case to reproduce the division by zero fixed in [1].
[1] https://lore.kernel.org/all/CAM0EoMm17wsYZmdFLshH3_-GrZtzd=i0xnoO2yiVB=-N4761mw@mail.gmail.com/
--- .../tc-testing/tc-tests/qdiscs/ets.json | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/qdiscs/ets.json +23 -0
@@ -984,5 +984,28 @@ "matchCount": "1", "teardown": [ ] + }, + { + "id": "41f5", + "name": "ETS offload where the sum of quanta wraps u32", + "category": [ + "qdisc", + "ets" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + "echo \"1 1 4\" > /sys/bus/netdevsim/new_device", + "ethtool -K $ETH hw-tc-offload on" + ], + "cmdUnderTest": "$TC qdisc add dev $ETH root ets quanta 4294967294 1 1", + "expExitCode": "0", + "verifyCmd": "$TC qdisc show dev $ETH", + "matchPattern": "qdisc ets .*bands 3 quanta 4294967294 1 1", + "matchCount": "1", + "teardown": [ + "echo \"1\" > /sys/bus/netdevsim/del_device" + ] } ]
Signature · 1 line
2.52.0