From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cong Wang Subject: [Patch net-next 2/3] net_sched: plug in qdisc ops change_tx_queue_len Date: Fri, 19 Jan 2018 15:09:32 -0800 Message-ID: <20180119230933.10009-3-xiyou.wangcong@gmail.com> References: <20180119230933.10009-1-xiyou.wangcong@gmail.com> Cc: john.fastabend@gmail.com, Cong Wang To: netdev@vger.kernel.org Return-path: Received: from mail-pf0-f194.google.com ([209.85.192.194]:35790 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756037AbeASXJ5 (ORCPT ); Fri, 19 Jan 2018 18:09:57 -0500 Received: by mail-pf0-f194.google.com with SMTP id t12so2460894pfg.2 for ; Fri, 19 Jan 2018 15:09:56 -0800 (PST) In-Reply-To: <20180119230933.10009-1-xiyou.wangcong@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 Signed-off-by: Cong Wang --- include/net/sch_generic.h | 2 ++ net/core/dev.c | 1 + net/sched/sch_generic.c | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index cd1be1f25c36..aae1baa1c30f 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); + void (*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 *); +void 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 99d353e4cbb2..24809d858a64 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -7058,6 +7058,7 @@ int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len) dev->tx_queue_len = orig_len; return res; } + dev_qdisc_change_tx_queue_len(dev); } return 0; diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index ef8b4ecde2ac..30aaeb3c1bf1 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -1178,6 +1178,28 @@ void dev_deactivate(struct net_device *dev) } EXPORT_SYMBOL(dev_deactivate); +static void qdisc_change_tx_queue_len(struct net_device *dev, + struct netdev_queue *dev_queue, + void *unused) +{ + struct Qdisc *qdisc = dev_queue->qdisc_sleeping; + const struct Qdisc_ops *ops = qdisc->ops; + + if (ops->change_tx_queue_len) + ops->change_tx_queue_len(qdisc, dev->tx_queue_len); +} + +void dev_qdisc_change_tx_queue_len(struct net_device *dev) +{ + bool up = dev->flags & IFF_UP; + + if (up) + dev_deactivate(dev); + netdev_for_each_tx_queue(dev, qdisc_change_tx_queue_len, NULL); + if (up) + dev_activate(dev); +} + static void dev_init_scheduler_queue(struct net_device *dev, struct netdev_queue *dev_queue, void *_qdisc) -- 2.13.0