Skip to contentSkip to conversation

net: hand off skb list to other cpu to submit to upper layer

RFC PATCH In review Zhang, Yanmin 1 participant 1 message Mar 11, 2009

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

RFC PATCH v2 2/3 net: hand off skb list to other cpu to submit to upper layer

Subject: net: hand off skb list to other cpu to submit to upper layer
From: Zhang Yanmin <[email protected]>

Add new sysfs interface /sys/class/net/ethXXX/rx_queueXXX/processing_cpu. Admin could use it to configure the binding between RX and cpu number. So it's convenient for driver to use the new capability.

Function alloc_netdev_rxtx_mq is called by drivers to initiate netdev with RX queue. 

---

include/linux/netdevice.h +27 -0
@@ -443,6 +443,10 @@ struct netdev_queue {
 	struct Qdisc		*qdisc_sleeping;
 } ____cacheline_aligned_in_smp;
 
+struct netdev_queue_attr {
+	struct kobject		kobj;
+	int			processing_cpu;
+};
 
 /*
  * This structure defines the management hooks for network devices.
@@ -760,6 +764,10 @@ struct net_device
 
 	struct netdev_queue	rx_queue;
 
+	/* Export by sysfs */
+	struct netdev_queue_attr *_rx_attr;
+	unsigned int		num_rx_queues;
+
 	struct netdev_queue	*_tx ____cacheline_aligned_in_smp;
 
 	/* Number of TX queues allocated at alloc_netdev_mq() time  */
@@ -770,6 +778,7 @@ struct net_device
 
 	unsigned long		tx_queue_len;	/* Max frames per queue allowed */
 	spinlock_t		tx_global_lock;
+
 /*
  * One part is mostly used on xmit path (device)
  */
@@ -1773,10 +1782,28 @@ static inline void netif_addr_unlock_bh(
 
 extern void		ether_setup(struct net_device *dev);
 
+static inline int netif_rx_processing_cpu(struct net_device *dev, int rx_num)
+{
+	int cpu = -1;
+
+	if (rx_num >= 0 && rx_num < dev->num_rx_queues)
+		cpu = dev->_rx_attr[rx_num].processing_cpu;
+
+	if (cpu == -1)
+		cpu = smp_processor_id();
+
+	return cpu;
+}
+
 /* Support for loadable net-drivers */
 extern struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 				       void (*setup)(struct net_device *),
 				       unsigned int queue_count);
+extern struct net_device *alloc_netdev_rxtx_mq(int sizeof_priv,
+				const char *name,
+				void (*setup)(struct net_device *),
+				unsigned int rx_queue_count,
+				unsigned int tx_queue_count);
 #define alloc_netdev(sizeof_priv, name, setup) \
 	alloc_netdev_mq(sizeof_priv, name, setup, 1)
 extern int		register_netdev(struct net_device *dev);
include/linux/etherdevice.h +3 -0
@@ -51,6 +51,9 @@ extern int eth_validate_addr(struct net_
 extern struct net_device *alloc_etherdev_mq(int sizeof_priv, unsigned int queue_count);
 #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
 
+extern struct net_device *alloc_etherdev_rxtx_mq(int sizeof_priv,
+		unsigned int rx_queue_count, unsigned int tx_queue_count);
+
 /**
  * is_zero_ether_addr - Determine if give Ethernet address is all zeros.
  * @addr: Pointer to a six-byte array containing the Ethernet address
net/core/dev.c +34 -0
@@ -4862,6 +4862,39 @@ struct net_device *alloc_netdev_mq(int s
 }
 EXPORT_SYMBOL(alloc_netdev_mq);
 
+struct net_device *alloc_netdev_rxtx_mq(int sizeof_priv,
+		const char *name,
+		void (*setup)(struct net_device *),
+		unsigned int rx_queue_count,
+		unsigned int tx_queue_count)
+{
+	struct netdev_queue_attr *rx;
+	struct net_device *dev;
+	int i;
+
+	dev = alloc_netdev_mq(sizeof_priv, name, setup, tx_queue_count);
+	if (dev && rx_queue_count) {
+		rx = kcalloc(rx_queue_count,
+			sizeof(struct netdev_queue_attr),
+			GFP_KERNEL);
+		if (!rx) {
+			printk(KERN_ERR "alloc_netdev: Unable to allocate "
+					"rx attributes.\n");
+			free_netdev(dev);
+			return NULL;
+		}
+
+		for (i = 0; i < rx_queue_count; i ++)
+			rx[i].processing_cpu = -1;
+
+		dev->_rx_attr = rx;
+		dev->num_rx_queues = rx_queue_count;
+	}
+
+	return dev;
+}
+EXPORT_SYMBOL(alloc_netdev_rxtx_mq);
+
 /**
  *	free_netdev - free network device
  *	@dev: device
@@ -4877,6 +4910,7 @@ void free_netdev(struct net_device *dev)
 	release_net(dev_net(dev));
 
 	kfree(dev->_tx);
+	kfree(dev->_rx_attr);
 
 	list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
 		netif_napi_del(p);
net/core/net-sysfs.c +93 -1

118 lines not on this page · raw message

net/ethernet/eth.c +8 -0
@@ -374,6 +374,14 @@ struct net_device *alloc_etherdev_mq(int
 }
 EXPORT_SYMBOL(alloc_etherdev_mq);
 
+struct net_device *alloc_etherdev_rxtx_mq(int sizeof_priv,
+		unsigned int rx_queue_count, unsigned int tx_queue_count)
+{
+	return alloc_netdev_rxtx_mq(sizeof_priv, "eth%d", ether_setup,
+			rx_queue_count, tx_queue_count);
+}
+EXPORT_SYMBOL(alloc_etherdev_rxtx_mq);
+
 static size_t _format_mac_addr(char *buf, int buflen,
 				const unsigned char *addr, int len)
 {