DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Ding, Xuan" <xuan.ding@intel.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>,
	"Xia, Chenbo" <chenbo.xia@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, "Hu, Jiayu" <jiayu.hu@intel.com>,
	"Jiang, Cheng1" <cheng1.jiang@intel.com>,
	"Pai G, Sunil" <sunil.pai.g@intel.com>
Subject: RE: [PATCH v1 1/2] vhost: add unsafe API to check inflight packets
Date: Fri, 6 May 2022 01:45:45 +0000	[thread overview]
Message-ID: <BN9PR11MB55138638EEB7BCA3882BBAEDE7C59@BN9PR11MB5513.namprd11.prod.outlook.com> (raw)
In-Reply-To: <d575c695-fc15-bf0e-78fe-7335c1074e00@redhat.com>

Hi Maxime,

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Friday, May 6, 2022 3:21 AM
> To: Ding, Xuan <xuan.ding@intel.com>; Xia, Chenbo <chenbo.xia@intel.com>
> Cc: dev@dpdk.org; Hu, Jiayu <jiayu.hu@intel.com>; Jiang, Cheng1
> <cheng1.jiang@intel.com>; Pai G, Sunil <sunil.pai.g@intel.com>
> Subject: Re: [PATCH v1 1/2] vhost: add unsafe API to check inflight packets
> 
> 
> 
> On 4/8/22 12:22, xuan.ding@intel.com wrote:
> > From: Xuan Ding <xuan.ding@intel.com>
> >
> > 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 <xuan.ding@intel.com>
> > ---
> >   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.

Thanks for your reminder, I can help to review this patch if necessary.

Regards,
Xuan

> 
> > +	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 <maxime.coquelin@redhat.com>
> 
> Thanks,
> Maxime


  reply	other threads:[~2022-05-06  1:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08 10:22 [PATCH v1 0/2] vhost: add unsafe API to get DMA " xuan.ding
2022-04-08 10:22 ` [PATCH v1 1/2] vhost: add unsafe API to check " xuan.ding
2022-05-05 19:21   ` Maxime Coquelin
2022-05-06  1:45     ` Ding, Xuan [this message]
2022-04-08 10:22 ` [PATCH v1 2/2] examples/vhost: use " xuan.ding
2022-05-05 19:55 ` [PATCH v1 0/2] vhost: add unsafe API to get DMA " Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BN9PR11MB55138638EEB7BCA3882BBAEDE7C59@BN9PR11MB5513.namprd11.prod.outlook.com \
    --to=xuan.ding@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=cheng1.jiang@intel.com \
    --cc=dev@dpdk.org \
    --cc=jiayu.hu@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=sunil.pai.g@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).