tasklet/rt: Prevent tasklets from going into infinite spin in RT
PATCH 1/1 tasklet/rt: Prevent tasklets from going into infinite spin in RT
Ingo,
I forward ported this code from 2.6.33.9-rt31, but I think you were the original author, as I found most of this code in the "tasklet-redesign.patch" from my broken out 2.6.24-rt patches. I committed it into my git tree (stable-rt) under your name, and added the Signed-off-by that you had in that patch, if you have and objections, please let me know. This patch should never see mainline, but it will probably be going into the -rt branch. I wrote up this change log, if there's something you don't like in it, let me know and I'll fix it.
Luis and Clark (I love saying that),
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
Thanks,
-- Steve
commit 8a69de1b881e32b2a23452e6f25c39587c6f5e0e
Author: Ingo Molnar <[email protected]> Date: Tue Nov 29 20:18:22 2011 -0500
tasklet/rt: Prevent tasklets from going into infinite spin in RT
When CONFIG_PREEMPT_RT_FULL is enabled, tasklets run as threads, and spinlocks turn are mutexes. But this can cause issues with tasks disabling tasklets. A tasklet runs under ksoftirqd, and if a tasklets are disabled with tasklet_disable(), the tasklet count is increased. When a tasklet runs, it checks this counter and if it is set, it adds itself back on the softirq queue and returns.
The problem arises in RT because ksoftirq will see that a softirq is ready to run (the tasklet softirq just re-armed itself), and will not sleep, but instead run the softirqs again. The tasklet softirq will still see that the count is non-zero and will not execute the tasklet and requeue itself on the softirq again, which will cause ksoftirqd to run it again and again and again.
It gets worse because ksoftirqd runs as a real-time thread. If it preempted the task that disabled tasklets, and that task has migration disabled, or can't run for other reasons, the tasklet softirq will never run because the count will never be zero, and ksoftirqd will go into an infinite loop. As an RT task, it this becomes a big problem.
This is a hack solution to have tasklet_disable stop tasklets, and when a tasklet runs, instead of requeueing the tasklet softirqd it delays it. When tasklet_enable() is called, and tasklets are waiting, then the tasklet_enable() will kick the tasklets to continue. This prevents the lock up from ksoftirq going into an infinite loop.
include/linux/interrupt.h +20 -19
@@ -501,8 +501,9 @@ extern void __send_remote_softirq(struct call_single_data *cp, int cpu, to be executed on some cpu at least once after this. * If the tasklet is already scheduled, but its execution is still not started, it will be executed only once. - * If this tasklet is already running on another CPU (or schedule is called - from tasklet itself), it is rescheduled for later. + * If this tasklet is already running on another CPU, it is rescheduled + for later. + * Schedule must not be called from the tasklet itself (a lockup occurs) * Tasklet is strictly serialized wrt itself, but not wrt another tasklets. If client needs some intertask synchronization, he makes it with spinlocks.
@@ -527,27 +528,36 @@ struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }enum {TASKLET_STATE_SCHED ,/* Tasklet is scheduled for execution */ -TASKLET_STATE_RUN /* Tasklet is running (SMP only) */ +TASKLET_STATE_RUN ,/* Tasklet is running (SMP only) */ +TASKLET_STATE_PENDING /* Tasklet is pending */ }; -#ifdef CONFIG_SMP +#define TASKLET_STATEF_SCHED (1 << TASKLET_STATE_SCHED) +#define TASKLET_STATEF_RUN (1 << TASKLET_STATE_RUN) +#define TASKLET_STATEF_PENDING (1 << TASKLET_STATE_PENDING) + +#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT_FULL )static inline int tasklet_trylock (struct tasklet_struct *t) {return !test_and_set_bit (TASKLET_STATE_RUN , &(t)->state); } +static inline int tasklet_tryunlock (struct tasklet_struct *t) +{ +return cmpxchg (&t->state,TASKLET_STATEF_RUN ,0 ) ==TASKLET_STATEF_RUN ; +} +static inline void tasklet_unlock (struct tasklet_struct *t) {smp_mb__before_clear_bit ();clear_bit (TASKLET_STATE_RUN , &(t)->state); } -static inline void tasklet_unlock_wait (struct tasklet_struct *t) -{ -while (test_bit (TASKLET_STATE_RUN , &(t)->state)) {barrier (); } -} +extern void tasklet_unlock_wait (struct tasklet_struct *t); +#else #define tasklet_trylock (t) 1 +#define tasklet_tryunlock (t) 1#define tasklet_unlock_wait (t) do { } while (0)#define tasklet_unlock (t) do { } while (0)#endif
@@ -596,17 +606,8 @@ static inline void tasklet_disable(struct tasklet_struct *t)smp_mb (); } -static inline void tasklet_enable (struct tasklet_struct *t) -{ -smp_mb__before_atomic_dec (); -atomic_dec (&t->count); -} - -static inline void tasklet_hi_enable (struct tasklet_struct *t) -{ -smp_mb__before_atomic_dec (); -atomic_dec (&t->count); -} +extern void tasklet_enable (struct tasklet_struct *t); +extern void tasklet_hi_enable (struct tasklet_struct *t);extern void tasklet_kill (struct tasklet_struct *t);extern void tasklet_kill_immediate (struct tasklet_struct *t,unsigned int cpu);
kernel/softirq.c +150 -58
273 lines not on this page · raw message
Quoted 11 lines · On Tue, 29 Nov 2011 20:55:20 -0500 Steven Rostedt <[email protected]> wrote:
Ingo,
I forward ported this code from 2.6.33.9-rt31, but I think you were the original author, as I found most of this code in the "tasklet-redesign.patch" from my broken out 2.6.24-rt patches. I committed it into my git tree (stable-rt) under your name, and added the Signed-off-by that you had in that patch, if you have and objections, please let me know. This patch should never see mainline, but it will probably be going into the -rt branch. I wrote up this change log, if there's something you don't like in it, let me know and I'll fix it.
Quoted 1 line
Luis and Clark (I love saying that),
No matter how many times you say it, I'm still not treking across the USA with Luis. :)
Quoted 4 lines
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
Yeah, since Luis is a couple of time zones ahead of us, maybe it'll all be fixed when we get up in the morning.
Clark
Quoted 10 lines · Steven Rostedt
Ingo,
I forward ported this code from 2.6.33.9-rt31, but I think you were the original author, as I found most of this code in the "tasklet-redesign.patch" from my broken out 2.6.24-rt patches. I committed it into my git tree (stable-rt) under your name, and added the Signed-off-by that you had in that patch, if you have and objections, please let me know. This patch should never see mainline, but it will probably be going into the -rt branch. I wrote up this change log, if there's something you don't like in it, let me know and I'll fix it.
I'm oh so happy to see this. I've been going nuts trying to figure out why the heck 33-rt doesn't go bonkers, but 30+ rt does.
Quoted 4 lines
Luis and Clark (I love saying that),
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
I'll most certainly be testing it too. With the below, and the conditional yield thingy disabled, all I have to do is boot x3550 M3 box, and it'll hang very frequently, but not always, with sirq-tasklet going stark raving mad. Yielding fix^Wmakes it not do the bad thing.
(somewhat less disgusting version of sirq threads patch;)
sched, rt: resurrect softirq threads for RT_FULL
--- include/linux/interrupt.h | 46 ++++++++++ kernel/irq/Kconfig | 7 + kernel/sched.c | 4 kernel/softirq.c | 194 ++++++++++++++++++++++++++++++++-------------- 4 files changed, 191 insertions(+), 60 deletions(-)
kernel/irq/Kconfig +7 -0
@@ -60,6 +60,13 @@ config IRQ_DOMAIN config IRQ_FORCED_THREADING bool +# Support forced sirq threading +config SIRQ_FORCED_THREADING + bool "Forced Soft IRQ threading" + depends on PREEMPT_RT_FULL + help + Split ksoftirqd into per SOFTIRQ threads + config SPARSE_IRQ bool "Support sparse irq numbering" depends on HAVE_SPARSE_IRQ
include/linux/interrupt.h +43 -3
71 lines not on this page · raw message
kernel/sched.c +2 -2
@@ -2082,7 +2082,7 @@ void account_system_vtime(struct task_st*/ if (hardirq_count ())__this_cpu_add (cpu_hardirq_time, delta); -else if (in_serving_softirq () && curr !=this_cpu_ksoftirqd ()) +else if (in_serving_softirq () && !this_cpu_ksoftirqd (curr))__this_cpu_add (cpu_softirq_time, delta);irq_time_write_end ();
@@ -4062,7 +4062,7 @@ static void irqtime_account_process_tick cpustat->irq =cputime64_add (cpustat->irq, tmp); }else if (irqtime_account_si_update ()) { cpustat->softirq =cputime64_add (cpustat->softirq, tmp); - }else if (this_cpu_ksoftirqd () == p) { + }else if (this_cpu_ksoftirqd (p)) {/* * ksoftirqd time do not get accounted in cpu_softirq_time. * So, we have to handle it separately here.
kernel/softirq.c +139 -55
322 lines not on this page · raw message
Quoted 16 lines · Clark Williams
Quoted 11 lines · On Tue, 29 Nov 2011 20:55:20 -0500 Steven Rostedt <[email protected]> wrote:
Ingo,
I forward ported this code from 2.6.33.9-rt31, but I think you were the original author, as I found most of this code in the "tasklet-redesign.patch" from my broken out 2.6.24-rt patches. I committed it into my git tree (stable-rt) under your name, and added the Signed-off-by that you had in that patch, if you have and objections, please let me know. This patch should never see mainline, but it will probably be going into the -rt branch. I wrote up this change log, if there's something you don't like in it, let me know and I'll fix it.
Quoted 1 line
Luis and Clark (I love saying that),
Quoted 8 lines
No matter how many times you say it, I'm still not treking across the USA with Luis. :)
Quoted 2 lines
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
Yeah, since Luis is a couple of time zones ahead of us, maybe it'll all be fixed when we get up in the morning.
I've got it running on a system here that frequently encountered the condition. I will let it perform some automated testing while I sleep. Should have results by morning (west coast US).
Signature · 1 line
Mike
Quoted 6 lines · Mike Galbraith
Quoted 2 lines · Steven Rostedt
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
I'll most certainly be testing it too.
The other me tested it too. Coincidentally, he was having the same darn problem with a fat enterprise config (on the same x3550 M3 too).
Thanks, I can now turn x3550 (by Pratt & Whitney) off for a bit.
-Mike
Hi Steven
Quoted 2 lines
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
Unfortunatly i am also experiencing these problems with ksoftirq running wild.
So i am also going to test this patch and see if it fixes our problem. It seems as if this bug is much more probable after UBIFS update and when "sched: RT throttling activated" hits.
Best regards
Tim
PS: Steven i just forgot the cc list so you got this mail twice, sorry.
Please ignore or at your wish use as "Deutschkurs" in german legalese:
Hottinger Baldwin Messtechnik GmbH, Im Tiefen See 45, 64293 Darmstadt, Germany | www.hbm.com
Registered as GmbH (German limited liability corporation) in the commercial register at the local court of Darmstadt, HRB 1147 Company domiciled in Darmstadt | CEO: Andreas Huellhorst | Chairman of the board: James Charles Webster
Als Gesellschaft mit beschraenkter Haftung eingetragen im Handelsregister des Amtsgerichts Darmstadt unter HRB 1147 Sitz der Gesellschaft: Darmstadt | Geschaeftsfuehrung: Andreas Huellhorst | Aufsichtsratsvorsitzender: James Charles Webster
The information in this email is confidential. It is intended solely for the addressee. If you are not the intended recipient, please let me know and delete this email.
Die in dieser E-Mail enthaltene Information ist vertraulich und lediglich für den Empfaenger bestimmt. Sollten Sie nicht der eigentliche Empfaenger sein, informieren Sie mich bitte kurz und loeschen diese E-Mail. --
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 95 lines · Mike Galbraith
Quoted 10 lines · Steven Rostedt
Ingo,
I forward ported this code from 2.6.33.9-rt31, but I think you were the original author, as I found most of this code in the "tasklet-redesign.patch" from my broken out 2.6.24-rt patches. I committed it into my git tree (stable-rt) under your name, and added the Signed-off-by that you had in that patch, if you have and objections, please let me know. This patch should never see mainline, but it will probably be going into the -rt branch. I wrote up this change log, if there's something you don't like in it, let me know and I'll fix it.
I'm oh so happy to see this. I've been going nuts trying to figure out why the heck 33-rt doesn't go bonkers, but 30+ rt does.
Quoted 4 lines
Luis and Clark (I love saying that),
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
I'll most certainly be testing it too. With the below, and the conditional yield thingy disabled, all I have to do is boot x3550 M3 box, and it'll hang very frequently, but not always, with sirq-tasklet going stark raving mad. Yielding fix^Wmakes it not do the bad thing.
(somewhat less disgusting version of sirq threads patch;)
sched, rt: resurrect softirq threads for
RT_FULLSigned-off-by Mike Galbraith <[email protected]>--- include/linux/interrupt.h | 46 ++++++++++ kernel/irq/Kconfig | 7 + kernel/sched.c | 4 kernel/softirq.c | 194 ++++++++++++++++++++++++++++++++-------------- 4 files changed, 191 insertions(+), 60 deletions(-)Index: linux-3.2-rt/kernel/irq/Kconfig
===================================================================kernel/irq/Kconfig +7
-0@@ -60,6 +60,13 @@ config IRQ_DOMAIN config IRQ_FORCED_THREADING bool +# Support forced sirq threading +config SIRQ_FORCED_THREADING + bool "Forced Soft IRQ threading" + depends on PREEMPT_RT_FULL + help + Split ksoftirqd into per SOFTIRQ threads + config SPARSE_IRQ bool "Support sparse irq numbering" depends on HAVE_SPARSE_IRQIndex:
linux-3.2-rt/include/linux/interrupt.h
===================================================================include/linux/interrupt.h +13
-1@@ -442,6 +442,9 @@ enum NR_SOFTIRQS }; +/* Update when adding new softirqs. */ +#define SOFTIRQ_MASK_ALL 0x3ff +/* map softirq index to softirq name. update 'softirq_to_name' in * kernel/softirq.c when adding a new softirq. */ @@ -457,10 +460,16 @@ struct softirq_action };#ifndef CONFIG_PREEMPT_RT_FULL +#define NR_SOFTIRQ_THREADS 1 asmlinkage void do_softirq(void); asmlinkage void __do_softirq(void);static inline void thread_do_softirq (void ) {do_softirq (); }#else +#ifdef CONFIG_SIRQ_FORCED_THREADING +#define NR_SOFTIRQ_THREADS NR_SOFTIRQS +#else +#define NR_SOFTIRQ_THREADS 1 +#endif extern void thread_do_softirq (void );#endif @@ -486,12 +495,43 @@ extern void softirq_check_pending_idle(v*/ DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list); -DECLARE_PER_CPU(struct task_struct *, ksoftirqd); +struct softirqdata { +int mask; +struct task_struct *tsk; +};
include/linux/interrupt.h extern void softirq_check_pending_idle(v · line 511
Quoted 10 lines
include/linux/interrupt.h +10
-0+ +DECLARE_PER_CPU(struct softirqdata [NR_SOFTIRQ_THREADS], ksoftirqd); + +static inline bool this_cpu_ksoftirqd (struct task_struct *p) +{ +int i; + +for (i =0 ; i <NR_SOFTIRQ_THREADS ; i++) { +if (p ==__get_cpu_var (ksoftirqd)[i].tsk) +return true;
You are not serious about that loop, are you ?
Quoted 4 lines
include/linux/interrupt.h +2
-1+ } -static inline struct task_struct *this_cpu_ksoftirqd (void ) +return false;
include/linux/interrupt.h extern void softirq_check_pending_idle(v · line 524
Quoted 10 lines
include/linux/interrupt.h +10
-0+} + +#ifdef CONFIG_PREEMPT_RT_FULL +static inline int task_sirq_mask (struct task_struct *p) +{ +int i; + +for (i =0 ; i <NR_SOFTIRQ_THREADS ; i++) { +if (p ==__get_cpu_var (ksoftirqd)[i].tsk) +return __get_cpu_var (ksoftirqd)[i].mask;
Looks you are
Quoted 11 lines
include/linux/interrupt.h +2
-4@@ -131,11 +155,18 @@ void softirq_check_pending_idle(void)*/ static void wakeup_softirqd (void ) { -/* Interrupts are disabled: no need to stop preemption */ -struct task_struct *tsk =__this_cpu_read (ksoftirqd); +struct task_struct *tsk; +u32 pending =local_softirq_pending (), mask, i; -if (tsk && tsk->state !=TASK_RUNNING ) -wake_up_process (tsk);
include/linux/interrupt.h void softirq_check_pending_idle(void) · line 170
Quoted 10 lines
include/linux/interrupt.h +9
-0+/* Interrupts are disabled: no need to stop preemption */ +for (i =0 ; pending && i <NR_SOFTIRQ_THREADS ; i++) { + mask =__get_cpu_var (ksoftirqd)[i].mask; +if (!(pending & mask)) +continue ; + tsk =__get_cpu_var (ksoftirqd)[i].tsk; +if (tsk && tsk->state !=TASK_RUNNING ) +wake_up_process (tsk); + } }
Dammned serious is seems. :)
I was looking into that as well, though I did not want to inflict it on 3.0 at this point.
Thanks,
tglx
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Mike Galbraith
include/linux/interrupt.h +8
-1@@ -486,12 +495,43 @@ extern void softirq_check_pending_idle(v*/ DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list); -DECLARE_PER_CPU(struct task_struct *, ksoftirqd); +struct softirqdata { +int mask; +struct task_struct *tsk; +}; + +DECLARE_PER_CPU(struct softirqdata [NR_SOFTIRQ_THREADS], ksoftirqd); + +static inline bool this_cpu_ksoftirqd (struct task_struct *p)
Quoted 8 lines
include/linux/interrupt.h extern void softirq_check_pending_idle(v · line 511
Quoted 6 lines
include/linux/interrupt.h +6
-0+{ +int i; + +for (i =0 ; i <NR_SOFTIRQ_THREADS ; i++) { +if (p ==__get_cpu_var (ksoftirqd)[i].tsk) +return true;You are not serious about that loop, are you ?
Well, it's a short loop, especially when NR_SOFTIRQ_THREADS = 1 (poof).
Quoted 9 lines
Quoted 9 lines
kernel/softirq.c +2
-2@@ -131,11 +155,18 @@ void softirq_check_pending_idle(void)*/ static void wakeup_softirqd (void ) { -/* Interrupts are disabled: no need to stop preemption */ -struct task_struct *tsk =__this_cpu_read (ksoftirqd); +struct task_struct *tsk; +u32 pending =local_softirq_pending (), mask, i;
Quoted 14 lines
kernel/softirq.c void softirq_check_pending_idle(void) · line 170
Quoted 12 lines
kernel/softirq.c +9
-2-if (tsk && tsk->state !=TASK_RUNNING ) -wake_up_process (tsk); +/* Interrupts are disabled: no need to stop preemption */ +for (i =0 ; pending && i <NR_SOFTIRQ_THREADS ; i++) { + mask =__get_cpu_var (ksoftirqd)[i].mask; +if (!(pending & mask)) +continue ; + tsk =__get_cpu_var (ksoftirqd)[i].tsk; +if (tsk && tsk->state !=TASK_RUNNING ) +wake_up_process (tsk); + } }Dammned serious is seems. :)
Deadly serious :)
For the problem at hand (timer wakeups), NR_SOFTIRQ_THREADS could be 2.
Quoted 6 lines
I was looking into that as well, though I did not want to inflict it on 3.0 at this point.
Thanks,
tglx
Quoted 12 lines · Mike Galbraith
Quoted 11 lines · Thomas Gleixner
Quoted 9 lines · Mike Galbraith
kernel/softirq.c +2
-2@@ -131,11 +155,18 @@ void softirq_check_pending_idle(void)*/ static void wakeup_softirqd (void ) { -/* Interrupts are disabled: no need to stop preemption */ -struct task_struct *tsk =__this_cpu_read (ksoftirqd); +struct task_struct *tsk; +u32 pending =local_softirq_pending (), mask, i;
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
kernel/softirq.c +4
-2-if (tsk && tsk->state !=TASK_RUNNING ) -wake_up_process (tsk); +/* Interrupts are disabled: no need to stop preemption */ +for (i =0 ; pending && i <NR_SOFTIRQ_THREADS ; i++) { + mask =__get_cpu_var (ksoftirqd)[i].mask; +if (!(pending & mask))Quoted 8 lines
kernel/softirq.c void softirq_check_pending_idle(void) · line 170
Quoted 6 lines
kernel/softirq.c +5
-0+continue ; + tsk =__get_cpu_var (ksoftirqd)[i].tsk; +if (tsk && tsk->state !=TASK_RUNNING ) +wake_up_process (tsk); + } }Dammned serious is seems. :)
'course here I should have just used the busy bits directly.
-Mike
On Tue, Nov 29, 2011 at 08:55:20PM -0500, Steven Rostedt wrote:
...
| I booted this patch against 3.0-rt stable, and it didn't crash ;) | Could you apply it and see if it fixes the hang that you've been seeing.
Steven,
I have a test box that would present the issue every 2 or 3 reboots, consistently. Using your patch I have already rebooted the box 30 times successfuly. And the test keeps going on... I feel confident to add my:
Cheers,
Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 23 lines · Mike Kravetz
Quoted 22 lines · Clark Williams
Quoted 11 lines · On Tue, 29 Nov 2011 20:55:20 -0500 Steven Rostedt <[email protected]> wrote:
Ingo,
I forward ported this code from 2.6.33.9-rt31, but I think you were the original author, as I found most of this code in the "tasklet-redesign.patch" from my broken out 2.6.24-rt patches. I committed it into my git tree (stable-rt) under your name, and added the Signed-off-by that you had in that patch, if you have and objections, please let me know. This patch should never see mainline, but it will probably be going into the -rt branch. I wrote up this change log, if there's something you don't like in it, let me know and I'll fix it.
Quoted 1 line
Luis and Clark (I love saying that),
No matter how many times you say it, I'm still not treking across the USA with Luis. :)
Quoted 2 lines
I booted this patch against 3.0-rt stable, and it didn't crash ;) Could you apply it and see if it fixes the hang that you've been seeing.
Quoted 6 lines
Quoted 2 lines
Yeah, since Luis is a couple of time zones ahead of us, maybe it'll all be fixed when we get up in the morning.
I've got it running on a system here that frequently encountered the condition. I will let it perform some automated testing while I sleep. Should have results by morning (west coast US).
133 successful test executions (just normal reboot/restart of system). Without patch, system would hang/stall during restart more than 50% of the time.
Signature · 1 line
Mike
PATCH RT] resurrect softirq threads for RT_FULL
In reply to Thomas GleixnerUn-hijack thread.
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Mike Galbraith
(quoted diff) +8
-1@@ -486,12 +495,43 @@ extern void softirq_check_pending_idle(v */ DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list); -DECLARE_PER_CPU(struct task_struct *, ksoftirqd); +struct softirqdata { + int mask; + struct task_struct *tsk; +}; + +DECLARE_PER_CPU(struct softirqdata [NR_SOFTIRQ_THREADS], ksoftirqd); + +static inline bool this_cpu_ksoftirqd(struct task_struct *p)
Quoted 8 lines
Review extern void softirq_check_pending_idle(v · line 511
Quoted 6 lines
(quoted diff) +6
-0+{ + int i; + + for (i = 0; i < NR_SOFTIRQ_THREADS; i++) { + if (p == __get_cpu_var(ksoftirqd)[i].tsk) + return true;You are not serious about that loop, are you ?
After some dainbramaged removal, it might look a little better.
sched, rt: resurrect softirq threads for RT_FULL
--- include/linux/interrupt.h | 21 ++++- kernel/irq/Kconfig | 7 + kernel/sched.c | 4 - kernel/softirq.c | 168 ++++++++++++++++++++++++++++++++-------------- 4 files changed, 145 insertions(+), 55 deletions(-)
kernel/irq/Kconfig +7 -0
@@ -60,6 +60,13 @@ config IRQ_DOMAIN config IRQ_FORCED_THREADING bool +# Support forced sirq threading +config SIRQ_FORCED_THREADING + bool "Forced Soft IRQ threading" + depends on PREEMPT_RT_FULL + help + Split ksoftirqd into per SOFTIRQ threads + config SPARSE_IRQ bool "Support sparse irq numbering" depends on HAVE_SPARSE_IRQ
include/linux/interrupt.h +18 -3
@@ -442,6 +442,9 @@ enum NR_SOFTIRQS }; +/* Update when adding new softirqs. */ +#define SOFTIRQ_MASK_ALL 0x3ff +/* map softirq index to softirq name. update 'softirq_to_name' in * kernel/softirq.c when adding a new softirq. */
@@ -457,10 +460,16 @@ struct softirq_action };#ifndef CONFIG_PREEMPT_RT_FULL +#define NR_SOFTIRQ_THREADS 1 asmlinkage void do_softirq(void); asmlinkage void __do_softirq(void);static inline void thread_do_softirq (void ) {do_softirq (); }#else +#ifdef CONFIG_SIRQ_FORCED_THREADING +#define NR_SOFTIRQ_THREADS NR_SOFTIRQS +#else +#define NR_SOFTIRQ_THREADS 1 +#endif extern void thread_do_softirq (void );#endif
@@ -486,11 +495,17 @@ extern void softirq_check_pending_idle(v*/ DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list); -DECLARE_PER_CPU(struct task_struct *, ksoftirqd); +struct softirqdata { +int mask; +struct task_struct *tsk; +}; + +DECLARE_PER_CPU(struct softirqdata [NR_SOFTIRQ_THREADS], ksoftirqd); +DECLARE_PER_CPU(struct task_struct *, local_softirq_thread); -static inline struct task_struct *this_cpu_ksoftirqd (void ) +static inline int task_is_ksoftirqd (struct task_struct *p) { -return this_cpu_read (ksoftirqd); +return p ==this_cpu_read (local_softirq_thread); }/* Try to send a softirq to a remote cpu. If this cannot be done, the
kernel/sched.c +2 -2
@@ -2082,7 +2082,7 @@ void account_system_vtime(struct task_st*/ if (hardirq_count ())__this_cpu_add (cpu_hardirq_time, delta); -else if (in_serving_softirq () && curr !=this_cpu_ksoftirqd ()) +else if (in_serving_softirq () && !task_is_ksoftirqd (curr))__this_cpu_add (cpu_softirq_time, delta);irq_time_write_end ();
@@ -4062,7 +4062,7 @@ static void irqtime_account_process_tick cpustat->irq =cputime64_add (cpustat->irq, tmp); }else if (irqtime_account_si_update ()) { cpustat->softirq =cputime64_add (cpustat->softirq, tmp); - }else if (this_cpu_ksoftirqd () == p) { + }else if (task_is_ksoftirqd (p)) {/* * ksoftirqd time do not get accounted in cpu_softirq_time. * So, we have to handle it separately here.
kernel/softirq.c +118 -50
303 lines not on this page · raw message