Skip to content

Commit

Permalink
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Browse files Browse the repository at this point in the history
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.

The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around.  On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).

Where appropriate, an arch may override the generic storage facility and do
something different with the variable.  On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.

Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions.  Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller.  A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.

I've build this code with allyesconfig for x86_64 and i386.  I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.

This will affect all archs.  Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:

	struct pt_regs *old_regs = set_irq_regs(regs);

And put the old one back at the end:

	set_irq_regs(old_regs);

Don't pass regs through to generic_handle_irq() or __do_IRQ().

In timer_interrupt(), this sort of change will be necessary:

	-	update_process_times(user_mode(regs));
	-	profile_tick(CPU_PROFILING, regs);
	+	update_process_times(user_mode(get_irq_regs()));
	+	profile_tick(CPU_PROFILING);

I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().

Some notes on the interrupt handling in the drivers:

 (*) input_dev() is now gone entirely.  The regs pointer is no longer stored in
     the input_dev struct.

 (*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking.  It does
     something different depending on whether it's been supplied with a regs
     pointer or not.

 (*) Various IRQ handler function pointers have been moved to type
     irq_handler_t.

Signed-Off-By: David Howells <[email protected]>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
  • Loading branch information
dhowells authored and David Howells committed Oct 5, 2006
1 parent da48279 commit 7d12e78
Show file tree
Hide file tree
Showing 1,079 changed files with 2,621 additions and 2,976 deletions.
5 changes: 2 additions & 3 deletions arch/frv/kernel/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@ unsigned long frv_dma_inprogress;
/*
* DMA irq handler - determine channel involved, grab status and call real handler
*/
static irqreturn_t dma_irq_handler(int irq, void *_channel, struct pt_regs *regs)
static irqreturn_t dma_irq_handler(int irq, void *_channel)
{
struct frv_dma_channel *channel = _channel;

frv_clear_dma_inprogress(channel - frv_dma_channels);
return channel->handler(channel - frv_dma_channels,
__get_DMAC(channel->ioaddr, CSTR),
channel->data,
regs);
channel->data);

} /* end dma_irq_handler() */

