Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp37520yba; Fri, 5 Apr 2019 01:18:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNnkH7jUy6hXRa4WIV2nFy83t2Puo06P+ttYV1lhEcp9h9qUVY417pmrTaCMEEfBSYrBni X-Received: by 2002:a17:902:2989:: with SMTP id h9mr11619461plb.26.1554452339632; Fri, 05 Apr 2019 01:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554452339; cv=none; d=google.com; s=arc-20160816; b=Om+ACIJExHAQ8oS8fDjs44c7lN3RfTsCu24PmpbwyJFUzHzt+mg97M+232s6NqAhm6 oJS+q5e50sw2FUdFcbM9AJ7MtN3JJNcmLR58//v7xHXDNsraLF9WBePzy2N+cSssvAF0 MkKcREAd0iCVCz5jvpdg7286xg6uvo22AdQhh9Fj8NQr52mXcNwOcNeR+v4EDv0kTREt xy9riPX44uZLpwxL0LYJCiAVpPypRzY6vRMcELxdL/HiMdxNbPTxalkk2pYjbmFAyrr4 7vlCJWPHYVC+pygOXWc3d68iKzLMfflBGdjfMg2WwtAT/Ro4LVAD0/7mn5jpdPHICybY z33w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Uww6dZz3lxCpRpT/ma2nFyPidH/CJqrtzpNQ35KEFAI=; b=um0L2FHVNcUIr6gtOXOIbL11lfI2eVXtl0e/dJV/K+fbRz0Pi4RzxY/5UZLFW0n/dO 7PqO6Zi4Xz1w6C2Tg61/1P9zI9/sporZTiDQYJyma/6VyugQZwh4tsWcWGhLrr1/hGxQ OmRMMjrzpJ2t719ufmsNC33H+/00tApYpb/ep+h1pQD6xdIfNVrWbWhsAXE17S3eD7DM 4+Sn6INUfQQTjLVCmKgnr7X8SiZeWTwSW2DMUbaAOF5W8MBw90oTpZ92QAJ3XP2Xpala z7OLLSog3JpZnPgqpra0BAw0tQvGH81+nsTtgyDsYrAF+3oMrNlYx1HIfZDkkM0Lha02 JkOQ== 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 b21si14373703pls.231.2019.04.05.01.18.44; Fri, 05 Apr 2019 01:18:59 -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 S1730283AbfDEIQx (ORCPT + 99 others); Fri, 5 Apr 2019 04:16:53 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45586 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbfDEIQx (ORCPT ); Fri, 5 Apr 2019 04:16:53 -0400 Received: by mail-wr1-f68.google.com with SMTP id s15so6822188wra.12 for ; Fri, 05 Apr 2019 01:16:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Uww6dZz3lxCpRpT/ma2nFyPidH/CJqrtzpNQ35KEFAI=; b=CydBjWdALs4C6pp2DFYbCWTYTBBGoOr175yzVAP+ATNCZr8y/zLZaWpcamfpDsdY/q J/zXGFF+nooAHuaMSf6/8q1mc2QxOaRijHa772zrHnUs1Nw8OFkKzvcuuMjomPPFZCHl bmKZab+6m5hEmwnss6valQRfPsjfnnjiREdl+CEp9nK5tnYIRn1eqd52NYdSt+KElN9w 8CH9OfELI0nyvMj2tTlaGBnDVyCj4GVeZlns5dtnDRg9S/C47JnjzXymRY7qIaEAxj70 dLqfZYPar+HPjNss8lrx7BILmVLFoxXdy83O+eE9fLNqNpO9LB/Csef9aKC9LJ7kGuBH Z2VA== X-Gm-Message-State: APjAAAUvQVkUXfm5ygiW92t/VcMe5PVgz/Xf742QtiOQhc2vyFSLHA5S tcOUBdmQ7ZUPQ6g2aC5FvkIYJw== X-Received: by 2002:adf:ed90:: with SMTP id c16mr7805750wro.74.1554452211647; Fri, 05 Apr 2019 01:16:51 -0700 (PDT) Received: from steredhat (host35-203-static.12-87-b.business.telecomitalia.it. [87.12.203.35]) by smtp.gmail.com with ESMTPSA id j11sm27420999wrw.85.2019.04.05.01.16.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Apr 2019 01:16:51 -0700 (PDT) Date: Fri, 5 Apr 2019 10:16:48 +0200 From: Stefano Garzarella To: Stefan Hajnoczi Cc: netdev@vger.kernel.org, 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: Re: [PATCH RFC 1/4] vsock/virtio: reduce credit update messages Message-ID: <20190405081648.2zflr7gxknk4q3a2@steredhat> References: <20190404105838.101559-1-sgarzare@redhat.com> <20190404105838.101559-2-sgarzare@redhat.com> <20190404191539.GB25152@stefanha-x1.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190404191539.GB25152@stefanha-x1.localdomain> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 04, 2019 at 08:15:39PM +0100, Stefan Hajnoczi wrote: > On Thu, Apr 04, 2019 at 12:58:35PM +0200, Stefano Garzarella wrote: > > @@ -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; > > Why s64? buf_alloc, fwd_cnt, and last_fwd_cnt are all u32. fwd_cnt - > last_fwd_cnt <= buf_alloc is always true. > Right, I'll use a u32 for free_space! Is is a leftover because initially I implemented something like virtio_transport_has_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); > > Locking? These fields should be accessed under tx_lock. > Yes, we need a lock, but looking in the code, vvs->fwd_cnd is written taking rx_lock (virtio_transport_dec_rx_pkt) and it is read with the tx_lock (virtio_transport_inc_tx_pkt). Maybe we should use another spin_lock shared between RX and TX for those fields or use atomic variables. What do you suggest? Thanks, Stefano