2019-06-04 11:11:33 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-09-06 12:58:51 +04:00
|
|
|
/*
|
|
|
|
* net/sched/sch_mq.c Classful multiqueue dummy scheduler
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Patrick McHardy <kaber@trash.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2009-09-06 12:58:51 +04:00
|
|
|
#include <linux/kernel.h>
|
2011-07-15 19:47:34 +04:00
|
|
|
#include <linux/export.h>
|
2009-09-06 12:58:51 +04:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/netlink.h>
|
2018-05-26 07:53:35 +03:00
|
|
|
#include <net/pkt_cls.h>
|
2009-09-06 12:58:51 +04:00
|
|
|
#include <net/pkt_sched.h>
|
2017-12-07 20:57:20 +03:00
|
|
|
#include <net/sch_generic.h>
|
2009-09-06 12:58:51 +04:00
|
|
|
|
|
|
|
struct mq_sched {
|
|
|
|
struct Qdisc **qdiscs;
|
|
|
|
};
|
|
|
|
|
2018-05-26 07:53:35 +03:00
|
|
|
static int mq_offload(struct Qdisc *sch, enum tc_mq_command cmd)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct tc_mq_qopt_offload opt = {
|
|
|
|
.command = cmd,
|
|
|
|
.handle = sch->handle,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_MQ, &opt);
|
|
|
|
}
|
|
|
|
|
2018-11-08 04:33:36 +03:00
|
|
|
static int mq_offload_stats(struct Qdisc *sch)
|
2018-05-26 07:53:37 +03:00
|
|
|
{
|
|
|
|
struct tc_mq_qopt_offload opt = {
|
|
|
|
.command = TC_MQ_STATS,
|
|
|
|
.handle = sch->handle,
|
|
|
|
.stats = {
|
|
|
|
.bstats = &sch->bstats,
|
|
|
|
.qstats = &sch->qstats,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-11-08 04:33:36 +03:00
|
|
|
return qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_MQ, &opt);
|
2018-05-26 07:53:37 +03:00
|
|
|
}
|
|
|
|
|
2009-09-06 12:58:51 +04:00
|
|
|
static void mq_destroy(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct mq_sched *priv = qdisc_priv(sch);
|
|
|
|
unsigned int ntx;
|
|
|
|
|
2018-05-26 07:53:35 +03:00
|
|
|
mq_offload(sch, TC_MQ_DESTROY);
|
|
|
|
|
2009-09-06 12:58:51 +04:00
|
|
|
if (!priv->qdiscs)
|
|
|
|
return;
|
|
|
|
for (ntx = 0; ntx < dev->num_tx_queues && priv->qdiscs[ntx]; ntx++)
|
2018-09-24 19:22:50 +03:00
|
|
|
qdisc_put(priv->qdiscs[ntx]);
|
2009-09-06 12:58:51 +04:00
|
|
|
kfree(priv->qdiscs);
|
|
|
|
}
|
|
|
|
|
2017-12-20 20:35:13 +03:00
|
|
|
static int mq_init(struct Qdisc *sch, struct nlattr *opt,
|
|
|
|
struct netlink_ext_ack *extack)
|
2009-09-06 12:58:51 +04:00
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct mq_sched *priv = qdisc_priv(sch);
|
|
|
|
struct netdev_queue *dev_queue;
|
|
|
|
struct Qdisc *qdisc;
|
|
|
|
unsigned int ntx;
|
|
|
|
|
|
|
|
if (sch->parent != TC_H_ROOT)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (!netif_is_multiqueue(dev))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
/* pre-allocate qdiscs, attachment can't fail */
|
|
|
|
priv->qdiscs = kcalloc(dev->num_tx_queues, sizeof(priv->qdiscs[0]),
|
|
|
|
GFP_KERNEL);
|
2017-02-10 21:31:49 +03:00
|
|
|
if (!priv->qdiscs)
|
2009-09-06 12:58:51 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
|
|
|
|
dev_queue = netdev_get_tx_queue(dev, ntx);
|
2016-03-02 19:21:43 +03:00
|
|
|
qdisc = qdisc_create_dflt(dev_queue, get_default_qdisc_ops(dev, ntx),
|
2009-09-06 12:58:51 +04:00
|
|
|
TC_H_MAKE(TC_H_MAJ(sch->handle),
|
2017-12-20 20:35:21 +03:00
|
|
|
TC_H_MIN(ntx + 1)),
|
|
|
|
extack);
|
2017-02-10 21:31:49 +03:00
|
|
|
if (!qdisc)
|
|
|
|
return -ENOMEM;
|
2009-09-06 12:58:51 +04:00
|
|
|
priv->qdiscs[ntx] = qdisc;
|
2015-12-02 07:08:51 +03:00
|
|
|
qdisc->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;
|
2009-09-06 12:58:51 +04:00
|
|
|
}
|
|
|
|
|
2009-09-10 05:11:23 +04:00
|
|
|
sch->flags |= TCQ_F_MQROOT;
|
2018-05-26 07:53:35 +03:00
|
|
|
|
|
|
|
mq_offload(sch, TC_MQ_CREATE);
|
2009-09-06 12:58:51 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mq_attach(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct mq_sched *priv = qdisc_priv(sch);
|
2013-12-05 23:12:02 +04:00
|
|
|
struct Qdisc *qdisc, *old;
|
2009-09-06 12:58:51 +04:00
|
|
|
unsigned int ntx;
|
|
|
|
|
|
|
|
for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
|
|
|
|
qdisc = priv->qdiscs[ntx];
|
2013-12-05 23:12:02 +04:00
|
|
|
old = dev_graft_qdisc(qdisc->dev_queue, qdisc);
|
|
|
|
if (old)
|
2018-09-24 19:22:50 +03:00
|
|
|
qdisc_put(old);
|
2013-12-05 23:12:02 +04:00
|
|
|
#ifdef CONFIG_NET_SCHED
|
|
|
|
if (ntx < dev->real_num_tx_queues)
|
2017-03-08 18:03:32 +03:00
|
|
|
qdisc_hash_add(qdisc, false);
|
2013-12-05 23:12:02 +04:00
|
|
|
#endif
|
|
|
|
|
2009-09-06 12:58:51 +04:00
|
|
|
}
|
|
|
|
kfree(priv->qdiscs);
|
|
|
|
priv->qdiscs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mq_dump(struct Qdisc *sch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct Qdisc *qdisc;
|
|
|
|
unsigned int ntx;
|
2017-12-07 20:57:39 +03:00
|
|
|
__u32 qlen = 0;
|
2009-09-06 12:58:51 +04:00
|
|
|
|
|
|
|
sch->q.qlen = 0;
|
|
|
|
memset(&sch->bstats, 0, sizeof(sch->bstats));
|
|
|
|
memset(&sch->qstats, 0, sizeof(sch->qstats));
|
|
|
|
|
2017-12-07 20:57:39 +03:00
|
|
|
/* MQ supports lockless qdiscs. However, statistics accounting needs
|
|
|
|
* to account for all, none, or a mix of locked and unlocked child
|
|
|
|
* qdiscs. Percpu stats are added to counters in-band and locking
|
|
|
|
* qdisc totals are added at end.
|
|
|
|
*/
|
2009-09-06 12:58:51 +04:00
|
|
|
for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
|
|
|
|
qdisc = netdev_get_tx_queue(dev, ntx)->qdisc_sleeping;
|
|
|
|
spin_lock_bh(qdisc_lock(qdisc));
|
2017-12-07 20:57:20 +03:00
|
|
|
|
|
|
|
if (qdisc_is_percpu_stats(qdisc)) {
|
2017-12-07 20:57:39 +03:00
|
|
|
qlen = qdisc_qlen_sum(qdisc);
|
|
|
|
__gnet_stats_copy_basic(NULL, &sch->bstats,
|
|
|
|
qdisc->cpu_bstats,
|
|
|
|
&qdisc->bstats);
|
|
|
|
__gnet_stats_copy_queue(&sch->qstats,
|
|
|
|
qdisc->cpu_qstats,
|
|
|
|
&qdisc->qstats, qlen);
|
2019-12-03 06:17:40 +03:00
|
|
|
sch->q.qlen += qlen;
|
2017-12-07 20:57:39 +03:00
|
|
|
} else {
|
|
|
|
sch->q.qlen += qdisc->q.qlen;
|
|
|
|
sch->bstats.bytes += qdisc->bstats.bytes;
|
|
|
|
sch->bstats.packets += qdisc->bstats.packets;
|
2018-05-26 07:53:37 +03:00
|
|
|
sch->qstats.qlen += qdisc->qstats.qlen;
|
2017-12-07 20:57:39 +03:00
|
|
|
sch->qstats.backlog += qdisc->qstats.backlog;
|
|
|
|
sch->qstats.drops += qdisc->qstats.drops;
|
|
|
|
sch->qstats.requeues += qdisc->qstats.requeues;
|
|
|
|
sch->qstats.overlimits += qdisc->qstats.overlimits;
|
2017-12-07 20:57:20 +03:00
|
|
|
}
|
|
|
|
|
2009-09-06 12:58:51 +04:00
|
|
|
spin_unlock_bh(qdisc_lock(qdisc));
|
|
|
|
}
|
2017-12-07 20:57:39 +03:00
|
|
|
|
2018-11-08 04:33:36 +03:00
|
|
|
return mq_offload_stats(sch);
|
2009-09-06 12:58:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct netdev_queue *mq_queue_get(struct Qdisc *sch, unsigned long cl)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
unsigned long ntx = cl - 1;
|
|
|
|
|
|
|
|
if (ntx >= dev->num_tx_queues)
|
|
|
|
return NULL;
|
|
|
|
return netdev_get_tx_queue(dev, ntx);
|
|
|
|
}
|
|
|
|
|
2009-09-15 13:53:07 +04:00
|
|
|
static struct netdev_queue *mq_select_queue(struct Qdisc *sch,
|
|
|
|
struct tcmsg *tcm)
|
2009-09-06 12:58:51 +04:00
|
|
|
{
|
2017-10-17 04:01:24 +03:00
|
|
|
return mq_queue_get(sch, TC_H_MIN(tcm->tcm_parent));
|
2009-09-06 12:58:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mq_graft(struct Qdisc *sch, unsigned long cl, struct Qdisc *new,
|
2017-12-20 20:35:17 +03:00
|
|
|
struct Qdisc **old, struct netlink_ext_ack *extack)
|
2009-09-06 12:58:51 +04:00
|
|
|
{
|
|
|
|
struct netdev_queue *dev_queue = mq_queue_get(sch, cl);
|
2018-11-13 01:58:14 +03:00
|
|
|
struct tc_mq_qopt_offload graft_offload;
|
2009-09-06 12:58:51 +04:00
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
|
|
|
|
if (dev->flags & IFF_UP)
|
|
|
|
dev_deactivate(dev);
|
|
|
|
|
|
|
|
*old = dev_graft_qdisc(dev_queue, new);
|
2012-12-11 19:54:33 +04:00
|
|
|
if (new)
|
2015-12-02 07:08:51 +03:00
|
|
|
new->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;
|
2009-09-06 12:58:51 +04:00
|
|
|
if (dev->flags & IFF_UP)
|
|
|
|
dev_activate(dev);
|
2018-11-13 01:58:14 +03:00
|
|
|
|
|
|
|
graft_offload.handle = sch->handle;
|
|
|
|
graft_offload.graft_params.queue = cl - 1;
|
|
|
|
graft_offload.graft_params.child_handle = new ? new->handle : 0;
|
|
|
|
graft_offload.command = TC_MQ_GRAFT;
|
|
|
|
|
|
|
|
qdisc_offload_graft_helper(qdisc_dev(sch), sch, new, *old,
|
|
|
|
TC_SETUP_QDISC_MQ, &graft_offload, extack);
|
2009-09-06 12:58:51 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct Qdisc *mq_leaf(struct Qdisc *sch, unsigned long cl)
|
|
|
|
{
|
|
|
|
struct netdev_queue *dev_queue = mq_queue_get(sch, cl);
|
|
|
|
|
|
|
|
return dev_queue->qdisc_sleeping;
|
|
|
|
}
|
|
|
|
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-25 02:51:29 +03:00
|
|
|
static unsigned long mq_find(struct Qdisc *sch, u32 classid)
|
2009-09-06 12:58:51 +04:00
|
|
|
{
|
|
|
|
unsigned int ntx = TC_H_MIN(classid);
|
|
|
|
|
|
|
|
if (!mq_queue_get(sch, ntx))
|
|
|
|
return 0;
|
|
|
|
return ntx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mq_dump_class(struct Qdisc *sch, unsigned long cl,
|
|
|
|
struct sk_buff *skb, struct tcmsg *tcm)
|
|
|
|
{
|
|
|
|
struct netdev_queue *dev_queue = mq_queue_get(sch, cl);
|
|
|
|
|
|
|
|
tcm->tcm_parent = TC_H_ROOT;
|
|
|
|
tcm->tcm_handle |= TC_H_MIN(cl);
|
|
|
|
tcm->tcm_info = dev_queue->qdisc_sleeping->handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mq_dump_class_stats(struct Qdisc *sch, unsigned long cl,
|
|
|
|
struct gnet_dump *d)
|
|
|
|
{
|
|
|
|
struct netdev_queue *dev_queue = mq_queue_get(sch, cl);
|
|
|
|
|
|
|
|
sch = dev_queue->qdisc_sleeping;
|
2019-11-28 09:29:09 +03:00
|
|
|
if (gnet_stats_copy_basic(&sch->running, d, sch->cpu_bstats,
|
|
|
|
&sch->bstats) < 0 ||
|
2019-03-28 18:53:12 +03:00
|
|
|
qdisc_qstats_copy(d, sch) < 0)
|
2009-09-06 12:58:51 +04:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mq_walk(struct Qdisc *sch, struct qdisc_walker *arg)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
unsigned int ntx;
|
|
|
|
|
|
|
|
if (arg->stop)
|
|
|
|
return;
|
|
|
|
|
|
|
|
arg->count = arg->skip;
|
|
|
|
for (ntx = arg->skip; ntx < dev->num_tx_queues; ntx++) {
|
|
|
|
if (arg->fn(sch, ntx + 1, arg) < 0) {
|
|
|
|
arg->stop = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
arg->count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct Qdisc_class_ops mq_class_ops = {
|
|
|
|
.select_queue = mq_select_queue,
|
|
|
|
.graft = mq_graft,
|
|
|
|
.leaf = mq_leaf,
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-25 02:51:29 +03:00
|
|
|
.find = mq_find,
|
2009-09-06 12:58:51 +04:00
|
|
|
.walk = mq_walk,
|
|
|
|
.dump = mq_dump_class,
|
|
|
|
.dump_stats = mq_dump_class_stats,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Qdisc_ops mq_qdisc_ops __read_mostly = {
|
|
|
|
.cl_ops = &mq_class_ops,
|
|
|
|
.id = "mq",
|
|
|
|
.priv_size = sizeof(struct mq_sched),
|
|
|
|
.init = mq_init,
|
|
|
|
.destroy = mq_destroy,
|
|
|
|
.attach = mq_attach,
|
|
|
|
.dump = mq_dump,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|