make skip_sw actually skip software
Subsystems (3)
cover make skip_sw actually skip software
Hi,
During development of flower-route[1], which I recently presented at FOSDEM[2], I noticed that CPU usage, would increase the more rules I installed into the hardware for IP forwarding offloading.
Since we use TC flower offload for the hottest prefixes, and leave the long tail to Linux / the CPU. we therefore need both the hardware and software datapath to perform well.
I found that skip_sw rules, are quite expensive in the kernel datapath, sice they must be evaluated and matched upon, before the kernel checks the skip_sw flag.
This patchset optimizes the case where all rules are skip_sw.
[1] flower-route
https://github.com/fiberby-dk/flower-route
[2] FOSDEM talk
https://fosdem.org/2024/schedule/event/fosdem-2024-3337-flying-higher-hardware-offloading-with-bird/
Asbjørn Sloth Tønnesen (3):
net: sched: cls_api: add skip_sw counter
net: sched: cls_api: add filter counter
net: sched: make skip_sw actually skip software
include/net/pkt_cls.h | 5 +++++ include/net/sch_generic.h | 3 +++ net/core/dev.c | 3 +++ net/sched/cls_api.c | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+)
Signature · 4 lines
Best regards Asbjørn Sloth Tønnesen Network Engineer Fiberby ApS
PATCH 1/3 net: sched: cls_api: add skip_sw counter
Maintain a count of skip_sw filters.
This counter is protected by the cb_lock, and is updated at the same time as offloadcnt.
--- include/net/sch_generic.h | 1 + net/sched/cls_api.c | 4 ++++ 2 files changed, 5 insertions(+)
include/net/sch_generic.h +1 -0
@@ -476,6 +476,7 @@ struct tcf_block {struct flow_block flow_block;struct list_head owner_list;bool keep_dst; +atomic_t skipswcnt;/* Number of skip_sw filters */ atomic_t offloadcnt;/* Number of oddloaded filters */ unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */ unsigned int lockeddevcnt;/* Number of devs that require rtnl lock. */
net/sched/cls_api.c +4 -0
@@ -3483,6 +3483,8 @@ static void tcf_block_offload_inc(struct tcf_block *block, u32 *flags)if (*flags &TCA_CLS_FLAGS_IN_HW )return ; *flags |=TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_inc (&block->skipswcnt);atomic_inc (&block->offloadcnt); }
@@ -3491,6 +3493,8 @@ static void tcf_block_offload_dec(struct tcf_block *block, u32 *flags)if (!(*flags &TCA_CLS_FLAGS_IN_HW ))return ; *flags &= ~TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_dec (&block->skipswcnt);atomic_dec (&block->offloadcnt); }
Signature · 1 line
2.43.0
Jamal Hadi Salim
maintainerRe: [PATCH net-next 1/3] net: sched: cls_api: add skip_sw counter
+Cc Vlad and Marcelo..
Quoted 17 lines · Asbjørn Sloth Tønnesen
Maintain a count of
skip_swfilters.This counter is protected by the
cb_lock, and is updated at the same time as offloadcnt.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/sch_generic.h | 1 + net/sched/cls_api.c | 4 ++++ 2 files changed, 5 insertions(+)include/net/sch_generic.h +0
-0
include/net/sch_generic.h struct tcf_block { · line 480
Quoted 5 lines
include/net/sch_generic.h +1
-0@@ -476,6 +476,7 @@ struct tcf_block {struct flow_block flow_block;struct list_head owner_list;bool keep_dst; +atomic_t skipswcnt;/* Number of skip_sw filters */ atomic_t offloadcnt;/* Number of oddloaded filters */
For your use case is skipswcnt ever going to be any different than offloadcnt?
cheers,
jamal
Quoted 27 lines
include/net/sch_generic.h +0
-0unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */ unsigned int lockeddevcnt;/* Number of devs that require rtnl lock. */ net/sched/cls_api.c +4
-1@@ -3483,6 +3483,8 @@ static void tcf_block_offload_inc(struct tcf_block *block, u32 *flags)if (*flags &TCA_CLS_FLAGS_IN_HW )return ; *flags |=TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_inc (&block->skipswcnt);atomic_inc (&block->offloadcnt); }@@ -3491,6 +3493,8 @@ static void tcf_block_offload_dec(struct tcf_block *block, u32 *flags)if (!(*flags &TCA_CLS_FLAGS_IN_HW ))return ; *flags &= ~TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_dec (&block->skipswcnt);atomic_dec (&block->offloadcnt); } --2.43.0
Re: [PATCH net-next 1/3] net: sched: cls_api: add skip_sw counter
Hi Jamal,
Thank you for the review.
Quoted 15 lines · Jamal Hadi Salim
+Cc Vlad and Marcelo..
Quoted 12 lines · Asbjørn Sloth Tønnesen
Maintain a count of
skip_swfilters.This counter is protected by the
cb_lock, and is updated at the same time as offloadcnt.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/sch_generic.h | 1 + net/sched/cls_api.c | 4 ++++ 2 files changed, 5 insertions(+)
Quoted 12 lines
include/net/sch_generic.h struct tcf_block { · line 480
Quoted 10 lines
include/net/sch_generic.h +1
-0@@ -476,6 +476,7 @@ struct tcf_block {struct flow_block flow_block;struct list_head owner_list;bool keep_dst; +atomic_t skipswcnt;/* Number of skip_sw filters */ atomic_t offloadcnt;/* Number of oddloaded filters */ For your use case is skipswcnt ever going to be any different than offloadcnt?
No, we only use skip_sw filters, since we only use TC as a control path to install skip_sw rules into hardware.
AFAICT offloadcnt is the sum of skip_sw filters, and filters with no flags which have implicitly been offloaded.
The reason that I didn't just use offloadcnt, is that I'm not sure if it is acceptable to treat implicitly offloaded rules without skip_sw, as if they were explicitly skip_sw. It sounds reasonable, given that the filters without skip_* flags shouldn't really care.
I tried to only trigger the TC bypass, in the cases that I was absolutely sure would be safe as a first step.
Quoted 31 lines
cheers,
jamalQuoted 27 lines
include/net/sch_generic.h +0
-0unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */ unsigned int lockeddevcnt;/* Number of devs that require rtnl lock. */ net/sched/cls_api.c +4
-1@@ -3483,6 +3483,8 @@ static void tcf_block_offload_inc(struct tcf_block *block, u32 *flags)if (*flags &TCA_CLS_FLAGS_IN_HW )return ; *flags |=TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_inc (&block->skipswcnt);atomic_inc (&block->offloadcnt); }@@ -3491,6 +3493,8 @@ static void tcf_block_offload_dec(struct tcf_block *block, u32 *flags)if (!(*flags &TCA_CLS_FLAGS_IN_HW ))return ; *flags &= ~TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_dec (&block->skipswcnt);atomic_dec (&block->offloadcnt); } --2.43.0
Signature · 4 lines
Best regards Asbjørn Sloth Tønnesen Network Engineer Fiberby - AS42541
Re: [PATCH net-next 1/3] net: sched: cls_api: add skip_sw counter
Quoted 35 lines · Asbjørn Sloth Tønnesen
Hi Jamal,
Thank you for the review.
Quoted 15 lines · Jamal Hadi Salim
+Cc Vlad and Marcelo..
Quoted 12 lines · Asbjørn Sloth Tønnesen
Maintain a count of
skip_swfilters.This counter is protected by the
cb_lock, and is updated at the same time as offloadcnt.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/sch_generic.h | 1 + net/sched/cls_api.c | 4 ++++ 2 files changed, 5 insertions(+)Quoted 11 lines
include/net/sch_generic.h struct tcf_block { · line 480
Quoted 10 lines
include/net/sch_generic.h +1
-0@@ -476,6 +476,7 @@ struct tcf_block {struct flow_block flow_block;struct list_head owner_list;bool keep_dst; +atomic_t skipswcnt;/* Number of skip_sw filters */ atomic_t offloadcnt;/* Number of oddloaded filters */ For your use case is skipswcnt ever going to be any different than offloadcnt?
No, we only use
skip_swfilters, since we only use TC as a control path to installskip_swrules into hardware.
Quoted 7 lines
AFAICT offloadcnt is the sum of
skip_swfilters, and filters with no flags which have implicitly been offloaded.The reason that I didn't just use offloadcnt, is that I'm not sure if it is acceptable to treat implicitly offloaded rules without
skip_sw, as if they were explicitlyskip_sw. It sounds reasonable, given that the filters without skip_* flags shouldn't really care.
It is not acceptable since there are valid use-cases where packets need to match sw filters that are supposedly also in-hw. For example, filters with tunnel_key set action during neighbor update event.
Quoted 35 lines
I tried to only trigger the TC bypass, in the cases that I was absolutely sure would be safe as a first step.
Quoted 30 lines
cheers,
jamalQuoted 27 lines
include/net/sch_generic.h +0
-0unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */ unsigned int lockeddevcnt;/* Number of devs that require rtnl lock. */ net/sched/cls_api.c +4
-1@@ -3483,6 +3483,8 @@ static void tcf_block_offload_inc(struct tcf_block *block, u32 *flags)if (*flags &TCA_CLS_FLAGS_IN_HW )return ; *flags |=TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_inc (&block->skipswcnt);atomic_inc (&block->offloadcnt); }@@ -3491,6 +3493,8 @@ static void tcf_block_offload_dec(struct tcf_block *block, u32 *flags)if (!(*flags &TCA_CLS_FLAGS_IN_HW ))return ; *flags &= ~TCA_CLS_FLAGS_IN_HW ; +if (tc_skip_sw (*flags)) +atomic_dec (&block->skipswcnt);atomic_dec (&block->offloadcnt); } --2.43.0
Re: [PATCH net-next 1/3] net: sched: cls_api: add skip_sw counter
In reply to Asbjørn Sloth TønnesenQuoted 6 lines · Thu, Feb 15, 2024 at 05:04:42PM CET, [email protected] wrote:
Maintain a count of
skip_swfilters.This counter is protected by the
cb_lock, and is updated at the same time as offloadcnt.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>
PATCH 2/3 net: sched: cls_api: add filter counter
In reply to Asbjørn Sloth TønnesenMaintain a count of filters per block.
Counter updates are protected by cb_lock, which is also used to protect the offload counters.
--- include/net/sch_generic.h | 2 ++ net/sched/cls_api.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+)
include/net/sch_generic.h +2 -0
@@ -427,6 +427,7 @@ struct tcf_proto {*/ spinlock_t lock;bool deleting; +bool counted;refcount_t refcnt;struct rcu_head rcu;struct hlist_node destroy_ht_node;
@@ -476,6 +477,7 @@ struct tcf_block {struct flow_block flow_block;struct list_head owner_list;bool keep_dst; +atomic_t filtercnt;/* Number of filters */ atomic_t skipswcnt;/* Number of skip_sw filters */ atomic_t offloadcnt;/* Number of oddloaded filters */ unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */
net/sched/cls_api.c +20 -0
@@ -411,11 +411,13 @@ static void tcf_proto_get(struct tcf_proto *tp) }static void tcf_chain_put (struct tcf_chain *chain); +static void tcf_block_filter_cnt_update (struct tcf_block *block,bool *counted,bool add);static void tcf_proto_destroy (struct tcf_proto *tp,bool rtnl_held,bool sig_destroy,struct netlink_ext_ack *extack) { tp->ops->destroy (tp, rtnl_held, extack); +tcf_block_filter_cnt_update (tp->chain->block, &tp->counted, false);if (sig_destroy)tcf_proto_signal_destroyed (tp->chain, tp);tcf_chain_put (tp->chain);
@@ -2364,6 +2366,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n, err = tp->ops->change (net, skb, tp, cl, t->tcm_handle, tca, &fh, flags, extack);if (err ==0 ) { +tcf_block_filter_cnt_update (block, &tp->counted, true);tfilter_notify (net, skb, n, tp, block, q, parent, fh,RTM_NEWTFILTER , false, rtnl_held, extack);tfilter_put (tp, fh);
@@ -3478,6 +3481,23 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts) }EXPORT_SYMBOL (tcf_exts_dump_stats); +static void tcf_block_filter_cnt_update (struct tcf_block *block,bool *counted,bool add) +{ +lockdep_assert_not_held (&block->cb_lock); + +down_write (&block->cb_lock); +if (*counted != add) { +if (add) { +atomic_inc (&block->filtercnt); + *counted = true; + }else { +atomic_dec (&block->filtercnt); + *counted = false; + } + } +up_write (&block->cb_lock); +} +static void tcf_block_offload_inc (struct tcf_block *block,u32 *flags) {if (*flags &TCA_CLS_FLAGS_IN_HW )
Signature · 1 line
2.43.0
Jiri Pirko
maintainerRe: [PATCH net-next 2/3] net: sched: cls_api: add filter counter
Quoted 58 lines · Thu, Feb 15, 2024 at 05:04:43PM CET, [email protected] wrote:
Maintain a count of filters per block.
Counter updates are protected by
cb_lock, which is also used to protect the offload counters.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>---
include/net/sch_generic.h| 2 ++net/sched/cls_api.c| 20 ++++++++++++++++++++2 files changed, 22 insertions(+)include/net/sch_generic.h +2
-0@@ -427,6 +427,7 @@ struct tcf_proto {*/ spinlock_t lock;bool deleting; +bool counted;refcount_t refcnt;struct rcu_head rcu;struct hlist_node destroy_ht_node;@@ -476,6 +477,7 @@ struct tcf_block {struct flow_block flow_block;struct list_head owner_list;bool keep_dst; +atomic_t filtercnt;/* Number of filters */ atomic_t skipswcnt;/* Number of skip_sw filters */ atomic_t offloadcnt;/* Number of oddloaded filters */ unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */ net/sched/cls_api.c +3
-0@@ -411,11 +411,13 @@ static void tcf_proto_get(struct tcf_proto *tp) }static void tcf_chain_put (struct tcf_chain *chain); +static void tcf_block_filter_cnt_update (struct tcf_block *block,bool *counted,bool add);static void tcf_proto_destroy (struct tcf_proto *tp,bool rtnl_held,bool sig_destroy,struct netlink_ext_ack *extack) { tp->ops->destroy (tp, rtnl_held, extack); +tcf_block_filter_cnt_update (tp->chain->block, &tp->counted, false);if (sig_destroy)tcf_proto_signal_destroyed (tp->chain, tp);tcf_chain_put (tp->chain);@@ -2364,6 +2366,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n, err = tp->ops->change (net, skb, tp, cl, t->tcm_handle, tca, &fh, flags, extack);if (err ==0 ) { +tcf_block_filter_cnt_update (block, &tp->counted, true);tfilter_notify (net, skb, n, tp, block, q, parent, fh,RTM_NEWTFILTER , false, rtnl_held, extack);tfilter_put (tp, fh);
net/sched/cls_api.c int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts) · line 3484
Quoted 4 lines
net/sched/cls_api.c +1
-0@@ -3478,6 +3481,23 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts) }EXPORT_SYMBOL (tcf_exts_dump_stats); +static void tcf_block_filter_cnt_update (struct tcf_block *block,bool *counted,bool add)
Can't you move this up to avoid forward declaration?
Quoted 22 lines
net/sched/cls_api.c +16
-0+{ +lockdep_assert_not_held (&block->cb_lock); + +down_write (&block->cb_lock); +if (*counted != add) { +if (add) { +atomic_inc (&block->filtercnt); + *counted = true; + }else { +atomic_dec (&block->filtercnt); + *counted = false; + } + } +up_write (&block->cb_lock); +} +static void tcf_block_offload_inc (struct tcf_block *block,u32 *flags) {if (*flags &TCA_CLS_FLAGS_IN_HW )Signature · 1 line
2.43.0
Re: [PATCH net-next 2/3] net: sched: cls_api: add filter counter
Hi Jiri,
Thanks for the review.
Quoted 62 lines · Jiri Pirko
Quoted 61 lines · Thu, Feb 15, 2024 at 05:04:43PM CET, [email protected] wrote:
Maintain a count of filters per block.
Counter updates are protected by
cb_lock, which is also used to protect the offload counters.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>---
include/net/sch_generic.h| 2 ++net/sched/cls_api.c| 20 ++++++++++++++++++++2 files changed, 22 insertions(+)include/net/sch_generic.h +2
-0@@ -427,6 +427,7 @@ struct tcf_proto {*/ spinlock_t lock;bool deleting; +bool counted;refcount_t refcnt;struct rcu_head rcu;struct hlist_node destroy_ht_node;@@ -476,6 +477,7 @@ struct tcf_block {struct flow_block flow_block;struct list_head owner_list;bool keep_dst; +atomic_t filtercnt;/* Number of filters */ atomic_t skipswcnt;/* Number of skip_sw filters */ atomic_t offloadcnt;/* Number of oddloaded filters */ unsigned int nooffloaddevcnt;/* Number of devs unable to do offload */ net/sched/cls_api.c +3
-0@@ -411,11 +411,13 @@ static void tcf_proto_get(struct tcf_proto *tp) }static void tcf_chain_put (struct tcf_chain *chain); +static void tcf_block_filter_cnt_update (struct tcf_block *block,bool *counted,bool add);static void tcf_proto_destroy (struct tcf_proto *tp,bool rtnl_held,bool sig_destroy,struct netlink_ext_ack *extack) { tp->ops->destroy (tp, rtnl_held, extack); +tcf_block_filter_cnt_update (tp->chain->block, &tp->counted, false);if (sig_destroy)tcf_proto_signal_destroyed (tp->chain, tp);tcf_chain_put (tp->chain);@@ -2364,6 +2366,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n, err = tp->ops->change (net, skb, tp, cl, t->tcm_handle, tca, &fh, flags, extack);if (err ==0 ) { +tcf_block_filter_cnt_update (block, &tp->counted, true);tfilter_notify (net, skb, n, tp, block, q, parent, fh,RTM_NEWTFILTER , false, rtnl_held, extack);tfilter_put (tp, fh);@@ -3478,6 +3481,23 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts) }EXPORT_SYMBOL (tcf_exts_dump_stats);
Quoted 3 lines
net/sched/cls_api.c int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts) · line 3484
Quoted 1 line
net/sched/cls_api.c +1
-0+static void tcf_block_filter_cnt_update (struct tcf_block *block,bool *counted,bool add)Can't you move this up to avoid forward declaration?
Sure, will do that in v2.
I had considered it, but in the end decided to keep it next to the related offloadcnt logic.
Quoted 22 lines
Quoted 22 lines
net/sched/cls_api.c +16
-0+{ +lockdep_assert_not_held (&block->cb_lock); + +down_write (&block->cb_lock); +if (*counted != add) { +if (add) { +atomic_inc (&block->filtercnt); + *counted = true; + }else { +atomic_dec (&block->filtercnt); + *counted = false; + } + } +up_write (&block->cb_lock); +} +static void tcf_block_offload_inc (struct tcf_block *block,u32 *flags) {if (*flags &TCA_CLS_FLAGS_IN_HW )Signature · 1 line
2.43.0
Signature · 4 lines
Best regards Asbjørn Sloth Tønnesen Network Engineer Fiberby - AS42541
PATCH 3/3 net: sched: make skip_sw actually skip software
In reply to Asbjørn Sloth TønnesenTC filters come in 3 variants:
- no flag (no opinion, process wherever possible)
- skip_hw (do not process filter by hardware)
- skip_sw (do not process filter by software)
However skip_sw is implemented so that the skip_sw flag can first be checked, after it has been matched.
IMHO it's common when using skip_sw, to use it on all rules.
So if all filters in a block is skip_sw filters, then we can bail early, we can thus avoid having to match the filters, just to check for the skip_sw flag.
+----------------------------+--------+--------+--------+ | Test description | Pre | Post | Rel. | | | kpps | kpps | chg. | +----------------------------+--------+--------+--------+ | basic forwarding + notrack | 1264.9 | 1277.7 | 1.01x | | switch to eswitch mode | 1067.1 | 1071.0 | 1.00x | | add ingress qdisc | 1056.0 | 1059.1 | 1.00x | +----------------------------+--------+--------+--------+ | 1 non-matching rule | 927.9 | 1057.1 | 1.14x | | 10 non-matching rules | 495.8 | 1055.6 | 2.13x | | 25 non-matching rules | 280.6 | 1053.5 | 3.75x | | 50 non-matching rules | 162.0 | 1055.7 | 6.52x | | 100 non-matching rules | 87.7 | 1019.0 | 11.62x | +----------------------------+--------+--------+--------+
perf top (100 n-m skip_sw rules - pre patch):
25.57% [kernel] [k] __skb_flow_dissect 20.77% [kernel] [k] rhashtable_jhash2 14.26% [kernel] [k] fl_classify 13.28% [kernel] [k] fl_mask_lookup 6.38% [kernel] [k] memset_orig 3.22% [kernel] [k] tcf_classify
perf top (100 n-m skip_sw rules - post patch):
4.28% [kernel] [k] __dev_queue_xmit 3.80% [kernel] [k] check_preemption_disabled 3.68% [kernel] [k] nft_do_chain 3.08% [kernel] [k] __netif_receive_skb_core.constprop.0 2.59% [kernel] [k] mlx5e_xmit 2.48% [kernel] [k] mlx5e_skb_from_cqe_mpwrq_nonlinear
Test setup:
DUT: Intel Xeon D-1518 (2.20GHz) w/ Nvidia/Mellanox ConnectX-6 Dx 2x100G Data rate measured on switch (Extreme X690), and DUT connected as a router on a stick, with pktgen and pktsink as VLANs. Pktgen was in range 12.79 - 12.95 Mpps across all tests.
--- include/net/pkt_cls.h | 5 +++++ net/core/dev.c | 3 +++ 2 files changed, 8 insertions(+)
include/net/pkt_cls.h +5 -0
@@ -74,6 +74,11 @@ static inline bool tcf_block_non_null_shared(struct tcf_block *block)return block && block->index; } +static inline bool tcf_block_has_skip_sw_only (struct tcf_block *block) +{ +return block &&atomic_read (&block->filtercnt) ==atomic_read (&block->skipswcnt); +} +static inline struct Qdisc *tcf_block_q (struct tcf_block *block) {WARN_ON (tcf_block_shared (block));
net/core/dev.c +3 -0
@@ -3910,6 +3910,9 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,if (!miniq)return ret; +if (tcf_block_has_skip_sw_only (miniq->block)) +return ret; +tc_skb_cb (skb)->mru =0 ;tc_skb_cb (skb)->post_ct = false;tcf_set_drop_reason (skb, *drop_reason);
Signature · 1 line
2.43.0
Jamal Hadi Salim
maintainerRe: [PATCH net-next 3/3] net: sched: make skip_sw actually skip software
Quoted 38 lines · Asbjørn Sloth Tønnesen
TC filters come in 3 variants:
- no flag (no opinion, process wherever possible)
-skip_hw(do not process filter by hardware)
-skip_sw(do not process filter by software)However
skip_swis implemented so that theskip_swflag can first be checked, after it has been matched.IMHO it's common when using
skip_sw, to use it on all rules.So if all filters in a block is
skip_swfilters, then we can bail early, we can thus avoid having to match the filters, just to check for theskip_swflag.+----------------------------+--------+--------+--------+ | Test description | Pre | Post | Rel. | | | kpps | kpps | chg. | +----------------------------+--------+--------+--------+ | basic forwarding + notrack | 1264.9 | 1277.7 | 1.01x | | switch to eswitch mode | 1067.1 | 1071.0 | 1.00x | | add ingress qdisc | 1056.0 | 1059.1 | 1.00x | +----------------------------+--------+--------+--------+ | 1 non-matching rule | 927.9 | 1057.1 | 1.14x | | 10 non-matching rules | 495.8 | 1055.6 | 2.13x | | 25 non-matching rules | 280.6 | 1053.5 | 3.75x | | 50 non-matching rules | 162.0 | 1055.7 | 6.52x | | 100 non-matching rules | 87.7 | 1019.0 | 11.62x | +----------------------------+--------+--------+--------+perf top (100 n-m
skip_swrules - pre patch):25.57% [kernel] [k] __skb_flow_dissect 20.77% [kernel] [k] rhashtable_jhash2 14.26% [kernel] [k] fl_classify 13.28% [kernel] [k] fl_mask_lookup 6.38% [kernel] [k] memset_orig 3.22% [kernel] [k] tcf_classify
Quoted 8 lines
perf top (100 n-m
skip_swrules - post patch):4.28% [kernel] [k] __dev_queue_xmit 3.80% [kernel] [k] check_preemption_disabled 3.68% [kernel] [k] nft_do_chain 3.08% [kernel] [k] __netif_receive_skb_core.constprop.0 2.59% [kernel] [k] mlx5e_xmit 2.48% [kernel] [k] mlx5e_skb_from_cqe_mpwrq_nonlinear
The concept makes sense - but i am wondering when you have a mix of skip_sw and skip_hw if it makes more sense to just avoid looking up skip_sw at all in the s/w datapath? Potentially by separating the hashes for skip_sw/hw. I know it's a deeper surgery - but would be more general purpose....unless i am missing something
Quoted 6 lines
Test setup:
DUT: Intel Xeon D-1518 (2.20GHz) w/ Nvidia/Mellanox ConnectX-6 Dx 2x100G Data rate measured on switch (Extreme X690), and DUT connected as a router on a stick, with pktgen and pktsink as VLANs. Pktgen was in range 12.79 - 12.95 Mpps across all tests.
Hrm. Those are "tiny" numbers (25G @64B is about 3x that). What are the packet sizes?
Perhaps the traffic generator is a limitation here?
Also feels like you are doing exact matches? A sample flower rule would have helped.
cheers,
jamal
Quoted 39 lines
Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/pkt_cls.h | 5 +++++ net/core/dev.c | 3 +++ 2 files changed, 8 insertions(+)include/net/pkt_cls.h +5
-0@@ -74,6 +74,11 @@ static inline bool tcf_block_non_null_shared(struct tcf_block *block)return block && block->index; } +static inline bool tcf_block_has_skip_sw_only (struct tcf_block *block) +{ +return block &&atomic_read (&block->filtercnt) ==atomic_read (&block->skipswcnt); +} +static inline struct Qdisc *tcf_block_q (struct tcf_block *block) {WARN_ON (tcf_block_shared (block));net/core/dev.c +3
-1@@ -3910,6 +3910,9 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,if (!miniq)return ret; +if (tcf_block_has_skip_sw_only (miniq->block)) +return ret; +tc_skb_cb (skb)->mru =0 ;tc_skb_cb (skb)->post_ct = false;tcf_set_drop_reason (skb, *drop_reason); --2.43.0
Re: [PATCH net-next 3/3] net: sched: make skip_sw actually skip software
Quoted 48 lines · Thu, Feb 15, 2024 at 06:49:05PM CET, [email protected] wrote:
Quoted 38 lines · Asbjørn Sloth Tønnesen
TC filters come in 3 variants:
- no flag (no opinion, process wherever possible)
-skip_hw(do not process filter by hardware)
-skip_sw(do not process filter by software)However
skip_swis implemented so that theskip_swflag can first be checked, after it has been matched.IMHO it's common when using
skip_sw, to use it on all rules.So if all filters in a block is
skip_swfilters, then we can bail early, we can thus avoid having to match the filters, just to check for theskip_swflag.+----------------------------+--------+--------+--------+ | Test description | Pre | Post | Rel. | | | kpps | kpps | chg. | +----------------------------+--------+--------+--------+ | basic forwarding + notrack | 1264.9 | 1277.7 | 1.01x | | switch to eswitch mode | 1067.1 | 1071.0 | 1.00x | | add ingress qdisc | 1056.0 | 1059.1 | 1.00x | +----------------------------+--------+--------+--------+ | 1 non-matching rule | 927.9 | 1057.1 | 1.14x | | 10 non-matching rules | 495.8 | 1055.6 | 2.13x | | 25 non-matching rules | 280.6 | 1053.5 | 3.75x | | 50 non-matching rules | 162.0 | 1055.7 | 6.52x | | 100 non-matching rules | 87.7 | 1019.0 | 11.62x | +----------------------------+--------+--------+--------+perf top (100 n-m
skip_swrules - pre patch):25.57% [kernel] [k] __skb_flow_dissect 20.77% [kernel] [k] rhashtable_jhash2 14.26% [kernel] [k] fl_classify 13.28% [kernel] [k] fl_mask_lookup 6.38% [kernel] [k] memset_orig 3.22% [kernel] [k] tcf_classifyQuoted 8 lines
perf top (100 n-m
skip_swrules - post patch):4.28% [kernel] [k] __dev_queue_xmit 3.80% [kernel] [k] check_preemption_disabled 3.68% [kernel] [k] nft_do_chain 3.08% [kernel] [k] __netif_receive_skb_core.constprop.0 2.59% [kernel] [k] mlx5e_xmit 2.48% [kernel] [k] mlx5e_skb_from_cqe_mpwrq_nonlinear
Quoted 4 lines
The concept makes sense - but i am wondering when you have a mix of
skip_swandskip_hwif it makes more sense to just avoid looking upskip_swat all in the s/w datapath? Potentially by separating the hashes for skip_sw/hw. I know it's a deeper surgery - but would be
Yeah, there could be 2 hashes: skip_sw/rest
rest is the only one that needs to be looked-up in kernel datapath. skip_sw is just for control path.
But is it worth the efford? I mean, since now, nobody seemed to care. If this patchset solves the problem for this usecase, I think it is enough.
In that case, I'm fine with this patch:
Quoted 56 lines
more general purpose....unless i am missing something
Quoted 6 lines
Test setup:
DUT: Intel Xeon D-1518 (2.20GHz) w/ Nvidia/Mellanox ConnectX-6 Dx 2x100G Data rate measured on switch (Extreme X690), and DUT connected as a router on a stick, with pktgen and pktsink as VLANs. Pktgen was in range 12.79 - 12.95 Mpps across all tests.Hrm. Those are "tiny" numbers (25G @64B is about 3x that). What are the packet sizes?
Perhaps the traffic generator is a limitation here?
Also feels like you are doing exact matches? A sample flower rule would have helped.cheers,
jamalQuoted 39 lines
Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/pkt_cls.h | 5 +++++ net/core/dev.c | 3 +++ 2 files changed, 8 insertions(+)include/net/pkt_cls.h +5
-0@@ -74,6 +74,11 @@ static inline bool tcf_block_non_null_shared(struct tcf_block *block)return block && block->index; } +static inline bool tcf_block_has_skip_sw_only (struct tcf_block *block) +{ +return block &&atomic_read (&block->filtercnt) ==atomic_read (&block->skipswcnt); +} +static inline struct Qdisc *tcf_block_q (struct tcf_block *block) {WARN_ON (tcf_block_shared (block));net/core/dev.c +3
-1@@ -3910,6 +3910,9 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,if (!miniq)return ret; +if (tcf_block_has_skip_sw_only (miniq->block)) +return ret; +tc_skb_cb (skb)->mru =0 ;tc_skb_cb (skb)->post_ct = false;tcf_set_drop_reason (skb, *drop_reason); --2.43.0
Jamal Hadi Salim
maintainerRe: [PATCH net-next 3/3] net: sched: make skip_sw actually skip software
Quoted 55 lines · Jiri Pirko
Quoted 48 lines · Thu, Feb 15, 2024 at 06:49:05PM CET, [email protected] wrote:
Quoted 38 lines · Asbjørn Sloth Tønnesen
TC filters come in 3 variants:
- no flag (no opinion, process wherever possible)
-skip_hw(do not process filter by hardware)
-skip_sw(do not process filter by software)However
skip_swis implemented so that theskip_swflag can first be checked, after it has been matched.IMHO it's common when using
skip_sw, to use it on all rules.So if all filters in a block is
skip_swfilters, then we can bail early, we can thus avoid having to match the filters, just to check for theskip_swflag.+----------------------------+--------+--------+--------+ | Test description | Pre | Post | Rel. | | | kpps | kpps | chg. | +----------------------------+--------+--------+--------+ | basic forwarding + notrack | 1264.9 | 1277.7 | 1.01x | | switch to eswitch mode | 1067.1 | 1071.0 | 1.00x | | add ingress qdisc | 1056.0 | 1059.1 | 1.00x | +----------------------------+--------+--------+--------+ | 1 non-matching rule | 927.9 | 1057.1 | 1.14x | | 10 non-matching rules | 495.8 | 1055.6 | 2.13x | | 25 non-matching rules | 280.6 | 1053.5 | 3.75x | | 50 non-matching rules | 162.0 | 1055.7 | 6.52x | | 100 non-matching rules | 87.7 | 1019.0 | 11.62x | +----------------------------+--------+--------+--------+perf top (100 n-m
skip_swrules - pre patch):25.57% [kernel] [k] __skb_flow_dissect 20.77% [kernel] [k] rhashtable_jhash2 14.26% [kernel] [k] fl_classify 13.28% [kernel] [k] fl_mask_lookup 6.38% [kernel] [k] memset_orig 3.22% [kernel] [k] tcf_classifyQuoted 8 lines
perf top (100 n-m
skip_swrules - post patch):4.28% [kernel] [k] __dev_queue_xmit 3.80% [kernel] [k] check_preemption_disabled 3.68% [kernel] [k] nft_do_chain 3.08% [kernel] [k] __netif_receive_skb_core.constprop.0 2.59% [kernel] [k] mlx5e_xmit 2.48% [kernel] [k] mlx5e_skb_from_cqe_mpwrq_nonlinearQuoted 4 lines
The concept makes sense - but i am wondering when you have a mix of
skip_swandskip_hwif it makes more sense to just avoid looking upskip_swat all in the s/w datapath? Potentially by separating the hashes for skip_sw/hw. I know it's a deeper surgery - but would be
Quoted 7 lines
Yeah, there could be 2 hashes: skip_sw/rest
rest is the only one that needs to be looked-up in kernel datapath.skip_swis just for control path.But is it worth the efford? I mean, since now, nobody seemed to care. If this patchset solves the problem for this usecase, I think it is enough.
May not be worth the effort - and this is a reasonable use case. The approach is a hack nonetheless and kills at least some insects. To address the issues Vlad brought up, perhaps we should wrap it under some kconfig.
cheers,
jamal
Quoted 62 lines
In that case, I'm fine with this patch:
Reviewed-by Jiri Pirko <[email protected]>Quoted 56 lines
more general purpose....unless i am missing something
Quoted 6 lines
Test setup:
DUT: Intel Xeon D-1518 (2.20GHz) w/ Nvidia/Mellanox ConnectX-6 Dx 2x100G Data rate measured on switch (Extreme X690), and DUT connected as a router on a stick, with pktgen and pktsink as VLANs. Pktgen was in range 12.79 - 12.95 Mpps across all tests.Hrm. Those are "tiny" numbers (25G @64B is about 3x that). What are the packet sizes?
Perhaps the traffic generator is a limitation here?
Also feels like you are doing exact matches? A sample flower rule would have helped.cheers,
jamalQuoted 39 lines
Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/pkt_cls.h | 5 +++++ net/core/dev.c | 3 +++ 2 files changed, 8 insertions(+)include/net/pkt_cls.h +5
-0@@ -74,6 +74,11 @@ static inline bool tcf_block_non_null_shared(struct tcf_block *block)return block && block->index; } +static inline bool tcf_block_has_skip_sw_only (struct tcf_block *block) +{ +return block &&atomic_read (&block->filtercnt) ==atomic_read (&block->skipswcnt); +} +static inline struct Qdisc *tcf_block_q (struct tcf_block *block) {WARN_ON (tcf_block_shared (block));net/core/dev.c +3
-1@@ -3910,6 +3910,9 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,if (!miniq)return ret; +if (tcf_block_has_skip_sw_only (miniq->block)) +return ret; +tc_skb_cb (skb)->mru =0 ;tc_skb_cb (skb)->post_ct = false;tcf_set_drop_reason (skb, *drop_reason); --2.43.0
Re: [PATCH net-next 3/3] net: sched: make skip_sw actually skip software
In reply to Jamal Hadi SalimHi Jamal,
Quoted 61 lines · Jamal Hadi Salim
Quoted 38 lines · Asbjørn Sloth Tønnesen
TC filters come in 3 variants:
- no flag (no opinion, process wherever possible)
-skip_hw(do not process filter by hardware)
-skip_sw(do not process filter by software)However
skip_swis implemented so that theskip_swflag can first be checked, after it has been matched.IMHO it's common when using
skip_sw, to use it on all rules.So if all filters in a block is
skip_swfilters, then we can bail early, we can thus avoid having to match the filters, just to check for theskip_swflag.+----------------------------+--------+--------+--------+ | Test description | Pre | Post | Rel. | | | kpps | kpps | chg. | +----------------------------+--------+--------+--------+ | basic forwarding + notrack | 1264.9 | 1277.7 | 1.01x | | switch to eswitch mode | 1067.1 | 1071.0 | 1.00x | | add ingress qdisc | 1056.0 | 1059.1 | 1.00x | +----------------------------+--------+--------+--------+ | 1 non-matching rule | 927.9 | 1057.1 | 1.14x | | 10 non-matching rules | 495.8 | 1055.6 | 2.13x | | 25 non-matching rules | 280.6 | 1053.5 | 3.75x | | 50 non-matching rules | 162.0 | 1055.7 | 6.52x | | 100 non-matching rules | 87.7 | 1019.0 | 11.62x | +----------------------------+--------+--------+--------+perf top (100 n-m
skip_swrules - pre patch):25.57% [kernel] [k] __skb_flow_dissect 20.77% [kernel] [k] rhashtable_jhash2 14.26% [kernel] [k] fl_classify 13.28% [kernel] [k] fl_mask_lookup 6.38% [kernel] [k] memset_orig 3.22% [kernel] [k] tcf_classifyQuoted 8 lines
perf top (100 n-m
skip_swrules - post patch):4.28% [kernel] [k] __dev_queue_xmit 3.80% [kernel] [k] check_preemption_disabled 3.68% [kernel] [k] nft_do_chain 3.08% [kernel] [k] __netif_receive_skb_core.constprop.0 2.59% [kernel] [k] mlx5e_xmit 2.48% [kernel] [k] mlx5e_skb_from_cqe_mpwrq_nonlinearThe concept makes sense - but i am wondering when you have a mix of
skip_swandskip_hwif it makes more sense to just avoid looking upskip_swat all in the s/w datapath? Potentially by separating the hashes for skip_sw/hw. I know it's a deeper surgery - but would be more general purpose....unless i am missing somethingQuoted 6 lines
Test setup:
DUT: Intel Xeon D-1518 (2.20GHz) w/ Nvidia/Mellanox ConnectX-6 Dx 2x100G Data rate measured on switch (Extreme X690), and DUT connected as a router on a stick, with pktgen and pktsink as VLANs. Pktgen was in range 12.79 - 12.95 Mpps across all tests.
Quoted 5 lines
Hrm. Those are "tiny" numbers (25G @64B is about 3x that). What are the packet sizes?
Perhaps the traffic generator is a limitation here?
Also feels like you are doing exact matches? A sample flower rule would have helped.
Yeah, I would also have liked those number to be higher. Sorry forgot to mention it is 64B packets.
Sadly, I used two machine to compensate for my lack of pktgen skills. I know that there are faster packet generators, but I just used the in-kernel one, and haven't invested much time into it, but the normal ethtool params mentioned in the doc didn't change much, and since it was still more than enough packets that DUT would go to 100% CPU, I didn't pursue it further.
pktgen A: Xeon E5-1620 v2 @ 3.70GHz w/ ConnectX-6 Dx and 100G link. pktgen B: Xeon(R) D-2123IT @ 2.20GHz w/ Intel X722 and 10G link.
Both pktgen boxes are running stock Debian bullseye kernel (v6.1)
I found this to work best:
./pktgen_sample05_flow_per_thread.sh -i enp8s0f0np0 -s 64 -d 10.53.22.3 -m 2a:11:22:33:21:11 -p 1024-65000 -t 8 -n 0
Datarates monitored through SNMP using:
snmpdelta -Cp 10 -c public -v 2c -Cs $hostname IF-MIB::ifInUcastPkts.1057 IF-MIB::ifOutUcastPkts.1057
VLAN config, MAC and IP addressing:
v21:
2a:11:22:33:21:11 - 10.53.21.1/27 - dut v21 (tagged VLAN)
2a:11:22:33:21:12 - 10.53.21.2/27 - pktgen-a (untagged)
2a:11:22:33:21:13 - 10.53.21.3/27 - pktgen-b (untagged)v22:
2a:11:22:33:22:21 - 10.53.22.2/31 - dut v22 (tagged VLAN)
2a:11:22:33:22:22 - 10.53.22.3/31 - packet drop (untagged)Switch MAC address table config:
# static entry create fdb 2a:11:22:33:21:11 vlan "v21" port 57
# blackhole pktsink create fdb 2a:11:22:33:22:22 vlan "v22" blackhole
flow control are disabled on all links:
ethtool -A $dev rx off tx off
I have uploaded the script used for the flower rules in the tests here:
https://files.fiberby.net/ast/2024/tc_skip_sw/flower_placement_tests.sh
Quoted 41 lines
cheers,
jamalQuoted 39 lines
Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/pkt_cls.h | 5 +++++ net/core/dev.c | 3 +++ 2 files changed, 8 insertions(+)include/net/pkt_cls.h +5
-0@@ -74,6 +74,11 @@ static inline bool tcf_block_non_null_shared(struct tcf_block *block)return block && block->index; } +static inline bool tcf_block_has_skip_sw_only (struct tcf_block *block) +{ +return block &&atomic_read (&block->filtercnt) ==atomic_read (&block->skipswcnt); +} +static inline struct Qdisc *tcf_block_q (struct tcf_block *block) {WARN_ON (tcf_block_shared (block));net/core/dev.c +3
-1@@ -3910,6 +3910,9 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,if (!miniq)return ret; +if (tcf_block_has_skip_sw_only (miniq->block)) +return ret; +tc_skb_cb (skb)->mru =0 ;tc_skb_cb (skb)->post_ct = false;tcf_set_drop_reason (skb, *drop_reason); --2.43.0
Signature · 4 lines
Best regards Asbjørn Sloth Tønnesen Network Engineer Fiberby - AS42541
Re: [PATCH net-next 3/3] net: sched: make skip_sw actually skip software
In reply to Asbjørn Sloth TønnesenQuoted 62 lines · Asbjørn Sloth Tønnesen
TC filters come in 3 variants:
- no flag (no opinion, process wherever possible)
-skip_hw(do not process filter by hardware)
-skip_sw(do not process filter by software)However
skip_swis implemented so that theskip_swflag can first be checked, after it has been matched.IMHO it's common when using
skip_sw, to use it on all rules.So if all filters in a block is
skip_swfilters, then we can bail early, we can thus avoid having to match the filters, just to check for theskip_swflag.+----------------------------+--------+--------+--------+ | Test description | Pre | Post | Rel. | | | kpps | kpps | chg. | +----------------------------+--------+--------+--------+ | basic forwarding + notrack | 1264.9 | 1277.7 | 1.01x | | switch to eswitch mode | 1067.1 | 1071.0 | 1.00x | | add ingress qdisc | 1056.0 | 1059.1 | 1.00x | +----------------------------+--------+--------+--------+ | 1 non-matching rule | 927.9 | 1057.1 | 1.14x | | 10 non-matching rules | 495.8 | 1055.6 | 2.13x | | 25 non-matching rules | 280.6 | 1053.5 | 3.75x | | 50 non-matching rules | 162.0 | 1055.7 | 6.52x | | 100 non-matching rules | 87.7 | 1019.0 | 11.62x | +----------------------------+--------+--------+--------+perf top (100 n-m
skip_swrules - pre patch):25.57% [kernel] [k] __skb_flow_dissect 20.77% [kernel] [k] rhashtable_jhash2 14.26% [kernel] [k] fl_classify 13.28% [kernel] [k] fl_mask_lookup 6.38% [kernel] [k] memset_orig 3.22% [kernel] [k] tcf_classifyperf top (100 n-m
skip_swrules - post patch):4.28% [kernel] [k] __dev_queue_xmit 3.80% [kernel] [k] check_preemption_disabled 3.68% [kernel] [k] nft_do_chain 3.08% [kernel] [k] __netif_receive_skb_core.constprop.0 2.59% [kernel] [k] mlx5e_xmit 2.48% [kernel] [k] mlx5e_skb_from_cqe_mpwrq_nonlinearTest setup:
DUT: Intel Xeon D-1518 (2.20GHz) w/ Nvidia/Mellanox ConnectX-6 Dx 2x100G Data rate measured on switch (Extreme X690), and DUT connected as a router on a stick, with pktgen and pktsink as VLANs. Pktgen was in range 12.79 - 12.95 Mpps across all tests.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/pkt_cls.h | 5 +++++ net/core/dev.c | 3 +++ 2 files changed, 8 insertions(+)include/net/pkt_cls.h +0
-0
include/net/pkt_cls.h static inline bool tcf_block_non_null_shared(struct tcf_block *block) · line 80
Quoted 7 lines
include/net/pkt_cls.h +4
-0@@ -74,6 +74,11 @@ static inline bool tcf_block_non_null_shared(struct tcf_block *block)return block && block->index; } +static inline bool tcf_block_has_skip_sw_only (struct tcf_block *block) +{ +return block &&atomic_read (&block->filtercnt) ==atomic_read (&block->skipswcnt); +}
Note that this introduces a read from heavily contended cache-line on data path for all classifiers, including the ones that don't support offloads. Wonder if this a concern for users running purely software tc.
Quoted 18 lines
include/net/pkt_cls.h +1
-0+static inline struct Qdisc *tcf_block_q (struct tcf_block *block) {WARN_ON (tcf_block_shared (block));net/core/dev.c +3
-0@@ -3910,6 +3910,9 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,if (!miniq)return ret; +if (tcf_block_has_skip_sw_only (miniq->block)) +return ret; +tc_skb_cb (skb)->mru =0 ;tc_skb_cb (skb)->post_ct = false;tcf_set_drop_reason (skb, *drop_reason);
Re: [PATCH net-next 3/3] net: sched: make skip_sw actually skip software
Hi Vlad,
Quoted 66 lines · Vlad Buslov
Quoted 65 lines · Asbjørn Sloth Tønnesen
TC filters come in 3 variants:
- no flag (no opinion, process wherever possible)
-skip_hw(do not process filter by hardware)
-skip_sw(do not process filter by software)However
skip_swis implemented so that theskip_swflag can first be checked, after it has been matched.IMHO it's common when using
skip_sw, to use it on all rules.So if all filters in a block is
skip_swfilters, then we can bail early, we can thus avoid having to match the filters, just to check for theskip_swflag.+----------------------------+--------+--------+--------+ | Test description | Pre | Post | Rel. | | | kpps | kpps | chg. | +----------------------------+--------+--------+--------+ | basic forwarding + notrack | 1264.9 | 1277.7 | 1.01x | | switch to eswitch mode | 1067.1 | 1071.0 | 1.00x | | add ingress qdisc | 1056.0 | 1059.1 | 1.00x | +----------------------------+--------+--------+--------+ | 1 non-matching rule | 927.9 | 1057.1 | 1.14x | | 10 non-matching rules | 495.8 | 1055.6 | 2.13x | | 25 non-matching rules | 280.6 | 1053.5 | 3.75x | | 50 non-matching rules | 162.0 | 1055.7 | 6.52x | | 100 non-matching rules | 87.7 | 1019.0 | 11.62x | +----------------------------+--------+--------+--------+perf top (100 n-m
skip_swrules - pre patch):25.57% [kernel] [k] __skb_flow_dissect 20.77% [kernel] [k] rhashtable_jhash2 14.26% [kernel] [k] fl_classify 13.28% [kernel] [k] fl_mask_lookup 6.38% [kernel] [k] memset_orig 3.22% [kernel] [k] tcf_classifyperf top (100 n-m
skip_swrules - post patch):4.28% [kernel] [k] __dev_queue_xmit 3.80% [kernel] [k] check_preemption_disabled 3.68% [kernel] [k] nft_do_chain 3.08% [kernel] [k] __netif_receive_skb_core.constprop.0 2.59% [kernel] [k] mlx5e_xmit 2.48% [kernel] [k] mlx5e_skb_from_cqe_mpwrq_nonlinearTest setup:
DUT: Intel Xeon D-1518 (2.20GHz) w/ Nvidia/Mellanox ConnectX-6 Dx 2x100G Data rate measured on switch (Extreme X690), and DUT connected as a router on a stick, with pktgen and pktsink as VLANs. Pktgen was in range 12.79 - 12.95 Mpps across all tests.Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>--- include/net/pkt_cls.h | 5 +++++ net/core/dev.c | 3 +++ 2 files changed, 8 insertions(+)include/net/pkt_cls.h +0
-0@@ -74,6 +74,11 @@ static inline bool tcf_block_non_null_shared(struct tcf_block *block)return block && block->index; }
Quoted 8 lines
include/net/pkt_cls.h static inline bool tcf_block_non_null_shared(struct tcf_block *block) · line 80
Quoted 4 lines
include/net/pkt_cls.h +4
-0+static inline bool tcf_block_has_skip_sw_only (struct tcf_block *block) +{ +return block &&atomic_read (&block->filtercnt) ==atomic_read (&block->skipswcnt); +}Note that this introduces a read from heavily contended cache-line on data path for all classifiers, including the ones that don't support offloads. Wonder if this a concern for users running purely software tc.
Unfortunately, I don't have access to any multi-CPU machines, so I haven't been able to test the impact of that.
Alternatively I guess I could also maintain a static key in the counter update logic.
Quoted 19 lines
Quoted 18 lines
include/net/pkt_cls.h +1
-0+static inline struct Qdisc *tcf_block_q (struct tcf_block *block) {WARN_ON (tcf_block_shared (block));net/core/dev.c +3
-0@@ -3910,6 +3910,9 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,if (!miniq)return ret; +if (tcf_block_has_skip_sw_only (miniq->block)) +return ret; +tc_skb_cb (skb)->mru =0 ;tc_skb_cb (skb)->post_ct = false;tcf_set_drop_reason (skb, *drop_reason);
Signature · 4 lines
Best regards Asbjørn Sloth Tønnesen Network Engineer Fiberby - AS42541
Hi,
On Thu, Feb 15, 2024 at 04:04:41PM +0000, Asbjørn Sloth Tønnesen wrote:
...
Quoted 5 lines
Since we use TC flower offload for the hottest prefixes, and leave the long tail to Linux / the CPU. we therefore need both the hardware and software datapath to perform well.
Quoted 7 lines
I found that
skip_swrules, are quite expensive in the kernel datapath, sice they must be evaluated and matched upon, before the kernel checks theskip_swflag.This patchset optimizes the case where all rules are
skip_sw.
The talk is interesting. Yet, I don't get how it is set up. How do you use a dedicated block for skip_sw, and then have a catch-all on sw again please?
I'm missing which traffic is being matched against the sw datapath. In theory, you have all the heavy duty filters offloaded, so the sw datapath should be seeing only a few packets, right?
Marcelo
Quoted 17 lines · Marcelo Ricardo Leitner
Hi,
On Thu, Feb 15, 2024 at 04:04:41PM +0000, Asbjørn Sloth Tønnesen wrote:
...Quoted 5 lines
Since we use TC flower offload for the hottest prefixes, and leave the long tail to Linux / the CPU. we therefore need both the hardware and software datapath to perform well.
Quoted 7 lines
I found that
skip_swrules, are quite expensive in the kernel datapath, sice they must be evaluated and matched upon, before the kernel checks theskip_swflag.This patchset optimizes the case where all rules are
skip_sw.
Quoted 7 lines
The talk is interesting. Yet, I don't get how it is set up. How do you use a dedicated block for
skip_sw, and then have a catch-all on sw again please?I'm missing which traffic is being matched against the sw datapath. In theory, you have all the heavy duty filters offloaded, so the sw datapath should be seeing only a few packets, right?
Yeah, I also didn't get the idea here. The cited paragraphs seem to contradict each other.
Hi Marcelo,
Quoted 12 lines · Marcelo Ricardo Leitner
On Thu, Feb 15, 2024 at 04:04:41PM +0000, Asbjørn Sloth Tønnesen wrote:
...Quoted 10 lines
Since we use TC flower offload for the hottest prefixes, and leave the long tail to Linux / the CPU. we therefore need both the hardware and software datapath to perform well.
I found that
skip_swrules, are quite expensive in the kernel datapath, sice they must be evaluated and matched upon, before the kernel checks theskip_swflag.
Quoted 6 lines
Quoted 2 lines
This patchset optimizes the case where all rules are
skip_sw.The talk is interesting. Yet, I don't get how it is set up. How do you use a dedicated block for
skip_sw, and then have a catch-all on sw again please?
Bird installs the DFZ Internet routing table into the main kernel table for the software datapath.
Bird also installs a subset of routing table into an aux. kernel table.
flower-route then picks up the routes from the aux. kernel table, and installs them as TC skip_sw filters.
On these machines we don't have any non-skip_sw TC filters.
Since 2021, we have statically offloaded all inbound traffic, since nexthop for our IP space is always the switch next to it, which does interior L3 routing. Thereby we could offload ~50% of the packets.
I have put an example of the static script here:
https://files.fiberby.net/ast/2024/tc_skip_sw/mlx5_static_offload.sh
And tc filter show dev enp5s0f0np0 ingress after running the script:
https://files.fiberby.net/ast/2024/tc_skip_sw/mlx_offload_demo_tc_dump.txt
Quoted 3 lines
I'm missing which traffic is being matched against the sw datapath. In theory, you have all the heavy duty filters offloaded, so the sw datapath should be seeing only a few packets, right?
We are an residential ISP, our traffic is therefore residential Internet traffic, we run the BGP routers as a router on a stick, the filters therefore see both inbound and outbound traffic.
~50% of packets are inbound traffic, our own prefixes are therefore the hottest prefixes. Most streaming traffic is handled internally, and is therefore not seen on our core routers. We regularly have 5%-10% of all outbound traffic going towards the same prefix, and have 50% of outbound traffic distributed across just a few prefixes.
We currently only offload our own prefixes, and a select few other known high-traffic prefixes.
The goal is to offload the majority of the trafic, but it is still early days for flower-route, and I need to implement some smarter chain layout first and dynamic filter placement based on hardware counters.
Even when I get flower-route to offload almost all traffic, there will still be a long tail of prefixes not in hardware, so the kernel still needs to not be pulled down by the offloaded filters.
Signature · 4 lines
Best regards Asbjørn Sloth Tønnesen Network Engineer Fiberby - AS42541
Quoted 36 lines · Asbjørn Sloth Tønnesen
Hi Marcelo,
Quoted 12 lines · Marcelo Ricardo Leitner
On Thu, Feb 15, 2024 at 04:04:41PM +0000, Asbjørn Sloth Tønnesen wrote:
...Quoted 10 lines
Since we use TC flower offload for the hottest prefixes, and leave the long tail to Linux / the CPU. we therefore need both the hardware and software datapath to perform well.
I found that
skip_swrules, are quite expensive in the kernel datapath, sice they must be evaluated and matched upon, before the kernel checks theskip_swflag.Quoted 6 lines
Quoted 2 lines
This patchset optimizes the case where all rules are
skip_sw.The talk is interesting. Yet, I don't get how it is set up. How do you use a dedicated block for
skip_sw, and then have a catch-all on sw again please?Bird installs the DFZ Internet routing table into the main kernel table for the software datapath.
Bird also installs a subset of routing table into an aux. kernel table.
flower-route then picks up the routes from the aux. kernel table, and installs them as TC
skip_swfilters.On these machines we don't have any non-skip_sw TC filters.
Since 2021, we have statically offloaded all inbound traffic, since nexthop for our IP space is always the switch next to it, which does interior L3 routing. Thereby we could offload ~50% of the packets.
Quoted 5 lines
I have put an example of the static script here:
https://files.fiberby.net/ast/2024/tc_skip_sw/mlx5_static_offload.shAnd
tc filter show dev enp5s0f0np0 ingressafter running the script:
https://files.fiberby.net/ast/2024/tc_skip_sw/mlx_offload_demo_tc_dump.txt
Ahh ok. So from tc/flower perspective, you actually offload everything. :-)
The part that was confusing to me is that what you need done in sw, you don't do it in tc sw, but rather with the IP the stack itself. So you actually offload a flower filter with these, lets say, exceptions.
It seems to me a better fix for this is to have action trap to "resume to sw" to itself. Then even if you have traffic that triggers a miss in hw, you could add a catch-all filter to trigger the trap.
With the catch-all idea, you may also instead of using trap directly, use a goto chain X. I just don't remember if you need to have a flow in chain X that is not offloaded, or an inexistant chain is enough.
These ideas are rooted on the fact that now the offloading can resume processing at a given chain, or even at a given action that triggered the miss. With this, it should skip all the filtering that is unnecessary in your case. IOW, instead of trying to make the filtering smarter, which current proposal would be limited to this use case pretty much (instead of using a dedicated list for skip_sw), it resumes the processing at a better spot, and with what we already have.
One caveat with this approach is that it will cause an skb_extension to be allocated for all this traffic that is handled in sw. There's a small performance penalty on it.
WDYT? Or maybe I missed something?
Quoted 16 lines
Quoted 5 lines
I'm missing which traffic is being matched against the sw datapath. In theory, you have all the heavy duty filters offloaded, so the sw datapath should be seeing only a few packets, right?
We are an residential ISP, our traffic is therefore residential Internet traffic, we run the BGP routers as a router on a stick, the filters therefore see both inbound and outbound traffic.
~50% of packets are inbound traffic, our own prefixes are therefore the hottest prefixes. Most streaming traffic is handled internally, and is therefore not seen on our core routers. We regularly have 5%-10% of all outbound traffic going towards the same prefix, and have 50% of outbound traffic distributed across just a few prefixes.
Quoted 6 lines
We currently only offload our own prefixes, and a select few other known high-traffic prefixes.
The goal is to offload the majority of the trafic, but it is still early days for flower-route, and I need to implement some smarter chain layout first and dynamic filter placement based on hardware counters.
Cool. Btw, be aware that after a few chain jumps, performance may drop considerably even if offloaded.
Quoted 11 lines
Even when I get flower-route to offload almost all traffic, there will still be a long tail of prefixes not in hardware, so the kernel still needs to not be pulled down by the offloaded filters.
--
Best regards
Asbjørn Sloth Tønnesen
Network Engineer
Fiberby - AS42541