Skip to contentSkip to conversation

Series short description

PATCH Applied John Fastabend 3 participants 8 messages Jan 17, 2011 – Jan 21, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v8 cover Series short description

Changed from v7, Ben Hutchings wants to actively manage queues from the ndo_setup_tc() routine. Presumably to change the number of tx queues creating n queues per traffic class. I agreed so this version updates the patch to work correctly in this case.

Previously I was calling ndo_setup_tc from netif_set_num_tx_queues(), to verify the queue offset/count but this would break any queue management so this is removed. Now the mappings are invalidated if the mapping requires it and it is expected that the netdevice configured a valid mapping so calling back into the driver is not needed. Validation is still required in the case of a netdevice that does not implement ndo_setup_tc() or to recover in cases where ndo_open is adjusting number of queues do to resource constraints.

Finally added some documentation to netdevice.h regarding the new ops routine.

---

John Fastabend (2):
net_sched: implement a root container qdisc sch_mqprio
net: implement mechanism for HW based QOS

 include/linux/netdevice.h |   68 +++++++
 include/linux/pkt_sched.h |   12 +
 net/core/dev.c            |   55 ++++++
 net/sched/Kconfig         |   12 +
 net/sched/Makefile        |    1 
 net/sched/sch_generic.c   |    4 
 net/sched/sch_mqprio.c    |  417 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 568 insertions(+), 1 deletions(-)
 create mode 100644 net/sched/sch_mqprio.c
Signature · 1 line
Signature
#1 lore raw

PATCH v8 1/2 net: implement mechanism for HW based QOS

This patch provides a mechanism for lower layer devices to steer traffic using skb->priority to tx queues. This allows for hardware based QOS schemes to use the default qdisc without incurring the penalties related to global state and the qdisc lock. While reliably receiving skbs on the correct tx ring to avoid head of line blocking resulting from shuffling in the LLD. Finally, all the goodness from txq caching and xps/rps can still be leveraged.

Many drivers and hardware exist with the ability to implement QOS schemes in the hardware but currently these drivers tend to rely on firmware to reroute specific traffic, a driver specific select_queue or the queue_mapping action in the qdisc.

By using select_queue for this drivers need to be updated for each and every traffic type and we lose the goodness of much of the upstream work. Firmware solutions are inherently inflexible. And finally if admins are expected to build a qdisc and filter rules to steer traffic this requires knowledge of how the hardware is currently configured. The number of tx queues and the queue offsets may change depending on resources. Also this approach incurs all the overhead of a qdisc with filters.

With the mechanism in this patch users can set skb priority using expected methods ie setsockopt() or the stack can set the priority directly. Then the skb will be steered to the correct tx queues aligned with hardware QOS traffic classes. In the normal case with single traffic class and all queues in this class everything works as is until the LLD enables multiple tcs.

To steer the skb we mask out the lower 4 bits of the priority and allow the hardware to configure upto 15 distinct classes of traffic. This is expected to be sufficient for most applications at any rate it is more then the 8021Q spec designates and is equal to the number of prio bands currently implemented in the default qdisc.

This in conjunction with a userspace application such as lldpad can be used to implement 8021Q transmission selection algorithms one of these algorithms being the extended transmission selection algorithm currently being used for DCB.

---

 include/linux/netdevice.h |   68 +++++++++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |   55 ++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 1 deletions(-)
include/linux/netdevice.h +68 -0
index 0f6b1c9..c973582 100644
@@ -646,6 +646,14 @@ struct xps_dev_maps {
     (nr_cpu_ids * sizeof(struct xps_map *)))
 #endif /* CONFIG_XPS */
 
