Skip to contentSkip to conversation

hyperv: Add support for virtual Receive Side Scaling (vRSS)

PATCH Superseded Haiyang Zhang 3 participants 6 messages Mar 15, 2014 – Mar 17, 2014

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

v2 cover hyperv: Add support for virtual Receive Side Scaling (vRSS)

In this updated version, I have re-written the send queue selection, which is based on ndo_select_queue now. I also applied the stop/wake queue for each queue separately as suggested by reviewers.

Tom Herbert <[email protected]> has submitted a Toeplitz library function with some optimization. But it's not accepted yet. I'm still using my Toeplitz implementation in netvsc module. Please accept my patch if no other issues, because it already provides significant performance enhancement at current state. I will be happy to switch to the Toeplitz library function when it's accepted in the future.

Haiyang Zhang (1):
hyperv: Add support for virtual Receive Side Scaling (vRSS)

 drivers/net/hyperv/hyperv_net.h   |  111 ++++++++++++++++++++++-
 drivers/net/hyperv/netvsc.c       |  132 +++++++++++++++++++++-----
 drivers/net/hyperv/netvsc_drv.c   |  104 ++++++++++++++++++++-
 drivers/net/hyperv/rndis_filter.c |  186 ++++++++++++++++++++++++++++++++++++-
 4 files changed, 500 insertions(+), 33 deletions(-)
Signature · 1 line
1.7.4.1
author maintainer
#1 lore raw

PATCH v2 1/1 hyperv: Add support for virtual Receive Side Scaling (vRSS)

This feature allows multiple channels to be used by each virtual NIC. It is available on Hyper-V host 2012 R2.

---
 drivers/net/hyperv/hyperv_net.h   |  111 ++++++++++++++++++++++-
 drivers/net/hyperv/netvsc.c       |  132 +++++++++++++++++++++-----
 drivers/net/hyperv/netvsc_drv.c   |  104 ++++++++++++++++++++-
 drivers/net/hyperv/rndis_filter.c |  186 ++++++++++++++++++++++++++++++++++++-
 4 files changed, 500 insertions(+), 33 deletions(-)
drivers/net/hyperv/hyperv_net.h +110 -1
index 13010b4..f67292f 100644
@@ -28,6 +28,98 @@
 #include <linux/hyperv.h>
 #include <linux/rndis.h>
 
+/* RSS related */
+#define OID_GEN_RECEIVE_SCALE_CAPABILITIES 0x00010203  /* query only */
+#define OID_GEN_RECEIVE_SCALE_PARAMETERS 0x00010204  /* query and set */
+
+#define NDIS_OBJECT_TYPE_RSS_CAPABILITIES 0x88
+#define NDIS_OBJECT_TYPE_RSS_PARAMETERS 0x89
+
+#define NDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2
+#define NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2
+
+struct ndis_obj_header {
+	u8 type;
+	u8 rev;
+	u16 size;
+} __packed;
+
+
+/* ndis_recv_scale_cap/cap_flag */
+#define NDIS_RSS_CAPS_MESSAGE_SIGNALED_INTERRUPTS 0x01000000
+#define NDIS_RSS_CAPS_CLASSIFICATION_AT_ISR       0x02000000
+#define NDIS_RSS_CAPS_CLASSIFICATION_AT_DPC       0x04000000
+#define NDIS_RSS_CAPS_USING_MSI_X                 0x08000000
+#define NDIS_RSS_CAPS_RSS_AVAILABLE_ON_PORTS      0x10000000
+#define NDIS_RSS_CAPS_SUPPORTS_MSI_X              0x20000000
+#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV4          0x00000100
+#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6          0x00000200
+#define NDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6_EX       0x00000400
+
+struct ndis_recv_scale_cap { /* NDIS_RECEIVE_SCALE_CAPABILITIES */
+	struct ndis_obj_header hdr;
+	u32 cap_flag;
+	u32 num_int_msg;
+	u32 num_recv_que;
+	u16 num_indirect_tabent;
+} __packed;
+
+
+/* ndis_recv_scale_param flags */
+#define NDIS_RSS_PARAM_FLAG_BASE_CPU_UNCHANGED     0x0001
+#define NDIS_RSS_PARAM_FLAG_HASH_INFO_UNCHANGED    0x0002
+#define NDIS_RSS_PARAM_FLAG_ITABLE_UNCHANGED       0x0004
+#define NDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED     0x0008
+#define NDIS_RSS_PARAM_FLAG_DISABLE_RSS            0x0010
+
+/* Hash info bits */
+#define NDIS_HASH_FUNC_TOEPLITZ 0x00000001
+#define NDIS_HASH_IPV4          0x00000100
+#define NDIS_HASH_TCP_IPV4      0x00000200
+#define NDIS_HASH_IPV6          0x00000400
+#define NDIS_HASH_IPV6_EX       0x00000800
+#define NDIS_HASH_TCP_IPV6      0x00001000
+#define NDIS_HASH_TCP_IPV6_EX   0x00002000
+
+#define NDIS_RSS_INDIRECTION_TABLE_MAX_SIZE_REVISION_2 (128 * 4)
+#define NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2   40
+
+#define ITAB_NUM 128
+#define HASH_KEYLEN NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2
+extern u8 hash_key[];
+
+struct ndis_recv_scale_param { /* NDIS_RECEIVE_SCALE_PARAMETERS */
+	struct ndis_obj_header hdr;
+
+	/* Qualifies the rest of the information */
+	u16 flag;
+
+	/* The base CPU number to do receive processing. not used */
+	u16 base_cpu_number;
+
+	/* This describes the hash function and type being enabled */
+	u32 hashinfo;
+
+	/* The size of indirection table array */
+	u16 indirect_tabsize;
+
+	/* The offset of the indirection table from the beginning of this
+	 * structure
+	 */
+	u32 indirect_taboffset;
+
+	/* The size of the hash secret key */
+	u16 hashkey_size;
+
+	/* The offset of the secret key from the beginning of this structure */
+	u32 kashkey_offset;
+
+	u32 processor_masks_offset;
+	u32 num_processor_masks;
+	u32 processor_masks_entry_size;
+};
+
+
 /* Fwd declaration */
 struct hv_netvsc_packet;
 struct ndis_tcp_ip_checksum_info;
