Message ID | 20180123181859.18583-3-xiyou.wangcong@gmail.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
Series | net_sched: reflect tx_queue_len change for pfifo_fast | expand |
On 01/23/2018 10:18 AM, Cong Wang wrote: > Introduce a new qdisc ops ->change_tx_queue_len() so that > each qdisc could decide how to implement this if it wants. > Previously we simply read dev->tx_queue_len, after pfifo_fast > switches to skb array, we need this API to resize the skb array > when we change dev->tx_queue_len. > > To avoid handling race conditions with TX BH, we need to > deactivate all TX queues before change the value and bring them > back after we are done, this also makes implementation easier. > > Cc: John Fastabend <john.fastabend@gmail.com> > Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> > --- > include/net/sch_generic.h | 2 ++ > net/core/dev.c | 1 + > net/sched/sch_generic.c | 33 +++++++++++++++++++++++++++++++++ > 3 files changed, 36 insertions(+) > > diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h > index cd1be1f25c36..d13dd129d085 100644 > --- a/include/net/sch_generic.h > +++ b/include/net/sch_generic.h > @@ -200,6 +200,7 @@ struct Qdisc_ops { > struct nlattr *arg, > struct netlink_ext_ack *extack); > void (*attach)(struct Qdisc *sch); > + int (*change_tx_queue_len)(struct Qdisc *, unsigned int); > > int (*dump)(struct Qdisc *, struct sk_buff *); > int (*dump_stats)(struct Qdisc *, struct gnet_dump *); > @@ -488,6 +489,7 @@ void qdisc_class_hash_remove(struct Qdisc_class_hash *, > void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *); > void qdisc_class_hash_destroy(struct Qdisc_class_hash *); > > +int dev_qdisc_change_tx_queue_len(struct net_device *dev); > void dev_init_scheduler(struct net_device *dev); > void dev_shutdown(struct net_device *dev); > void dev_activate(struct net_device *dev); > diff --git a/net/core/dev.c b/net/core/dev.c > index 913655e82859..a9d7d883416d 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -7059,6 +7059,7 @@ int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len) > dev->tx_queue_len = orig_len; > return res; > } > + return dev_qdisc_change_tx_queue_len(dev); > } > > return 0; > diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c > index 1816bde47256..08f9fa27e06e 100644 > --- a/net/sched/sch_generic.c > +++ b/net/sched/sch_generic.c > @@ -1178,6 +1178,39 @@ void dev_deactivate(struct net_device *dev) > } > EXPORT_SYMBOL(dev_deactivate); > > +static int qdisc_change_tx_queue_len(struct net_device *dev, > + struct netdev_queue *dev_queue) > +{ > + struct Qdisc *qdisc = dev_queue->qdisc_sleeping; > + const struct Qdisc_ops *ops = qdisc->ops; > + > + if (ops->change_tx_queue_len) > + return ops->change_tx_queue_len(qdisc, dev->tx_queue_len); > + return 0; > +} > + > +int dev_qdisc_change_tx_queue_len(struct net_device *dev) > +{ > + bool up = dev->flags & IFF_UP; > + unsigned int i; > + int ret = 0; > + > + if (up) > + dev_deactivate(dev); > + > + for (i = 0; i < dev->num_tx_queues; i++) { > + ret = qdisc_change_tx_queue_len(dev, &dev->_tx[i]); > + > + /* TODO: revert changes on a partial failure */ > + if (ret) > + break; After another look it seems we can solve this without too much pain by using skb_array_resize_multiple() in patch 3/3. Then pass the error pack here via qdisc_change_tx_queue_len and reset queue length to orig_length. Mind giving it a try? Or else I'll do it Friday probably. Thanks, John
On Wed, Jan 24, 2018 at 4:05 PM, John Fastabend <john.fastabend@gmail.com> wrote: > On 01/23/2018 10:18 AM, Cong Wang wrote: >> +int dev_qdisc_change_tx_queue_len(struct net_device *dev) >> +{ >> + bool up = dev->flags & IFF_UP; >> + unsigned int i; >> + int ret = 0; >> + >> + if (up) >> + dev_deactivate(dev); >> + >> + for (i = 0; i < dev->num_tx_queues; i++) { >> + ret = qdisc_change_tx_queue_len(dev, &dev->_tx[i]); >> + >> + /* TODO: revert changes on a partial failure */ >> + if (ret) >> + break; > > After another look it seems we can solve this without too much pain > by using skb_array_resize_multiple() in patch 3/3. Then pass the > error pack here via qdisc_change_tx_queue_len and reset queue length > to orig_length. Yeah, I was not aware of that API, looks reasonable. But, since you are referring to dev_qdisc_change_tx_queue_len(), it doesn't help 2/3 because we still have to iterate each tx queue, so the above comment still stands. I will update patch 3/3. Thanks.
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index cd1be1f25c36..d13dd129d085 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -200,6 +200,7 @@ struct Qdisc_ops { struct nlattr *arg, struct netlink_ext_ack *extack); void (*attach)(struct Qdisc *sch); + int (*change_tx_queue_len)(struct Qdisc *, unsigned int); int (*dump)(struct Qdisc *, struct sk_buff *); int (*dump_stats)(struct Qdisc *, struct gnet_dump *); @@ -488,6 +489,7 @@ void qdisc_class_hash_remove(struct Qdisc_class_hash *, void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *); void qdisc_class_hash_destroy(struct Qdisc_class_hash *); +int dev_qdisc_change_tx_queue_len(struct net_device *dev); void dev_init_scheduler(struct net_device *dev); void dev_shutdown(struct net_device *dev); void dev_activate(struct net_device *dev); diff --git a/net/core/dev.c b/net/core/dev.c index 913655e82859..a9d7d883416d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -7059,6 +7059,7 @@ int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len) dev->tx_queue_len = orig_len; return res; } + return dev_qdisc_change_tx_queue_len(dev); } return 0; diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index 1816bde47256..08f9fa27e06e 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -1178,6 +1178,39 @@ void dev_deactivate(struct net_device *dev) } EXPORT_SYMBOL(dev_deactivate); +static int qdisc_change_tx_queue_len(struct net_device *dev, + struct netdev_queue *dev_queue) +{ + struct Qdisc *qdisc = dev_queue->qdisc_sleeping; + const struct Qdisc_ops *ops = qdisc->ops; + + if (ops->change_tx_queue_len) + return ops->change_tx_queue_len(qdisc, dev->tx_queue_len); + return 0; +} + +int dev_qdisc_change_tx_queue_len(struct net_device *dev) +{ + bool up = dev->flags & IFF_UP; + unsigned int i; + int ret = 0; + + if (up) + dev_deactivate(dev); + + for (i = 0; i < dev->num_tx_queues; i++) { + ret = qdisc_change_tx_queue_len(dev, &dev->_tx[i]); + + /* TODO: revert changes on a partial failure */ + if (ret) + break; + } + + if (up) + dev_activate(dev); + return ret; +} + static void dev_init_scheduler_queue(struct net_device *dev, struct netdev_queue *dev_queue, void *_qdisc)
Introduce a new qdisc ops ->change_tx_queue_len() so that each qdisc could decide how to implement this if it wants. Previously we simply read dev->tx_queue_len, after pfifo_fast switches to skb array, we need this API to resize the skb array when we change dev->tx_queue_len. To avoid handling race conditions with TX BH, we need to deactivate all TX queues before change the value and bring them back after we are done, this also makes implementation easier. Cc: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> --- include/net/sch_generic.h | 2 ++ net/core/dev.c | 1 + net/sched/sch_generic.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+)