preempt: add in_serving_irq() and apply to rcutiny and vsprintf
Subsystems (4)
PATCH 1/1 preempt: add in_serving_irq() and apply to rcutiny and vsprintf
At some places we need to determine whether we're in nmi, hardirq or softirq context. This adds a macro in_serving_irq() as a shortcut for that.
Meanwhile, apply this new macro to existing code in rcutiny and vsprintf.
--- include/linux/preempt.h | 4 +++- include/linux/rcutiny.h | 3 +-- lib/vsprintf.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)
include/linux/preempt.h +3 -1
@@ -92,12 +92,14 @@* in_nmi() - We're in NMI context * in_hardirq() - We're in hard IRQ context * in_serving_softirq() - We're in softirq context +* in_serving_irq() - We're in nmi, hardirq or softirq context * in_task() - We're in task context */ #define in_nmi () (nmi_count())#define in_hardirq () (hardirq_count())#define in_serving_softirq () (softirq_count() & SOFTIRQ_OFFSET) -#define in_task () (!(in_nmi() | in_hardirq() | in_serving_softirq())) +#define in_serving_irq () (in_nmi() | in_hardirq() | in_serving_softirq()) +#define in_task () (!in_serving_irq())/* * The following macros are deprecated and should not be used in new code:
include/linux/rcutiny.h +1 -2
@@ -87,8 +87,7 @@ static inline void rcu_irq_exit_irqson(void) { }static inline void rcu_irq_enter_irqson (void ) { }static inline void rcu_irq_exit (void ) { }static inline void rcu_irq_exit_check_preempt (void ) { } -#define rcu_is_idle_cpu (cpu) \ - (is_idle_task(current) && !in_nmi() && !in_hardirq() && !in_serving_softirq()) +#define rcu_is_idle_cpu (cpu) (is_idle_task(current) && !in_serving_irq())static inline void exit_rcu (void ) { }static inline bool rcu_preempt_need_deferred_qs (struct task_struct *t) {
lib/vsprintf.c +1 -1
@@ -865,7 +865,7 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,* kptr_restrict==1 cannot be used in IRQ context * because its test for CAP_SYSLOG would be meaningless. */ -if (in_hardirq () ||in_serving_softirq () ||in_nmi ()) { +if (in_serving_irq ()) {if (spec.field_width ==-1 ) spec.field_width =2 *sizeof (ptr);return error_string (buf, end,"pK-error" , spec);
Signature · 1 line
2.30.2
Quoted 21 lines · Changbin Du
At some places we need to determine whether we're in nmi, hardirq or softirq context. This adds a macro
in_serving_irq()as a shortcut for that.Meanwhile, apply this new macro to existing code in rcutiny and vsprintf.
Signed-off-by Changbin Du <[email protected]>--- include/linux/preempt.h | 4 +++- include/linux/rcutiny.h | 3 +-- lib/vsprintf.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)include/linux/preempt.h +0
-0@@ -92,12 +92,14 @@* in_nmi() - We're in NMI context * in_hardirq() - We're in hard IRQ context * in_serving_softirq() - We're in softirq context
include/linux/preempt.h line 103
Quoted 10 lines
include/linux/preempt.h +3
-1+* in_serving_irq() - We're in nmi, hardirq or softirq context * in_task() - We're in task context */ #define in_nmi () (nmi_count())#define in_hardirq () (hardirq_count())#define in_serving_softirq () (softirq_count() & SOFTIRQ_OFFSET) -#define in_task () (!(in_nmi() | in_hardirq() | in_serving_softirq())) +#define in_serving_irq () (in_nmi() | in_hardirq() | in_serving_softirq()) +#define in_task () (!in_serving_irq())
So in_serving_irq() is !in_task(), right? If so, why not...
include/linux/rcutiny.h static inline void rcu_irq_exit_irqson(void) { } · line 90
Quoted 13 lines
include/linux/preempt.h +0
-0/* * The following macros are deprecated and should not be used in new code: include/linux/rcutiny.h +1
-2@@ -87,8 +87,7 @@ static inline void rcu_irq_exit_irqson(void) { }static inline void rcu_irq_enter_irqson (void ) { }static inline void rcu_irq_exit (void ) { }static inline void rcu_irq_exit_check_preempt (void ) { } -#define rcu_is_idle_cpu (cpu) \ - (is_idle_task(current) && !in_nmi() && !in_hardirq() && !in_serving_softirq()) +#define rcu_is_idle_cpu (cpu) (is_idle_task(current) && !in_serving_irq())
... use in_task() here, and ...
lib/vsprintf.c char *restricted_pointer(char *buf, char *end, const void *ptr, · line 868
Quoted 13 lines
include/linux/rcutiny.h +0
-0static inline void exit_rcu (void ) { }static inline bool rcu_preempt_need_deferred_qs (struct task_struct *t) {lib/vsprintf.c +1
-1@@ -865,7 +865,7 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,* kptr_restrict==1 cannot be used in IRQ context * because its test for CAP_SYSLOG would be meaningless. */ -if (in_hardirq () ||in_serving_softirq () ||in_nmi ()) { +if (in_serving_irq ()) {
... use !in_task() here?
And don't introduce the in_serving_irq() at all.
Regards,
Boqun
Quoted 6 lines
lib/vsprintf.c +0
-0if (spec.field_width ==-1 ) spec.field_width =2 *sizeof (ptr);return error_string (buf, end,"pK-error" , spec);Signature · 1 line
2.30.2
Quoted 26 lines · Boqun Feng
Quoted 25 lines · Changbin Du
At some places we need to determine whether we're in nmi, hardirq or softirq context. This adds a macro
in_serving_irq()as a shortcut for that.Meanwhile, apply this new macro to existing code in rcutiny and vsprintf.
Signed-off-by Changbin Du <[email protected]>--- include/linux/preempt.h | 4 +++- include/linux/rcutiny.h | 3 +-- lib/vsprintf.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)include/linux/preempt.h +1
-0@@ -92,12 +92,14 @@* in_nmi() - We're in NMI context * in_hardirq() - We're in hard IRQ context * in_serving_softirq() - We're in softirq context +* in_serving_irq() - We're in nmi, hardirq or softirq context * in_task() - We're in task context */ #define in_nmi () (nmi_count())
Quoted 9 lines
include/linux/preempt.h line 103
Quoted 6 lines
include/linux/preempt.h +2
-1#define in_hardirq () (hardirq_count())#define in_serving_softirq () (softirq_count() & SOFTIRQ_OFFSET) -#define in_task () (!(in_nmi() | in_hardirq() | in_serving_softirq())) +#define in_serving_irq () (in_nmi() | in_hardirq() | in_serving_softirq()) +#define in_task () (!in_serving_irq())So
in_serving_irq()is !in_task(), right? If so, why not...
Adding in_serving_irq() is to reflect the real purpose so improve readability. And can we preserve that !in_task() means in serving irq context in future? I don't know.
Signature · 2 lines
Cheers, Changbin Du
[Cc Thomas and Frederic since they contributed the clean-up to these macros recently]
Background for discussion:
https://lore.kernel.org/lkml/[email protected]/
Quoted 36 lines · Changbin Du
Quoted 26 lines · Boqun Feng
Quoted 25 lines · Changbin Du
At some places we need to determine whether we're in nmi, hardirq or softirq context. This adds a macro
in_serving_irq()as a shortcut for that.Meanwhile, apply this new macro to existing code in rcutiny and vsprintf.
Signed-off-by Changbin Du <[email protected]>--- include/linux/preempt.h | 4 +++- include/linux/rcutiny.h | 3 +-- lib/vsprintf.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)include/linux/preempt.h +1
-0@@ -92,12 +92,14 @@* in_nmi() - We're in NMI context * in_hardirq() - We're in hard IRQ context * in_serving_softirq() - We're in softirq context +* in_serving_irq() - We're in nmi, hardirq or softirq context * in_task() - We're in task context */ #define in_nmi () (nmi_count())Quoted 9 lines
include/linux/preempt.h line 103
Quoted 6 lines
include/linux/preempt.h +2
-1#define in_hardirq () (hardirq_count())#define in_serving_softirq () (softirq_count() & SOFTIRQ_OFFSET) -#define in_task () (!(in_nmi() | in_hardirq() | in_serving_softirq())) +#define in_serving_irq () (in_nmi() | in_hardirq() | in_serving_softirq()) +#define in_task () (!in_serving_irq())So
in_serving_irq()is !in_task(), right? If so, why not...
Quoted 3 lines
Adding
in_serving_irq()is to reflect the real purpose so improve readability. And can we preserve that !in_task() means in serving irq context in future? I don't know.
Sure, no one could predict the future. But if a third context (other than thread context and {hard,soft}irq context) comes up, which I think is highly unlikely, we could (and should) audit all callsites of in_task() for necessary adjustment. And introducing in_serving_irq() won't help us in that case, because we will still need to audit usage of in_serving_irq(), for example, let's say rcu_is_idle_cpu() for RCU_TINY is defined as
#define rcu_is_idle_cpu(cpu) (is_idle_task(current) && !in_serving_irq())
and we have a new type of context, and we can use in_other() to test whether we are in it. Now even with in_serving_irq() introduced, we still need to make sure the correct version of rcu_is_idle_cpu() is either
(is_idle_task(current) && (!in_serving_irq() && !in_other()))
or
(is_idle_task(current) && !in_serving_irq())
Therefore, I don't see the point of introducing in_serving_irq().
Regards,
Boqun
Quoted 3 lines
Signature · 2 lines
Cheers, Changbin Du
Quoted 63 lines · Boqun Feng
[Cc Thomas and Frederic since they contributed the clean-up to these macros recently]
Background for discussion:
https://lore.kernel.org/lkml/[email protected]/Quoted 36 lines · Changbin Du
Quoted 26 lines · Boqun Feng
Quoted 25 lines · Changbin Du
At some places we need to determine whether we're in nmi, hardirq or softirq context. This adds a macro
in_serving_irq()as a shortcut for that.Meanwhile, apply this new macro to existing code in rcutiny and vsprintf.
Signed-off-by Changbin Du <[email protected]>--- include/linux/preempt.h | 4 +++- include/linux/rcutiny.h | 3 +-- lib/vsprintf.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)include/linux/preempt.h +1
-0@@ -92,12 +92,14 @@* in_nmi() - We're in NMI context * in_hardirq() - We're in hard IRQ context * in_serving_softirq() - We're in softirq context +* in_serving_irq() - We're in nmi, hardirq or softirq context * in_task() - We're in task context */ #define in_nmi () (nmi_count())Quoted 9 lines
include/linux/preempt.h line 103
Quoted 6 lines
include/linux/preempt.h +2
-1#define in_hardirq () (hardirq_count())#define in_serving_softirq () (softirq_count() & SOFTIRQ_OFFSET) -#define in_task () (!(in_nmi() | in_hardirq() | in_serving_softirq())) +#define in_serving_irq () (in_nmi() | in_hardirq() | in_serving_softirq()) +#define in_task () (!in_serving_irq())So
in_serving_irq()is !in_task(), right? If so, why not...Quoted 3 lines
Adding
in_serving_irq()is to reflect the real purpose so improve readability. And can we preserve that !in_task() means in serving irq context in future? I don't know.Sure, no one could predict the future. But if a third context (other than thread context and {hard,soft}irq context) comes up, which I think is highly unlikely, we could (and should) audit all callsites of
in_task()for necessary adjustment. And introducingin_serving_irq()won't help us in that case, because we will still need to audit usage ofin_serving_irq(), for example, let's sayrcu_is_idle_cpu()forRCU_TINYis defined as#define rcu_is_idle_cpu(cpu) (is_idle_task(current) && !in_serving_irq())and we have a new type of context, and we can use
in_other()to test whether we are in it. Now even within_serving_irq()introduced, we still need to make sure the correct version ofrcu_is_idle_cpu()is either
Quoted 8 lines
(is_idle_task(current) && (!in_serving_irq() && !in_other()))or
(is_idle_task(current) && !in_serving_irq())Therefore, I don't see the point of introducing
in_serving_irq().
ok, as in_serving_irq() is only used in two places, it is not common to judge if it is in serving irq context. So this new macro doesn't help much.
Quoted 6 lines
Regards,
BoqunQuoted 3 lines
Signature · 2 lines
Cheers, Changbin Du
Signature · 2 lines
Cheers, Changbin Du