[Devel] [PATCH VZ9 02/11] vhost: dynamically allocate vhost_worker
Andrey Zhadchenko
andrey.zhadchenko at virtuozzo.com
Thu Jan 4 20:02:11 MSK 2024
From: Mike Christie <michael.christie at oracle.com>
This patchset allows us to allocate multiple workers, so this has us
move from the vhost_worker that's embedded in the vhost_dev to
dynamically allocating it.
Signed-off-by: Mike Christie <michael.christie at oracle.com>
Message-Id: <20230626232307.97930-3-michael.christie at oracle.com>
Signed-off-by: Michael S. Tsirkin <mst at redhat.com>
---------
Half of this commit is already present. Add the rest.
(cherry picked from ms commit c011bb669ddc)
https://virtuozzo.atlassian.net/browse/PSBM-152375
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
drivers/vhost/vhost.c | 20 ++++++++++++--------
drivers/vhost/vhost.h | 2 +-
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 3421525c8e20..2dd032fbf642 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -235,21 +235,23 @@ void vhost_dev_flush(struct vhost_dev *dev)
{
struct vhost_flush_struct flush;
- if (dev->worker) {
- init_completion(&flush.wait_event);
- vhost_work_init(&flush.work, vhost_flush_work);
+ init_completion(&flush.wait_event);
+ vhost_work_init(&flush.work, vhost_flush_work);
- vhost_work_queue(dev, &flush.work);
+ if (vhost_work_queue(dev, &flush.work))
wait_for_completion(&flush.wait_event);
- }
}
EXPORT_SYMBOL_GPL(vhost_dev_flush);
-void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
+bool vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
{
if (!dev->worker)
- return;
-
+ return false;
+ /*
+ * vsock can queue while we do a VHOST_SET_OWNER, so we have a smp_wmb
+ * when setting up the worker. We don't have a smp_rmb here because
+ * test_and_set_bit gives us a mb already.
+ */
if (!test_and_set_bit(VHOST_WORK_QUEUED, &work->flags)) {
/* We can only add the work to the list after we're
* sure it was not in the list.
@@ -258,6 +260,8 @@ void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
llist_add(&work->node, &dev->worker->work_list);
wake_up_process(dev->worker->task);
}
+
+ return true;
}
EXPORT_SYMBOL_GPL(vhost_work_queue);
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 2df99e657ec6..9ff8c0afcead 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -44,7 +44,7 @@ struct vhost_poll {
};
void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn);
-void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work);
+bool vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work);
bool vhost_has_work(struct vhost_dev *dev);
void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
--
2.39.3
More information about the Devel
mailing list