From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_NEOMUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6360C4360F for ; Fri, 5 Apr 2019 08:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7EAC121738 for ; Fri, 5 Apr 2019 08:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730237AbfDEIQx (ORCPT ); Fri, 5 Apr 2019 04:16:53 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35865 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729861AbfDEIQx (ORCPT ); Fri, 5 Apr 2019 04:16:53 -0400 Received: by mail-wr1-f68.google.com with SMTP id y13so6893521wrd.3 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=OJAPeFOg21dTG/1fzXDEw+bEnua2H5jhiwJAKdSG9YDtTbcOlRHY8yELNUaFXEJlAq 3qVO+ysiMM7+htohOG59j4srmuKkbb3wRNtwg+XFWwBXbh5DtQninuvBcN1tcE1RwknD 1mPH7dpb79Pd+5+Gptj78BKVxz5z79IE53FVQMnP3aJPeUpdG/fkHCsSSrfSxaQ44fU4 c6pLHorf8oU5G4zF9p9S42uViSu4yARy3rX69D+2P6uhc6y9DT2r6tX4cGNSEV01AZej R8HPeKYDwT6itTgxf3pqrQ/+oDGy/gNSz/jksaKcqWROxwueV4UFP6nXLK5+pwanLSBa U1cA== X-Gm-Message-State: APjAAAW3Uy3piXvQRd0iKBZ4Tcw+/KjThMWsHA935NGV9yElBsvau5EI kpPiqJyNzPkHSRkK/umMR63AhA== X-Google-Smtp-Source: APXvYqyuZBKB/PW1tVCBvjF2nKCoZ5C0nZIjguoLcgoed+Cl7o9B1C0DZOJcTj5mJ5ILobNYGBpUnA== 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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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