[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1458350065-32666-5-git-send-email-kys@microsoft.com>
Date: Fri, 18 Mar 2016 18:14:25 -0700
From: "K. Y. Srinivasan" <kys@...rosoft.com>
To: gregkh@...uxfoundation.org, linux-kernel@...r.kernel.org,
devel@...uxdriverproject.org, olaf@...fle.de, apw@...onical.com,
vkuznets@...hat.com, jasowang@...hat.c
Cc: "K. Y. Srinivasan" <kys@...rosoft.com>
Subject: [PATCH 5/5] Drivers: hv: vmbus: Implement copy-free read APIs
Implement copy-free read APIs.
Signed-off-by: K. Y. Srinivasan <kys@...rosoft.com>
---
drivers/hv/ring_buffer.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++
include/linux/hyperv.h | 6 +++++
2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index c2c2b2e..c80e1f3 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -444,3 +444,58 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info,
return ret;
}
+
+/*
+ * In-place read functions.
+ */
+bool get_next_pkt_raw(struct vmbus_channel *channel,
+ struct vmpacket_descriptor **desc)
+{
+ struct hv_ring_buffer_info *ring_info = &channel->inbound;
+ u32 read_loc = ring_info->ring_buffer->read_index;
+ void *ring_buffer = hv_get_ring_buffer(ring_info);
+ struct vmpacket_descriptor *cur_desc;
+ u32 packetlen;
+ u32 dsize = ring_info->ring_datasize;
+ u32 bytes_avail_toread = hv_get_bytes_to_read(ring_info);
+
+ if (bytes_avail_toread < sizeof(struct vmpacket_descriptor))
+ return false;
+
+ if ((read_loc + sizeof(*desc)) > dsize)
+ return false;
+
+ cur_desc = ring_buffer + read_loc;
+ packetlen = cur_desc->len8 << 3;
+
+ if ((read_loc + packetlen + 8) > (dsize - 1))
+ return false;
+
+ *desc = cur_desc;
+ return true;
+}
+EXPORT_SYMBOL_GPL(get_next_pkt_raw);
+
+void put_pkt_raw(struct vmbus_channel *channel,
+ struct vmpacket_descriptor *desc)
+{
+ struct hv_ring_buffer_info *ring_info = &channel->inbound;
+ u32 read_loc = ring_info->ring_buffer->read_index;
+ u32 packetlen = desc->len8 << 3;
+ u32 dsize = ring_info->ring_datasize;
+
+ if ((read_loc + packetlen + 8) > dsize)
+ BUG();
+
+ /*
+ * Make sure all reads are done before we update the read index since
+ * the writer may start writing to the read area once the read index
+ * is updated.
+ */
+ virt_mb();
+ ring_info->ring_buffer->read_index += packetlen + 8;
+
+ if (hv_need_to_signal_on_read(ring_info))
+ vmbus_set_event(channel);
+}
+EXPORT_SYMBOL_GPL(put_pkt_raw);
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index a6b053c..455f3f0 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -1035,6 +1035,12 @@ extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
u32 *buffer_actual_len,
u64 *requestid);
+bool get_next_pkt_raw(struct vmbus_channel *channel,
+ struct vmpacket_descriptor **desc);
+
+void put_pkt_raw(struct vmbus_channel *channel,
+ struct vmpacket_descriptor *desc);
+
extern void vmbus_ontimer(unsigned long data);
--
1.7.4.1
Powered by blists - more mailing lists