Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751419AbdFYTbf (ORCPT ); Sun, 25 Jun 2017 15:31:35 -0400 Received: from a2nlsmtp01-04.prod.iad2.secureserver.net ([198.71.225.38]:53214 "EHLO a2nlsmtp01-04.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751380AbdFYTbd (ORCPT ); Sun, 25 Jun 2017 15:31:33 -0400 x-originating-ip: 107.180.71.197 From: kys@exchange.microsoft.com To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com, leann.ogasawara@canonical.com, marcelo.cerri@canonical.com, sthemmin@microsoft.com Cc: Stephen Hemminger , "K. Y. Srinivasan" Subject: [PATCH 3/6] vmbus: refactor hv_signal_on_read Date: Sun, 25 Jun 2017 12:30:26 -0700 Message-Id: <1498419029-4127-3-git-send-email-kys@exchange.microsoft.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1498418991-4071-1-git-send-email-kys@exchange.microsoft.com> References: <1498418991-4071-1-git-send-email-kys@exchange.microsoft.com> Reply-To: kys@microsoft.com X-CMAE-Envelope: MS4wfHp661FbwAkK8EmbaDkxbp5CLNTsy1ExEM0+UNJHCS29lta/vIir6X+sxsm9zMxaYQXaA7wB6x7IcVovBHn4crt5qQz2EDzc6rAFkWGJt6DI0OYRxbmm 3DLuUhXRh2sxxOPFNL6jWrKg+pEdV+JvFB4GFlqCi2wpO51kHhE0nBmdYvX13MOxPsvMLIiSMqVvwiOj9f0i/UbKTooFJPtfI9SLJBfNAY+MJzSAhJKH4Ne5 14VtqJuKl7r3lQeL9HvRRTcxqdFKQHfpcyb40BCYYV8/Z3NcYveMbwS3SptgX4XigDE9hFt1viaZYBxvQ6jPm9YkE3ZAcEu2BL0sAK8vZ5K2aj899cefX00K 9ntsEANfFgbZXl2+tHYbW+Ke6meeIttX/LgIBtlpA3twuMVcmNXkPdXIZ2JB6Rqzliv3PbT2UTKEGrV/J9R+B2sgDuZYfb3sn3ZeHiPrgzaoVDvZxxByjJih iq6XTLRWPEltNjX3SD3+hUWMSDzioSlgkveErfDCl0YF3dJrIyXSQgIJFicpFFuSXD8894QG9vPIlhE5UPC/gNrbOcxGYf11wyordA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4751 Lines: 138 From: Stephen Hemminger The function hv_signal_on_read was defined in hyperv.h and only used in one place in ring_buffer code. Clearer to just move it inline there. Signed-off-by: Stephen Hemminger Signed-off-by: K. Y. Srinivasan --- drivers/hv/ring_buffer.c | 32 ++++++++++++++++++++++++++++- include/linux/hyperv.h | 49 ---------------------------------------------- 2 files changed, 30 insertions(+), 51 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index f299817..a9021f1 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "hyperv_vmbus.h" @@ -357,7 +358,7 @@ struct vmpacket_descriptor *hv_pkt_iter_first(struct vmbus_channel *channel) { struct hv_ring_buffer_info *rbi = &channel->inbound; - /* set state for later hv_signal_on_read() */ + /* set state for later hv_pkt_iter_close */ rbi->cached_read_index = rbi->ring_buffer->read_index; if (hv_pkt_iter_avail(rbi) < sizeof(struct vmpacket_descriptor)) @@ -400,6 +401,8 @@ struct vmpacket_descriptor * void hv_pkt_iter_close(struct vmbus_channel *channel) { struct hv_ring_buffer_info *rbi = &channel->inbound; + u32 cur_write_sz, cached_write_sz; + u32 pending_sz; /* * Make sure all reads are done before we update the read index since @@ -409,6 +412,31 @@ void hv_pkt_iter_close(struct vmbus_channel *channel) virt_rmb(); rbi->ring_buffer->read_index = rbi->priv_read_index; - hv_signal_on_read(channel); + /* + * Issue a full memory barrier before making the signaling decision. + * Here is the reason for having this barrier: + * If the reading of the pend_sz (in this function) + * were to be reordered and read before we commit the new read + * index (in the calling function) we could + * have a problem. If the host were to set the pending_sz after we + * have sampled pending_sz and go to sleep before we commit the + * read index, we could miss sending the interrupt. Issue a full + * memory barrier to address this. + */ + virt_mb(); + + pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz); + /* If the other end is not blocked on write don't bother. */ + if (pending_sz == 0) + return; + + cur_write_sz = hv_get_bytes_to_write(rbi); + + if (cur_write_sz < pending_sz) + return; + + cached_write_sz = hv_get_cached_bytes_to_write(rbi); + if (cached_write_sz < pending_sz) + vmbus_setevent(channel); } EXPORT_SYMBOL_GPL(hv_pkt_iter_close); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index b1549c9..0262267 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1458,55 +1458,6 @@ int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id, } /* - * 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 inline void hv_signal_on_read(struct vmbus_channel *channel) -{ - u32 cur_write_sz, cached_write_sz; - u32 pending_sz; - struct hv_ring_buffer_info *rbi = &channel->inbound; - - /* - * Issue a full memory barrier before making the signaling decision. - * Here is the reason for having this barrier: - * If the reading of the pend_sz (in this function) - * were to be reordered and read before we commit the new read - * index (in the calling function) we could - * have a problem. If the host were to set the pending_sz after we - * have sampled pending_sz and go to sleep before we commit the - * read index, we could miss sending the interrupt. Issue a full - * memory barrier to address this. - */ - virt_mb(); - - pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz); - /* If the other end is not blocked on write don't bother. */ - if (pending_sz == 0) - return; - - cur_write_sz = hv_get_bytes_to_write(rbi); - - if (cur_write_sz < pending_sz) - return; - - cached_write_sz = hv_get_cached_bytes_to_write(rbi); - if (cached_write_sz < pending_sz) - vmbus_setevent(channel); -} - -/* * Mask off host interrupt callback notifications */ static inline void hv_begin_read(struct hv_ring_buffer_info *rbi) -- 1.7.1