Skip to content

Commit f25f4e4

Browse files
ppwaskieDavid S. Miller
authored andcommitted
[CORE] Stack changes to add multiqueue hardware support API
Add the multiqueue hardware device support API to the core network stack. Allow drivers to allocate multiple queues and manage them at the netdev level if they choose to do so. Added a new field to sk_buff, namely queue_mapping, for drivers to know which tx_ring to select based on OS classification of the flow. Signed-off-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com> Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a093bf0 commit f25f4e4

10 files changed

Lines changed: 158 additions & 30 deletions

File tree

‎drivers/net/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ menuconfig NETDEVICES
2525
# that for each of the symbols.
2626
if NETDEVICES
2727

28+
config NETDEVICES_MULTIQUEUE
29+
bool "Netdevice multiple hardware queue support"
30+
---help---
31+
Say Y here if you want to allow the network stack to use multiple
32+
hardware TX queues on an ethernet device.
33+
34+
Most people will say N here.
35+
2836
config IFB
2937
tristate "Intermediate Functional Block support"
3038
depends on NET_CLS_ACT

‎include/linux/etherdevice.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ extern void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev
3939
extern int eth_header_cache(struct neighbour *neigh,
4040
struct hh_cache *hh);
4141

42-
extern struct net_device *alloc_etherdev(int sizeof_priv);
42+
extern struct net_device *alloc_etherdev_mq(int sizeof_priv, unsigned int queue_count);
43+
#define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
4344

4445
/**
4546
* is_zero_ether_addr - Determine if give Ethernet address is all zeros.

‎include/linux/netdevice.h‎

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ struct wireless_dev;
108108
#define MAX_HEADER (LL_MAX_HEADER + 48)
109109
#endif
110110

111+
struct net_device_subqueue
112+
{
113+
/* Give a control state for each queue. This struct may contain
114+
* per-queue locks in the future.
115+
*/
116+
unsigned long state;
117+
};
118+
111119
/*
112120
* Network device statistics. Akin to the 2.0 ether stats but
113121
* with byte counters.
@@ -331,6 +339,7 @@ struct net_device
331339
#define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */
332340
#define NETIF_F_GSO 2048 /* Enable software GSO. */
333341
#define NETIF_F_LLTX 4096 /* LockLess TX */
342+
#define NETIF_F_MULTI_QUEUE 16384 /* Has multiple TX/RX queues */
334343

335344
/* Segmentation offload features */
336345
#define NETIF_F_GSO_SHIFT 16
@@ -557,6 +566,10 @@ struct net_device
557566

558567
/* rtnetlink link ops */
559568
const struct rtnl_link_ops *rtnl_link_ops;
569+
570+
/* The TX queue control structures */
571+
unsigned int egress_subqueue_count;
572+
struct net_device_subqueue egress_subqueue[0];
560573
};
561574
#define to_net_dev(d) container_of(d, struct net_device, dev)
562575

@@ -565,9 +578,7 @@ struct net_device
565578

566579
static inline void *netdev_priv(const struct net_device *dev)
567580
{
568-
return (char *)dev + ((sizeof(struct net_device)
569-
+ NETDEV_ALIGN_CONST)
570-
& ~NETDEV_ALIGN_CONST);
581+
return dev->priv;
571582
}
572583

573584
#define SET_MODULE_OWNER(dev) do { } while (0)
@@ -719,6 +730,62 @@ static inline int netif_running(const struct net_device *dev)
719730
return test_bit(__LINK_STATE_START, &dev->state);
720731
}
721732

