From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3EED3A0535 for ; Tue, 4 Feb 2020 16:03:39 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 080C81C1E7; Tue, 4 Feb 2020 16:03:39 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by dpdk.org (Postfix) with ESMTP id 47F6B1C1E7 for ; Tue, 4 Feb 2020 16:03:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580828616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-to: resent-cc:resent-from:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post; bh=Z0k+Olqu72hrpWfcWB/byrTv73diRtV6VCqxdtb3ORg=; b=dWTgQv5brcQozLph4DJz3frQ8VIAXiGLbc2XvOLK22ooCSatDy3bGRS7TWlC3wJQtC8W3I 21smpFRCpgOs8cHEc1tQdHuHTw6oUakaZv2ried5msQUzMdydrNR0tH8Jt//vrCmSBwnvj hKO6B6KWeDsbt7jM/vSr+8VGhaxKMvo= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-119-fYZphAlMNYqedbpaaqylDA-1; Tue, 04 Feb 2020 10:03:34 -0500 Received: by mail-wr1-f72.google.com with SMTP id w17so5242974wrr.9 for ; Tue, 04 Feb 2020 07:03:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:message-id:in-reply-to:references :mime-version:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:errors-to:subject:resent-from :resent-to:resent-cc:date:content-transfer-encoding; bh=Z0k+Olqu72hrpWfcWB/byrTv73diRtV6VCqxdtb3ORg=; b=jY0kJ8ha2awLczEwZGtfyhynRj2c4PBb7O7R9nwJn3XYprAnxESxet6gpfX3v/Gsbp cR2mHGXD9TAZb62T7pSYGhbilIKISfY/nA2Hnb91Ozj874y1t++odrxs5w/loG+ZjRBH RqeJGxYz4jQTWkINhDNurXzNps/ORxiF00RbEV1tJKMbl7+H9VpChqlsgCzCw8HVo3Fi oxcq1ItCPISQbH3OIMzwSDA1bM3RZI9CFA5s+nzZSuXSAkfGfVzwkKfAxWOzqNFP9vJb aIV9wESJArRtFBIT7lziRzuhPZuMc/qg3Ga0s1Pr4DK5DACK7LVxyuChAKdngYVFXG9H AvOw== X-Gm-Message-State: APjAAAXZ+xvKIr/0qOajZxBdLZwVIV5hqjfCOszNMwKPycjvJOkkuZnD lkf7JQV9f+wlo5oAmYqlyCQCPyf8DaBNRE0s/zS0CZEMOQIFOV5Yg9yqVxVyXQurva5hweUsWG9 642zYlCk= X-Received: by 2002:adf:eacb:: with SMTP id o11mr23916778wrn.128.1580828611331; Tue, 04 Feb 2020 07:03:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxEY0BGaORq8WAfVF9wUvEPRu/dTpyNM7DTpChBcBz7kmlcwaWvjqqAcFIlIv4JgGDVk+2gIQ== X-Received: by 2002:adf:eacb:: with SMTP id o11mr23916764wrn.128.1580828611122; Tue, 04 Feb 2020 07:03:31 -0800 (PST) Received: from eperezma.remote.csb (static-143-30-231-77.ipcom.comunitel.net. [77.231.30.143]) by smtp.gmail.com with ESMTPSA id s8sm4119800wmh.26.2020.02.04.07.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:03:30 -0800 (PST) Received: by 2002:a0c:da05:0:0:0:0:0 with SMTP id x5csp876943qvj; Wed, 29 Jan 2020 11:33:35 -0800 (PST) X-Received: by 2002:aa7:c2da:: with SMTP id m26mr517797edp.244.1580326415159; Wed, 29 Jan 2020 11:33:35 -0800 (PST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [207.211.31.120]) by mx.google.com with ESMTPS id h6si1759050edt.55.2020.01.29.11.33.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jan 2020 11:33:35 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-ECUxPC5cPRuMD7DX8myarQ-1; Wed, 29 Jan 2020 14:33:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FC6D80156B for ; Wed, 29 Jan 2020 19:33:32 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9CBDB118DF4F; Wed, 29 Jan 2020 19:33:32 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97D0C10B7CB0 for ; Wed, 29 Jan 2020 19:33:32 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F273185AB99 for ; Wed, 29 Jan 2020 19:33:32 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by relay.mimecast.com with ESMTP id us-mta-40-Ks4VuSvCMUGicOw_fY377A-1; Wed, 29 Jan 2020 14:33:28 -0500 Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 28BE91C045; Wed, 29 Jan 2020 20:33:22 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 507571C035 for ; Wed, 29 Jan 2020 20:33:20 +0100 (CET) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-65qMBLsnOpWzTGMt9VG_Aw-1; Wed, 29 Jan 2020 14:33:17 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6495013E6; Wed, 29 Jan 2020 19:33:16 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-117-72.ams2.redhat.com [10.36.117.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 905E05C541; Wed, 29 Jan 2020 19:33:12 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: dev@dpdk.org, yong.liu@intel.com Cc: Maxime Coquelin , Adrian Moreno Zapata , Jason Wang , "Michael S. Tsirkin" Message-Id: <20200129193310.9157-1-eperezma@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 65qMBLsnOpWzTGMt9VG_Aw-1 X-MC-Unique: Ks4VuSvCMUGicOw_fY377A-1 X-MC-Unique: ECUxPC5cPRuMD7DX8myarQ-1 X-MC-Unique: fYZphAlMNYqedbpaaqylDA-1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Resent-From: eperezma@redhat.com Resent-To: Kevin Traynor Resent-Cc: stable@dpdk.org Date: Tue, 04 Feb 2020 16:03:29 +0100 X-Mailer: Evolution 3.28.5 (3.28.5-6.el8) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [PATCH] vhost: flush shadow tx if there is no more packets X-BeenThere: stable@dpdk.org List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Resent-Message-Id: <20200204150339.080C81C1E7@dpdk.org> Resent-Date: Tue, 4 Feb 2020 16:03:39 +0100 (CET) The current implementation of vhost_net in packed vring tries to fill the shadow vector before send any actual changes to the guest. While this can be beneficial for the throughput, it conflicts with some bufferfloats methods like the linux kernel napi, that stops transmitting packets if there are too much bytes/buffers in the driver. To solve it, we flush the shadow packets at the end of virtio_dev_tx_packed if we have starved the vring, i.e., the next buffer is not available for the device. Since this last check can be expensive because of the atomic, we only check it if we have not obtained the expected (count) packets. If it happens to obtain "count" packets and there is no more available packets the caller needs to keep call virtio_dev_tx_packed again. Signed-off-by: Eugenio P=C3=A9rez --- lib/librte_vhost/virtio_net.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 21c311732..ac2842b2d 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -2133,6 +2133,20 @@ virtio_dev_tx_packed_zmbuf(struct virtio_net *dev, =09return pkt_idx; } =20 +static __rte_always_inline bool +next_desc_is_avail(const struct vhost_virtqueue *vq) +{ +=09bool wrap_counter =3D vq->avail_wrap_counter; +=09uint16_t next_used_idx =3D vq->last_used_idx + 1; + +=09if (next_used_idx >=3D vq->size) { +=09=09next_used_idx -=3D vq->size; +=09=09wrap_counter ^=3D 1; +=09} + +=09return desc_is_avail(&vq->desc_packed[next_used_idx], wrap_counter); +} + static __rte_noinline uint16_t virtio_dev_tx_packed(struct virtio_net *dev, =09=09 struct vhost_virtqueue *vq, @@ -2165,9 +2179,20 @@ virtio_dev_tx_packed(struct virtio_net *dev, =20 =09} while (remained); =20 -=09if (vq->shadow_used_idx) +=09if (vq->shadow_used_idx) { =09=09do_data_copy_dequeue(vq); =20 +=09=09if (remained && !next_desc_is_avail(vq)) { +=09=09=09/* +=09=09=09 * The guest may be waiting to TX some buffers to +=09=09=09 * enqueue more to avoid bufferfloat, so we try to +=09=09=09 * reduce latency here. +=09=09=09 */ +=09=09=09vhost_flush_dequeue_shadow_packed(dev, vq); +=09=09=09vhost_vring_call_packed(dev, vq); +=09=09} +=09} + =09return pkt_idx; } =20 --=20 2.18.1