All of lore.kernel.org
 help / color / mirror / Atom feed
From: "K. Y. Srinivasan" <kys@microsoft.com>
To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com,
	jasowang@redhat.com
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Subject: [PATCH 26/28] Drivers: hv: Implement flow management on the send side
Date: Sat,  1 Dec 2012 06:46:57 -0800	[thread overview]
Message-ID: <1354373219-31374-26-git-send-email-kys@microsoft.com> (raw)
In-Reply-To: <1354373219-31374-1-git-send-email-kys@microsoft.com>

Implement flow management on the send side. When the sender is blocked, the reader
can potentially signal the sender to indicate there is now room to send.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
---
 drivers/hv/channel.c      |   12 ++++++++-
 drivers/hv/hyperv_vmbus.h |    2 +-
 drivers/hv/ring_buffer.c  |   51 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 9303252..064257e 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -735,6 +735,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
 	u32 packetlen;
 	u32 userlen;
 	int ret;
+	bool signal = false;
 
 	*buffer_actual_len = 0;
 	*requestid = 0;
@@ -761,8 +762,10 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
 
 	/* Copy over the packet to the user buffer */
 	ret = hv_ringbuffer_read(&channel->inbound, buffer, userlen,
-			     (desc.offset8 << 3));
+			     (desc.offset8 << 3), &signal);
 
+	if (signal)
+		vmbus_setevent(channel);
 
 	return 0;
 }
@@ -779,6 +782,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
 	u32 packetlen;
 	u32 userlen;
 	int ret;
+	bool signal = false;
 
 	*buffer_actual_len = 0;
 	*requestid = 0;
@@ -805,7 +809,11 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
 	*requestid = desc.trans_id;
 
 	/* Copy over the entire packet to the user buffer */
-	ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0);
+	ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0,
+				 &signal);
+
+	if (signal)
+		vmbus_setevent(channel);
 
 	return 0;
 }
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index becb106..ac111f2 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -550,7 +550,7 @@ int hv_ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer,
 int hv_ringbuffer_read(struct hv_ring_buffer_info *ring_info,
 		   void *buffer,
 		   u32 buflen,
-		   u32 offset);
+		   u32 offset, bool *signal);
 
 
 void hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 2a0babc..cafa72f 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -84,6 +84,50 @@ static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi)
 	return false;
 }
 
+/*
+ * To optimize the flow management on the send-side,
+ * when the sender is blocked because of lack of
+ * sufficient space in the ring buffer, potential the
+ * consumer of the ring buffer can signal the producer.
+ * This is controlled by the following parameters:
+ *
+ * 1. pending_send_sz: This is the size in bytes that the
+ *    producer is trying to send.
+ * 2. The feature bit feat_pending_send_sz set to indicate if
+ *    the consumer of the ring will signal when the ring
+ *    state transitions from being full to a state where
+ *    there is room for the producer to send the pending packet.
+ */
+
+static bool hv_need_to_signal_on_read(u32 old_rd,
+					 struct hv_ring_buffer_info *rbi)
+{
+	u32 prev_write_sz;
+	u32 cur_write_sz;
+	u32 r_size;
+	u32 write_loc = rbi->ring_buffer->write_index;
+	u32 read_loc = rbi->ring_buffer->read_index;
+	u32 pending_sz = rbi->ring_buffer->pending_send_sz;
+
+	/*
+	 * If the other end is not blocked on write don't bother.
+	 */
+	if (pending_sz == 0)
+		return false;
+
+	r_size = rbi->ring_datasize;
+	cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc) :
+			read_loc - write_loc;
+
+	prev_write_sz = write_loc >= old_rd ? r_size - (write_loc - old_rd) :
+			old_rd - write_loc;
+
+
+	if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz))
+		return true;
+
+	return false;
+}
 
 /*
  * hv_get_next_write_location()
@@ -461,13 +505,14 @@ int hv_ringbuffer_peek(struct hv_ring_buffer_info *Inring_info,
  *
  */
 int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer,