+#define TC_MAX_QUEUE	16
+#define TC_BITMASK	15
+/* HW offloaded queuing disciplines txq count and offset maps */
+struct netdev_tc_txq {
+	u16 count;
+	u16 offset;
+};
+
 /*
  * This structure defines the management hooks for network devices.
  * The following hooks can be defined; unless noted otherwise, they are
@@ -756,6 +764,11 @@ struct xps_dev_maps {
  * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
  *			  struct nlattr *port[]);
  * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
+ * int (*ndo_setup_tc)(struct net_device *dev, u8 tc)
+ * 	Called to setup 'tc' number of traffic classes in the net device. This
+ * 	is always called from the stack with the rtnl lock held and netif tx
+ * 	queues stopped. This allows the netdevice to perform queue management
+ * 	safely.
  */
 #define HAVE_NET_DEVICE_OPS
 struct net_device_ops {
@@ -814,6 +827,7 @@ struct net_device_ops {
 						   struct nlattr *port[]);
 	int			(*ndo_get_vf_port)(struct net_device *dev,
 						   int vf, struct sk_buff *skb);
+	int			(*ndo_setup_tc)(struct net_device *dev, u8 tc);
 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
 	int			(*ndo_fcoe_enable)(struct net_device *dev);
 	int			(*ndo_fcoe_disable)(struct net_device *dev);
@@ -1146,6 +1160,9 @@ struct net_device {
 	/* Data Center Bridging netlink ops */
 	const struct dcbnl_rtnl_ops *dcbnl_ops;
 #endif
+	u8 num_tc;
+	struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
+	u8 prio_tc_map[TC_BITMASK + 1];
 
 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
 	/* max exchange id for FCoE LRO by ddp */
@@ -1162,6 +1179,57 @@ struct net_device {
 #define	NETDEV_ALIGN		32
 
 static inline
+int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
+{
+	return dev->prio_tc_map[prio & TC_BITMASK];
+}
+
+static inline
+int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
+{
+	if (tc >= dev->num_tc)
+		return -EINVAL;
+
+	dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
+	return 0;
+}
+
+static inline
+void netdev_reset_tc(struct net_device *dev)
+{
+	dev->num_tc = 0;
+	memset(dev->tc_to_txq, 0, sizeof(dev->tc_to_txq));
+	memset(dev->prio_tc_map, 0, sizeof(dev->prio_tc_map));
+}
+
+static inline
+int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset)
+{
+	if (tc >= dev->num_tc)
+		return -EINVAL;
+
+	dev->tc_to_txq[tc].count = count;
+	dev->tc_to_txq[tc].offset = offset;
+	return 0;
+}
+
+static inline
+int netdev_set_num_tc(struct net_device *dev, u8 num_tc)
+{
+	if (num_tc > TC_MAX_QUEUE)
+		return -EINVAL;
+
+	dev->num_tc = num_tc;
+	return 0;
+}
+
+static inline
+int netdev_get_num_tc(struct net_device *dev)
+{
+	return dev->num_tc;
+}
+
+static inline
 struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
 					 unsigned int index)
 {
net/core/dev.c +54 -1

85 lines not on this page · raw message

#6 lore raw

PATCH v8 2/2 net_sched: implement a root container qdisc sch_mqprio

In reply to John Fastabend

This implements a mqprio queueing discipline that by default creates a pfifo_fast qdisc per tx queue and provides the needed configuration interface.

Using the mqprio qdisc the number of tcs currently in use along with the range of queues alloted to each class can be configured. By default skbs are mapped to traffic classes using the skb priority. This mapping is configurable.

Configurable parameters,

struct tc_mqprio_qopt {
	__u8    num_tc;
	__u8    prio_tc_map[TC_BITMASK + 1];
	__u8    hw;
	__u16   count[TC_MAX_QUEUE];
	__u16   offset[TC_MAX_QUEUE];
};

Here the count/offset pairing give the queue alignment and the prio_tc_map gives the mapping from skb->priority to tc.

The hw bit determines if the hardware should configure the count and offset values. If the hardware bit is set then the operation will fail if the hardware does not implement the ndo_setup_tc operation. This is to avoid undetermined states where the hardware may or may not control the queue mapping. Also minimal bounds checking is done on the count/offset to verify a queue does not exceed num_tx_queues and that queue ranges do not overlap. Otherwise it is left to user policy or hardware configuration to create useful mappings.

It is expected that hardware QOS schemes can be implemented by creating appropriate mappings of queues in ndo_tc_setup().

One expected use case is drivers will use the ndo_setup_tc to map queue ranges onto 802.1Q traffic classes. This provides a generic mechanism to map network traffic onto these traffic classes and removes the need for lower layer drivers to know specifics about traffic types.

---

 include/linux/pkt_sched.h |   12 +
 net/sched/Kconfig         |   12 +
 net/sched/Makefile        |    1 
 net/sched/sch_generic.c   |    4 
 net/sched/sch_mqprio.c    |  417 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 446 insertions(+), 0 deletions(-)
 create mode 100644 net/sched/sch_mqprio.c
include/linux/pkt_sched.h +12 -0
index 2cfa4bc..776cd93 100644
@@ -481,4 +481,16 @@ struct tc_drr_stats {
 	__u32	deficit;
 };
 
+/* MQPRIO */
+#define TC_QOPT_BITMASK 15
+#define TC_QOPT_MAX_QUEUE 16
+
+struct tc_mqprio_qopt {
+	__u8	num_tc;
+	__u8	prio_tc_map[TC_QOPT_BITMASK + 1];
+	__u8	hw;
+	__u16	count[TC_QOPT_MAX_QUEUE];
+	__u16	offset[TC_QOPT_MAX_QUEUE];
+};
+
 #endif
net/sched/Kconfig +12 -0
index a36270a..f52f5eb 100644
@@ -205,6 +205,18 @@ config NET_SCH_DRR
 
 	  If unsure, say N.
 
+config NET_SCH_MQPRIO
+	tristate "Multi-queue priority scheduler (MQPRIO)"
+	help
+	  Say Y here if you want to use the Multi-queue Priority scheduler.
+	  This scheduler allows QOS to be offloaded on NICs that have support
+	  for offloading QOS schedulers.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called sch_mqprio.
+
+	  If unsure, say N.
+
 config NET_SCH_INGRESS
 	tristate "Ingress Qdisc"
 	depends on NET_CLS_ACT
net/sched/Makefile +1 -0
index 960f5db..26ce681 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_NET_SCH_MULTIQ)	+= sch_multiq.o
 obj-$(CONFIG_NET_SCH_ATM)	+= sch_atm.o
 obj-$(CONFIG_NET_SCH_NETEM)	+= sch_netem.o
 obj-$(CONFIG_NET_SCH_DRR)	+= sch_drr.o
+obj-$(CONFIG_NET_SCH_MQPRIO)	+= sch_mqprio.o
 obj-$(CONFIG_NET_CLS_U32)	+= cls_u32.o
 obj-$(CONFIG_NET_CLS_ROUTE4)	+= cls_route.o
 obj-$(CONFIG_NET_CLS_FW)	+= cls_fw.o
net/sched/sch_generic.c +4 -0
index 34dc598..723b278 100644
@@ -540,6 +540,7 @@ struct Qdisc_ops pfifo_fast_ops __read_mostly = {
 	.dump		=	pfifo_fast_dump,
 	.owner		=	THIS_MODULE,
 };
+EXPORT_SYMBOL(pfifo_fast_ops);
 
 struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
 			  struct Qdisc_ops *ops)