Expand Down
4 changes: 2 additions & 2 deletions arch/frv/kernel/irq-mb93091.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static struct irq_chip frv_fpga_pic = {
/*
* FPGA PIC interrupt handler
*/
static irqreturn_t fpga_interrupt(int irq, void *_mask, struct pt_regs *regs)
static irqreturn_t fpga_interrupt(int irq, void *_mask)
{
uint16_t imr, mask = (unsigned long) _mask;

Expand All @@ -95,7 +95,7 @@ static irqreturn_t fpga_interrupt(int irq, void *_mask, struct pt_regs *regs)
irq = 31 - irq;
mask &= ~(1 << irq);

generic_handle_irq(IRQ_BASE_FPGA + irq, regs);
generic_handle_irq(IRQ_BASE_FPGA + irq);
}

return IRQ_HANDLED;
Expand Down
4 changes: 2 additions & 2 deletions arch/frv/kernel/irq-mb93093.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static struct irq_chip frv_fpga_pic = {
/*
* FPGA PIC interrupt handler
*/
static irqreturn_t fpga_interrupt(int irq, void *_mask, struct pt_regs *regs)
static irqreturn_t fpga_interrupt(int irq, void *_mask)
{
uint16_t imr, mask = (unsigned long) _mask;

Expand All @@ -94,7 +94,7 @@ static irqreturn_t fpga_interrupt(int irq, void *_mask, struct pt_regs *regs)
irq = 31 - irq;
mask &= ~(1 << irq);

generic_irq_handle(IRQ_BASE_FPGA + irq, regs);
generic_irq_handle(IRQ_BASE_FPGA + irq);
}

return IRQ_HANDLED;
Expand Down
4 changes: 2 additions & 2 deletions arch/frv/kernel/irq-mb93493.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static struct irq_chip frv_mb93493_pic = {
/*
* MB93493 PIC interrupt handler
*/
static irqreturn_t mb93493_interrupt(int irq, void *_piqsr, struct pt_regs *regs)
static irqreturn_t mb93493_interrupt(int irq, void *_piqsr)
{
volatile void *piqsr = _piqsr;
uint32_t iqsr;
Expand All @@ -106,7 +106,7 @@ static irqreturn_t mb93493_interrupt(int irq, void *_piqsr, struct pt_regs *regs
irq = 31 - irq;
iqsr &= ~(1 << irq);

generic_handle_irq(IRQ_BASE_MB93493 + irq, regs);
generic_handle_irq(IRQ_BASE_MB93493 + irq);
}

return IRQ_HANDLED;
Expand Down
2 changes: 1 addition & 1 deletion arch/frv/kernel/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static struct irq_chip frv_cpu_pic = {
asmlinkage void do_IRQ(void)
{
irq_enter();
generic_handle_irq(__get_IRL(), __frame);
generic_handle_irq(__get_IRL());
irq_exit();
}

Expand Down
8 changes: 4 additions & 4 deletions arch/frv/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ unsigned long __nongprelbss __dsu_clock_speed_HZ;
unsigned long __nongprelbss __serial_clock_speed_HZ;
unsigned long __delay_loops_MHz;

static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs *regs);
static irqreturn_t timer_interrupt(int irq, void *dummy);

static struct irqaction timer_irq = {
timer_interrupt, IRQF_DISABLED, CPU_MASK_NONE, "timer", NULL, NULL
Expand All @@ -55,7 +55,7 @@ static inline int set_rtc_mmss(unsigned long nowtime)
* timer_interrupt() needs to keep up the real-time clock,
* as well as call the "do_timer()" routine every clocktick
*/
static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
static irqreturn_t timer_interrupt(int irq, void *dummy)
{
/* last time the cmos clock got updated */
static long last_rtc_update = 0;
Expand All @@ -70,8 +70,8 @@ static irqreturn_t timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
write_seqlock(&xtime_lock);

do_timer(1);
update_process_times(user_mode(regs));
profile_tick(CPU_PROFILING, regs);
update_process_times(user_mode(get_irq_regs()));
profile_tick(CPU_PROFILING);

/*
* If we have an externally synchronized Linux clock, then update
Expand Down
18 changes: 10 additions & 8 deletions arch/i386/kernel/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,11 +1193,11 @@ EXPORT_SYMBOL(switch_ipi_to_APIC_timer);
* value into /proc/profile.
*/

inline void smp_local_timer_interrupt(struct pt_regs * regs)
inline void smp_local_timer_interrupt(void)
{
profile_tick(CPU_PROFILING, regs);
profile_tick(CPU_PROFILING);
#ifdef CONFIG_SMP
update_process_times(user_mode_vm(regs));
update_process_times(user_mode_vm(irq_regs));
#endif

/*
Expand All @@ -1223,6 +1223,7 @@ inline void smp_local_timer_interrupt(struct pt_regs * regs)

fastcall void smp_apic_timer_interrupt(struct pt_regs *regs)
{
struct pt_regs *old_regs = set_irq_regs(regs);
int cpu = smp_processor_id();

/*
Expand All @@ -1241,12 +1242,13 @@ fastcall void smp_apic_timer_interrupt(struct pt_regs *regs)
* interrupt lock, which is the WrongThing (tm) to do.
*/
irq_enter();
smp_local_timer_interrupt(regs);
smp_local_timer_interrupt();
irq_exit();
set_irq_regs(old_regs);
}

#ifndef CONFIG_SMP
static void up_apic_timer_interrupt_call(struct pt_regs *regs)
static void up_apic_timer_interrupt_call(void)
{
int cpu = smp_processor_id();

Expand All @@ -1255,11 +1257,11 @@ static void up_apic_timer_interrupt_call(struct pt_regs *regs)
*/
per_cpu(irq_stat, cpu).apic_timer_irqs++;

smp_local_timer_interrupt(regs);
smp_local_timer_interrupt();
}
#endif

void smp_send_timer_broadcast_ipi(struct pt_regs *regs)
void smp_send_timer_broadcast_ipi(void)
{
cpumask_t mask;

Expand All @@ -1272,7 +1274,7 @@ void smp_send_timer_broadcast_ipi(struct pt_regs *regs)
* We can directly call the apic timer interrupt handler
* in UP case. Minus all irq related functions
*/
up_apic_timer_interrupt_call(regs);
up_apic_timer_interrupt_call();
#endif
}
}
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/kernel/i8259.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ void init_8259A(int auto_eoi)
*/


static irqreturn_t math_error_irq(int cpl, void *dev_id, struct pt_regs *regs)
static irqreturn_t math_error_irq(int cpl, void *dev_id)
{
extern void math_error(void __user *);
outb(0,0xF0);
if (ignore_fpu_irq || !boot_cpu_data.hard_math)
return IRQ_NONE;
math_error((void __user *)regs->eip);
math_error((void __user *)get_irq_regs()->eip);
return IRQ_HANDLED;
}

Expand Down
12 changes: 7 additions & 5 deletions arch/i386/kernel/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
*/
fastcall unsigned int do_IRQ(struct pt_regs *regs)
{
struct pt_regs *old_regs;
/* high bit used in ret_from_ code */
int irq = ~regs->orig_eax;
struct irq_desc *desc = irq_desc + irq;
Expand All @@ -67,6 +68,7 @@ fastcall unsigned int do_IRQ(struct pt_regs *regs)
BUG();
}

old_regs = set_irq_regs(regs);
irq_enter();
#ifdef CONFIG_DEBUG_STACKOVERFLOW
/* Debugging check for stack overflow: is there less than 1KB free? */
Expand Down Expand Up @@ -95,7 +97,7 @@ fastcall unsigned int do_IRQ(struct pt_regs *regs)
* current stack (which is the irq stack already after all)
*/
if (curctx != irqctx) {
int arg1, arg2, arg3, ebx;
int arg1, arg2, ebx;

/* build the stack frame on the IRQ stack */
isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
Expand All @@ -114,17 +116,17 @@ fastcall unsigned int do_IRQ(struct pt_regs *regs)
" xchgl %%ebx,%%esp \n"
" call *%%edi \n"
" movl %%ebx,%%esp \n"
: "=a" (arg1), "=d" (arg2), "=c" (arg3), "=b" (ebx)
: "0" (irq), "1" (desc), "2" (regs), "3" (isp),
: "=a" (arg1), "=d" (arg2), "=b" (ebx)
: "0" (irq), "1" (desc), "2" (isp),
"D" (desc->handle_irq)
: "memory", "cc"
);
} else
#endif
desc->handle_irq(irq, desc, regs);
desc->handle_irq(irq, desc);

irq_exit();

set_irq_regs(old_regs);
return 1;
}

Expand Down
6 changes: 6 additions & 0 deletions arch/i386/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ static inline void leave_mm (unsigned long cpu)

fastcall void smp_invalidate_interrupt(struct pt_regs *regs)
{
struct pt_regs *old_regs = set_irq_regs(regs);
unsigned long cpu;

cpu = get_cpu();
Expand Down Expand Up @@ -351,6 +352,7 @@ fastcall void smp_invalidate_interrupt(struct pt_regs *regs)
smp_mb__after_clear_bit();
out:
put_cpu_no_resched();
set_irq_regs(old_regs);
}

static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
Expand Down Expand Up @@ -605,11 +607,14 @@ void smp_send_stop(void)
*/
fastcall void smp_reschedule_interrupt(struct pt_regs *regs)
{
struct pt_regs *old_regs = set_irq_regs(regs);
ack_APIC_irq();
set_irq_regs(old_regs);
}

fastcall void smp_call_function_interrupt(struct pt_regs *regs)
{
struct pt_regs *old_regs = set_irq_regs(regs);
void (*func) (void *info) = call_data->func;
void *info = call_data->info;
int wait = call_data->wait;
Expand All @@ -632,6 +637,7 @@ fastcall void smp_call_function_interrupt(struct pt_regs *regs)
mb();
atomic_inc(&call_data->finished);
}
set_irq_regs(old_regs);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions arch/i386/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ EXPORT_SYMBOL(profile_pc);
* Time Stamp Counter value at the time of the timer interrupt, so that
* we later on can estimate the time of day more exactly.
*/
irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
irqreturn_t timer_interrupt(int irq, void *dev_id)
{
/*
* Here we are in the timer irq handler. We just have irqs locally
Expand All @@ -188,7 +188,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
}
#endif

do_timer_interrupt_hook(regs);
do_timer_interrupt_hook();


if (MCA_bus) {
Expand All @@ -209,7 +209,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)

#ifdef CONFIG_X86_LOCAL_APIC
if (using_apic_timer)
smp_send_timer_broadcast_ipi(regs);
smp_send_timer_broadcast_ipi();
#endif

return IRQ_HANDLED;
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/kernel/time_hpet.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ int hpet_rtc_dropped_irq(void)
return 1;
}

irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
{
struct rtc_time curr_time;
unsigned long rtc_int_flag = 0;
Expand Down Expand Up @@ -480,7 +480,7 @@ irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
}
if (call_rtc_interrupt) {
rtc_int_flag |= (RTC_IRQF | (RTC_NUM_INTS << 8));
rtc_interrupt(rtc_int_flag, dev_id, regs);
rtc_interrupt(rtc_int_flag, dev_id);
}
return IRQ_HANDLED;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/i386/kernel/vm86.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ static int irqbits;
| (1 << SIGUSR1) | (1 << SIGUSR2) | (1 << SIGIO) | (1 << SIGURG) \
| (1 << SIGUNUSED) )

static irqreturn_t irq_handler(int intno, void *dev_id, struct pt_regs * regs)
static irqreturn_t irq_handler(int intno, void *dev_id)
{
int irq_bit;
unsigned long flags;
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/mach-visws/visws_apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static struct hw_interrupt_type piix4_virtual_irq_type = {
* enable_irq gets the right irq. This 'master' irq is never directly
* manipulated by any driver.
*/
static irqreturn_t piix4_master_intr(int irq, void *dev_id, struct pt_regs * regs)
static irqreturn_t piix4_master_intr(int irq, void *dev_id)
{
int realirq;
irq_desc_t *desc;
Expand Down Expand Up @@ -244,7 +244,7 @@ static irqreturn_t piix4_master_intr(int irq, void *dev_id, struct pt_regs * reg
kstat_cpu(smp_processor_id()).irqs[realirq]++;

if (likely(desc->action != NULL))
handle_IRQ_event(realirq, regs, desc->action);
handle_IRQ_event(realirq, desc->action);

if (!(desc->status & IRQ_DISABLED))
enable_8259A_irq(realirq);
Expand Down
2 changes: 1 addition & 1 deletion arch/i386/mach-voyager/voyager_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ voyager_detect(struct voyager_bios_info *bios)
}

void
voyager_system_interrupt(int cpl, void *dev_id, struct pt_regs *regs)
voyager_system_interrupt(int cpl, void *dev_id)
{
printk("Voyager: detected system interrupt\n");
}
Expand Down
Loading

0 comments on commit 7d12e78

Please sign in to comment.