RE: [Fault-injection-developer] RFC: KIRQ
Status: Alpha
Brought to you by:
rustyl
From: Wang, S. <sta...@in...> - 2002-12-21 10:36:31
|
Thanks for your careful review and helpful comments :) I will apply your comments to the code:) -Stan > -----Original Message----- > From: Rusty Lynch [mailto:ru...@li...] > Sent: 2002=C4=EA12=D4=C221=C8=D5 1:31 > To: Wang, Stanley; fau...@li... > Subject: Re: [Fault-injection-developer] RFC: KIRQ >=20 >=20 > > Hi, folks > > I revised the KIRQ according to Rusty's comment. > >=20 > > # This is a BitKeeper generated patch for the following project: > > # Project Name: Linux kernel tree > > # This patch format is intended for GNU patch command=20 > version 2.5 or higher. > > # This patch includes the following deltas: > > # ChangeSet 1.901 -> 1.902 =20 > > # arch/i386/Kconfig 1.14 -> 1.16 =20 > > # arch/i386/kernel/Makefile 1.31 -> 1.32 =20 > > # (new) -> 1.4 arch/i386/kernel/kirq.c > > # (new) -> 1.3 include/asm-i386/kirq.h > > # > > # The following is the BitKeeper ChangeSet Log > > # -------------------------------------------- > > # 02/12/20 st...@ma... 1.892.1.3 > > # Refine config file. > > # -------------------------------------------- > > # 02/12/20 st...@ma... 1.902 > > # Merge manticore.sh.intel.com:/home/stanley/linux-2.5 > > # into manticore.sh.intel.com:/home/stanley/work/2.5-kirq > > # -------------------------------------------- > > # > > diff -Nru a/arch/i386/Kconfig b/arch/i386/Kconfig > > --- a/arch/i386/Kconfig Fri Dec 20 14:24:01 2002 > > +++ b/arch/i386/Kconfig Fri Dec 20 14:24:01 2002 > > @@ -1544,6 +1544,14 @@ > > best used in conjunction with the NMI watchdog so that spinlock > > deadlocks are also debuggable. > > =20 > > +config KIRQ > > + bool "Kernel Irq interceptor for X86(experimental)" > > + depends on DEBUG_KERNEL && EXPERIMENTAL > > + help > > + This option enable an IRQ interceptor. You can get the control > > + before any specified ISR is executing and decide whether it > > + should be executing through "register_kirq/unregister_kirq". > > + > > config DEBUG_HIGHMEM > > bool "Highmem debugging" > > depends on DEBUG_KERNEL && HIGHMEM > > diff -Nru a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile > > --- a/arch/i386/kernel/Makefile Fri Dec 20 14:24:01 2002 > > +++ b/arch/i386/kernel/Makefile Fri Dec 20 14:24:01 2002 > > @@ -4,7 +4,7 @@ > > =20 > > EXTRA_TARGETS :=3D head.o init_task.o > > =20 > > -export-objs :=3D mca.o i386_ksyms.o time.o > > +export-objs :=3D mca.o i386_ksyms.o time.o kirq.o > > =20 > > obj-y :=3D process.o semaphore.o signal.o entry.o traps.o=20 > irq.o vm86.o \ > > ptrace.o i8259.o ioport.o ldt.o setup.o time.o sys_i386.o \ > > @@ -29,6 +29,7 @@ > > obj-$(CONFIG_PROFILING) +=3D profile.o > > obj-$(CONFIG_EDD) +=3D edd.o > > obj-$(CONFIG_MODULES) +=3D module.o > > +obj-$(CONFIG_KIRQ) +=3D kirq.o > > obj-y +=3D sysenter.o > > =20 > > EXTRA_AFLAGS :=3D -traditional > > diff -Nru a/arch/i386/kernel/kirq.c b/arch/i386/kernel/kirq.c > > --- /dev/null Wed Dec 31 16:00:00 1969 > > +++ b/arch/i386/kernel/kirq.c Fri Dec 20 14:24:01 2002 > > @@ -0,0 +1,103 @@ > > +/* Support for kernel irq interceptor. > > + (C) 2002 Stanley Wang <sta...@in...>. > > +*/ > > + > > +#include <linux/config.h> > > +#include <linux/kernel.h> > > +#include <linux/module.h> > > +#include <linux/spinlock.h> > > +#include <linux/mm.h> > > +#include <linux/slab.h> > > +#include <linux/irq.h> > > +#include <linux/interrupt.h> > > +#include <asm/kirq.h> > > + > > +void kirq_handler(int irq, void *dev_id, struct pt_regs *regs) > > +{ > > + int i; > > + struct kirq *p =3D kirq_list + irq; > > + if (p->handler !=3D NULL){ > > + i =3D (*(p->handler))(p, irq, dev_id, regs); > > + if ( i =3D=3D 0 ) > > + (*(p->isr))(irq, dev_id, regs); > > + }else{ > > + printk(KERN_ERR "Miss KIRQ handler!\n"); >=20 > This might be a little too cryptic for a system admin > to figure out what is happening from the system log file. >=20 > How about: > printk(KERN_ERR "%s: Dropping unexpected interrupt #%i\n",=20 > __FUNCTION__, irq);=20 >=20 > > + } > > + return; > > +} > > + > > +int register_kirq(int irq, char *devname, kirq_handler_t handler) > > +{ > > + struct irqaction *action; > > + irq_desc_t *desc =3D irq_desc + irq; > > + struct kirq *p =3D kirq_list + irq; > > + unsigned long flags; > > +=20 > > + if (handler =3D=3D NULL) { > > + printk(KERN_ERR "Register KIRQ failed: Missing handler!\n"); > > + } > > + > > + if (p->handler) { > > + printk(KERN_ERR "Register KIRQ failed: KIRQ already > > exist!\n"); > > + } >=20 > Did you mean to return an error on the conditions above? >=20 > > +=20 > > + spin_lock_irqsave(&desc->lock,flags); > > +=20 > > + action =3D desc->action; > > + while (action) { > > + if (strcmp(action->name,devname)) { > > + action =3D action->next; > > + }else{ > > + break; > > + } > > + } > > + > > + if (!action) { > > + spin_unlock_irqrestore(&desc->lock,flags); > > + return -1;=20 > > + } > > + > > + p->isr =3D action->handler; > > + p->handler =3D handler; > > + p->dev_id =3D action->dev_id; > > +=20 > > + action->handler =3D kirq_handler; > > +=20 > > + spin_unlock_irqrestore(&desc->lock,flags); > > + > > + return 0; > > +} > > + > > +int unregister_kirq(int irq) > > +{ > > + struct irqaction *action; > > + irq_desc_t *desc =3D irq_desc + irq; > > + struct kirq *p =3D kirq_list + irq; > > + unsigned long flags; > > +=20 > > + spin_lock_irqsave(&desc->lock,flags); > > +=20 > > + action =3D desc->action; > > + while ( action && action->dev_id !=3D p->dev_id) { > > + action =3D action->next; > > + } > > + > > + if (!action) { > > + printk(KERN_ERR "Unregister KIRQ failed!\n"); > > + spin_unlock_irqrestore(&desc->lock,flags); > > + return -1; > > + } > > + > > + action->handler =3D p->isr; > > +=20 > > + p->isr =3D NULL; > > + p->handler =3D NULL; > > + p->dev_id =3D NULL; > > +=20 > > + spin_unlock_irqrestore(&desc->lock,flags); > > + > > + return 0; > > +} > > +EXPORT_SYMBOL_GPL(register_kirq); > > +EXPORT_SYMBOL_GPL(unregister_kirq); > > + > > diff -Nru a/include/asm-i386/kirq.h b/include/asm-i386/kirq.h > > --- /dev/null Wed Dec 31 16:00:00 1969 > > +++ b/include/asm-i386/kirq.h Fri Dec 20 14:24:01 2002 > > @@ -0,0 +1,28 @@ > > +#ifndef _ASM_KIRQ_H > > +#define _ASM_KIRQ_H > > + > > +#include <linux/errno.h> > > + > > +/* Define return value for kirq handler. */ > > +#define KIRQ_CONTINUE 0 > > +#define KIRQ_SKIP 1 > > + > > +struct kirq; > > +typedef int (*kirq_handler_t)(struct kirq *, int, void *,=20 > struct pt_regs > > *); > > +struct kirq { > > + void *dev_id; > > + void (*isr)(int, void *, struct pt_regs *); > > + kirq_handler_t handler; > > +}; > > + > > +struct kirq kirq_list[NR_IRQS] =3D > > + { [0 ... NR_IRQS-1] =3D { NULL, NULL, NULL}}; > > + > > +#ifdef CONFIG_KIRQ > > +extern int register_kirq(int irq, char *devname,=20 > kirq_handler_t handler); > > +extern int unregister_kirq(int irq); > > +#else > > +int register_kirq(int irq, char *devname, kirq_handler_t=20 > handler) { return > > -ENOSYS; } > > +int unregister_kirq(int irq) {} > > +#endif /*CONFIG_KIRQ*/ > > +#endif /*_ASM_KIRQ_H*/ > >=20 > > Your Sincerely, > > Stanley Wang=20 > >=20 > > SW Engineer, Intel Corporation. > > Intel China Software Lab.=20 > > Tel: 021-52574545 ext. 1171=20 > > iNet: 8-752-1171=20 > > =20 > > Opinions expressed are those of the author and do not=20 > represent Intel > > Corporation > >=20 > >=20 > > ------------------------------------------------------- > > This SF.NET email is sponsored by: Geek Gift Procrastinating? > > Get the perfect geek gift now! Before the Holidays pass you by. > > T H I N K G E E K . C O M http://www.thinkgeek.com/sf/ > > _______________________________________________ > > Fault-injection-developer mailing list > > Fau...@li... > >=20 https://lists.sourceforge.net/lists/listinfo/fault-injection-developer |