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 9A150A0501; Thu, 5 May 2022 21:21:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7EA974014F; Thu, 5 May 2022 21:21:26 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.129.74]) by mails.dpdk.org (Postfix) with ESMTP id 51DFF40042 for ; Thu, 5 May 2022 21:21:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651778484; 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=fHWKJM48RSWlvB3+o8HrlN9lPzanSY+N6kBKzQ+jnn8=; b=HWpwKa2Kr0ZSlQpxoLVVdij9HuJeNFXy6sMrhq7AF3F9A7cEdBESz1Ywn2Mtas+C00MwPl p6Xk8UkuJlG3Yuy1Fbc3aukhORJ0FLL/xv1ckU0IsQURNjyJYupCbIEF6YPeQwkxhEK2u2 8kiiVbcP6bwm5xYNzrps/7qtLD8foLk= 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-199-v6d-cyDaMtSTYa1c72K4nA-1; Thu, 05 May 2022 15:21:23 -0400 X-MC-Unique: v6d-cyDaMtSTYa1c72K4nA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0DBE6833942; Thu, 5 May 2022 19:21:23 +0000 (UTC) Received: from [10.39.208.18] (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E14E3401DBE; Thu, 5 May 2022 19:21:21 +0000 (UTC) Message-ID: Date: Thu, 5 May 2022 21:21:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v1 1/2] vhost: add unsafe API to check inflight packets To: xuan.ding@intel.com, chenbo.xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, cheng1.jiang@intel.com, sunil.pai.g@intel.com References: <20220408102214.11994-1-xuan.ding@intel.com> <20220408102214.11994-2-xuan.ding@intel.com> From: Maxime Coquelin In-Reply-To: <20220408102214.11994-2-xuan.ding@intel.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 4/8/22 12:22, xuan.ding@intel.com wrote: > From: Xuan Ding > > In async data path, when vring state changes or device is destroyed, > it is necessary to know the number of inflight packets in DMA engine. > This patch provides a thread unsafe API to return the number of > inflight packets for a vhost queue without using any lock. > > Signed-off-by: Xuan Ding > --- > doc/guides/prog_guide/vhost_lib.rst | 6 ++++++ > doc/guides/rel_notes/release_22_07.rst | 4 ++++ > lib/vhost/rte_vhost_async.h | 17 +++++++++++++++++ > lib/vhost/version.map | 4 ++++ > lib/vhost/vhost.c | 26 ++++++++++++++++++++++++++ > 5 files changed, 57 insertions(+) > > diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst > index 886f8f5e72..f287b76ebf 100644 > --- a/doc/guides/prog_guide/vhost_lib.rst > +++ b/doc/guides/prog_guide/vhost_lib.rst > @@ -271,6 +271,12 @@ The following is an overview of some key Vhost API functions: > This function returns the amount of in-flight packets for the vhost > queue using async acceleration. > > + * ``rte_vhost_async_get_inflight_thread_unsafe(vid, queue_id)`` > + > + Get the number of inflight packets for a vhost queue without performing > + any locking. It should only be used within the vhost ops, which already > + holds the lock. > + > * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count, dma_id, vchan_id)`` > > Clear inflight packets which are submitted to DMA engine in vhost async data > diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst > index 42a5f2d990..a0c5d9459b 100644 > --- a/doc/guides/rel_notes/release_22_07.rst > +++ b/doc/guides/rel_notes/release_22_07.rst > @@ -55,6 +55,10 @@ New Features > Also, make sure to start the actual text at the margin. > ======================================================= > > +* **Added vhost API to get the number of inflight packets.** > + > + Added an API which can get the number of inflight packets in > + vhost async data path without using lock. > > Removed Items > ------------- > diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h > index f1293c6a9d..70234debf9 100644 > --- a/lib/vhost/rte_vhost_async.h > +++ b/lib/vhost/rte_vhost_async.h > @@ -139,6 +139,23 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id, > __rte_experimental > int rte_vhost_async_get_inflight(int vid, uint16_t queue_id); > > +/** > + * This function is lock-free version to return the amount of in-flight > + * packets for the vhost queue which uses async channel acceleration. > + * > + * @note This function does not perform any locking, it should only be > + * used within the vhost ops, which already holds the lock. > + * > + * @param vid > + * id of vhost device to enqueue data > + * @param queue_id > + * queue id to enqueue data > + * @return > + * the amount of in-flight packets on success; -1 on failure > + */ > +__rte_experimental > +int rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id); > + > /** > * This function checks async completion status and clear packets for > * a specific vhost device queue. Packets which are inflight will be > diff --git a/lib/vhost/version.map b/lib/vhost/version.map > index 0a66c5840c..5841315386 100644 > --- a/lib/vhost/version.map > +++ b/lib/vhost/version.map > @@ -87,6 +87,10 @@ EXPERIMENTAL { > > # added in 22.03 > rte_vhost_async_dma_configure; > + > + # added in 22.07 > + rte_vhost_async_get_inflight_thread_unsafe; > + > }; > > INTERNAL { > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c > index 2f96a28dac..df0bb9d043 100644 > --- a/lib/vhost/vhost.c > +++ b/lib/vhost/vhost.c > @@ -1907,6 +1907,32 @@ rte_vhost_async_get_inflight(int vid, uint16_t queue_id) > return ret; > } > > +int > +rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id) > +{ > + struct vhost_virtqueue *vq; > + struct virtio_net *dev = get_device(vid); > + int ret = -1; > + > + if (dev == NULL) > + return ret; > + > + if (queue_id >= VHOST_MAX_VRING) > + return ret; > + > + vq = dev->virtqueue[queue_id]; > + > + if (vq == NULL) > + return ret; FYI, I'm going to post a patch that adds a call to rte_spinlock_is_locked() to catch possible misuses of the API. > + if (!vq->async) > + return ret; > + > + ret = vq->async->pkts_inflight_n; > + > + return ret; > +} > + > int > rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, > struct rte_vhost_power_monitor_cond *pmc) > Reviewed-by: Maxime Coquelin Thanks, Maxime