All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tasklets: simplify code in tasklet_action_common()
@ 2021-04-30 12:25 Mingzhe Yang
  2021-08-10 13:12 ` Thomas Gleixner
  0 siblings, 1 reply; 3+ messages in thread
From: Mingzhe Yang @ 2021-04-30 12:25 UTC (permalink / raw)
  To: tglx, peterz; +Cc: linux-kernel, yuxin.wooo, becausehan, huan.xie, Mingzhe Yang

Use tasklet_is_disabled() to simplify the code in tasklet_action_common.

Signed-off-by: Mingzhe Yang <cainiao666999@gmail.com>
---
 include/linux/interrupt.h | 11 +++++++++++
 kernel/softirq.c          | 14 +++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 4777850..b0fba4d 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -721,6 +721,17 @@ static inline void tasklet_enable(struct tasklet_struct *t)
 	atomic_dec(&t->count);
 }
 
+static inline bool tasklet_is_enabled(struct tasklet_struct *t)
+{
+	smp_rmb();
+	return !atomic_read(&t->count);
+}
+
+static inline bool tasklet_is_disabled(struct tasklet_struct *t)
+{
+	return !tasklet_is_enabled(t);
+}
+
 extern void tasklet_kill(struct tasklet_struct *t);
 extern void tasklet_init(struct tasklet_struct *t,
 			 void (*func)(unsigned long), unsigned long data);
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 4992853..ee36b15 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -778,16 +778,16 @@ static void tasklet_action_common(struct softirq_action *a,
 		list = list->next;
 
 		if (tasklet_trylock(t)) {
-			if (!atomic_read(&t->count)) {
-				if (tasklet_clear_sched(t)) {
-					if (t->use_callback)
-						t->callback(t);
-					else
-						t->func(t->data);
-				}
+			if (tasklet_is_disabled(t) || !tasklet_clear_sched(t)) {
 				tasklet_unlock(t);
 				continue;
 			}
+
+			if (t->use_callback)
+				t->callback(t);
+			else
+				t->func(t->data);
+
 			tasklet_unlock(t);
 		}
 
-- 
1.8.3.1


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

* Re: [PATCH] tasklets: simplify code in tasklet_action_common()
  2021-04-30 12:25 [PATCH] tasklets: simplify code in tasklet_action_common() Mingzhe Yang
@ 2021-08-10 13:12 ` Thomas Gleixner
  2021-08-25 10:07   ` Mingzhe Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Gleixner @ 2021-08-10 13:12 UTC (permalink / raw)
  To: Mingzhe Yang, peterz
  Cc: linux-kernel, yuxin.wooo, becausehan, huan.xie, Mingzhe Yang

On Fri, Apr 30 2021 at 20:25, Mingzhe Yang wrote:

> Use tasklet_is_disabled() to simplify the code in
> tasklet_action_common.

This changelog is not really helpful. Use a new function does not tell
anything. Neither does it explain why there need to be two new functions
and worse
  
> +static inline bool tasklet_is_enabled(struct tasklet_struct *t)
> +{
> +	smp_rmb();

why there is suddenly a new undocumented SMP barrier in the code.

> +	return !atomic_read(&t->count);
> +}
> +
> +static inline bool tasklet_is_disabled(struct tasklet_struct *t)
> +{
> +	return !tasklet_is_enabled(t);
> +}
> +

Aside of that there is no point in exposing these functions in a global
header.

Thanks,

        tglx

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

* Re: [PATCH] tasklets: simplify code in tasklet_action_common()
  2021-08-10 13:12 ` Thomas Gleixner
@ 2021-08-25 10:07   ` Mingzhe Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Mingzhe Yang @ 2021-08-25 10:07 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: peterz, linux-kernel, yuxin.wooo, becausehan, huan.xie

Hi tglx,
Thanks for your review!

Sorry, I didn't think carefully enough about this patch.

I want to simplify code in tasklet_action_common, because it has more
than 3 levels of indentation. Let me try again without any new functions.

diff --git a/kernel/softirq.c b/kernel/softirq.c
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -777,16 +777,16 @@ static void tasklet_action_common(struct
softirq_action *a,
                list = list->next;

                if (tasklet_trylock(t)) {
-                       if (!atomic_read(&t->count)) {
-                               if (tasklet_clear_sched(t)) {
-                                       if (t->use_callback)
-                                               t->callback(t);
-                                       else
-                                               t->func(t->data);
-                               }
+                       if (atomic_read(&t->count) || !tasklet_clear_sched(t)) {
                                tasklet_unlock(t);
                                continue;
                        }
+
+                       if (t->use_callback)
+                               t->callback(t);
+                       else
+                               t->func(t->data);
+
                        tasklet_unlock(t);
                }

--
Thanks,

        Mingzhe Yang

On Tue, Aug 10, 2021 at 9:12 PM Thomas Gleixner <tglx@linutronix.de> wrote:
>
> On Fri, Apr 30 2021 at 20:25, Mingzhe Yang wrote:
>
> > Use tasklet_is_disabled() to simplify the code in
> > tasklet_action_common.
>
> This changelog is not really helpful. Use a new function does not tell
> anything. Neither does it explain why there need to be two new functions
> and worse
>
> > +static inline bool tasklet_is_enabled(struct tasklet_struct *t)
> > +{
> > +     smp_rmb();
>
> why there is suddenly a new undocumented SMP barrier in the code.
>
> > +     return !atomic_read(&t->count);
> > +}
> > +
> > +static inline bool tasklet_is_disabled(struct tasklet_struct *t)
> > +{
> > +     return !tasklet_is_enabled(t);
> > +}
> > +
>
> Aside of that there is no point in exposing these functions in a global
> header.
>
> Thanks,
>
>         tglx

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

end of thread, other threads:[~2021-08-25 10:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 12:25 [PATCH] tasklets: simplify code in tasklet_action_common() Mingzhe Yang
2021-08-10 13:12 ` Thomas Gleixner
2021-08-25 10:07   ` Mingzhe Yang

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.