net: implement mechanism for HW based QOS
Subsystems (3)
PATCH v6 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 | 52 +++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 1 deletions(-)
include/linux/netdevice.h +65 -0
@@ -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) */ #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 32static 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 +51 -1
82 lines not on this page · raw message
PATCH v6 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 | 415 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 444 insertions(+), 0 deletions(-) create mode 100644 net/sched/sch_mqprio.c
include/linux/pkt_sched.h +12 -0
@@ -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
@@ -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
@@ -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
@@ -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 +415 -0
415 lines not on this page · raw message
Re: [net-next-2.6 PATCH v6 2/2] net_sched: implement a root container qdisc sch_mqprio
Quoted 71 lines · John Fastabend
This implements a mqprio queueing discipline that by default creates a
pfifo_fastqdisc 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_mapgives the mapping fromskb->priorityto 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_tcoperation. 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 exceednum_tx_queuesand 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_tcto 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.Signed-off-by John Fastabend <[email protected]>---
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 | 415 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 444 insertions(+), 0 deletions(-) create mode 100644 net/sched/sch_mqprio.cinclude/linux/pkt_sched.h +11
-0@@ -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 ]; +};
...
include/linux/pkt_sched.h
Quoted 6 lines
include/linux/pkt_sched.h +6
-0+static int mqprio_parse_opt (struct net_device *dev,struct tc_mqprio_qopt *qopt) +{ +int i, j; + +/* Verify num_tc is not out of max range */ +if (qopt->num_tc >TC_QOPT_MAX_QUEUE )
If these TC_QOPTs really couldn't be avoided you should probably check them with BUILD_BUG_ON() but use only TC_MAX_QUEUE/TC_BITMASK everywhere. Otherwise, it looks OK to me.
Jarek P.
Re: [net-next-2.6 PATCH v6 2/2] net_sched: implement a root container qdisc sch_mqprio
Quoted 85 lines · Jarek Poplawski
Quoted 71 lines · John Fastabend
This implements a mqprio queueing discipline that by default creates a
pfifo_fastqdisc 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_mapgives the mapping fromskb->priorityto 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_tcoperation. 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 exceednum_tx_queuesand 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_tcto 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.Signed-off-by John Fastabend <[email protected]>---
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 | 415 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 444 insertions(+), 0 deletions(-) create mode 100644 net/sched/sch_mqprio.cinclude/linux/pkt_sched.h +11
-0@@ -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 ]; +};...
include/linux/pkt_sched.h
Quoted 6 lines
include/linux/pkt_sched.h +6
-0+static int mqprio_parse_opt (struct net_device *dev,struct tc_mqprio_qopt *qopt) +{ +int i, j; + +/* Verify num_tc is not out of max range */ +if (qopt->num_tc >TC_QOPT_MAX_QUEUE )If these
TC_QOPTsreally couldn't be avoided you should probably check them withBUILD_BUG_ON()but use only TC_MAX_QUEUE/TC_BITMASK everywhere. Otherwise, it looks OK to me.
Quoted 1 line
Jarek P.
I couldn't think of any better way. I'll add the BUILD_BUG_ON() macros.
Thanks
John
Quoted 70 lines · John Fastabend
This patch provides a mechanism for lower layer devices to steer traffic using
skb->priorityto 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_queueor thequeue_mappingaction in the qdisc.By using
select_queuefor 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.
Signed-off-by John Fastabend <[email protected]>---
include/linux/netdevice.h | 65 +++++++++++++++++++++++++++++++++++++++++++++ net/core/dev.c | 52 +++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 1 deletions(-)include/linux/netdevice.h +8
-0@@ -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
include/linux/netdevice.h struct xps_dev_maps { · line 767
Quoted 4 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) ?
Quoted 9 lines
include/linux/netdevice.h +2
-0*/ #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);
...
Quoted 21 lines
include/linux/netdevice.h +21
-0+/* netif_setup_tc - Handle tc mappings on real_num_tx_queues change +* @dev: Network device +* @txq: number of queues available +* +* If real_num_tx_queues is changed the tc mappings may no longer be +* valid. To resolve this if the net_device supports ndo_setup_tc +* call the ops routine with the new queue number. If the ops is not +* available verify the tc mapping remains valid and if not NULL the +* mapping. With no priorities mapping to this offset/count pair it +* will no longer be used. In the worst case TC0 is invalid nothing +* can be done so disable priority mappings. +*/ +void netif_setup_tc (struct net_device *dev,unsigned int txq) +{ +const struct net_device_ops *ops = dev->netdev_ops; + +if (ops->ndo_setup_tc) { + ops->ndo_setup_tc (dev, dev->num_tc, txq); + }else { +int i; +struct netdev_tc_txq *tc = &dev->tc_to_txq[0 ];
include/linux/netdevice.h
Quoted 10 lines
include/linux/netdevice.h +10
-0+ +/* If TC0 is invalidated disable TC mapping */ +if (tc->offset + tc->count > txq) { + dev->num_tc =0 ; +return ; + } + +/* Invalidated prio to tc mappings set to TC0 */ +for (i =1 ; i <TC_BITMASK +1 ; i++) { +int q =netdev_get_prio_tc_map (dev, i);
(empty line)
Btw, probably some warning should be logged on config change here.
Quoted 12 lines
include/linux/netdevice.h +8
-0+ tc = &dev->tc_to_txq[q]; + +if (tc->offset + tc->count > txq) +netdev_set_prio_tc_map (dev, i,0 ); + } + } +} +/* * Routine to help set real_num_tx_queues. To avoid skbs mapped to queues * greater then real_num_tx_queues stale skbs on the qdisc must be flushed.
include/linux/netdevice.h int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) · line 1658
Quoted 6 lines
include/linux/netdevice.h +3
-0@@ -1614,6 +1653,9 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)if (txq < dev->real_num_tx_queues)qdisc_reset_all_tx_gt (dev, txq); + +if (dev->num_tc) +netif_setup_tc (dev, txq);
Should be before qdisc_reset_all_tx_gt (above).
Jarek P.
Quoted 115 lines · Jarek Poplawski
Quoted 70 lines · John Fastabend
This patch provides a mechanism for lower layer devices to steer traffic using
skb->priorityto 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_queueor thequeue_mappingaction in the qdisc.By using
select_queuefor 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.
Signed-off-by John Fastabend <[email protected]>---
include/linux/netdevice.h | 65 +++++++++++++++++++++++++++++++++++++++++++++ net/core/dev.c | 52 +++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 1 deletions(-)include/linux/netdevice.h +8
-0@@ -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 include/linux/netdevice.h struct xps_dev_maps { · line 767
Quoted 4 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) ?
Quoted 9 lines
include/linux/netdevice.h +2
-0*/ #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);...
Quoted 26 lines
include/linux/netdevice.h +26
-0+/* netif_setup_tc - Handle tc mappings on real_num_tx_queues change +* @dev: Network device +* @txq: number of queues available +* +* If real_num_tx_queues is changed the tc mappings may no longer be +* valid. To resolve this if the net_device supports ndo_setup_tc +* call the ops routine with the new queue number. If the ops is not +* available verify the tc mapping remains valid and if not NULL the +* mapping. With no priorities mapping to this offset/count pair it +* will no longer be used. In the worst case TC0 is invalid nothing +* can be done so disable priority mappings. +*/ +void netif_setup_tc (struct net_device *dev,unsigned int txq) +{ +const struct net_device_ops *ops = dev->netdev_ops; + +if (ops->ndo_setup_tc) { + ops->ndo_setup_tc (dev, dev->num_tc, txq); + }else { +int i; +struct netdev_tc_txq *tc = &dev->tc_to_txq[0 ]; + +/* If TC0 is invalidated disable TC mapping */ +if (tc->offset + tc->count > txq) { + dev->num_tc =0 ; +return ;
Quoted 9 lines
include/linux/netdevice.h
Quoted 5 lines
include/linux/netdevice.h +5
-0+ } + +/* Invalidated prio to tc mappings set to TC0 */ +for (i =1 ; i <TC_BITMASK +1 ; i++) { +int q =netdev_get_prio_tc_map (dev, i);(empty line)
Btw, probably some warning should be logged on config change here.
OK maybe I should see about making at least my local checkpatch script look for this. Also added pr_warnings here.
Quoted 21 lines
Quoted 12 lines
include/linux/netdevice.h +8
-0+ tc = &dev->tc_to_txq[q]; + +if (tc->offset + tc->count > txq) +netdev_set_prio_tc_map (dev, i,0 ); + } + } +} +/* * Routine to help set real_num_tx_queues. To avoid skbs mapped to queues * greater then real_num_tx_queues stale skbs on the qdisc must be flushed. include/linux/netdevice.h int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) · line 1658
Quoted 6 lines
include/linux/netdevice.h +3
-0@@ -1614,6 +1653,9 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)if (txq < dev->real_num_tx_queues)qdisc_reset_all_tx_gt (dev, txq); + +if (dev->num_tc) +netif_setup_tc (dev, txq);Should be before
qdisc_reset_all_tx_gt(above).
Quoted 1 line
Jarek P.
I will fix this. Thanks!