[Devel] [PATCH RH9 v2 08/10] drivers/vhost: add API to queue work at virtqueue worker

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Sep 8 18:32:55 MSK 2022


Add routines to queue works on virtqueue assigned workers

https://jira.sw.ru/browse/PSBM-139414
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/vhost/vhost.c | 22 ++++++++++++++++++++++
 drivers/vhost/vhost.h |  5 +++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 750f17afa47a..3c79f6abdc13 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -272,6 +272,17 @@ static void vhost_worker_flush(struct vhost_worker *w)
 	wait_for_completion(&flush.wait_event);
 }
 
+void vhost_work_flush_vq(struct vhost_virtqueue *vq)
+{
+	struct vhost_worker *w = READ_ONCE(vq->worker);
+
+	if (!w)
+		return;
+
+	vhost_worker_flush(w);
+}
+EXPORT_SYMBOL_GPL(vhost_work_flush_vq);
+
 /* Flush any work that has been scheduled. When calling this, don't hold any
  * locks that are also used by the callback. */
 void vhost_poll_flush(struct vhost_poll *poll)
@@ -291,6 +302,17 @@ void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
 }
 EXPORT_SYMBOL_GPL(vhost_work_queue);
 
+void vhost_work_queue_vq(struct vhost_virtqueue *vq, struct vhost_work *work)
+{
+	struct vhost_worker *w = READ_ONCE(vq->worker);
+
+	if (!w)
+		return;
+
+	vhost_work_queue_at_worker(w, work);
+}
+EXPORT_SYMBOL_GPL(vhost_work_queue_vq);
+
 /* A lockless hint for busy polling code to exit the loop */
 bool vhost_has_work(struct vhost_dev *dev)
 {
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 9632f6501617..dc7428c26cbe 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -142,6 +142,11 @@ struct vhost_virtqueue {
 	struct vhost_worker *worker;
 };
 
+/* Queue the work on virtqueue assigned worker */
+void vhost_work_queue_vq(struct vhost_virtqueue *vq, struct vhost_work *work);
+/* Flush virtqueue assigned worker */
+void vhost_work_flush_vq(struct vhost_virtqueue *vq);
+
 struct vhost_msg_node {
   union {
 	  struct vhost_msg msg;
-- 
2.31.1



More information about the Devel mailing list