733+
/*
734+
* Routines to manage the subqueues on a device. We only need start
735+
* stop, and a check if it's stopped. All other device management is
736+
* done at the overall netdevice level.
737+
* Also test the device if we're multiqueue.
738+
*/
739+
static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
740+
{
741+
#ifdef CONFIG_NETDEVICES_MULTIQUEUE
742+
clear_bit(__LINK_STATE_XOFF, &dev->egress_subqueue[queue_index].state);
743+
#endif
744+
}
745+
746+
static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
747+
{
748+
#ifdef CONFIG_NETDEVICES_MULTIQUEUE
749+
#ifdef CONFIG_NETPOLL_TRAP
750+
if (netpoll_trap())
751+
return;
752+
#endif
753+
set_bit(__LINK_STATE_XOFF, &dev->egress_subqueue[queue_index].state);
754+
#endif
755+
}
756+
757+
static inline int netif_subqueue_stopped(const struct net_device *dev,
758+
u16 queue_index)
759+
{
760+
#ifdef CONFIG_NETDEVICES_MULTIQUEUE
761+
return test_bit(__LINK_STATE_XOFF,
762+
&dev->egress_subqueue[queue_index].state);
763+
#else
764+
return 0;
765+
#endif
766+
}
767+
768+
static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
769+
{
770+
#ifdef CONFIG_NETDEVICES_MULTIQUEUE
771+
#ifdef CONFIG_NETPOLL_TRAP
772+
if (netpoll_trap())
773+
return;
774+
#endif
775+
if (test_and_clear_bit(__LINK_STATE_XOFF,
776+
&dev->egress_subqueue[queue_index].state))
777+
__netif_schedule(dev);
778+
#endif
779+
}
780+
781+
static inline int netif_is_multiqueue(const struct net_device *dev)
782+
{
783+
#ifdef CONFIG_NETDEVICES_MULTIQUEUE
784+
return (!!(NETIF_F_MULTI_QUEUE & dev->features));
785+
#else
786+
return 0;
787+
#endif
788+
}
722789

723790
/* Use this variant when it is known for sure that it
724791
* is executing from interrupt context.
@@ -1009,8 +1076,11 @@ static inline void netif_tx_disable(struct net_device *dev)
10091076
extern void ether_setup(struct net_device *dev);
10101077

10111078
/* Support for loadable net-drivers */
1012-
extern struct net_device *alloc_netdev(int sizeof_priv, const char *name,
1013-
void (*setup)(struct net_device *));
1079+
extern struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
1080+
void (*setup)(struct net_device *),
1081+
unsigned int queue_count);
1082+
#define alloc_netdev(sizeof_priv, name, setup) \
1083+
alloc_netdev_mq(sizeof_priv, name, setup, 1)
10141084
extern int register_netdev(struct net_device *dev);
10151085
extern void unregister_netdev(struct net_device *dev);
10161086
/* Functions used for secondary unicast and multicast support */

