All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb/c67x00: Replace tasklet with work
@ 2021-01-11  4:40 Davidlohr Bueso
  2021-01-11  8:37 ` Sergei Shtylyov
       [not found] ` <20210111090533.1450-1-hdanton@sina.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2021-01-11  4:40 UTC (permalink / raw)
  To: jacmet; +Cc: gregkh, linux-usb, linux-kernel, dave, Davidlohr Bueso

Tasklets have long been deprecated as being too heavy on the system
by running in irq context - and this is not a performance critical
path. If a higher priority process wants to run, it must wait for
the tasklet to finish before doing so.

c67x00_do_work() will now run in process context and have further
concurrency (tasklets being serialized among themselves), but this
is done holding the c67x00->lock, so it should be fine. Furthermore,
this patch fixes the usage of the lock in the callback as otherwise
it would need to be irq-safe.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
 drivers/usb/c67x00/c67x00-hcd.h   |  2 +-
 drivers/usb/c67x00/c67x00-sched.c | 12 +++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/c67x00/c67x00-hcd.h b/drivers/usb/c67x00/c67x00-hcd.h
index 6b6b04a3fe0f..6332a6b5dce6 100644
--- a/drivers/usb/c67x00/c67x00-hcd.h
+++ b/drivers/usb/c67x00/c67x00-hcd.h
@@ -76,7 +76,7 @@ struct c67x00_hcd {
 	u16 next_td_addr;
 	u16 next_buf_addr;
 
-	struct tasklet_struct tasklet;
+	struct work_struct work;
 
 	struct completion endpoint_disable;
 
diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c
index e65f1a0ae80b..af60f4fdd340 100644
--- a/drivers/usb/c67x00/c67x00-sched.c
+++ b/drivers/usb/c67x00/c67x00-sched.c
@@ -1123,24 +1123,26 @@ static void c67x00_do_work(struct c67x00_hcd *c67x00)
 
 /* -------------------------------------------------------------------------- */
 
-static void c67x00_sched_tasklet(struct tasklet_struct *t)
+static void c67x00_sched_work(struct work_struct *work)
 {
-	struct c67x00_hcd *c67x00 = from_tasklet(c67x00, t, tasklet);
+	struct c67x00_hcd *c67x00;
+
+	c67x00 = container_of(work, struct c67x00_hcd, work);
 	c67x00_do_work(c67x00);
 }
 
 void c67x00_sched_kick(struct c67x00_hcd *c67x00)
 {
-	tasklet_hi_schedule(&c67x00->tasklet);
+        queue_work(system_highpri_wq, &c67x00->work);
 }
 
 int c67x00_sched_start_scheduler(struct c67x00_hcd *c67x00)
 {
-	tasklet_setup(&c67x00->tasklet, c67x00_sched_tasklet);
+        INIT_WORK(&c67x00->work, c67x00_sched_work);
 	return 0;
 }
 
 void c67x00_sched_stop_scheduler(struct c67x00_hcd *c67x00)
 {
-	tasklet_kill(&c67x00->tasklet);
+        cancel_work_sync(&c67x00->work);
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb/c67x00: Replace tasklet with work
  2021-01-11  4:40 [PATCH] usb/c67x00: Replace tasklet with work Davidlohr Bueso
@ 2021-01-11  8:37 ` Sergei Shtylyov
       [not found] ` <20210111090533.1450-1-hdanton@sina.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Sergei Shtylyov @ 2021-01-11  8:37 UTC (permalink / raw)
  To: Davidlohr Bueso, jacmet; +Cc: gregkh, linux-usb, linux-kernel, Davidlohr Bueso

Hello!

On 11.01.2021 7:40, Davidlohr Bueso wrote:

> Tasklets have long been deprecated as being too heavy on the system
> by running in irq context - and this is not a performance critical
> path. If a higher priority process wants to run, it must wait for
> the tasklet to finish before doing so.
> 
> c67x00_do_work() will now run in process context and have further
> concurrency (tasklets being serialized among themselves), but this
> is done holding the c67x00->lock, so it should be fine. Furthermore,
> this patch fixes the usage of the lock in the callback as otherwise
> it would need to be irq-safe.
> 
> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
[...]
> diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c
> index e65f1a0ae80b..af60f4fdd340 100644
> --- a/drivers/usb/c67x00/c67x00-sched.c
> +++ b/drivers/usb/c67x00/c67x00-sched.c
> @@ -1123,24 +1123,26 @@ static void c67x00_do_work(struct c67x00_hcd *c67x00)
>   
>   /* -------------------------------------------------------------------------- */
>   
> -static void c67x00_sched_tasklet(struct tasklet_struct *t)
> +static void c67x00_sched_work(struct work_struct *work)
>   {
> -	struct c67x00_hcd *c67x00 = from_tasklet(c67x00, t, tasklet);
> +	struct c67x00_hcd *c67x00;
> +
> +	c67x00 = container_of(work, struct c67x00_hcd, work);
>   	c67x00_do_work(c67x00);
>   }
>   
>   void c67x00_sched_kick(struct c67x00_hcd *c67x00)
>   {
> -	tasklet_hi_schedule(&c67x00->tasklet);
> +        queue_work(system_highpri_wq, &c67x00->work);

     Use a tab to indent, please.

>   }
>   
>   int c67x00_sched_start_scheduler(struct c67x00_hcd *c67x00)
>   {
> -	tasklet_setup(&c67x00->tasklet, c67x00_sched_tasklet);
> +        INIT_WORK(&c67x00->work, c67x00_sched_work);

    Here as well.

>   	return 0;
>   }
>   
>   void c67x00_sched_stop_scheduler(struct c67x00_hcd *c67x00)
>   {
> -	tasklet_kill(&c67x00->tasklet);
> +        cancel_work_sync(&c67x00->work);

    And here.

[...]

MBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb/c67x00: Replace tasklet with work
       [not found] ` <20210111090533.1450-1-hdanton@sina.com>
@ 2021-01-11 19:22   ` Davidlohr Bueso
  0 siblings, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2021-01-11 19:22 UTC (permalink / raw)
  To: Hillf Danton; +Cc: jacmet, gregkh, linux-usb, linux-kernel, Davidlohr Bueso

On Mon, 11 Jan 2021, Hillf Danton wrote:

>On Sun, 10 Jan 2021 20:40:50 -0800 Davidlohr Bueso wrote:
>> Tasklets have long been deprecated as being too heavy on the system
>> by running in irq context - and this is not a performance critical
>> path. If a higher priority process wants to run, it must wait for
>> the tasklet to finish before doing so.
>>
>> c67x00_do_work() will now run in process context and have further
>> concurrency (tasklets being serialized among themselves), but this
>> is done holding the c67x00->lock, so it should be fine. Furthermore,
>> this patch fixes the usage of the lock in the callback as otherwise
>> it would need to be irq-safe.
>
>Can you add a couple of words about the need to be irq-safe because
>no lock is taken for scheduling either tasklet or work?

I was refering to the locking in the c67x00_do_work() tasklet callback.
Because it is currently under irq it should be disabling irq (or at least
BH) but after this patch that is no longer the case.

>>
>> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
>> ---
>>  drivers/usb/c67x00/c67x00-hcd.h   |  2 +-
>>  drivers/usb/c67x00/c67x00-sched.c | 12 +++++++-----
>>  2 files changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/usb/c67x00/c67x00-hcd.h b/drivers/usb/c67x00/c67x00-hcd.h
>> index 6b6b04a3fe0f..6332a6b5dce6 100644
>> --- a/drivers/usb/c67x00/c67x00-hcd.h
>> +++ b/drivers/usb/c67x00/c67x00-hcd.h
>> @@ -76,7 +76,7 @@ struct c67x00_hcd {
>>	u16 next_td_addr;
>>	u16 next_buf_addr;
>>
>> -	struct tasklet_struct tasklet;
>> +	struct work_struct work;
>>
>>	struct completion endpoint_disable;
>>
>> diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c
>> index e65f1a0ae80b..af60f4fdd340 100644
>> --- a/drivers/usb/c67x00/c67x00-sched.c
>> +++ b/drivers/usb/c67x00/c67x00-sched.c
>> @@ -1123,24 +1123,26 @@ static void c67x00_do_work(struct c67x00_hcd *c67x00)
>>
>>  /* -------------------------------------------------------------------------- */
>>
>> -static void c67x00_sched_tasklet(struct tasklet_struct *t)
>> +static void c67x00_sched_work(struct work_struct *work)
>>  {
>> -	struct c67x00_hcd *c67x00 = from_tasklet(c67x00, t, tasklet);
>> +	struct c67x00_hcd *c67x00;
>> +
>> +	c67x00 = container_of(work, struct c67x00_hcd, work);
>>	c67x00_do_work(c67x00);
>>  }
>>
>>  void c67x00_sched_kick(struct c67x00_hcd *c67x00)
>>  {
>> -	tasklet_hi_schedule(&c67x00->tasklet);
>> +        queue_work(system_highpri_wq, &c67x00->work);
>
>Better if one line comment is added for highpri, given this is not a
>performance critical path.

I'm not sure the value here, considering the highprio is not being
changed here. There are a few drivers who use highpri workqueue and
care about latencies but they are still not performance critical (to
the overall system that is, which is what I meant by that).

Thanks,
Davidlohr

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-11 19:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11  4:40 [PATCH] usb/c67x00: Replace tasklet with work Davidlohr Bueso
2021-01-11  8:37 ` Sergei Shtylyov
     [not found] ` <20210111090533.1450-1-hdanton@sina.com>
2021-01-11 19:22   ` Davidlohr Bueso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.