[PATCH] vhost: Make use of the helper macro kthread_run()

Yin Xiujiang posted 1 patch 4 years, 5 months ago
drivers/vhost/vhost.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] vhost: Make use of the helper macro kthread_run()
Posted by Yin Xiujiang 4 years, 5 months ago
Repalce kthread_create/wake_up_process() with kthread_run()
to simplify the code.

Signed-off-by: Yin Xiujiang <yinxiujiang@kylinos.cn>
---
 drivers/vhost/vhost.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 59edb5a1ffe2..19e9eda9fc71 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -595,7 +595,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
 
 	dev->kcov_handle = kcov_common_handle();
 	if (dev->use_worker) {
-		worker = kthread_create(vhost_worker, dev,
+		worker = kthread_run(vhost_worker, dev,
 					"vhost-%d", current->pid);
 		if (IS_ERR(worker)) {
 			err = PTR_ERR(worker);
@@ -603,7 +603,6 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
 		}
 
 		dev->worker = worker;
-		wake_up_process(worker); /* avoid contributing to loadavg */
 
 		err = vhost_attach_cgroups(dev);
 		if (err)
-- 
2.30.0

Re: [PATCH] vhost: Make use of the helper macro kthread_run()
Posted by Jason Wang 4 years, 5 months ago
On Thu, Jan 27, 2022 at 10:08 AM Yin Xiujiang <yinxiujiang@kylinos.cn> wrote:
>
> Repalce kthread_create/wake_up_process() with kthread_run()
> to simplify the code.
>
> Signed-off-by: Yin Xiujiang <yinxiujiang@kylinos.cn>
> ---
>  drivers/vhost/vhost.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 59edb5a1ffe2..19e9eda9fc71 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -595,7 +595,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
>
>         dev->kcov_handle = kcov_common_handle();
>         if (dev->use_worker) {
> -               worker = kthread_create(vhost_worker, dev,
> +               worker = kthread_run(vhost_worker, dev,
>                                         "vhost-%d", current->pid);

Mike plans to introduce user_worker_create() to allow rlimit check[1].
So this is probably not needed.

Thanks

[1] https://www.spinics.net/lists/kernel/msg4161030.html (I'm not sure
this is the recent version, please check the list)


>                 if (IS_ERR(worker)) {
>                         err = PTR_ERR(worker);
> @@ -603,7 +603,6 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
>                 }
>
>                 dev->worker = worker;
> -               wake_up_process(worker); /* avoid contributing to loadavg */
>
>                 err = vhost_attach_cgroups(dev);
>                 if (err)
> --
> 2.30.0
>

Re: [PATCH] vhost: Make use of the helper macro kthread_run()
Posted by Michael S. Tsirkin 4 years, 5 months ago
On Thu, Jan 27, 2022 at 10:08:07AM +0800, Yin Xiujiang wrote:
> Repalce kthread_create/wake_up_process() with kthread_run()
> to simplify the code.
> 
> Signed-off-by: Yin Xiujiang <yinxiujiang@kylinos.cn>
> ---
>  drivers/vhost/vhost.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 59edb5a1ffe2..19e9eda9fc71 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -595,7 +595,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
>  
>  	dev->kcov_handle = kcov_common_handle();
>  	if (dev->use_worker) {
> -		worker = kthread_create(vhost_worker, dev,
> +		worker = kthread_run(vhost_worker, dev,
>  					"vhost-%d", current->pid);
>  		if (IS_ERR(worker)) {
>  			err = PTR_ERR(worker);
> @@ -603,7 +603,6 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
>  		}
>  
>  		dev->worker = worker;
> -		wake_up_process(worker); /* avoid contributing to loadavg */
>  
>  		err = vhost_attach_cgroups(dev);
>  		if (err)

I think if you do this, you need to set dev->worker earlier.

> -- 
> 2.30.0