Skip to contentSkip to conversation

net/hyperv: Add flow control based on hi/low watermark

PATCH Applied Haiyang Zhang 2 participants 3 messages Mar 27, 2012 – Apr 3, 2012

Subsystems (3)
lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

v3 cover net/hyperv: Add flow control based on hi/low watermark

This patch is targeting 'net-next' tree (when re-opened).

Haiyang Zhang (1):
net/hyperv: Add flow control based on hi/low watermark

 drivers/hv/ring_buffer.c        |   31 -----------------------------
 drivers/net/hyperv/netvsc.c     |   41 +++++++++++++++++++++++++++++++++++---
 drivers/net/hyperv/netvsc_drv.c |    6 ++++-
 include/linux/hyperv.h          |   27 +++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 36 deletions(-)
Signature · 1 line
1.7.4.1
author maintainer
#1 lore raw

PATCH v3 1/1 net/hyperv: Add flow control based on hi/low watermark

In the existing code, we only stop queue when the ringbuffer is full, so the current packet has to be dropped or retried from upper layer.

This patch stops the tx queue when available ringbuffer is below the low watermark. So the ringbuffer still has small amount of space available for the current packet. This will reduce the overhead of retries on sending.

---
 drivers/hv/ring_buffer.c        |   31 -----------------------------
 drivers/net/hyperv/netvsc.c     |   41 +++++++++++++++++++++++++++++++++++---
 drivers/net/hyperv/netvsc_drv.c |    6 ++++-
 include/linux/hyperv.h          |   27 +++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 36 deletions(-)
drivers/hv/ring_buffer.c +0 -31
index 8af25a0..7233c88 100644
@@ -30,37 +30,6 @@
 #include "hyperv_vmbus.h"
 
 
-/* #defines */
-
-
-/* Amount of space to write to */
-#define BYTES_AVAIL_TO_WRITE(r, w, z) \
-	((w) >= (r)) ? ((z) - ((w) - (r))) : ((r) - (w))
-
-
-/*
- *
- * hv_get_ringbuffer_availbytes()
- *
- * Get number of bytes available to read and to write to
- * for the specified ring buffer
- */
-static inline void
-hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
-			  u32 *read, u32 *write)
-{
-	u32 read_loc, write_loc;
-
-	smp_read_barrier_depends();
-
-	/* Capture the read/write indices before they changed */
-	read_loc = rbi->ring_buffer->read_index;
-	write_loc = rbi->ring_buffer->write_index;
-
-	*write = BYTES_AVAIL_TO_WRITE(read_loc, write_loc, rbi->ring_datasize);
-	*read = rbi->ring_datasize - *write;
-}
-
 /*
  * hv_get_next_write_location()
  *
drivers/net/hyperv/netvsc.c +37 -4

69 lines not on this page · raw message

drivers/net/hyperv/netvsc_drv.c +5 -1
index dd29478..a0cc127 100644
@@ -224,9 +224,13 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
 		net->stats.tx_packets++;
 	} else {
 		kfree(packet);
+		if (ret != -EAGAIN) {
+			dev_kfree_skb_any(skb);
+			net->stats.tx_dropped++;
+		}
 	}
 
-	return ret ? NETDEV_TX_BUSY : NETDEV_TX_OK;
+	return (ret == -EAGAIN) ? NETDEV_TX_BUSY : NETDEV_TX_OK;
 }
 
 /*
include/linux/hyperv.h +27 -0
index 5852545..6af8738 100644
@@ -274,6 +274,33 @@ struct hv_ring_buffer_debug_info {
 	u32 bytes_avail_towrite;
 };
 
+
+/*
+ *
+ * hv_get_ringbuffer_availbytes()
+ *
+ * Get number of bytes available to read and to write to
+ * for the specified ring buffer
+ */
+static inline void
+hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
+			  u32 *read, u32 *write)
+{
+	u32 read_loc, write_loc, dsize;
+
+	smp_read_barrier_depends();
+
+	/* Capture the read/write indices before they changed */
+	read_loc = rbi->ring_buffer->read_index;
+	write_loc = rbi->ring_buffer->write_index;
+	dsize = rbi->ring_datasize;
+
+	*write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
+		read_loc - write_loc;
+	*read = dsize - *write;
+}
+
+
 /*
  * We use the same version numbering for all Hyper-V modules.
  *
Signature · 1 line
1.7.4.1
maintainer Applied
#2 lore raw

From: Haiyang Zhang <[email protected]>
Date: Tue, 27 Mar 2012 16:20:45 -0700

Quoted 10 lines

In the existing code, we only stop queue when the ringbuffer is full, so the current packet has to be dropped or retried from upper layer.

This patch stops the tx queue when available ringbuffer is below the low watermark. So the ringbuffer still has small amount of space available for the current packet. This will reduce the overhead of retries on sending.

Applied to net-next