@@ -39,6 +131,8 @@ struct xferpage_packet {
 
 	/* # of netvsc packets this xfer packet contains */
 	u32 count;
+
+	struct vmbus_channel *channel;
 };
 
 /*
@@ -54,6 +148,9 @@ struct hv_netvsc_packet {
 	bool is_data_pkt;
 	u16 vlan_tci;
 
+	u16 q_idx;
+	struct vmbus_channel *channel;
+
 	/*
 	 * Valid only for receives when we break a xfer page packet
 	 * into multiple netvsc packets
@@ -120,6 +217,7 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
 int netvsc_recv_callback(struct hv_device *device_obj,
 			struct hv_netvsc_packet *packet,
 			struct ndis_tcp_ip_checksum_info *csum_info);
+extern void netvsc_channel_cb(void *context);
 int rndis_filter_open(struct hv_device *dev);
 int rndis_filter_close(struct hv_device *dev);
 int rndis_filter_device_add(struct hv_device *dev,
@@ -131,6 +229,7 @@ int rndis_filter_receive(struct hv_device *dev,
 int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter);
 int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac);
 
+extern int ring_size;
 
 #define NVSP_INVALID_PROTOCOL_VERSION	((u32)0xFFFFFFFF)
 
@@ -522,6 +621,8 @@ struct nvsp_message {
 
 #define NETVSC_PACKET_SIZE                      2048
 
+#define VRSS_SEND_TAB_SIZE 16
+
 /* Per netvsc channel-specific */
 struct netvsc_device {
 	struct hv_device *dev;
@@ -555,10 +656,18 @@ struct netvsc_device {
 
 	struct net_device *ndev;
 
+	struct vmbus_channel *chn_table[NR_CPUS];
+	u32 send_table[VRSS_SEND_TAB_SIZE];
+	u32 num_chn;
+	atomic_t queue_sends[NR_CPUS];
+
 	/* Holds rndis device info */
 	void *extension;
-	/* The recive buffer for this device */
+
+	/* The primary channel callback buffer */
 	unsigned char cb_buffer[NETVSC_PACKET_SIZE];
+	/* The sub channel callback buffer */
+	unsigned char *sub_cb_buf;
 };
 
 /* NdisInitialize message */
drivers/net/hyperv/netvsc.c +106 -26

285 lines not on this page · raw message

drivers/net/hyperv/netvsc_drv.c +100 -4

160 lines not on this page · raw message

drivers/net/hyperv/rndis_filter.c +184 -2

234 lines not on this page · raw message

Signature · 1 line
1.7.4.1
maintainer
#2 lore raw

From: Haiyang Zhang <[email protected]>
Date: Sat, 15 Mar 2014 10:18:07 -0700

drivers/net/hyperv/netvsc.c static void netvsc_send_completion(struct netvsc_device *net_device, · line 507

Quoted 11 lines
drivers/net/hyperv/netvsc.c +6 -5
-		if (netif_queue_stopped(ndev) && !net_device->start_remove &&
-			(hv_ringbuf_avail_percent(&device->channel->outbound)
-			> RING_AVAIL_PERCENT_HIWATER ||
-			num_outstanding_sends < 1))
-				netif_wake_queue(ndev);
+		if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx))
+			&& !net_device->start_remove &&
+			(hv_ringbuf_avail_percent(&channel->outbound)
+			> RING_AVAIL_PERCENT_HIWATER || queue_sends < 1))
+				netif_tx_wake_queue(netdev_get_tx_queue(
+						    ndev, q_idx));

