From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D83FA42B2A; Wed, 17 May 2023 11:09:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0FE442D2F; Wed, 17 May 2023 11:09:02 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 650854114A for ; Wed, 17 May 2023 11:09:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684314539; 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: in-reply-to:in-reply-to:references:references; bh=q4L5prnidxqi8bdQ9JYTRVD+0dnlAfo32PGFitT4KoE=; b=JSXlntnrPGhoDmqP90urLkS2PMD2q7Lq9cFpmRX/UnlQjEjdN8rtVZB/O8mWvwBqh4PryN HcyHTsAHfYASVcc+y1VYkBUS900YF8dz9UHJl85fmCkPFNwH+WC2+cCbKNxyD/Hp+M0QLi vlqDIkK57srCs2XrT6gcAQ/GgrrXr8Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-345-WPZ1DnAoN-yEPyV2cgVjig-1; Wed, 17 May 2023 05:08:58 -0400 X-MC-Unique: WPZ1DnAoN-yEPyV2cgVjig-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4459485A588; Wed, 17 May 2023 09:08:58 +0000 (UTC) Received: from ebuild.redhat.com (unknown [10.39.195.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 874A5492B00; Wed, 17 May 2023 09:08:57 +0000 (UTC) From: Eelco Chaudron To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com Cc: dev@dpdk.org Subject: [PATCH v3 2/4] vhost: make the guest_notifications statistic counter atomic Date: Wed, 17 May 2023 11:08:56 +0200 Message-Id: <168431453456.558450.8798179744539843068.stgit@ebuild.local> In-Reply-To: <168431450017.558450.16680518469610688737.stgit@ebuild.local> References: <168431450017.558450.16680518469610688737.stgit@ebuild.local> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Making the guest_notifications statistic counter atomic, allows it to be safely incremented while holding the read access_lock. Signed-off-by: Eelco Chaudron --- lib/vhost/vhost.c | 8 ++++++++ lib/vhost/vhost.h | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 74bdbfd810..8ff6434c93 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -2086,6 +2086,10 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id, rte_rwlock_write_lock(&vq->access_lock); for (i = 0; i < VHOST_NB_VQ_STATS; i++) { + /* + * No need to the read atomic counters as such, due to the + * above write access_lock preventing them to be updated. + */ stats[i].value = *(uint64_t *)(((char *)vq) + vhost_vq_stat_strings[i].offset); stats[i].id = i; @@ -2112,6 +2116,10 @@ int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id) vq = dev->virtqueue[queue_id]; rte_rwlock_write_lock(&vq->access_lock); + /* + * No need to the reset atomic counters as such, due to the + * above write access_lock preventing them to be updated. + */ memset(&vq->stats, 0, sizeof(vq->stats)); rte_rwlock_write_unlock(&vq->access_lock); diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 5c939ef06f..37609c7c8d 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -135,11 +135,12 @@ struct virtqueue_stats { uint64_t broadcast; /* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */ uint64_t size_bins[8]; - uint64_t guest_notifications; uint64_t iotlb_hits; uint64_t iotlb_misses; uint64_t inflight_submitted; uint64_t inflight_completed; + /* Counters below are atomic, and should be incremented as such. */ + uint64_t guest_notifications; }; /** @@ -907,7 +908,8 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq) unlikely(!signalled_used_valid)) { eventfd_write(vq->callfd, (eventfd_t) 1); if (dev->flags & VIRTIO_DEV_STATS_ENABLED) - vq->stats.guest_notifications++; + __atomic_fetch_add(&vq->stats.guest_notifications, + 1, __ATOMIC_RELAXED); if (dev->notify_ops->guest_notified) dev->notify_ops->guest_notified(dev->vid); } @@ -917,7 +919,8 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq) && (vq->callfd >= 0)) { eventfd_write(vq->callfd, (eventfd_t)1); if (dev->flags & VIRTIO_DEV_STATS_ENABLED) - vq->stats.guest_notifications++; + __atomic_fetch_add(&vq->stats.guest_notifications, + 1, __ATOMIC_RELAXED); if (dev->notify_ops->guest_notified) dev->notify_ops->guest_notified(dev->vid); }