‎include/linux/skbuff.h‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ typedef unsigned char *sk_buff_data_t;
196196
* @sk: Socket we are owned by
197197
* @tstamp: Time we arrived
198198
* @dev: Device we arrived on/are leaving by
199-
* @iif: ifindex of device we arrived on
200199
* @transport_header: Transport layer header
201200
* @network_header: Network layer header
202201
* @mac_header: Link layer header
@@ -231,6 +230,8 @@ typedef unsigned char *sk_buff_data_t;
231230
* @nfctinfo: Relationship of this skb to the connection
232231
* @nfct_reasm: netfilter conntrack re-assembly pointer
233232
* @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
233+
* @iif: ifindex of device we arrived on
234+
* @queue_mapping: Queue mapping for multiqueue devices
234235
* @tc_index: Traffic control index
235236
* @tc_verd: traffic control verdict
236237
* @dma_cookie: a cookie to one of several possible DMA operations
@@ -246,8 +247,6 @@ struct sk_buff {
246247
struct sock *sk;
247248
ktime_t tstamp;
248249
struct net_device *dev;
249-
int iif;
250-
/* 4 byte hole on 64 bit*/
251250

252251
struct dst_entry *dst;
253252
struct sec_path *sp;
@@ -290,12 +289,18 @@ struct sk_buff {
290289
#ifdef CONFIG_BRIDGE_NETFILTER
291290
struct nf_bridge_info *nf_bridge;
292291
#endif
292+
293+
int iif;
294+
__u16 queue_mapping;
295+
293296
#ifdef CONFIG_NET_SCHED
294297
__u16 tc_index; /* traffic control index */
295298
#ifdef CONFIG_NET_CLS_ACT
296299
__u16 tc_verd; /* traffic control verdict */
297300
#endif
298301
#endif
302+
/* 2 byte hole */
303+
299304
#ifdef CONFIG_NET_DMA
300305
dma_cookie_t dma_cookie;
301306
#endif
@@ -1725,6 +1730,20 @@ static inline void skb_init_secmark(struct sk_buff *skb)
17251730
{ }
17261731
#endif
17271732

1733+
static inline void skb_set_queue_mapping(struct sk_buff *skb, u16 queue_mapping)
1734+
{
1735+
#ifdef CONFIG_NETDEVICES_MULTIQUEUE
1736+
skb->queue_mapping = queue_mapping;
1737+
#endif
1738+
}
1739+
1740+
static inline void skb_copy_queue_mapping(struct sk_buff *to, const struct sk_buff *from)
1741+
{
1742+
#ifdef CONFIG_NETDEVICES_MULTIQUEUE
1743+
to->queue_mapping = from->queue_mapping;
1744+
#endif
1745+
}
1746+
17281747
static inline int skb_is_gso(const struct sk_buff *skb)
17291748
{
17301749
return skb_shinfo(skb)->gso_size;

‎net/core/dev.c‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,9 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
14291429
skb->next = nskb;
14301430
return rc;
14311431
}
1432-
if (unlikely(netif_queue_stopped(dev) && skb->next))
1432+
if (unlikely((netif_queue_stopped(dev) ||
1433+
netif_subqueue_stopped(dev, skb->queue_mapping)) &&
1434+
skb->next))
14331435
return NETDEV_TX_BUSY;
14341436
} while (skb->next);
14351437

@@ -1547,6 +1549,8 @@ int dev_queue_xmit(struct sk_buff *skb)
15471549
spin_lock(&dev->queue_lock);
15481550
q = dev->qdisc;
15491551
if (q->enqueue) {
1552+
/* reset queue_mapping to zero */
1553+
skb->queue_mapping = 0;
15501554
rc = q->enqueue(skb, q);
15511555
qdisc_run(dev);
15521556
spin_unlock(&dev->queue_lock);
@@ -1576,7 +1580,8 @@ int dev_queue_xmit(struct sk_buff *skb)
15761580

15771581
HARD_TX_LOCK(dev, cpu);
15781582

1579-
if (!netif_queue_stopped(dev)) {
1583+
if (!netif_queue_stopped(dev) &&
1584+
!netif_subqueue_stopped(dev, skb->queue_mapping)) {
15801585
rc = 0;
15811586
if (!dev_hard_start_xmit(skb, dev)) {
15821587
HARD_TX_UNLOCK(dev);
@@ -3539,16 +3544,18 @@ static struct net_device_stats *internal_stats(struct net_device *dev)
35393544
}
35403545

35413546
/**
3542-
* alloc_netdev - allocate network device
3547+
* alloc_netdev_mq - allocate network device
35433548
* @sizeof_priv: size of private data to allocate space for
35443549
* @name: device name format string
35453550
* @setup: callback to initialize device
3551+
* @queue_count: the number of subqueues to allocate
35463552
*
35473553
* Allocates a struct net_device with private data area for driver use
3548-
* and performs basic initialization.
3554+
* and performs basic initialization. Also allocates subquue structs
3555+
* for each queue on the device at the end of the netdevice.
35493556
*/
3550-
struct net_device *alloc_netdev(int sizeof_priv, const char *name,
3551-
void (*setup)(struct net_device *))
3557+
struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
3558+
void (*setup)(struct net_device *), unsigned int queue_count)
35523559
{
35533560
void *p;
35543561
struct net_device *dev;
@@ -3557,7 +3564,9 @@ struct net_device *alloc_netdev(int sizeof_priv, const char *name,
35573564
BUG_ON(strlen(name) >= sizeof(dev->name));
35583565

35593566
/* ensure 32-byte alignment of both the device and private area */
3560-
alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
3567+
alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST +
3568+
(sizeof(struct net_device_subqueue) * queue_count)) &
3569+
~NETDEV_ALIGN_CONST;
35613570
alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
35623571

35633572
p = kzalloc(alloc_size, GFP_KERNEL);
@@ -3570,15 +3579,22 @@ struct net_device *alloc_netdev(int sizeof_priv, const char *name,
35703579
(((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
35713580
dev->padded = (char *)dev - (char *)p;
35723581

3573-
if (sizeof_priv)
3574-
dev->priv = netdev_priv(dev);
3582+
if (sizeof_priv) {
3583+
dev->priv = ((char *)dev +
3584+
((sizeof(struct net_device) +
3585+
(sizeof(struct net_device_subqueue) *
3586+
queue_count) + NETDEV_ALIGN_CONST)
3587+
& ~NETDEV_ALIGN_CONST));
3588+
}
3589+
3590+
dev->egress_subqueue_count = queue_count;
35753591

35763592
dev->get_stats = internal_stats;
35773593
setup(dev);
35783594
strcpy(dev->name, name);
35793595
return dev;
35803596
}
3581-
EXPORT_SYMBOL(alloc_netdev);
3597+
EXPORT_SYMBOL(alloc_netdev_mq);
35823598

35833599
/**
35843600
* free_netdev - free network device

‎net/core/netpoll.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ static void queue_process(struct work_struct *work)
6666

6767
local_irq_save(flags);
6868
netif_tx_lock(dev);
69-
if (netif_queue_stopped(dev) ||
70-
dev->hard_start_xmit(skb, dev) != NETDEV_TX_OK) {
69+
if ((netif_queue_stopped(dev) ||
70+
netif_subqueue_stopped(dev, skb->queue_mapping)) ||
71+
dev->hard_start_xmit(skb, dev) != NETDEV_TX_OK) {
7172
skb_queue_head(&npinfo->txq, skb);
7273
netif_tx_unlock(dev);
7374
local_irq_restore(flags);
@@ -254,7 +255,8 @@ static void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
254255
for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
255256
tries > 0; --tries) {
256257
if (netif_tx_trylock(dev)) {
257-
if (!netif_queue_stopped(dev))
258+
if (!netif_queue_stopped(dev) &&
259+
!netif_subqueue_stopped(dev, skb->queue_mapping))
258260
status = dev->hard_start_xmit(skb, dev);
259261
netif_tx_unlock(dev);
260262

‎net/core/pktgen.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,7 +3139,9 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
31393139
}
31403140
}
31413141

3142-
if (netif_queue_stopped(odev) || need_resched()) {
3142+
if ((netif_queue_stopped(odev) ||
3143+
netif_subqueue_stopped(odev, pkt_dev->skb->queue_mapping)) ||
3144+
need_resched()) {
31433145
idle_start = getCurUs();
31443146

31453147
if (!netif_running(odev)) {
@@ -3154,7 +3156,8 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
31543156

31553157
pkt_dev->idle_acc += getCurUs() - idle_start;
31563158

3157-
if (netif_queue_stopped(odev)) {
3159+
if (netif_queue_stopped(odev) ||
3160+
netif_subqueue_stopped(odev, pkt_dev->skb->queue_mapping)) {
31583161
pkt_dev->next_tx_us = getCurUs(); /* TODO */
31593162
pkt_dev->next_tx_ns = 0;
31603163
goto out; /* Try the next interface */
@@ -3181,7 +3184,8 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
31813184
}
31823185

31833186
netif_tx_lock_bh(odev);
3184-
if (!netif_queue_stopped(odev)) {
3187+
if (!netif_queue_stopped(odev) &&
3188+
!netif_subqueue_stopped(odev, pkt_dev->skb->queue_mapping)) {
31853189

31863190
atomic_inc(&(pkt_dev->skb->users));
31873191
retry_now:

‎net/core/skbuff.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
419419
n->nohdr = 0;
420420
C(pkt_type);
421421
C(ip_summed);
422+
skb_copy_queue_mapping(n, skb);
422423
C(priority);
423424
#if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
424425
C(ipvs_property);
@@ -460,6 +461,7 @@ static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
460461
#endif
461462
new->sk = NULL;
462463
new->dev = old->dev;
464+
skb_copy_queue_mapping(new, old);
463465
new->priority = old->priority;
464466
new->protocol = old->protocol;
465467
new->dst = dst_clone(old->dst);
@@ -1932,6 +1934,7 @@ struct sk_buff *skb_segment(struct sk_buff *skb, int features)
19321934
tail = nskb;
19331935

19341936
nskb->dev = skb->dev;
1937+
skb_copy_queue_mapping(nskb, skb);
19351938
nskb->priority = skb->priority;
19361939
nskb->protocol = skb->protocol;
19371940
nskb->dst = dst_clone(skb->dst);

0 commit comments

Comments
 (0)