Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1291746
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | "K. Y. Srinivasan" <kys@microsoft.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH 7/9] Drivers: hv: ring_buffer: remove code duplication from hv_ringbuffer_peek/read() |
| Date | Tue, 15 Dec 2015 02:30:02 +0100 |
| Message-ID | <qFMBc-5DF-7@gated-at.bofh.it> (permalink) |
| References | <qFMBb-5DF-3@gated-at.bofh.it> <qFMBb-5DF-5@gated-at.bofh.it> |
| X-Original-To | gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com |
| X-Originating-IP | 72.167.245.219 |
| X-Mailer | git-send-email 1.7.4.1 |
| X-Cmae-Envelope | MS4wfHD1WsYHz0RldvKsruij8tVGrdfeoEZIAbvS5WzG150uETplZjYTQNjZZGy14ofB7VKbiFkeEmL6u+TnWipngnWF3Vc+N4Uk88dqBSLQMlKarBMWNhb+ A0EPFg74NXnC9vtQUxouabNYTv4nTSzX99/2a5nRYiqfg9fuY976kldLPzMoyFhlCk1CRZrI1OyOMq9dO0eOngB0Bzc4snnYqpUB/zbkTjpqZ6e/3vDGEBWo CR/Ccyw6sbGQgIGAkSMvuhNnLLJao7COKAwrDKY6YRjgQsypjjAPPw9vcks4QtUU3rl1kvz7QeFoLMU+1EkrNKuicW0AVvvRqCkjrfG8qeGYmdnCC5F4ikGN V10GCXQaZDI0ycs05CNXUgPe1Fy0dlyslxT2tKO4FpsBjhSou9Lk/h3wRjtlLJscl69cLkk+ |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 115 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | "K. Y. Srinivasan" <kys@microsoft.com> |
| X-Original-Date | Mon, 14 Dec 2015 19:01:59 -0800 |
| X-Original-Message-ID | <1450148521-28447-7-git-send-email-kys@microsoft.com> |
| X-Original-References | <1450148455-28399-1-git-send-email-kys@microsoft.com> <1450148521-28447-1-git-send-email-kys@microsoft.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1291746 |
Show key headers only | View raw
From: Vitaly Kuznetsov <vkuznets@redhat.com>
hv_ringbuffer_peek() does the same as hv_ringbuffer_read() without
advancing the read index. The only functional change this patch brings
is moving hv_need_to_signal_on_read() call under the ring_lock but this
function is just a couple of comparisons.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
drivers/hv/ring_buffer.c | 68 +++++++++++++++++-----------------------------
1 files changed, 25 insertions(+), 43 deletions(-)
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 7bca513..07f9408 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -380,47 +380,9 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info,
return 0;
}
-
-/* Read without advancing the read index. */
-int hv_ringbuffer_peek(struct hv_ring_buffer_info *Inring_info,
- void *Buffer, u32 buflen)
-{
- u32 bytes_avail_towrite;
- u32 bytes_avail_toread;
- u32 next_read_location = 0;
- unsigned long flags;
-
- spin_lock_irqsave(&Inring_info->ring_lock, flags);
-
- hv_get_ringbuffer_availbytes(Inring_info,
- &bytes_avail_toread,
- &bytes_avail_towrite);
-
- /* Make sure there is something to read */
- if (bytes_avail_toread < buflen) {
-
- spin_unlock_irqrestore(&Inring_info->ring_lock, flags);
-
- return -EAGAIN;
- }
-
- /* Convert to byte offset */
- next_read_location = hv_get_next_read_location(Inring_info);
-
- next_read_location = hv_copyfrom_ringbuffer(Inring_info,
- Buffer,
- buflen,
- next_read_location);
-
- spin_unlock_irqrestore(&Inring_info->ring_lock, flags);
-
- return 0;
-}
-
-
-/* Read and advance the read index. */
-int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer,
- u32 buflen, u32 offset, bool *signal)
+static inline int __hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info,
+ void *buffer, u32 buflen, u32 offset,
+ bool *signal, bool advance)
{
u32 bytes_avail_towrite;
u32 bytes_avail_toread;
@@ -452,6 +414,9 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer,
buflen,
next_read_location);
+ if (!advance)
+ goto out_unlock;
+
next_read_location = hv_copyfrom_ringbuffer(inring_info,
&prev_indices,
sizeof(u64),
@@ -467,9 +432,26 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer,
/* Update the read index */
hv_set_next_read_location(inring_info, next_read_location);
- spin_unlock_irqrestore(&inring_info->ring_lock, flags);
-
*signal = hv_need_to_signal_on_read(bytes_avail_towrite, inring_info);
+out_unlock:
+ spin_unlock_irqrestore(&inring_info->ring_lock, flags);
return 0;
}
+
+/* Read from ring buffer without advancing the read index. */
+int hv_ringbuffer_peek(struct hv_ring_buffer_info *inring_info,
+ void *buffer, u32 buflen)
+{
+ return __hv_ringbuffer_read(inring_info, buffer, buflen,
+ 0, NULL, false);
+}
+
+/* Read from ring buffer and advance the read index. */
+int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info,
+ void *buffer, u32 buflen, u32 offset,
+ bool *signal)
+{
+ return __hv_ringbuffer_read(inring_info, buffer, buflen,
+ offset, signal, true);
+}
--
1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH 7/9] Drivers: hv: ring_buffer: remove code duplication from hv_ringbuffer_peek/read() "K. Y. Srinivasan" <kys@microsoft.com> - 2015-12-15 02:30 +0100
csiph-web