Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3386685pxb; Fri, 4 Feb 2022 07:32:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJx56w8MnvZxvR12GfaHMrBzy1ELvGcEMbgAav8oo6ErAZczozD7jzZSrVwbtAeiqH4fD5kx X-Received: by 2002:a17:907:6d17:: with SMTP id sa23mr2999654ejc.164.1643988760536; Fri, 04 Feb 2022 07:32:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643988760; cv=none; d=google.com; s=arc-20160816; b=QOmIQjMArS/N1LPix2VcEEf5YncTHAizvFSMd4+d4n0K2LnQ6k/m99zI/kQeUGTWG+ uhobqaw2vfy/loAd7IKr9bIAVirdw6D6+CVGdlTvWnEq3N0g727wY171EBuyqgejtf+L DjfqWdkCG1s3ZXnPhoM/Z/F7e6d2X+xqsRCtCaJDuH3OvYIHCGrEpvM+KlscoQDGZ7tg aQq6vk9hBOn9mPQVL7EiWFJ9J1vzf1dN4Vf2I4vrJfCeAXa///w97BRxg9BynD0DvtPY C6lhmIlXFhZYUvWgZU0J0QkW6+fS4dpnFn4sVIv1kQM1cenZDtyuDOCPIliIx1WWX1Xt ctIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wVSUqNEz2jDEjuO9vqQ6YiHSzS42/Um2cKAf3ocZuFc=; b=wZ7zT9jY+Qdw9cD5zL7fzs8rJGvxNVmiANi5SX+wAMVRqTRdT5ITrlHQyOCgJ6TnVz PpLwz1BBrqPw1wvpGDr0Tq8aH2AXHGh9Tlrw2jkyuy7XzSO2o0/3aQrUXmeI+r2kYmkR 0QFR+cSGx8PrmBuQNRDZkXQrW53eWigLHwNS9dWjnur8jt4qhZPqpR5HhgcVPKtUXOv8 T7pcEWFoDuCmen5SU6NRhrEH8donRi/D3BQ4WWri9HUfTkwYLHoB6zqJ+7je2lB0xhXg YqgXsZJQUXNpYSQobXHTCLGX+VOlb1CrKI0qcqHCSFMHp7gx/ukH3PC6tAfDdsZh8c0K gMtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VWLm1dW1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx11si1318710edb.302.2022.02.04.07.32.13; Fri, 04 Feb 2022 07:32:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VWLm1dW1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbiBBLYU (ORCPT + 99 others); Wed, 2 Feb 2022 06:24:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54642 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbiBBLYP (ORCPT ); Wed, 2 Feb 2022 06:24:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643801055; 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: in-reply-to:in-reply-to:references:references; bh=wVSUqNEz2jDEjuO9vqQ6YiHSzS42/Um2cKAf3ocZuFc=; b=VWLm1dW1NJnudlJF4BfhrEDicWl15XvT7pdAjGfhlN3kwnad5TeLpRtPchhCA3f33PjtpQ 5u7IzEpDYw5lW2QvVcFtktJMzKaGDD9c1HcGfggHymVp5Wyw3wreOj9LIxHpuzGsgjmzKd EdoYqkxpY2T21gKxNKaldxzG7h5WPkI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-3-gxzGsacoPwSYHi46bF-VGw-1; Wed, 02 Feb 2022 06:24:12 -0500 X-MC-Unique: gxzGsacoPwSYHi46bF-VGw-1 Received: by mail-wr1-f71.google.com with SMTP id s25-20020adfa299000000b001d8d032255fso6705671wra.14 for ; Wed, 02 Feb 2022 03:24:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wVSUqNEz2jDEjuO9vqQ6YiHSzS42/Um2cKAf3ocZuFc=; b=lmcHl4/aC0HVw90CikC3H8Splqqw7mJguN1grTnKdCdjYoBSPq1lolm0SZomhwkDY3 O9Cp3mtXST6K+uajYcV+q8gLwzO68+1fgFM54IH2aUxXNV4PAfE0/VZehWbQ+5dCQ70t f92qQXlXZjFg3MJT8vYjpOkPUvttXVcot/tu8aY5L78LSnLRyGQxDQuuiSSusfs9JBTC vcn0CQmh6RZB15R3CdqSGme1pLGKFMgyOqXJwwBUOc2hCWJqOYEq9ogDn5kLsBdshlv4 pPjuvT+iP35026xAOVdWl0NoMXwZiA8+ayYQxzooQJ2YABVlpD1tqZ4dsNfcT+wS03tp HpiA== X-Gm-Message-State: AOAM533LIbYKjhkWl2P41kXQs8AFSP7KWfyQdEXRAnKrjOXUUGiqdx7N NQ1lDdKHQewATTWtDPwKKfYW36DBOowFJZnmYben/p+SRRRMzDwBa4w7tNtJ8udiICzfZo2szIg 9lzp3yg01K0vkLbqJnpgxk+kj X-Received: by 2002:adf:eb83:: with SMTP id t3mr24004835wrn.240.1643801051273; Wed, 02 Feb 2022 03:24:11 -0800 (PST) X-Received: by 2002:adf:eb83:: with SMTP id t3mr24004815wrn.240.1643801051038; Wed, 02 Feb 2022 03:24:11 -0800 (PST) Received: from redhat.com ([2.52.5.34]) by smtp.gmail.com with ESMTPSA id g6sm5047158wmq.3.2022.02.02.03.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:24:09 -0800 (PST) Date: Wed, 2 Feb 2022 06:24:05 -0500 From: "Michael S. Tsirkin" To: Stefan Hajnoczi Cc: Stefano Garzarella , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, Jason Wang , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v3] vhost: cache avail index in vhost_enable_notify() Message-ID: <20220202062340-mutt-send-email-mst@kernel.org> References: <20220128094129.40809-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 02, 2022 at 11:14:30AM +0000, Stefan Hajnoczi wrote: > On Fri, Jan 28, 2022 at 10:41:29AM +0100, Stefano Garzarella wrote: > > In vhost_enable_notify() we enable the notifications and we read > > the avail index to check if new buffers have become available in > > the meantime. > > > > We do not update the cached avail index value, so when the device > > will call vhost_get_vq_desc(), it will find the old value in the > > cache and it will read the avail index again. > > > > It would be better to refresh the cache every time we read avail > > index, so let's change vhost_enable_notify() caching the value in > > `avail_idx` and compare it with `last_avail_idx` to check if there > > are new buffers available. > > > > We don't expect a significant performance boost because > > the above path is not very common, indeed vhost_enable_notify() > > is often called with unlikely(), expecting that avail index has > > not been updated. > > > > We ran virtio-test/vhost-test and noticed minimal improvement as > > expected. To stress the patch more, we modified vhost_test.ko to > > call vhost_enable_notify()/vhost_disable_notify() on every cycle > > when calling vhost_get_vq_desc(); in this case we observed a more > > evident improvement, with a reduction of the test execution time > > of about 3.7%. > > > > Signed-off-by: Stefano Garzarella > > --- > > v3 > > - reworded commit description [Stefan] > > --- > > drivers/vhost/vhost.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > index 59edb5a1ffe2..07363dff559e 100644 > > --- a/drivers/vhost/vhost.c > > +++ b/drivers/vhost/vhost.c > > @@ -2543,8 +2543,9 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq) > > &vq->avail->idx, r); > > return false; > > } > > + vq->avail_idx = vhost16_to_cpu(vq, avail_idx); > > > > - return vhost16_to_cpu(vq, avail_idx) != vq->avail_idx; > > + return vq->avail_idx != vq->last_avail_idx; > > } > > EXPORT_SYMBOL_GPL(vhost_enable_notify); > > This changes behavior (fixes a bug?): previously the function returned > false when called with avail buffers still pending (vq->last_avail_idx < > vq->avail_idx). Now it returns true because we compare against > vq->last_avail_idx and I think that's reasonable. > > Reviewed-by: Stefan Hajnoczi I don't see the behaviour change... could you explain the scanario in more detail pls? Thanks!