genirq: Handle force threading of irqs with primary and thread handler
PATCH 1/1 genirq: Handle force threading of irqs with primary and thread handler
Force threading of interrupts does not really deal with interrupts which are requested with a primary and a threaded handler. The current policy is to leave them alone and let the primary handler run in interrupt context, but we set the ONESHOT flag for those interrupts as well.
Kohji Okuno debugged a problem with the SDHCI driver where the interrupt thread waits for a hardware interrupt to trigger, which can't work well because the hardware interrupt is masked due to the ONESHOT flag being set. He proposed to set the ONESHOT flag only if the interrupt does not provide a thread handler.
Though that does not work either because these interrupts can be shared. So the other interrupt would rightfully get the ONESHOT flag set and therefor the same situation would happen again.
To deal with this proper, we need to force thread the primary handler of such interrupts as well. That means that the primary interrupt handler is treated as any other primary interrupt handler which is not marked IRQF_NO_THREAD. The threaded handler becomes a separate thread so the SDHCI flow logic can be handled gracefully.
The same issue was reported against 4.1-rt.
--- include/linux/interrupt.h | 2 kernel/irq/manage.c | 160 +++++++++++++++++++++++++++++++++------------- 2 files changed, 120 insertions(+), 42 deletions(-)
include/linux/interrupt.h +2 -0
@@ -102,6 +102,7 @@ typedef irqreturn_t (*irq_handler_t)(int* @flags: flags (see IRQF_* above) * @thread_fn: interrupt handler function for threaded interrupts * @thread: thread pointer for threaded interrupts +* @secondary: pointer to secondary irqaction (force threading) * @thread_flags: flags related to @thread * @thread_mask: bitmask for keeping track of @thread activity * @dir: pointer to the proc/irq/NN/name entry
@@ -113,6 +114,7 @@ struct irqaction {struct irqaction *next;irq_handler_t thread_fn;struct task_struct *thread; +struct irqaction *secondary;unsigned int irq;unsigned int flags;unsigned long thread_flags;
kernel/irq/manage.c +118 -42
256 lines not on this page · raw message
From: Thomas Gleixner <[email protected]>
Date: Mon, 21 Sep 2015 11:01:10 +0200
Quoted 7 lines
To deal with this proper, we need to force thread the primary handler of such interrupts as well. That means that the primary interrupt handler is treated as any other primary interrupt handler which is not marked
IRQF_NO_THREAD. The threaded handler becomes a separate thread so the SDHCI flow logic can be handled gracefully.The same issue was reported against 4.1-rt.
Hi tglx,
I tried your patch. It worked good for me.
Many thanks,
Kohji Okuno
tip-bot for Thomas Gleixner
merge botgenirq: Handle force threading of irqs with primary and thread handler
Commit-ID: 2a1d3ab8986d1b2f598ffc42351d94166fa0f022 Gitweb: http://git.kernel.org/tip/2a1d3ab8986d1b2f598ffc42351d94166fa0f022 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 21 Sep 2015 11:01:10 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Tue, 22 Sep 2015 12:39:57 +0200
genirq: Handle force threading of irqs with primary and thread handler
Force threading of interrupts does not really deal with interrupts which are requested with a primary and a threaded handler. The current policy is to leave them alone and let the primary handler run in interrupt context, but we set the ONESHOT flag for those interrupts as well.
Kohji Okuno debugged a problem with the SDHCI driver where the interrupt thread waits for a hardware interrupt to trigger, which can't work well because the hardware interrupt is masked due to the ONESHOT flag being set. He proposed to set the ONESHOT flag only if the interrupt does not provide a thread handler.
Though that does not work either because these interrupts can be shared. So the other interrupt would rightfully get the ONESHOT flag set and therefor the same situation would happen again.
To deal with this proper, we need to force thread the primary handler of such interrupts as well. That means that the primary interrupt handler is treated as any other primary interrupt handler which is not marked IRQF_NO_THREAD. The threaded handler becomes a separate thread so the SDHCI flow logic can be handled gracefully.
The same issue was reported against 4.1-rt.
--- include/linux/interrupt.h | 2 + kernel/irq/manage.c | 158 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 119 insertions(+), 41 deletions(-)
include/linux/interrupt.h +2 -0
@@ -102,6 +102,7 @@ typedef irqreturn_t (*irq_handler_t)(int, void *);* @flags: flags (see IRQF_* above) * @thread_fn: interrupt handler function for threaded interrupts * @thread: thread pointer for threaded interrupts +* @secondary: pointer to secondary irqaction (force threading) * @thread_flags: flags related to @thread * @thread_mask: bitmask for keeping track of @thread activity * @dir: pointer to the proc/irq/NN/name entry
@@ -113,6 +114,7 @@ struct irqaction {struct irqaction *next;irq_handler_t thread_fn;struct task_struct *thread; +struct irqaction *secondary;unsigned int irq;unsigned int flags;unsigned long thread_flags;
kernel/irq/manage.c +117 -41
255 lines not on this page · raw message
Hi Thomas,
Quoted 33 lines · tip-bot for Thomas Gleixner
Commit-ID: 2a1d3ab8986d1b2f598ffc42351d94166fa0f022 Gitweb: http://git.kernel.org/tip/2a1d3ab8986d1b2f598ffc42351d94166fa0f022 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 21 Sep 2015 11:01:10 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Tue, 22 Sep 2015 12:39:57 +0200genirq: Handle force threading of irqs with primary and thread handler
Force threading of interrupts does not really deal with interrupts which are requested with a primary and a threaded handler. The current policy is to leave them alone and let the primary handler run in interrupt context, but we set the ONESHOT flag for those interrupts as well.
Kohji Okuno debugged a problem with the SDHCI driver where the interrupt thread waits for a hardware interrupt to trigger, which can't work well because the hardware interrupt is masked due to the ONESHOT flag being set. He proposed to set the ONESHOT flag only if the interrupt does not provide a thread handler.
Though that does not work either because these interrupts can be shared. So the other interrupt would rightfully get the ONESHOT flag set and therefor the same situation would happen again.
To deal with this proper, we need to force thread the primary handler of such interrupts as well. That means that the primary interrupt handler is treated as any other primary interrupt handler which is not marked
IRQF_NO_THREAD. The threaded handler becomes a separate thread so the SDHCI flow logic can be handled gracefully.The same issue was reported against 4.1-rt.
Quoted 7 lines
Reported-and-tested-by Kohji Okuno <[email protected]>Reported-By Michal Smucr <[email protected]>Reported-and-tested-by Nathan Sullivan <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>Cc Sebastian Andrzej Siewior <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>
this commit causes a performance regression for the USB driver on several platforms (anybody using drivers/usb/dwc3, basically).
Here's the USB throughput with linux-next in 3 different scenarios:
1) Linux next without threadirqs cmdline
test 0: sent 256.00 MB read 33.02 MB/s write 30.01 MB/s
2) Linux next with threadirqs on cmdline
test 0: sent 256.00 MB read 30.70 MB/s write 27.89 MB/s
3) Linux next with threadirqs on cmdline + revert of $subject
test 0: sent 256.00 MB read 32.93 MB/s write 29.85 MB/s
Considering this is trying to solve an issue found on the SDHCI driver, shouldn't that be fixed instead ? Another option would be, of course, to add IRQF_NO_THREAD to dwc3, but I'd like to avoid that if possible.
The way we try to use dwc3 is rather simple, actually. We use the primary handle *only* to detect is $this device generated the IRQ and if did we wake up the thread. We also don't make use of ONESHOT because we mask $this device IRQs in the primary handler and only unmask after the thread runs.
It's a bit surprising, to me at least, that simply running everything as a thread would have such a measurable impact, but it does.
Signature · 1 line
balbi
Quoted 13 lines · Felipe Balbi
this commit causes a performance regression for the USB driver on several platforms (anybody using
drivers/usb/dwc3, basically).Here's the USB throughput with linux-next in 3 different scenarios:
1) Linux next without threadirqs cmdline
test 0: sent 256.00 MB read 33.02 MB/s write 30.01 MB/s2) Linux next with threadirqs on cmdline
test 0: sent 256.00 MB read 30.70 MB/s write 27.89 MB/s
Quoted 8 lines
3) Linux next with threadirqs on cmdline + revert of $subject
test 0: sent 256.00 MB read 32.93 MB/s write 29.85 MB/sConsidering this is trying to solve an issue found on the SDHCI driver, shouldn't that be fixed instead ? Another option would be, of course, to add
IRQF_NO_THREADto dwc3, but I'd like to avoid that if possible.
It's not only an issue for SDHCI. It's a general problem with other drivers as well.
Quoted 5 lines
The way we try to use dwc3 is rather simple, actually. We use the primary handle *only* to detect is $this device generated the IRQ and if did we wake up the thread. We also don't make use of ONESHOT because we mask $this device IRQs in the primary handler and only unmask after the thread runs.
So in your case IRQF_NO_THREAD is really the solution. It will keep your primary handler handled in the hard interrupt context. That will work on RT as well.
Quoted 2 lines
It's a bit surprising, to me at least, that simply running everything as a thread would have such a measurable impact, but it does.
I'm surprised of the size of the impact as well. I wouldn't have expected that another kernel thread context switch makes such a difference.
Thanks,
tglx
Hi,
Quoted 32 lines · Thomas Gleixner
Quoted 13 lines · Felipe Balbi
this commit causes a performance regression for the USB driver on several platforms (anybody using
drivers/usb/dwc3, basically).Here's the USB throughput with linux-next in 3 different scenarios:
1) Linux next without threadirqs cmdline
test 0: sent 256.00 MB read 33.02 MB/s write 30.01 MB/s2) Linux next with threadirqs on cmdline
test 0: sent 256.00 MB read 30.70 MB/s write 27.89 MB/sQuoted 8 lines
3) Linux next with threadirqs on cmdline + revert of $subject
test 0: sent 256.00 MB read 32.93 MB/s write 29.85 MB/sConsidering this is trying to solve an issue found on the SDHCI driver, shouldn't that be fixed instead ? Another option would be, of course, to add
IRQF_NO_THREADto dwc3, but I'd like to avoid that if possible.It's not only an issue for SDHCI. It's a general problem with other drivers as well.
Quoted 5 lines
The way we try to use dwc3 is rather simple, actually. We use the primary handle *only* to detect is $this device generated the IRQ and if did we wake up the thread. We also don't make use of ONESHOT because we mask $this device IRQs in the primary handler and only unmask after the thread runs.
Quoted 3 lines
So in your case
IRQF_NO_THREADis really the solution. It will keep your primary handler handled in the hard interrupt context. That will work on RT as well.
all right. I'll patch that up. Thanks
Signature · 1 line
balbi