[Devel] [PATCH RH9 09/10] drivers/vhost: allow polls to be bound to workers via vqs
Konstantin Khorenko
khorenko at virtuozzo.com
Sat Sep 3 00:54:12 MSK 2022
On 16.08.2022 09:44, Andrey Zhadchenko wrote:
> Allow vhost polls to be associated with vqs so we can queue them
> on assigned workers.
> If polls are not associated with specific vqs queue them on the first
> worker.
>
> https://jira.sw.ru/browse/PSBM-139414
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
> ---
> drivers/vhost/vhost.c | 24 ++++++++++++++++--------
> drivers/vhost/vhost.h | 4 +++-
> 2 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 5cf3d8eccfff..cb25d5a022bc 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -170,7 +170,7 @@ static int vhost_poll_wakeup(wait_queue_entry_t *wait, unsigned mode, int sync,
> if (!(key_to_poll(key) & poll->mask))
> return 0;
>
> - if (!poll->dev->use_worker)
> + if (!poll->vq->dev->use_worker)
> work->fn(work);
> else
> vhost_poll_queue(poll);
> @@ -185,19 +185,27 @@ void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn)
> }
> EXPORT_SYMBOL_GPL(vhost_work_init);
>
> -/* Init poll structure */
> void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
> __poll_t mask, struct vhost_dev *dev)
> +{
> + vhost_poll_init_vq(poll, fn, mask, dev->vqs[0]);
> +}
> +EXPORT_SYMBOL_GPL(vhost_poll_init);
> +
> +
> +/* Init poll structure */
> +void vhost_poll_init_vq(struct vhost_poll *poll, vhost_work_fn_t fn,
> + __poll_t mask, struct vhost_virtqueue *vq)
> {
> init_waitqueue_func_entry(&poll->wait, vhost_poll_wakeup);
> init_poll_funcptr(&poll->table, vhost_poll_func);
> poll->mask = mask;
> - poll->dev = dev;
> + poll->vq = vq;
> poll->wqh = NULL;
>
> vhost_work_init(&poll->work, fn);
> }
> -EXPORT_SYMBOL_GPL(vhost_poll_init);
> +EXPORT_SYMBOL_GPL(vhost_poll_init_vq);
>
> /* Start polling a file. We add ourselves to file's wait queue. The caller must
> * keep a reference to a file until after vhost_poll_stop is called. */
> @@ -289,7 +297,7 @@ EXPORT_SYMBOL_GPL(vhost_work_flush_vq);
> * locks that are also used by the callback. */
> void vhost_poll_flush(struct vhost_poll *poll)
> {
> - vhost_work_dev_flush(poll->dev);
> + vhost_work_flush_vq(poll->vq);
> }
> EXPORT_SYMBOL_GPL(vhost_poll_flush);
>
> @@ -324,7 +332,7 @@ EXPORT_SYMBOL_GPL(vhost_has_work);
>
> void vhost_poll_queue(struct vhost_poll *poll)
> {
> - vhost_work_queue(poll->dev, &poll->work);
> + vhost_work_queue_vq(poll->vq, &poll->work);
> }
> EXPORT_SYMBOL_GPL(vhost_poll_queue);
>
> @@ -573,8 +581,8 @@ void vhost_dev_init(struct vhost_dev *dev,
> mutex_init(&vq->mutex);
> vhost_vq_reset(dev, vq);
> if (vq->handle_kick)
> - vhost_poll_init(&vq->poll, vq->handle_kick,
> - EPOLLIN, dev);
> + vhost_poll_init_vq(&vq->poll, vq->handle_kick,
> + EPOLLIN, vq);
> }
> }
> EXPORT_SYMBOL_GPL(vhost_dev_init);
> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index dc7428c26cbe..4182fd7fceaf 100644
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -40,7 +40,7 @@ struct vhost_poll {
> wait_queue_entry_t wait;
> struct vhost_work work;
> __poll_t mask;
> - struct vhost_dev *dev;
> + struct vhost_virtqueue *vq;
> };
>
> void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn);
> @@ -49,6 +49,8 @@ bool vhost_has_work(struct vhost_dev *dev);
>
> void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
> __poll_t mask, struct vhost_dev *dev);
> +void vhost_poll_init_vq(struct vhost_poll *poll, vhost_work_fn_t fn,
> + __poll_t mask, struct vhost_virtqueue *vq);
> int vhost_poll_start(struct vhost_poll *poll, struct file *file);
> void vhost_poll_stop(struct vhost_poll *poll);
> void vhost_poll_flush(struct vhost_poll *poll);
LGTM
More information about the Devel
mailing list