From patchwork Fri Mar 23 00:15:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 10302537 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2D786600CC for ; Fri, 23 Mar 2018 00:17:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F52C28AB1 for ; Fri, 23 Mar 2018 00:17:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 146AF28AB4; Fri, 23 Mar 2018 00:17:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B720028AB1 for ; Fri, 23 Mar 2018 00:17:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751908AbeCWARG (ORCPT ); Thu, 22 Mar 2018 20:17:06 -0400 Received: from a2nlsmtp01-02.prod.iad2.secureserver.net ([198.71.225.36]:41126 "EHLO a2nlsmtp01-02.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751889AbeCWARE (ORCPT ); Thu, 22 Mar 2018 20:17:04 -0400 Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id zANHeFbOaC9PZzANHe5QIG; Thu, 22 Mar 2018 17:16:03 -0700 x-originating-ip: 107.180.71.197 Received: from longli by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.89_1) (envelope-from ) id 1ezANH-0008Jk-9E; Thu, 22 Mar 2018 17:16:03 -0700 From: Long Li To: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , "James E . J . Bottomley" , "Martin K . Petersen" , devel@linuxdriverproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Long Li Subject: [PATCH 2/3] Netvsc: Use the vmbus functiton to calculate ring buffer percentage Date: Thu, 22 Mar 2018 17:15:37 -0700 Message-Id: <20180323001538.31876-2-longli@linuxonhyperv.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180323001538.31876-1-longli@linuxonhyperv.com> References: <20180323001538.31876-1-longli@linuxonhyperv.com> X-CMAE-Envelope: MS4wfG305MfkxXzo5w34EqwXBhc5ABXK0d4Qw+b8b7GuQvNYHgndcF8MGVfuG4+Pths+RNYl5FZkSAPgMzKRieAnQ+RZ9SbhEENBxV0l545MZgTKXmd29HF0 HXwVshJHAeYetLyQ2kpXxpLhQTxLQ1Qc5/4pxac1uN+yNVOQiwkveUn9K+kadSLSz/j9zM/qOD1NA/muxTca/somJFyeR2fMxENphtcYDxIlz0RkOomuYLvY b1hDeCBzdeZo22XUd6dDZp/PG3xdL49FGfz4OINdFuEKsVE2/sQXfNelcTBcd8e8FQB/1bDhSBlTiuO+qBXsBT9Y1j/tJYf+2r4n19ypXzYLdbg8gGS789yz AV/H4yEbbdHjMZTo8JtEUni1PJN6lpjDnIm807z7zsDnJFI6uX8sdgVtuo+fpRNDweU+U4WZGdVxi/JAq96eDRrFokh0uAC6L4gHyG4SMBrnnUjzmDKOWNmV keXxkAI6iYcCHWUtdV1WPGwaOpu7oejl9abhVZqm/OMd4YASgovGuX2eN2g= Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Long Li In Vmbus, we have defined a function to calculate available ring buffer percentage to write. Use that function and remove duplicate netvsc code. Signed-off-by: Long Li Reviewed-by: Haiyang Zhang --- drivers/net/hyperv/netvsc.c | 17 +++-------------- drivers/net/hyperv/netvsc_drv.c | 3 --- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 0265d703eb03..8af0069e4d8c 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -31,7 +31,6 @@ #include #include #include -#include #include @@ -590,17 +589,6 @@ void netvsc_device_remove(struct hv_device *device) #define RING_AVAIL_PERCENT_HIWATER 20 #define RING_AVAIL_PERCENT_LOWATER 10 -/* - * Get the percentage of available bytes to write in the ring. - * The return value is in range from 0 to 100. - */ -static u32 hv_ringbuf_avail_percent(const struct hv_ring_buffer_info *ring_info) -{ - u32 avail_write = hv_get_bytes_to_write(ring_info); - - return reciprocal_divide(avail_write * 100, netvsc_ring_reciprocal); -} - static inline void netvsc_free_send_slot(struct netvsc_device *net_device, u32 index) { @@ -649,7 +637,8 @@ static void netvsc_send_tx_complete(struct netvsc_device *net_device, wake_up(&net_device->wait_drain); if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx)) && - (hv_ringbuf_avail_percent(&channel->outbound) > RING_AVAIL_PERCENT_HIWATER || + (hv_get_avail_to_write_percent(&channel->outbound) > + RING_AVAIL_PERCENT_HIWATER || queue_sends < 1)) { netif_tx_wake_queue(netdev_get_tx_queue(ndev, q_idx)); ndev_ctx->eth_stats.wake_queue++; @@ -757,7 +746,7 @@ static inline int netvsc_send_pkt( struct netdev_queue *txq = netdev_get_tx_queue(ndev, packet->q_idx); u64 req_id; int ret; - u32 ring_avail = hv_ringbuf_avail_percent(&out_channel->outbound); + u32 ring_avail = hv_get_avail_to_write_percent(&out_channel->outbound); nvmsg.hdr.msg_type = NVSP_MSG1_TYPE_SEND_RNDIS_PKT; if (skb) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index faea0be18924..b0b1c2fd2b7b 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -55,7 +54,6 @@ static unsigned int ring_size __ro_after_init = 128; module_param(ring_size, uint, S_IRUGO); MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); unsigned int netvsc_ring_bytes __ro_after_init; -struct reciprocal_value netvsc_ring_reciprocal __ro_after_init; static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | NETIF_MSG_IFUP | @@ -2186,7 +2184,6 @@ static int __init netvsc_drv_init(void) ring_size); } netvsc_ring_bytes = ring_size * PAGE_SIZE; - netvsc_ring_reciprocal = reciprocal_value(netvsc_ring_bytes); ret = vmbus_driver_register(&netvsc_drv); if (ret)