FRV: Improve FRV's use of generic IRQ handling
PATCH 1/3 FRV: Improve FRV's use of generic IRQ handling
From: David Howells <[email protected]>
Improve FRV's use of generic IRQ handling:
(*) Use generic_handle_irq() rather than __do_IRQ() as the latter is obsolete.
(*) Don't implement enable() and disable() ops as these will fall back to
using unmask() and mask().
(*) Provide mask_ack() functions to avoid a call each to mask() and ack().
(*) Make the cascade handlers always return IRQ_HANDLED.
(*) Implement the mask() and unmask() functions in the same order as they're
listed in the ops table.
---
arch/frv/kernel/irq-mb93091.c | 36 +++++++++++++++++++----------------- arch/frv/kernel/irq-mb93093.c | 36 +++++++++++++++++++----------------- arch/frv/kernel/irq-mb93493.c | 35 ++++++++++++++--------------------- arch/frv/kernel/irq.c | 15 +-------------- 4 files changed, 53 insertions(+), 69 deletions(-)
arch/frv/kernel/irq-mb93091.c +19 -17
@@ -36,41 +36,45 @@ #define __clr_IFR(M) do { __reg16(0xffc0/* * on-motherboard FPGA PIC operations */ -static void frv_fpga_enable (unsigned int irq) +static void frv_fpga_mask (unsigned int irq) {uint16_t imr =__get_IMR (); - imr &= ~(1 << (irq -IRQ_BASE_FPGA )); + imr |=1 << (irq -IRQ_BASE_FPGA );__set_IMR (imr); } -static void frv_fpga_disable (unsigned int irq) +static void frv_fpga_ack (unsigned int irq) +{ +__clr_IFR (1 << (irq -IRQ_BASE_FPGA )); +} + +static void frv_fpga_mask_ack (unsigned int irq) {uint16_t imr =__get_IMR (); imr |=1 << (irq -IRQ_BASE_FPGA ); -__set_IMR (imr); -} -static void frv_fpga_ack (unsigned int irq) -{__clr_IFR (1 << (irq -IRQ_BASE_FPGA )); } -static void frv_fpga_end (unsigned int irq) +static void frv_fpga_unmask (unsigned int irq) { +uint16_t imr =__get_IMR (); + + imr &= ~(1 << (irq -IRQ_BASE_FPGA )); + +__set_IMR (imr); }static struct irq_chip frv_fpga_pic = { .name ="mb93091" , - .enable = frv_fpga_enable, - .disable = frv_fpga_disable, .ack = frv_fpga_ack, - .mask = frv_fpga_disable, - .unmask = frv_fpga_enable, - .end = frv_fpga_end, + .mask = frv_fpga_mask, + .mask_ack = frv_fpga_mask_ack, + .unmask = frv_fpga_unmask, };/*
@@ -79,7 +83,6 @@ static struct irq_chip frv_fpga_pic = {static irqreturn_t fpga_interrupt (int irq,void *_mask,struct pt_regs *regs) {uint16_t imr, mask = (unsigned long ) _mask; -irqreturn_t iret =0 ; imr =__get_IMR (); mask = mask & ~imr &__get_IFR ();
@@ -92,11 +95,10 @@ static irqreturn_t fpga_interrupt(int ir irq =31 - irq; mask &= ~(1 << irq); -if (__do_IRQ (IRQ_BASE_FPGA + irq, regs)) - iret |=IRQ_HANDLED ; +generic_handle_irq (IRQ_BASE_FPGA + irq, regs); } -return iret; +return IRQ_HANDLED ; }/*
arch/frv/kernel/irq-mb93093.c +19 -17
@@ -35,40 +35,44 @@ #define __clr_IFR(M) do { __reg16(0x02)/* * off-CPU FPGA PIC operations */ -static void frv_fpga_enable (unsigned int irq) +static void frv_fpga_mask (unsigned int irq) {uint16_t imr =__get_IMR (); - imr &= ~(1 << (irq -IRQ_BASE_FPGA )); - + imr |=1 << (irq -IRQ_BASE_FPGA );__set_IMR (imr); } -static void frv_fpga_disable (unsigned int irq) +static void frv_fpga_ack (unsigned int irq) +{ +__clr_IFR (1 << (irq -IRQ_BASE_FPGA )); +} + +static void frv_fpga_mask_ack (unsigned int irq) {uint16_t imr =__get_IMR (); imr |=1 << (irq -IRQ_BASE_FPGA ); -__set_IMR (imr); -} -static void frv_fpga_ack (unsigned int irq) -{__clr_IFR (1 << (irq -IRQ_BASE_FPGA )); } -static void frv_fpga_end (unsigned int irq) +static void frv_fpga_unmask (unsigned int irq) { +uint16_t imr =__get_IMR (); + + imr &= ~(1 << (irq -IRQ_BASE_FPGA )); + +__set_IMR (imr); }static struct irq_chip frv_fpga_pic = { .name ="mb93093" , - .enable = frv_fpga_enable, - .disable = frv_fpga_disable, .ack = frv_fpga_ack, - .mask = frv_fpga_disable, - .unmask = frv_fpga_enable, + .mask = frv_fpga_mask, + .mask_ack = frv_fpga_mask_ack, + .unmask = frv_fpga_unmask, .end = frv_fpga_end, };
@@ -78,7 +82,6 @@ static struct irq_chip frv_fpga_pic = {static irqreturn_t fpga_interrupt (int irq,void *_mask,struct pt_regs *regs) {uint16_t imr, mask = (unsigned long ) _mask; -irqreturn_t iret =0 ; imr =__get_IMR (); mask = mask & ~imr &__get_IFR ();
@@ -91,11 +94,10 @@ static irqreturn_t fpga_interrupt(int ir irq =31 - irq; mask &= ~(1 << irq); -if (__do_IRQ (IRQ_BASE_FPGA + irq, regs)) - iret |=IRQ_HANDLED ; +generic_irq_handle (IRQ_BASE_FPGA + irq, regs); } -return iret; +return IRQ_HANDLED ; }/*
arch/frv/kernel/irq-mb93493.c +14 -21
@@ -43,8 +43,9 @@ #define IRQ_ROUTING \/* * daughter board PIC operations +* - there is no way to ACK interrupts in the MB93493 chip */ -static void frv_mb93493_enable (unsigned int irq) +static void frv_mb93493_mask (unsigned int irq) {uint32_t iqsr;volatile void *piqsr;
@@ -55,11 +56,15 @@ static void frv_mb93493_enable(unsigned piqsr =__addr_MB93493_IQSR (0 ); iqsr =readl (piqsr); - iqsr |=1 << (irq -IRQ_BASE_MB93493 +16 ); + iqsr &= ~(1 << (irq -IRQ_BASE_MB93493 +16 ));writel (iqsr, piqsr); } -static void frv_mb93493_disable (unsigned int irq) +static void frv_mb93493_ack (unsigned int irq) +{ +} + +static void frv_mb93493_unmask (unsigned int irq) {uint32_t iqsr;volatile void *piqsr;
@@ -70,26 +75,16 @@ static void frv_mb93493_disable(unsigned piqsr =__addr_MB93493_IQSR (0 ); iqsr =readl (piqsr); - iqsr &= ~(1 << (irq -IRQ_BASE_MB93493 +16 )); + iqsr |=1 << (irq -IRQ_BASE_MB93493 +16 );writel (iqsr, piqsr); } -static void frv_mb93493_ack (unsigned int irq) -{ -} - -static void frv_mb93493_end (unsigned int irq) -{ -} -static struct irq_chip frv_mb93493_pic = { .name ="mb93093" , - .enable = frv_mb93493_enable, - .disable = frv_mb93493_disable, .ack = frv_mb93493_ack, - .mask = frv_mb93493_disable, - .unmask = frv_mb93493_enable, - .end = frv_mb93493_end, + .mask = frv_mb93493_mask, + .mask_ack = frv_mb93493_mask, + .unmask = frv_mb93493_unmask, };/*
@@ -98,7 +93,6 @@ static struct irq_chip frv_mb93493_pic =static irqreturn_t mb93493_interrupt (int irq,void *_piqsr,struct pt_regs *regs) {volatile void *piqsr = _piqsr; -irqreturn_t iret =0 ;uint32_t iqsr; iqsr =readl (piqsr);
@@ -112,11 +106,10 @@ static irqreturn_t mb93493_interrupt(int irq =31 - irq; iqsr &= ~(1 << irq); -if (__do_IRQ (IRQ_BASE_MB93493 + irq, regs)) - iret |=IRQ_HANDLED ; +generic_handle_irq (IRQ_BASE_MB93493 + irq, regs); } -return iret; +return IRQ_HANDLED ; }/*
arch/frv/kernel/irq.c +1 -14
@@ -97,19 +97,8 @@ int show_interrupts(struct seq_file *p,/* * on-CPU PIC operations */ -static void frv_cpupic_enable (unsigned int irqlevel) -{ -__clr_MASK (irqlevel); -} - -static void frv_cpupic_disable (unsigned int irqlevel) -{ -__set_MASK (irqlevel); -} -static void frv_cpupic_ack (unsigned int irqlevel) { -__set_MASK (irqlevel);__clr_RC (irqlevel);__clr_IRL (); }
@@ -138,8 +127,6 @@ static void frv_cpupic_end(unsigned intstatic struct irq_chip frv_cpu_pic = { .name ="cpu" , - .enable = frv_cpupic_enable, - .disable = frv_cpupic_disable, .ack = frv_cpupic_ack, .mask = frv_cpupic_mask, .mask_ack = frv_cpupic_mask_ack,
@@ -156,7 +143,7 @@ static struct irq_chip frv_cpu_pic = { asmlinkage void do_IRQ(void) {irq_enter (); -__do_IRQ (__get_IRL (), __frame); +generic_handle_irq (__get_IRL (), __frame);irq_exit (); }
PATCH 2/3 FRV: Permit __do_IRQ() to be dispensed with
From: David Howells <[email protected]>
Permit __do_IRQ() to be dispensed with based on a configuration option.
---
arch/frv/Kconfig | 4 ++++ include/linux/irq.h | 6 ++++++ kernel/irq/handle.c | 2 ++ 3 files changed, 12 insertions(+), 0 deletions(-)
arch/frv/Kconfig +4 -0
@@ -29,6 +29,10 @@ config GENERIC_HARDIRQS bool default y +config GENERIC_HARDIRQS_NO__DO_IRQ + bool + default y + config GENERIC_TIME bool default y
include/linux/irq.h +6 -0
@@ -320,7 +320,9 @@ handle_irq_name(void fastcall (*handle)(* Monolithic do_IRQ implementation. * (is an explicit fastcall, because i386 4KSTACKS calls it from assembly) */ +#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs); +#endif /* * Architectures call this to let the generic IRQ layer
@@ -332,10 +334,14 @@ static inline void generic_handle_irq(un {struct irq_desc *desc = irq_desc + irq; +#ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ + desc->handle_irq (irq, desc, regs); +#else if (likely (desc->handle_irq)) desc->handle_irq (irq, desc, regs);else __do_IRQ (irq, regs); +#endif }/* Handling of unhandled and spurious interrupts: */
kernel/irq/handle.c +2 -0
@@ -149,6 +149,7 @@ irqreturn_t handle_IRQ_event(unsigned inreturn retval; } +#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ /** * __do_IRQ - original all in one highlevel IRQ handler * @irq: the interrupt number
@@ -248,6 +249,7 @@ out: return 1; } +#endif #ifdef CONFIG_TRACE_IRQFLAGS
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
include/linux/irq.h static inline void generic_handle_irq(un
Quoted 5 lines · David Howells
include/linux/irq.h +3
-0+#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ +#ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ +#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
I think the myriad of arch switches and the resulting #ifdef noise, just to get rid of a _single_ unused global function, is pretty lame. (and that's of course not your fault)
The real solution would be to use gcc -ffunction-sections plus ld --gc-sections to automatically get rid of unused global functions, at link time. I'm wondering how hard it would be to enhance kbuild to do that - x86_64 already uses -ffunction-sections (if CONFIG_REORDER), so the big question is how usable is ld --gc-sections. Such a feature would be quite important for embedded systems (and for RAM footprint in general) as it would save a significant amount of .text and .data.
Ingo
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
Quoted 12 lines · Ingo Molnar
include/linux/irq.h static inline void generic_handle_irq(un
Quoted 5 lines · David Howells
include/linux/irq.h +3
-0+#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ +#ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ +#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ I think the myriad of arch switches and the resulting #ifdef noise, just to get rid of a _single_ unused global function, is pretty lame. (and that's of course not your fault)
Quoted 7 lines
The real solution would be to use gcc -ffunction-sections plus ld --gc-sections to automatically get rid of unused global functions, at link time. I'm wondering how hard it would be to enhance kbuild to do that -
x86_64already uses -ffunction-sections (ifCONFIG_REORDER), so the big question is how usable is ld --gc-sections. Such a feature would be quite important for embedded systems (and for RAM footprint in general) as it would save a significant amount of .text and .data.
It can't optimize __do_IRQ() out in any case if one uses generic_handle_irq() because of the test in there which can't be predicted at compile time. My fault ... Maybe we should go back to having generic_handle_irq() not do the NULL test and not call __do_IRQ() and have another generic_handle_irq_compat() or some stupid name like that do what the current generic_handle_irq() does. I added that to handle the case of partial conversion (which we still have to deal with on powerpc as arch/ppc hasn't been converted).
Ben.
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
Quoted 3 lines · Benjamin Herrenschmidt
It can't optimize
__do_IRQ()out in any case if one usesgeneric_handle_irq()because of the test in there which can't be predicted at compile time.
Do you realise that powerpc still uses __do_IRQ if CONFIG_IRQSTACKS=y? You should probably fix that.
David
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
Quoted 8 lines · David Howells
Quoted 3 lines · Benjamin Herrenschmidt
It can't optimize
__do_IRQ()out in any case if one usesgeneric_handle_irq()because of the test in there which can't be predicted at compile time.Do you realise that powerpc still uses
__do_IRQifCONFIG_IRQSTACKS=y? You should probably fix that.
At the moment, there is no hurry as this code is shared with arch/ppc which hasn't been ported to genirq, so we need to handle both cases. (Though I'm not sure we ever get CONFIG_IRQSTACKS with arch/ppc ... I should probably check). The code uses desc->handle_irq and falls back to __do_IRQ() if that is NULL.
Ben.
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
In reply to Ingo MolnarQuoted 7 lines · Ingo Molnar
The real solution would be to use gcc -ffunction-sections plus ld --gc-sections to automatically get rid of unused global functions, at link time. I'm wondering how hard it would be to enhance kbuild to do that -
x86_64already uses -ffunction-sections (ifCONFIG_REORDER), so the big question is how usable is ld --gc-sections. Such a feature would be quite important for embedded systems (and for RAM footprint in general) as it would save a significant amount of .text and .data.
A patch to do this was submitted already by Marcelo Tosatti ..
http://lkml.org/lkml/2006/6/4/169
Daniel
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
Quoted 10 lines · Daniel Walker
Quoted 7 lines · Ingo Molnar
The real solution would be to use gcc -ffunction-sections plus ld --gc-sections to automatically get rid of unused global functions, at link time. I'm wondering how hard it would be to enhance kbuild to do that -
x86_64already uses -ffunction-sections (ifCONFIG_REORDER), so the big question is how usable is ld --gc-sections. Such a feature would be quite important for embedded systems (and for RAM footprint in general) as it would save a significant amount of .text and .data.
Quoted 3 lines
A patch to do this was submitted already by Marcelo Tosatti ..
ah, i missed that patch in the June lock validator frenzy. The results are astounding:
Quoted 1 line
Quoted 1 line
vmlinux shrinks from 1090389 to 983933 bytes, or 106k (~= 10%).
Andrew, Linus, Kai, Sam: a must-have feature! This saves more kernel kernel image RAM than all the other kernel shrinking efforts of the past 2 years combined - at zero cost.
Ingo
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
In reply to Ingo MolnarQuoted 3 lines · Ingo Molnar
The real solution would be to use gcc -ffunction-sections plus ld --gc-sections to automatically get rid of unused global functions, at link time.
It's easy. It's already possible with FRV. Just add the attached patch and enable the new option. However, you also need to compile without debugging code, otherwise it has little effect. I think stabs links bring stuff in or something.
David
---
arch/frv/Kconfig +8 -0
@@ -342,6 +342,14 @@ menu "Power management options" source kernel/power/Kconfig endmenu +config GC_SECTIONS + bool "Garbage collect unused functions and data" + default y + help + Tell the compiler to place all functions and variables in their own + sections and then tell the linker to discard any section that aren't + referred to. + endmenu
Re: [PATCH 2/3] FRV: Permit __do_IRQ() to be dispensed with
Quoted 11 lines · David Howells
Quoted 3 lines · Ingo Molnar
The real solution would be to use gcc -ffunction-sections plus ld --gc-sections to automatically get rid of unused global functions, at link time.
It's easy. It's already possible with FRV. Just add the attached patch and enable the new option. However, you also need to compile without debugging code, otherwise it has little effect. I think stabs links bring stuff in or something.
It's a wide spread problem so I think something more generic is appropriate.
Does the code in Marcelo's patch make sense for FRV, or vis-versa?
Daniel
PATCH 3/3 FRV: Mark __do_IRQ() deprecated
In reply to David HowellsFrom: David Howells <[email protected]>
Mark __do_IRQ() as being deprecated (as Ben Herrenschmidt says it is).
Rename the real __do_IRQ() to __do_IRQ_deprecated() and wrap this in an inline function called __do_IRQ() that is deprecated to prevent generic_handle_irq() from giving deprecation warnings on every file.
---
include/linux/irq.h | 11 +++++++++-- kernel/irq/handle.c | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-)
include/linux/irq.h +9 -2
@@ -319,9 +319,16 @@ handle_irq_name(void fastcall (*handle)(/* * Monolithic do_IRQ implementation. * (is an explicit fastcall, because i386 4KSTACKS calls it from assembly) +* - This is obsolete; generic_handle_irq() should be used instead. */ #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ -extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs); +extern fastcall unsigned int __do_IRQ_deprecated(unsigned int irq, struct pt_regs *regs); + +static inline __deprecated fastcall +unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs) +{ +return __do_IRQ_deprecated (irq, regs); +}#endif /*
@@ -340,7 +347,7 @@ #elseif (likely (desc->handle_irq)) desc->handle_irq (irq, desc, regs);else -__do_IRQ (irq, regs); +__do_IRQ_deprecated (irq, regs);#endif }
kernel/irq/handle.c +4 -2
@@ -151,7 +151,7 @@ irqreturn_t handle_IRQ_event(unsigned in#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ /** -* __do_IRQ - original all in one highlevel IRQ handler +* __do_IRQ_deprecated - original all in one highlevel IRQ handler * @irq: the interrupt number * @regs: pointer to a register structure *
@@ -161,8 +161,10 @@ #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_I* * This is the original x86 implementation which is used for every * interrupt type. +* +* This is obsolete; generic_handle_irq() should be used instead. */ -fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs) +fastcall unsigned int __do_IRQ_deprecated(unsigned int irq, struct pt_regs *regs) {struct irq_desc *desc = irq_desc + irq;struct irqaction *action;