This is not indented properly, make it:

	if (A && B &&
	    (C >
             D || E < 1))

Never put operators at the beginning of a conditional line, always at the end.

author maintainer
#3 lore raw
Quoted 32 lines

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Monday, March 17, 2014 4:20 PM
To: Haiyang Zhang
Cc: [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net-next,v2,1/1] hyperv: Add support for virtual Receive Side Scaling (vRSS)

From: Haiyang Zhang <[email protected]>
Date: Sat, 15 Mar 2014 10:18:07 -0700

Review

Quoted 1 line
(quoted diff) +0 -1
-		if (netif_queue_stopped(ndev) && !net_device->start_remove

&&

drivers/net/hyperv/netvsc.c static void netvsc_send_completion(struct netvsc_device *net_device,

Quoted 9 lines
(quoted diff) +0 -1
-			(hv_ringbuf_avail_percent(&device->channel-

outbound)

drivers/net/hyperv/netvsc.c +4 -3
-			> RING_AVAIL_PERCENT_HIWATER ||
-			num_outstanding_sends < 1))
-				netif_wake_queue(ndev);
+		if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx))
+			&& !net_device->start_remove &&
+			(hv_ringbuf_avail_percent(&channel->outbound)
+			> RING_AVAIL_PERCENT_HIWATER || queue_sends <

1))

drivers/net/hyperv/netvsc.c static void netvsc_send_completion(struct netvsc_device *net_device, · line 507

Quoted 2 lines
drivers/net/hyperv/netvsc.c +2 -0
+				netif_tx_wake_queue(netdev_get_tx_queue(
+						    ndev, q_idx));

This is not indented properly, make it:

Quoted 5 lines
	if (A && B &&
	    (C >
             D || E < 1))

Never put operators at the beginning of a conditional line, always at the end.

I will do.

Thanks,
- Haiyang

#4 lore raw
In reply to Haiyang Zhang

On Sat, 2014-03-15 at 10:18 -0700, Haiyang Zhang wrote:
[...]

drivers/net/hyperv/netvsc_drv.c struct net_device_context { · line 53

Quoted 5 lines

#define RING_SIZE_MIN 64

drivers/net/hyperv/netvsc_drv.c +1 -1
-static int ring_size = 128;
+int ring_size = 128;
 module_param(ring_size, int, S_IRUGO);
 MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");

You have to add some driver-specific prefix to the variable name if it is going to be extern. (And use module_param_named to avoid changing the parameter name too.)

[...]

drivers/net/hyperv/rndis_filter.c cleanup: · line 709

Quoted 7 lines
drivers/net/hyperv/rndis_filter.c +7 -0
+u8 hash_key[HASH_KEYLEN] = {
+	0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
+	0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
+	0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
+	0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
+	0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
+};

[...]

Same for this one.

Ben.

Signature · 3 lines
Ben Hutchings
I'm always amazed by the number of people who take up solipsism because
they heard someone else explain it. - E*Borg on alt.fan.pratchett

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

author maintainer
#5 lore raw
Quoted 33 lines

-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Monday, March 17, 2014 4:28 PM
To: Haiyang Zhang
Cc: [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next,v2,1/1] hyperv: Add support for virtual Receive Side Scaling (vRSS)

On Sat, 2014-03-15 at 10:18 -0700, Haiyang Zhang wrote:
[...]

Quoted 5 lines

#define RING_SIZE_MIN 64

drivers/net/hyperv/netvsc_drv.c +1 -1
-static int ring_size = 128;
+int ring_size = 128;
 module_param(ring_size, int, S_IRUGO);  MODULE_PARM_DESC(ring_size,

"Ring buffer size (# of pages)");

You have to add some driver-specific prefix to the variable name if it is going to be extern. (And use module_param_named to avoid changing the parameter name too.)

[...]

Quoted 6 lines
drivers/net/hyperv/rndis_filter.c +6 -0
+u8 hash_key[HASH_KEYLEN] = {
+	0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
+	0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
+	0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
+	0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
+	0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa };

[...]

Quoted 2 lines

Same for this one.

I will do.

Thanks,
- Haiyang