Skip to contentSkip to conversation

net: implement mechanism for HW based QOS

PATCH Superseded John Fastabend 3 participants 5 messages Jan 7, 2011 – Jan 14, 2011

Subsystems (3)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 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 a 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 |   65 +++++++++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |   61 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 1 deletions(-)
include/linux/netdevice.h +65 -0
index 0f6b1c9..b1dbbed 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,7 @@ 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);
+ * void (*ndo_setup_tc)(struct net_device *dev, u8 tc, unsigned int txq)
  */
 #define HAVE_NET_DEVICE_OPS
 struct net_device_ops {
@@ -814,6 +823,8 @@ 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,
+						unsigned int txq);
 #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 +1157,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 +1176,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 +60 -1

91 lines not on this page · raw message

#1 lore raw

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

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    |  418 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 447 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 +418 -0

418 lines not on this page · raw message

Acked-by on v7 2/2
#2 lore raw

Re: [net-next-2.6 PATCH v7 2/2] net_sched: implement a root container qdisc sch_mqprio

Quoted 35 lines · 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().

Quoted 7 lines

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.

#3 lore raw
In reply to John Fastabend

I'm actually having a go at implementing this, as a result of which I have some more questions:

On Fri, 2011-01-07 at 14:45 -0800, John Fastabend wrote:
[...]

Quoted 7 lines

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 a single traffic class and all queues in this class everything works as is until the LLD enables multiple tcs.

Quoted 6 lines

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.

What is the meaning of a class number? Is it simply higher number => higher priority? If there are exactly 8 classes, can they be assumed to match the 802.1q priority classes?

Quoted 4 lines

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.

Should an Ethernet driver/hardware insert a 802.1q priority tag if it implements this, or should that be left to higher levels?

Quoted 11 lines

---

 include/linux/netdevice.h |   65 +++++++++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |   61 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 1 deletions(-)
include/linux/netdevice.h +0 -0
index 0f6b1c9..b1dbbed 100644

[...]

include/linux/netdevice.h struct xps_dev_maps { · line 767

Quoted 5 lines
include/linux/netdevice.h +1 -0
@@ -756,6 +764,7 @@ 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);
+ * void (*ndo_setup_tc)(struct net_device *dev, u8 tc, unsigned int txq)

[...]

This is not documentation, it is just repetition!

Please specify what the parameters mean. In particular, what is the purpose of the txq parameter; can it be different from dev->real_num_tx_queues?

Is this operation allowed to change the number of TX queues? I was looking at scaling the number of queues according to the number of classes.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#4 lore raw
Quoted 3 lines · Ben Hutchings

I'm actually having a go at implementing this, as a result of which I have some more questions:

Nice.

Quoted 16 lines · John Fastabend

[...]

Quoted 7 lines

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 a single traffic class and all queues in this class everything works as is until the LLD enables multiple tcs.

Quoted 6 lines

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.

Quoted 3 lines

What is the meaning of a class number? Is it simply higher number => higher priority? If there are exactly 8 classes, can they be assumed to match the 802.1q priority classes?

The exact meaning will depend on how the hardware is configured. With DCB configured the class number is going to have a different meaning then when DCB is disabled. Paring any specific configuration using 'strict priority' should be expected. This would simply be higher number => higher priority.

Merely having 8 classes should not be assumed to match the 802.1q priority classes. As soon as you say 802.1q priority classes I expect to see 802.1q priority tagged frames. This patch doesn't enforce any sort of tagging. However if you set up 8 traffic classes and built a qos egress map with 'ip link' that matched then this would be fair to say. I intentionally tried to leave this up to user space policy to configure no reason to try and enforce configurations IMHO. Notice you could go wrong with this and create configurations that probably make little sense but again I think this is a user space problem and at least in the DCB case we can have 'lldpad' manage this.

By the way defaulting to 'strict priority' is the 802.1Q spec suggestion for bridges that do not support the credit-based shaper algorithm. And the default mapping for 8 traffic classes is priorities map 1:1 with classes so this all lines up to get what you assumed.

Quoted 8 lines
Quoted 5 lines

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.

Should an Ethernet driver/hardware insert a 802.1q priority tag if it implements this, or should that be left to higher levels?

I am not so sure about this. I tend to like using the mechanisms already in place, the egress qos mapping, to add 802.1q priority tag. But it looks like some drivers add the tags explicitly. And also there appears to be some expectation that the 802.1q priority tag is added to all packets even those sent on non-vlan devices at least in the DCB case.

Quoted 13 lines
Quoted 12 lines

---

 include/linux/netdevice.h |   65 +++++++++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |   61 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 1 deletions(-)
include/linux/netdevice.h +0 -0
index 0f6b1c9..b1dbbed 100644

[...]

Quoted 9 lines

include/linux/netdevice.h struct xps_dev_maps { · line 767

Quoted 5 lines
include/linux/netdevice.h +1 -0
@@ -756,6 +764,7 @@ 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);
+ * void (*ndo_setup_tc)(struct net_device *dev, u8 tc, unsigned int txq)

[...]

This is not documentation, it is just repetition!

Point taken. It does seem to be the trend though.

Quoted 3 lines

Please specify what the parameters mean. In particular, what is the purpose of the txq parameter; can it be different from dev->real_num_tx_queues?

'tc' is the number of traffic classes to enable and 'txq' is the number of queues in use. This should be dev->real_num_tx_queues except when called from netif_set_real_num_tx_queues where the new number of queues is used. This is done to prevent steering skb's to rings that may no longer exist.

Quoted 4 lines

Is this operation allowed to change the number of TX queues? I was looking at scaling the number of queues according to the number of classes.

As is no. Changing the number of TX queues can't be done cleanly because calling netif_set_real_num_tx_queues() calls ndo_tc_setup(). I was expecting other netlink messages would change the tx queue numbers.

However I think I like this better... In order to make this possible I can remove the ndo_tc_setup() call from netif_set_real_num_tc_queues(). Then the 'txq' param can be removed making this call a bit neater as well. The downside of this is drivers will need to ensure that calling netif_set_real_num_tx_queues() will not break the mapping otherwise the mapping gets invalidated. I'll have to see but this might be OK.

Thanks,
John.

Quoted 3 lines

Ben.