Skip to contentSkip to conversation

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

PATCH Superseded Haiyang Zhang 5 participants 12 messages Dec 18, 2013 – Dec 19, 2013

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

PATCH 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   |  159 ++++++++++++++++++++++++++++++++++
 drivers/net/hyperv/netvsc.c       |  120 ++++++++++++++++++++------
 drivers/net/hyperv/netvsc_drv.c   |   94 +++++++++++++++++++-
 drivers/net/hyperv/rndis_filter.c |  171 ++++++++++++++++++++++++++++++++++++-
 4 files changed, 511 insertions(+), 33 deletions(-)
drivers/net/hyperv/hyperv_net.h +159 -0
index a26eecb..055ab94 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;
 
@@ -38,6 +130,8 @@ struct xferpage_packet {
 
 	/* # of netvsc packets this xfer packet contains */
 	u32 count;
+
+	struct vmbus_channel *channel;
 };
 
 /*
@@ -53,6 +147,9 @@ struct hv_netvsc_packet {
 	bool is_data_pkt;
 	u16 vlan_tci;
 
+	bool is_hash;
+	u32 hash;
+
 	/*
 	 * Valid only for receives when we break a xfer page packet
 	 * into multiple netvsc packets
@@ -118,6 +215,7 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
 				unsigned int status);
 int netvsc_recv_callback(struct hv_device *device_obj,
 			struct hv_netvsc_packet *packet);
+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,
@@ -134,11 +232,15 @@ int rndis_filter_send(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)
 
 #define NVSP_PROTOCOL_VERSION_1		2
 #define NVSP_PROTOCOL_VERSION_2		0x30002
+#define NVSP_PROTOCOL_VERSION_4		0x40000
+#define NVSP_PROTOCOL_VERSION_5		0x50000
 
 enum {
 	NVSP_MSG_TYPE_NONE = 0,
@@ -193,6 +295,23 @@ enum {
 
 	NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE,
 	NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
+
+	NVSP_MSG2_MAX = NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP,
+
+	/* Version 4 messages */
+	NVSP_MSG4_TYPE_SEND_VF_ASSOCIATION,
+	NVSP_MSG4_TYPE_SWITCH_DATA_PATH,
+	NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
+
+	NVSP_MSG4_MAX = NVSP_MSG4_TYPE_UPLINK_CONNECT_STATE_DEPRECATED,
+
+	/* Version 5 messages */
+	NVSP_MSG5_TYPE_OID_QUERY_EX,
+	NVSP_MSG5_TYPE_OID_QUERY_EX_COMP,
+	NVSP_MSG5_TYPE_SUBCHANNEL,
+	NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
+
+	NVSP_MSG5_MAX = NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
 };
 
 enum {
@@ -447,10 +566,44 @@ union nvsp_2_message_uber {
 	struct nvsp_2_free_rxbuf free_rxbuf;
 } __packed;
 
+enum nvsp_subchannel_operation {
+	NVSP_SUBCHANNEL_NONE = 0,
+	NVSP_SUBCHANNEL_ALLOCATE,
+	NVSP_SUBCHANNEL_MAX
+};
+
+struct nvsp_5_subchannel_request {
+	u32 op;
+	u32 num_subchannels;
+} __packed;
+
+struct nvsp_5_subchannel_complete {
+	u32 status;
+	u32 num_subchannels; /* Actual number of subchannels allocated */
+} __packed;
+
+struct nvsp_5_send_indirect_table {
+	/* The number of entries in the send indirection table */
+	u32 count;
+
+	/* The offset of the send indireciton table from top of this struct.
+	 * The send indirection table tells which channel to put the send
+	 * traffic on. Each entry is a channel number.
+	 */
+	u32 offset;
+} __packed;
+
+union nvsp_5_message_uber {
+	struct nvsp_5_subchannel_request subchn_req;
+	struct nvsp_5_subchannel_complete subchn_comp;
+	struct nvsp_5_send_indirect_table send_table;
+} __packed;
+
 union nvsp_all_messages {
 	union nvsp_message_init_uber init_msg;
 	union nvsp_1_message_uber v1_msg;
 	union nvsp_2_message_uber v2_msg;
+	union nvsp_5_message_uber v5_msg;
 } __packed;
 
 /* ALL Messages */
@@ -471,6 +624,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;
@@ -504,6 +659,10 @@ struct netvsc_device {
 
 	struct net_device *ndev;
 
+	struct vmbus_channel *chn_table[NR_CPUS];
+	u32 send_table[VRSS_SEND_TAB_SIZE];
+	u32 num_chn;
+
 	/* Holds rndis device info */
 	void *extension;
 };
drivers/net/hyperv/netvsc.c +94 -26

270 lines not on this page · raw message

drivers/net/hyperv/netvsc_drv.c +89 -5

162 lines not on this page · raw message

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

213 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 2 lines · Haiyang Zhang

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

[...]

Quoted 2 lines
drivers/net/hyperv/netvsc.c +0 -0

[...]

Quoted 34 lines
drivers/net/hyperv/netvsc.c +10 -4
@@ -525,15 +535,21 @@ int netvsc_send(struct hv_device *device,
 	else
 		req_id = 0;
 
+	if (packet->is_hash)
+		out_channel = net_device->chn_table[net_device->send_table[
+					packet->hash % VRSS_SEND_TAB_SIZE]];
+	if (out_channel == NULL)
+		out_channel = device->channel;
+
 	if (packet->page_buf_cnt) {
-		ret = vmbus_sendpacket_pagebuffer(device->channel,
+		ret = vmbus_sendpacket_pagebuffer(out_channel,
 						  packet->page_buf,
 						  packet->page_buf_cnt,
 						  &sendMessage,
 						  sizeof(struct nvsp_message),
 						  req_id);
 	} else {
-		ret = vmbus_sendpacket(device->channel, &sendMessage,
+		ret = vmbus_sendpacket(out_channel, &sendMessage,
 				sizeof(struct nvsp_message),
 				req_id,
 				VM_PKT_DATA_INBAND,
@@ -544,15 +560,15 @@ int netvsc_send(struct hv_device *device,
 		atomic_inc(&net_device->num_outstanding_sends);
 		if (hv_ringbuf_avail_percent(&device->channel->outbound) <
 			RING_AVAIL_PERCENT_LOWATER) {
-			netif_stop_queue(ndev);
+			netif_tx_stop_all_queues(ndev);
 			if (atomic_read(&net_device->
 				num_outstanding_sends) < 1)
-				netif_wake_queue(ndev);
+				netif_tx_wake_all_queues(ndev);

drivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 574

Quoted 10 lines
drivers/net/hyperv/netvsc.c +2 -2
 		}
 	} else if (ret == -EAGAIN) {
-		netif_stop_queue(ndev);
+		netif_tx_stop_all_queues(ndev);
 		if (atomic_read(&net_device->num_outstanding_sends) < 1) {
-			netif_wake_queue(ndev);
+			netif_tx_wake_all_queues(ndev);
 			ret = -ENOSPC;
 		}
 	} else {

This doesn't makes any sense to me. How can you safely share the same channels between all TX queues?

I think you need to associate TX queues and channels 1-1. If you are required to map packets to TX queues using the Toeplitz hash, you should implement ndo_select_queue and do the mapping there. Then in netvsc_send() you would use the queue number from the skb to find which channel to use and which queue may need to be stopped/woken.

[...]

Quoted 2 lines
drivers/net/hyperv/netvsc_drv.c +0 -0

[...]

Quoted 19 lines
drivers/net/hyperv/netvsc_drv.c +19 -0
+/* Toeplitz hash function
+ * data: network byte order
+ * return: host byte order
+ */
+static u32 comp_hash(u8 *key, int klen, u8 *data, int dlen)
+{
+	union sub_key subk;
+	int k_next = 4;
+	u8 dt;
+	int i, j;
+	u32 ret = 0;
+
+	subk.k = 0;
+	subk.ka = ntohl(*(u32 *)key);
+
+	for (i = 0; i < dlen; i++) {
+		subk.kb = key[k_next];
+		k_next = (k_next + 1) % klen;
+		dt = data[i];

drivers/net/hyperv/netvsc_drv.c static int netvsc_close(struct net_device *net) · line 159

Quoted 10 lines
drivers/net/hyperv/netvsc_drv.c +10 -0
+		for (j = 0; j < 8; j++) {
+			if (dt & 0x80)
+				ret ^= subk.ka;
+			dt <<= 1;
+			subk.k <<= 1;
+		}
+	}
+
+	return ret;
+}

This looks incredibly slow. I've seen software implementations that are likely to be more efficient, e.g.
<http://thread.gmane.org/gmane.linux.network/284612/>

[...]

Quoted 24 lines
drivers/net/hyperv/netvsc_drv.c +6 -1
@@ -411,9 +483,11 @@ static int netvsc_probe(struct hv_device *dev,
 	struct net_device *net = NULL;
 	struct net_device_context *net_device_ctx;
 	struct netvsc_device_info device_info;
+	struct netvsc_device *nvdev;
 	int ret;
 
-	net = alloc_etherdev(sizeof(struct net_device_context));
+	net = alloc_etherdev_mq(sizeof(struct net_device_context),
+				num_online_cpus());
 	if (!net)
 		return -ENOMEM;
 
@@ -435,6 +509,9 @@ static int netvsc_probe(struct hv_device *dev,
 	SET_ETHTOOL_OPS(net, &ethtool_ops);
 	SET_NETDEV_DEV(net, &dev->device);
 
+	netif_set_real_num_tx_queues(net, 1);
+	netif_set_real_num_rx_queues(net, 1);
+
 	ret = register_netdev(net);
 	if (ret != 0) {
 		pr_err("Unable to register netdev.\n");

drivers/net/hyperv/netvsc_drv.c static int netvsc_probe(struct hv_device *dev, · line 536

Quoted 7 lines
drivers/net/hyperv/netvsc_drv.c +4 -0
@@ -453,6 +530,13 @@ static int netvsc_probe(struct hv_device *dev,
 		return ret;
 	}
 	memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
+	nvdev = hv_get_drvdata(dev);
+	rtnl_lock();
+	netif_set_real_num_tx_queues(net, nvdev->num_chn);
+	netif_set_real_num_rx_queues(net, nvdev->num_chn);

[...]

These functions can fail if called after registering the net device, so you should either call them with the final values earlier or handle failure here.

Also, I notice that dev_addr is only set after registering; that should be fixed.

Ben.

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

-----Original Message-----
From: Ben Hutchings [mailto:[email protected]]
Sent: Thursday, December 19, 2013 12:46 PM
To: Haiyang Zhang
Cc: [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net-next] hyperv: Add support for Virtual Receive Side Scaling (vRSS)

drivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 574

Quoted 11 lines · Haiyang Zhang

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

drivers/net/hyperv/netvsc.c +2 -2
 	} else if (ret == -EAGAIN) {
-		netif_stop_queue(ndev);
+		netif_tx_stop_all_queues(ndev);
 		if (atomic_read(&net_device->num_outstanding_sends) < 1) {
-			netif_wake_queue(ndev);
+			netif_tx_wake_all_queues(ndev);
 			ret = -ENOSPC;
 		}
 	} else {

This doesn't makes any sense to me. How can you safely share the same channels between all TX queues?

I think you need to associate TX queues and channels 1-1. If you are required to map packets to TX queues using the Toeplitz hash, you should implement ndo_select_queue and do the mapping there. Then in
netvsc_send() you would use the queue number from the skb to find which channel to use and which queue may need to be stopped/woken.

[...]

Quoted 2 lines
drivers/net/hyperv/netvsc_drv.c +0 -0

[...]

Quoted 4 lines

+/* Toeplitz hash function
+ * data: network byte order
+ * return: host byte order
+ */

This looks incredibly slow. I've seen software implementations that are likely to be more efficient, e.g.
<http://thread.gmane.org/gmane.linux.network/284612/>

[...]

Quoted 8 lines

int netvsc_probe(struct hv_device *dev,

drivers/net/hyperv/netvsc_drv.c +4 -0
 		return ret;
 	}
 	memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
+	nvdev = hv_get_drvdata(dev);
+	rtnl_lock();
+	netif_set_real_num_tx_queues(net, nvdev->num_chn);
+	netif_set_real_num_rx_queues(net, nvdev->num_chn);

[...]

Quoted 5 lines

These functions can fail if called after registering the net device, so you should either call them with the final values earlier or handle failure here.

Also, I notice that dev_addr is only set after registering; that should be fixed.

Thank you for the suggestions! I will re-write the send queue selection, enhance the hash calculation, also fix the initialization sequence.

Thanks,
- Haiyang

#3 lore raw
Quoted 2 lines · Haiyang Zhang

Thank you for the suggestions! I will re-write the send queue selection, enhance the hash calculation, also fix the initialization sequence.

Btw, Toeplitz hash function should either go into lib/hash.c as well or include/linux/hash.h to avoid ending up w/ various implementations in multiple places.

author maintainer
#4 lore raw
Quoted 12 lines

-----Original Message-----
From: Daniel Borkmann [mailto:[email protected]]
Sent: Thursday, December 19, 2013 1:45 PM
To: Haiyang Zhang
Cc: Ben Hutchings; [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH net-next] hyperv: Add support for Virtual Receive Side Scaling (vRSS)

Quoted 8 lines
Quoted 2 lines · Haiyang Zhang

Thank you for the suggestions! I will re-write the send queue selection, enhance the hash calculation, also fix the initialization sequence.

Btw, Toeplitz hash function should either go into lib/hash.c as well or include/linux/hash.h to avoid ending up w/ various implementations in multiple places.

Will do.

Thanks,
- Haiyang

#5 lore raw

I posted an implementation of library functions for Toeplitz (see [PATCH 1/2] net: Toeplitz library functions). This includes some pre-computation of the table to get reasonable performance in the host. Please take a look.

On the other hand, if you're computing a hash in the host, do you really need Toeplitz, flow_dissector already supports a good hash computation and can parse many more packets than just plain UDP/TCP. We probably only should be doing Toeplitz in the host if we need to match HW computed values.

Quoted 25 lines · Haiyang Zhang
Quoted 12 lines

-----Original Message-----
From: Daniel Borkmann [mailto:[email protected]]
Sent: Thursday, December 19, 2013 1:45 PM
To: Haiyang Zhang
Cc: Ben Hutchings; [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH net-next] hyperv: Add support for Virtual Receive Side Scaling (vRSS)

Quoted 8 lines
Quoted 2 lines · Haiyang Zhang

Thank you for the suggestions! I will re-write the send queue selection, enhance the hash calculation, also fix the initialization sequence.

Btw, Toeplitz hash function should either go into lib/hash.c as well or include/linux/hash.h to avoid ending up w/ various implementations in multiple places.

Will do.

Thanks,
- Haiyang

author maintainer
#6 lore raw
Quoted 17 lines

-----Original Message-----
From: Tom Herbert [mailto:[email protected]]
Sent: Thursday, December 19, 2013 2:59 PM
To: Haiyang Zhang
Cc: Daniel Borkmann; Ben Hutchings; [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net-next] hyperv: Add support for Virtual Receive Side Scaling (vRSS)

I posted an implementation of library functions for Toeplitz (see [PATCH 1/2]
net: Toeplitz library functions). This includes some pre-computation of the table to get reasonable performance in the host. Please take a look.

Quoted 5 lines

On the other hand, if you're computing a hash in the host, do you really need Toeplitz, flow_dissector already supports a good hash computation and can parse many more packets than just plain UDP/TCP.
We probably only should be doing Toeplitz in the host if we need to match HW computed values.

The Hyper-V host requires the guest to select channel based on Toeplitz hash, so we need to compute it on the guest.

Regarding the Toeplitz function, do you mean this patch?
http://patchwork.ozlabs.org/patch/277344/
This doesn't contain the implementation. Could you point me to the actual code?

Thanks,
- Haiyang

#7 lore raw

Patch is below. This version did most pre-computation of the variants I built, but results in largest table (40*256*4 bytes), This gives performance roughly comparable with jhash (roughly same as jhash for IPv4, about 30% more cycles for IPv6). I have the simpler less memory intensive versions also if you're interested, these are 10x worse cycles so I wouldn't want those in critical path.
----
Introduce Toeplitz hash functions. Toeplitz is a hash used primarily in NICs to performan RSS flow steering. This is a software implemenation of that. In order to make the hash calculation efficient, we precompute the possible hash values for each inidividual byte of input. The input length is up to 40 bytes, so we make an array of cache[40][256].

The implemenation was verified against MSDN "Verify RSS hash" sample values.

---
 include/linux/netdevice.h |  3 +++
 include/linux/toeplitz.h  | 27 +++++++++++++++++++
 lib/Kconfig               |  3 +++
 lib/Makefile              |  2 ++
 lib/toeplitz.c            | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 net/Kconfig               |  5 ++++
 net/core/dev.c            | 11 ++++++++
 7 files changed, 117 insertions(+)
 create mode 100644 include/linux/toeplitz.h
 create mode 100644 lib/toeplitz.c
include/linux/netdevice.h +3 -0
index 3de49ac..546caf2 100644
@@ -38,6 +38,7 @@
 #include <linux/dmaengine.h>
 #include <linux/workqueue.h>
 #include <linux/dynamic_queue_limits.h>
+#include <linux/toeplitz.h>
 
 #include <linux/ethtool.h>
 #include <net/net_namespace.h>
@@ -195,6 +196,8 @@ struct net_device_stats {
 extern struct static_key rps_needed;
 #endif
 
+extern struct toeplitz *toeplitz_net;
+
 struct neighbour;
 struct neigh_parms;
 struct sk_buff;
include/linux/toeplitz.h new file +27 -0
new file mode 100644
index 0000000..bc0b8e8
@@ -0,0 +1,27 @@
+#ifndef __LINUX_TOEPLITZ_H
+#define __LINUX_TOEPLITZ_H
+
+#define TOEPLITZ_KEY_LEN 40
+
+struct toeplitz {
+       u8 key_vals[TOEPLITZ_KEY_LEN];
+       u32 key_cache[TOEPLITZ_KEY_LEN][256];
+};
+
+static inline unsigned int
+toeplitz_hash(const unsigned char *bytes,
+             struct toeplitz *toeplitz, int n)
+{
+       int i;
+       unsigned int result = 0;
+
+       for (i = 0; i < n; i++)
+               result ^= toeplitz->key_cache[i][bytes[i]];
+
+        return result;
+};
+
+extern struct toeplitz *toeplitz_alloc(void);
+extern void toeplitz_init(struct toeplitz *toeplitz, u8 *key_vals);
+
+#endif /* __LINUX_TOEPLITZ_H */
lib/Kconfig +3 -0
index b3c8be0..463b2b1 100644
@@ -359,6 +359,9 @@ config CPU_RMAP
 config DQL
        bool
 
+config TOEPLITZ
+       bool
+
 #
 # Netlink attribute parsing support is select'ed if needed
 #
lib/Makefile +2 -0
index f3bb2cb..a28349b 100644
@@ -133,6 +133,8 @@ obj-$(CONFIG_CORDIC) += cordic.o
 
 obj-$(CONFIG_DQL) += dynamic_queue_limits.o
 
+obj-$(CONFIG_TOEPLITZ) += toeplitz.o
+
 obj-$(CONFIG_MPILIB) += mpi/
 obj-$(CONFIG_SIGNATURE) += digsig.o
 
lib/toeplitz.c new file +66 -0

66 lines not on this page · raw message

net/Kconfig +5 -0
index b50dacc..860c9fa 100644
@@ -254,6 +254,11 @@ config BQL
        select DQL
        default y
 
+config NET_TOEPLITZ
+       boolean
+       select TOEPLITZ
+       default n
+
 config BPF_JIT
        bool "enable BPF Just In Time compiler"
        depends on HAVE_BPF_JIT
net/core/dev.c +0 -0
index 5c713f2..074f530 100644
@@ -6633,6 +6633,9 @@ static struct pernet_operations __net_initdata

default_device_ops = {
.exit_batch = default_device_exit_batch,
};

+struct toeplitz *toeplitz_net; +EXPORT_SYMBOL(toeplitz_net);
+
/*
* Initialize the DEV module. At boot time this walks the device list and
* unhooks any devices that fail to initialise (normally hardware not
@@ -6656,6 +6659,14 @@ static int __init net_dev_init(void)

        if (netdev_kobject_init())
                goto out;

+#ifdef CONFIG_NET_TOEPLITZ
+ toeplitz_net = toeplitz_alloc();
+ if (!toeplitz_net)
+ goto out;
+
+ toeplitz_init(toeplitz_net, NULL);
+#endif
+

        INIT_LIST_HEAD(&ptype_all);
        for (i = 0; i < PTYPE_HASH_SIZE; i++)
                INIT_LIST_HEAD(&ptype_base[i]);
Quoted 33 lines · Haiyang Zhang
Quoted 17 lines

-----Original Message-----
From: Tom Herbert [mailto:[email protected]]
Sent: Thursday, December 19, 2013 2:59 PM
To: Haiyang Zhang
Cc: Daniel Borkmann; Ben Hutchings; [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net-next] hyperv: Add support for Virtual Receive Side Scaling (vRSS)

I posted an implementation of library functions for Toeplitz (see [PATCH 1/2]
net: Toeplitz library functions). This includes some pre-computation of the table to get reasonable performance in the host. Please take a look.

Quoted 5 lines

On the other hand, if you're computing a hash in the host, do you really need Toeplitz, flow_dissector already supports a good hash computation and can parse many more packets than just plain UDP/TCP.
We probably only should be doing Toeplitz in the host if we need to match HW computed values.

The Hyper-V host requires the guest to select channel based on Toeplitz hash, so we need to compute it on the guest.

Regarding the Toeplitz function, do you mean this patch?
http://patchwork.ozlabs.org/patch/277344/
This doesn't contain the implementation. Could you point me to the actual code?

Thanks,
- Haiyang

#8 lore raw
Quoted 4 lines · Tom Herbert

Patch is below. This version did most pre-computation of the variants I built, but results in largest table (40*256*4 bytes), This gives performance roughly comparable with jhash (roughly same as jhash for IPv4, about 30% more cycles for IPv6). I have the simpler less memory

Quoted 8 lines

intensive versions also if you're interested, these are 10x worse cycles so I wouldn't want those in critical path.
----
Introduce Toeplitz hash functions. Toeplitz is a hash used primarily in NICs to performan RSS flow steering. This is a software implemenation of that. In order to make the hash calculation efficient, we precompute the possible hash values for each inidividual byte of input. The input length is up to 40 bytes, so we make an array of cache[40][256].

[...]

You haven't addressed my comments here:
<http://article.gmane.org/gmane.linux.network/284753>

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
maintainer
#9 lore raw
In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Thu, 19 Dec 2013 13:43:06 -0800

lib/toeplitz.c line 30

Quoted 12 lines
lib/toeplitz.c new file +12 -0
+       u32 v, r;
+       int off, rem;
+
+       off = idx / 8;
+       rem = idx % 8;
+
+       v = (((unsigned int)key[off]) << 24) +
+           (((unsigned int)key[off + 1]) << 16) +
+           (((unsigned int)key[off + 2]) << 8) +
+           (((unsigned int)key[off + 3]));
+
+       r = v << rem | (unsigned int)key[off + 4] >> (8 - rem);

Minor nit, since the type you are using is "u32", that's probably what you should be casting to in these spots instead of "unsigned int".

author maintainer
#10 lore raw
In reply to Tom Herbert
Quoted 11 lines

-----Original Message-----
From: Tom Herbert [mailto:[email protected]]
Sent: Thursday, December 19, 2013 4:43 PM
To: Haiyang Zhang
Cc: Daniel Borkmann; Ben Hutchings; [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net-next] hyperv: Add support for Virtual Receive Side Scaling (vRSS)

Quoted 7 lines

Patch is below. This version did most pre-computation of the variants I built, but results in largest table (40*256*4 bytes), This gives performance roughly comparable with jhash (roughly same as jhash for IPv4, about 30% more cycles for IPv6). I have the simpler less memory intensive versions also if you're interested, these are 10x worse cycles so I wouldn't want those in critical path.
----

Thank you for the code. We like the fast implementation even it uses a bit more memory. Are you going to address the comments and re-submit the code soon?

Thanks,
- Haiyang

#11 lore raw
Quoted 19 lines · Haiyang Zhang
Quoted 11 lines

-----Original Message-----
From: Tom Herbert [mailto:[email protected]]
Sent: Thursday, December 19, 2013 4:43 PM
To: Haiyang Zhang
Cc: Daniel Borkmann; Ben Hutchings; [email protected]; [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net-next] hyperv: Add support for Virtual Receive Side Scaling (vRSS)

Quoted 7 lines

Patch is below. This version did most pre-computation of the variants I built, but results in largest table (40*256*4 bytes), This gives performance roughly comparable with jhash (roughly same as jhash for IPv4, about 30% more cycles for IPv6). I have the simpler less memory intensive versions also if you're interested, these are 10x worse cycles so I wouldn't want those in critical path.
----

Quoted 3 lines

Thank you for the code. We like the fast implementation even it uses a bit more memory. Are you going to address the comments and re-submit the code soon?

I'll take another look now that there's some new motivation :-)

Quoted 2 lines

Thanks,
- Haiyang