-		   u32 buflen, u32 offset)
+		   u32 buflen, u32 offset, bool *signal)
 {
 	u32 bytes_avail_towrite;
 	u32 bytes_avail_toread;
 	u32 next_read_location = 0;
 	u64 prev_indices = 0;
 	unsigned long flags;
+	u32 old_read;
 
 	if (buflen <= 0)
 		return -EINVAL;
@@ -478,6 +523,8 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer,
 				&bytes_avail_toread,
 				&bytes_avail_towrite);
 
+	old_read = bytes_avail_toread;
+
 	/* Make sure there is something to read */
 	if (bytes_avail_toread < buflen) {
 		spin_unlock_irqrestore(&inring_info->ring_lock, flags);
@@ -508,5 +555,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer,
 
 	spin_unlock_irqrestore(&inring_info->ring_lock, flags);
 
+	*signal = hv_need_to_signal_on_read(old_read, inring_info);
+
 	return 0;
 }
-- 
1.7.4.1


  parent reply	other threads:[~2012-12-01 14:24 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-01 14:46 [PATCH 00/28] Drivers: hv: Update the Vmbus protocol K. Y. Srinivasan
2012-12-01 14:46 ` [PATCH 01/28] Drivers: hv: Implement routines for read side signaling optimization K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 02/28] Drivers: hv: Add state to manage batched reading K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 03/28] Drivers: hv: Turn off batched reading for util drivers K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 04/28] Drivers: hv: Optimize signaling in the read path K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 05/28] Drivers: hv: Optimize the signaling on the write path K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 06/28] Drivers: hv: Get rid of hv_get_ringbuffer_interrupt_mask() K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 07/28] Drivers: hv: Support handling multiple VMBUS versions K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 08/28] Drivers: hv: Update the ring buffer structure to match win8 functionality K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 09/28] Drivers: hv: Extend/modify vmbus_channel_offer_channel for win7 and beyond K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 10/28] Drivers: hv: Save and export negotiated vmbus version K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 11/28] Drivers: hv: Change the signature for hv_signal_event() K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 12/28] Drivers: hv: Change the signature of vmbus_set_event() K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 13/28] Drivers: hv: Move vmbus version definitions to hyperv.h K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 14/28] Drivers: hv: Manage signaling state on a per-connection basis K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 15/28] Drivers: hv: Cleanup vmbus_set_event() to support win7 and beyond K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 16/28] Drivers: hv: Setup a mapping for Hyper-V's notion cpu ID K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 17/28] Drivers: hv: Add state to manage incoming channel interrupt load K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 18/28] Drivers: hv: Modify the interrupt handling code to support win8 and beyond K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 19/28] Drivers: hv: Add code to distribute channel interrupt load K. Y. Srinivasan
2013-01-17 19:38     ` Greg KH
2013-01-17 21:28       ` KY Srinivasan
2012-12-01 14:46   ` [PATCH 20/28] Drivers: hv: Get rid of the unused global signaling state K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 21/28] Drivers: hv: Get rid of unnecessary request for offers K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 22/28] Drivers: hv: Manage event tasklets on per-cpu basis K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 23/28] Drivers: hv: Handle vmbus interrupts concurrently on all cpus K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 24/28] Drivers: hv: Add a check to deal with spurious interrupts K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 25/28] Drivers: hv: Enable protocol negotiation with win8 hosts K. Y. Srinivasan
2012-12-01 14:46   ` K. Y. Srinivasan [this message]
2012-12-01 14:46   ` [PATCH 27/28] Drivers: hv: Capture the host build information K. Y. Srinivasan
2012-12-01 14:46   ` [PATCH 28/28] Drivers: hv: Cleanup and consolidate reporting of build/version info K. Y. Srinivasan
2013-01-17 19:42 ` [PATCH 00/28] Drivers: hv: Update the Vmbus protocol Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354373219-31374-26-git-send-email-kys@microsoft.com \
    --to=kys@microsoft.com \
    --cc=apw@canonical.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.