diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst index 0d9eca1f7d..e8bb8c9b7b 100644 --- a/doc/guides/prog_guide/vhost_lib.rst +++ b/doc/guides/prog_guide/vhost_lib.rst @@ -297,6 +297,12 @@ The following is an overview of some key Vhost API functions: Clear in-flight packets which are submitted to async channel in vhost async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)`` + + Notify the guest that used descriptors have been added to the vring. This function + will return -EAGAIN when vq's access lock is held by other thread, user should try + again later. + * ``rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id, struct rte_vhost_stat_name *names, unsigned int size)`` This function returns the names of the queue statistics. It requires diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst index c62acde891..6722832f3f 100644 --- a/doc/guides/rel_notes/release_22_11.rst +++ b/doc/guides/rel_notes/release_22_11.rst @@ -188,6 +188,12 @@ New Features Added support to unconfigure DMA vChannel that is no longer used by the vhost library. +* **Added non-blocking notify API to vhost library.** + + Added ``rte_vhost_vring_call_nonblock`` API to notify the guest that + used descriptors have been added to the vring in non-blocking way. + User should check the return value of this API and try again if needed. + * **Added support for MACsec in rte_security.** Added MACsec transform for rte_security session and added new API diff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h index bb7d86a432..d22b25cd4e 100644 --- a/lib/vhost/rte_vhost.h +++ b/lib/vhost/rte_vhost.h @@ -909,6 +909,21 @@ rte_vhost_clr_inflight_desc_packed(int vid, uint16_t vring_idx, */ int rte_vhost_vring_call(int vid, uint16_t vring_idx); +/** + * Notify the guest that used descriptors have been added to the vring. This + * function acts as a memory barrier. This function will return -EAGAIN when + * vq's access lock is held by other thread, user should try again later. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @return + * 0 on success, -1 on failure, -EAGAIN for another retry + */ +__rte_experimental +int rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx); + /** * Get vhost RX queue avail count. * diff --git a/lib/vhost/version.map b/lib/vhost/version.map index 0b61870870..d64786fa71 100644 --- a/lib/vhost/version.map +++ b/lib/vhost/version.map @@ -97,6 +97,7 @@ EXPERIMENTAL { # added in 22.11 rte_vhost_async_dma_unconfigure; + rte_vhost_vring_call_nonblock; }; INTERNAL { diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 1bb01c2a2e..19c7b92c32 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1318,6 +1318,36 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) return 0; } +int +rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx) +{ + struct virtio_net *dev; + struct vhost_virtqueue *vq; + + dev = get_device(vid); + if (!dev) + return -1; + + if (vring_idx >= VHOST_MAX_VRING) + return -1; + + vq = dev->virtqueue[vring_idx]; + if (!vq) + return -1; + + if (!rte_spinlock_trylock(&vq->access_lock)) + return -EAGAIN; + + if (vq_is_packed(dev)) + vhost_vring_call_packed(dev, vq); + else + vhost_vring_call_split(dev, vq); + + rte_spinlock_unlock(&vq->access_lock); + + return 0; +} + uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id) {