[Devel] [PATCH RH9 03/10] drivers/vhost: adjust vhost to flush all workers

Konstantin Khorenko khorenko at virtuozzo.com
Fri Sep 2 18:17:57 MSK 2022


On 16.08.2022 09:43, Andrey Zhadchenko wrote:
> Make vhost_work_dev_flush support several workers and flush
> them simultaneously
> 
> https://jira.sw.ru/browse/PSBM-139414
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
> ---
>   drivers/vhost/vhost.c | 16 +++++++++++-----
>   1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 968601325a37..e05cee622dd5 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -246,14 +246,20 @@ static void vhost_work_queue_at_worker(struct vhost_worker *w,
>   
>   void vhost_work_dev_flush(struct vhost_dev *dev)
>   {
> -	struct vhost_flush_struct flush;
> +	struct vhost_flush_struct flush[VHOST_MAX_WORKERS];
> +	int i, nworkers;
>   
>   	if (dev->workers[0].worker) {

May be to use if (dev->use_worker) here like in vhost_dev_cleanup() or
just drop this "if" at all?
The dev->nworkers value must be correct anyway.

> -		init_completion(&flush.wait_event);
> -		vhost_work_init(&flush.work, vhost_flush_work);
> +		nworkers = READ_ONCE(dev->nworkers);
>   
> -		vhost_work_queue(dev, &flush.work);
> -		wait_for_completion(&flush.wait_event);
> +		for (i = 0; i < nworkers; i++) {
> +			init_completion(&flush[i].wait_event);
> +			vhost_work_init(&flush[i].work, vhost_flush_work);
> +			vhost_work_queue_at_worker(&dev->workers[i], &flush[i].work);
> +		}
> +
> +		for (i = 0; i < nworkers; i++)
> +			wait_for_completion(&flush[i].wait_event);
>   	}
>   }
>   EXPORT_SYMBOL_GPL(vhost_work_dev_flush);


More information about the Devel mailing list