tasklets: simplify code in tasklet_action_common()
PATCH 1/1 tasklets: simplify code in tasklet_action_common()
Use tasklet_is_disabled() to simplify the code in tasklet_action_common.
--- include/linux/interrupt.h | 11 +++++++++++ kernel/softirq.c | 14 +++++++------- 2 files changed, 18 insertions(+), 7 deletions(-)
include/linux/interrupt.h +11 -0
@@ -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);
kernel/softirq.c +7 -7
@@ -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); }
Signature · 1 line
1.8.3.1
Quoted 2 lines · Mingzhe Yang
Use
tasklet_is_disabled()to simplify the code intasklet_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
include/linux/interrupt.h static inline void tasklet_enable(struct tasklet_struct *t) · line 726
Quoted 3 lines
include/linux/interrupt.h +3
-0+static inline bool tasklet_is_enabled (struct tasklet_struct *t) +{ +smp_rmb ();
why there is suddenly a new undocumented SMP barrier in the code.
include/linux/interrupt.h static inline void tasklet_enable(struct tasklet_struct *t) · line 734
Quoted 8 lines
include/linux/interrupt.h +8
-0+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
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.
kernel/softirq.c +0 -0
@@ -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
Quoted 31 lines · Thomas Gleixner
Quoted 2 lines · Mingzhe Yang
Use
tasklet_is_disabled()to simplify the code intasklet_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
Review
Quoted 3 lines
(quoted diff) +3
-0+static inline bool tasklet_is_enabled(struct tasklet_struct *t) +{ + smp_rmb();why there is suddenly a new undocumented SMP barrier in the code.
Review
Quoted 8 lines
(quoted diff) +8
-0+ 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