Improvements to the DSA deferred xmit
Subsystems (3)
Vladimir Oltean
maintainercover Improvements to the DSA deferred xmit
The DSA deferred xmit mechanism is currently used by a single driver (sja1105) because the transmission of some operations requires SPI access in the fastpath.
This 2-patch series makes this mechanism better for everybody:
- For those who don't use it, thanks to one less assignment in the hotpath
- For those who do, by making its scheduling more amenable and moving it outside the generic workqueue (since it still deals with packet hotpath, after all)
Vladimir Oltean (2):
net: dsa: Remove deferred_xmit from dsa_skb_cb
net: dsa: Create a kernel thread for each port's deferred xmit work
include/net/dsa.h | 4 ++-- net/dsa/slave.c | 53 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 16 deletions(-)
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH 1/2 net: dsa: Remove deferred_xmit from dsa_skb_cb
The introduction of the deferred xmit mechanism in DSA has made the hotpath slightly more inefficient for everybody, since DSA_SKB_CB(skb)->deferred_xmit needed to be initialized to false for every transmitted frame, in order to figure out whether the driver requested deferral or not. That was necessary to avoid kfree_skb from freeing the skb.
But actually we can just remove that variable in the skb->cb and counteract the effect of kfree_skb with skb_get, much to the same effect. The advantage, of course, being that anybody who doesn't use deferred xmit doesn't need to do any extra operation in the hotpath.
--- include/net/dsa.h | 1 - net/dsa/slave.c | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-)
include/net/dsa.h +0 -1
@@ -88,7 +88,6 @@ struct dsa_device_ops {struct dsa_skb_cb {struct sk_buff *clone; -bool deferred_xmit; };struct __dsa_skb_cb {
net/dsa/slave.c +6 -6
@@ -518,7 +518,6 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) s->tx_bytes += skb->len;u64_stats_update_end (&s->syncp); -DSA_SKB_CB (skb)->deferred_xmit = false;DSA_SKB_CB (skb)->clone =NULL ;/* Identify PTP protocol packets, clone them, and pass them to the
@@ -531,8 +530,7 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)*/ nskb = p->xmit (skb, dev);if (!nskb) { -if (!DSA_SKB_CB (skb)->deferred_xmit) -kfree_skb (skb); +kfree_skb (skb);return NETDEV_TX_OK ; }
@@ -543,10 +541,12 @@ void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev) {struct dsa_port *dp =dsa_slave_to_port (dev); -DSA_SKB_CB (skb)->deferred_xmit = true; - -skb_queue_tail (&dp->xmit_queue, skb); +/* Increase refcount so the kfree_skb in dsa_slave_xmit +* won't really free the packet. +*/ +skb_queue_tail (&dp->xmit_queue,skb_get (skb));schedule_work (&dp->xmit_work); +return NULL ; }EXPORT_SYMBOL_GPL (dsa_defer_xmit);
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH 2/2 net: dsa: Create a kernel thread for each port's deferred xmit work
In reply to Vladimir OlteanBecause this callback can be used on certain switches (at the moment only sja1105) to do TX timstamping, this should have been a kernel thread from the get-go.
PTP is a time-critical protocol and requires the ability to control the scheduling priority with tools such as chrt, as opposed to just executing the work in the generic workqueue.
If the user switch ports are named swp0, swp1, swp2, the kernel threads will be named dsa_swp0_xmit, dsa_swp1_xmit, dsa_swp2_xmit.
--- include/net/dsa.h | 3 ++- net/dsa/slave.c | 43 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-)
include/net/dsa.h +2 -1
@@ -189,7 +189,8 @@ struct dsa_port {struct phylink *pl;struct phylink_config pl_config; -struct work_struct xmit_work; +struct kthread_worker *xmit_worker; +struct kthread_work xmit_work;struct sk_buff_head xmit_queue;struct list_head list;
net/dsa/slave.c +34 -9
97 lines not on this page · raw message
Signature · 1 line
2.17.1
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Fri, 27 Dec 2019 03:42:06 +0200
Quoted 11 lines
The DSA deferred xmit mechanism is currently used by a single driver (sja1105) because the transmission of some operations requires SPI access in the fastpath.
This 2-patch series makes this mechanism better for everybody:
- For those who don't use it, thanks to one less assignment in the hotpath
- For those who do, by making its scheduling more amenable and moving it outside the generic workqueue (since it still deals with packet hotpath, after all)
Two comments about this patch series, I think it needs more work:
1) This adds the thread and the xmit queue but not code that actually uses it. You really have to provide the support code in the driver at the same time you add the new facitlity so we can actually see how it'll be used.
2) Patch #1 talks about a tradeoff. Replacing the CB initialization of the field skb_get(). But this skb_get() is an atomic operation and thus much more expensive for users of the deferred xmit scheme.
Thanks.
Vladimir Oltean
maintainerHi David,
Quoted 3 lines · David Miller
Two comments about this patch series, I think it needs more work:
Thanks for looking at this series.
Quoted 5 lines
1) This adds the thread and the xmit queue but not code that actually uses it. You really have to provide the support code in the driver at the same time you add the new facitlity so we can actually see how it'll be used.
There is no API change here. There was, and still is, a single caller of dsa_defer_xmit in the kernel, from net/dsa/tag_sja1105.c:
if (unlikely(sja1105_is_link_local(skb)))
return dsa_defer_xmit(skb, netdev);The whole difference is that what used to be a schedule_work() in that function is now a kthread_queue_work() call.
Quoted 4 lines
2) Patch #1 talks about a tradeoff. Replacing the CB initialization of the field
skb_get(). But thisskb_get()is an atomic operation and thus much more expensive for users of the deferred xmit scheme.
Ok, I'll admit I hadn't considered the exact penalty introduced by skb_get, but I think it is a matter of proportions.
Worst case I expect no more than 64 packets per second to be transmitted using the deferred xmit mechanism: there are 4 switch ports, PTP runs with a sync interval of 1/8 seconds, and the STP hello timer is 2 seconds. So, not a lot of traffic.
On the other hand, clearing the deferred_xmit bool from the skb->cb is something that everybody else (including this driver for "normal" traffic) needs to do at line rate, just for the above 64 packets per second (in the worst case) to be possible.
Quoted 1 line
Thanks.
Regards,
-Vladimir
Quoted 29 lines · Vladimir Oltean
Hi David,
Quoted 3 lines · David Miller
Two comments about this patch series, I think it needs more work:
Thanks for looking at this series.
Quoted 5 lines
1) This adds the thread and the xmit queue but not code that actually uses it. You really have to provide the support code in the driver at the same time you add the new facitlity so we can actually see how it'll be used.
There is no API change here. There was, and still is, a single caller of
dsa_defer_xmitin the kernel, fromnet/dsa/tag_sja1105.c:if (unlikely(sja1105_is_link_local(skb))) return dsa_defer_xmit(skb, netdev);The whole difference is that what used to be a
schedule_work()in that function is now akthread_queue_work()call.Quoted 4 lines
2) Patch #1 talks about a tradeoff. Replacing the CB initialization of the field
skb_get(). But thisskb_get()is an atomic operation and thus much more expensive for users of the deferred xmit scheme.
Quoted 10 lines
Ok, I'll admit I hadn't considered the exact penalty introduced by
skb_get, but I think it is a matter of proportions.
Worst case I expect no more than 64 packets per second to be transmitted using the deferred xmit mechanism: there are 4 switch ports, PTP runs with a sync interval of 1/8 seconds, and the STP hello timer is 2 seconds. So, not a lot of traffic.
On the other hand, clearing thedeferred_xmitbool from theskb->cbis something that everybody else (including this driver for "normal" traffic) needs to do at line rate, just for the above 64 packets per second (in the worst case) to be possible.
I sincerely think your transmit path is so radically different that your sja1105 driver should simply be absorbing all of this logic and the core DSA framework should be free of any deferred transmit logic. Can you consider doing that before the merge window ends?
Signature · 1 line
Florian
Quoted 4 lines · Florian Fainelli
I sincerely think your transmit path is so radically different that your sja1105 driver should simply be absorbing all of this logic and the core DSA framework should be free of any deferred transmit logic. Can you consider doing that before the merge window ends?
+1
Thanks,
Richard