@@ -674,6 +675,7 @@ struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue,
 
 	return oqdisc;
 }
+EXPORT_SYMBOL(dev_graft_qdisc);
 
 static void attach_one_default_qdisc(struct net_device *dev,
 				     struct netdev_queue *dev_queue,
@@ -761,6 +763,7 @@ void dev_activate(struct net_device *dev)
 		dev_watchdog_up(dev);
 	}
 }
+EXPORT_SYMBOL(dev_activate);
 
 static void dev_deactivate_queue(struct net_device *dev,
 				 struct netdev_queue *dev_queue,
@@ -840,6 +843,7 @@ void dev_deactivate(struct net_device *dev)
 	list_add(&dev->unreg_list, &single);
 	dev_deactivate_many(&single);
 }
+EXPORT_SYMBOL(dev_deactivate);
 
 static void dev_init_scheduler_queue(struct net_device *dev,
 				     struct netdev_queue *dev_queue,
net/sched/sch_mqprio.c new file +417 -0

417 lines not on this page · raw message

#3 lore raw

PATCH 1/1 net: netif_setup_tc() is static

In reply to David Miller
Quoted 9 lines · David Miller

From: John Fastabend <[email protected]>
Date: Mon, 17 Jan 2011 10:06:04 -0800

Quoted 2 lines

This patch provides a mechanism for lower layer devices to steer traffic using skb->priority to tx queues.

...

Quoted 1 line

Applied.

Hi John

Should netif_setup_tc() be static, or is it meant to be exported somehow ?

[PATCH net-next-2.6] net: netif_setup_tc() is static

---

net/core/dev.c +1 -1
index 2730352..47d3d78 100644
@@ -1605,7 +1605,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
  * expected that drivers will fix this mapping if they can before
  * calling netif_set_real_num_tx_queues.
  */
-void netif_setup_tc(struct net_device *dev, unsigned int txq)
+static void netif_setup_tc(struct net_device *dev, unsigned int txq)
 {
 	int i;
 	struct netdev_tc_txq *tc = &dev->tc_to_txq[0];
author Acked-by on v1 1/1
#4 lore raw

Re: [PATCH net-next-2.6] net: netif_setup_tc() is static

Quoted 13 lines · Eric Dumazet
Quoted 9 lines · David Miller

From: John Fastabend <[email protected]>
Date: Mon, 17 Jan 2011 10:06:04 -0800

Quoted 2 lines

This patch provides a mechanism for lower layer devices to steer traffic using skb->priority to tx queues.

...

Quoted 1 line

Applied.

Hi John

Quoted 7 lines

Should netif_setup_tc() be static, or is it meant to be exported somehow ?

[PATCH net-next-2.6] net: netif_setup_tc() is static

---

Yes this should be static. Thanks Eric!

maintainer Applied
#5 lore raw

Re: [PATCH net-next-2.6] net: netif_setup_tc() is static

From: John Fastabend <[email protected]>
Date: Fri, 21 Jan 2011 09:54:53 -0800

Quoted 17 lines · Eric Dumazet
Quoted 16 lines · David Miller
Quoted 9 lines

From: John Fastabend <[email protected]>
Date: Mon, 17 Jan 2011 10:06:04 -0800

Quoted 2 lines

This patch provides a mechanism for lower layer devices to steer traffic using skb->priority to tx queues.

...

Quoted 1 line

Applied.

Hi John

Should netif_setup_tc() be static, or is it meant to be exported somehow ?

Quoted 6 lines
Quoted 4 lines

[PATCH net-next-2.6] net: netif_setup_tc() is static

---

Applied, thanks.