Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1081074yba; Thu, 4 Apr 2019 03:59:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6J3jSrl+S2T442rcH36Zogn/FY4lqrepmdgAFm8lX1tbU6ezahT97h/qURchzbJCDQHfc X-Received: by 2002:a63:ef09:: with SMTP id u9mr5209967pgh.126.1554375590106; Thu, 04 Apr 2019 03:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554375590; cv=none; d=google.com; s=arc-20160816; b=HFUJ5QcAn5E0tIqiqiZc0foyqEXrVAC21/bn5SfgddKMGdDC4ZWnJcsl96WQV9ul/g tiqC9LQ+9aPVOZnUFD0YOks8En68Ttf641LPEKJ7ADQOQy15XDeTcg3iF2NXPdTV81ze XYf6/Qz6n+tflGDScPS6zcjTWwKtnvceFtBMt4dIozsn9mSqepo3dsJioHicnd9uRnxL OzYRyeg2wVcXpDFkmp3WZ6tYHuO6nvdgbHyIZFulC/b+ThFilFQP+ouh8QkSTXGamBMw hNsfTw/5Xc9PWvLgQ9C0W2kpOfThM44zzC3JGMf0jBmqi4qVLT6ja8Mk8/SStAOYUrtd IX2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6J7vBR9+sH7Wj0+GWDImXQKdbGJP3+gfHtbwoNE/iIY=; b=zlsJ6LIC5rtj6bkl4UqPJoV9kJF4xy6Jxjv5hpUimUmux7gaReFvvnqtNXUQRBQrJ0 X0mAG47Zi7c9FDhUA2A7UhQdqVhgSfgZ6H84jXpI4/fS6EecHAaOkv1jfGNKT5jWgGoo SMbDvDZfAubN1vm/oIqin3xHawINYkfoBsLWdsjorxryN3jX8IhabH+O4+Rj6yI+KgHf g1VxE5dNYtTpR+nBeDL04E56S8Of5qc2PWiNLo6yz5WFpXeIolPYZp9/DphqU9bMTLwL Fg2ohENA7cdT7JDllmdZdgTphT51nVzW6UcI5dsNz6HILO/zkbKfoxkpwST6bPTZL8Mu e9MQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si8970156pgv.163.2019.04.04.03.59.35; Thu, 04 Apr 2019 03:59:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729711AbfDDK6w (ORCPT + 99 others); Thu, 4 Apr 2019 06:58:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51694 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726694AbfDDK6t (ORCPT ); Thu, 4 Apr 2019 06:58:49 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 480ED3164992; Thu, 4 Apr 2019 10:58:49 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-25.ams2.redhat.com [10.36.117.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45CFB1001DC9; Thu, 4 Apr 2019 10:58:47 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Jason Wang , "Michael S. Tsirkin" , Stefan Hajnoczi , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, "David S. Miller" Subject: [PATCH RFC 1/4] vsock/virtio: reduce credit update messages Date: Thu, 4 Apr 2019 12:58:35 +0200 Message-Id: <20190404105838.101559-2-sgarzare@redhat.com> In-Reply-To: <20190404105838.101559-1-sgarzare@redhat.com> References: <20190404105838.101559-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 04 Apr 2019 10:58:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to reduce the number of credit update messages, we send them only when the space available seen by the transmitter is less than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE. Signed-off-by: Stefano Garzarella --- include/linux/virtio_vsock.h | 1 + net/vmw_vsock/virtio_transport_common.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index e223e2632edd..6d7a22cc20bf 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -37,6 +37,7 @@ struct virtio_vsock_sock { u32 tx_cnt; u32 buf_alloc; u32 peer_fwd_cnt; + u32 last_fwd_cnt; u32 peer_buf_alloc; /* Protected by rx_lock */ diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 602715fc9a75..f32301d823f5 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -206,6 +206,7 @@ static void virtio_transport_dec_rx_pkt(struct virtio_vsock_sock *vvs, void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct virtio_vsock_pkt *pkt) { spin_lock_bh(&vvs->tx_lock); + vvs->last_fwd_cnt = vvs->fwd_cnt; pkt->hdr.fwd_cnt = cpu_to_le32(vvs->fwd_cnt); pkt->hdr.buf_alloc = cpu_to_le32(vvs->buf_alloc); spin_unlock_bh(&vvs->tx_lock); @@ -256,6 +257,7 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, struct virtio_vsock_sock *vvs = vsk->trans; struct virtio_vsock_pkt *pkt; size_t bytes, total = 0; + s64 free_space; int err = -EFAULT; spin_lock_bh(&vvs->rx_lock); @@ -288,9 +290,15 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, } spin_unlock_bh(&vvs->rx_lock); - /* Send a credit pkt to peer */ - virtio_transport_send_credit_update(vsk, VIRTIO_VSOCK_TYPE_STREAM, - NULL); + /* We send a credit update only when the space available seen + * by the transmitter is less than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + */ + free_space = vvs->buf_alloc - (vvs->fwd_cnt - vvs->last_fwd_cnt); + if (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE) { + virtio_transport_send_credit_update(vsk, + VIRTIO_VSOCK_TYPE_STREAM, + NULL); + } return total; -- 2.20.1