RE: Understanding Interrupts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Michael,

You are correct that interrupts are disable automatically when an
interrupt handler is accessed thru interrupt gate, but kernel re-enables
the interrupts in handle_IRQ_event() function. 

> Is this to protect the code before the
> handler from being interrupted? If so, why is this neccesary?

Actually when interrupt occures the offset field in the interrup gate
points to the function (MACRO written in assembly language) whose
pointer is saved in interrupt array (read the code in i8259.c). This
function pushes the negetive number (IRQ number - 256) (read the code at
http://lxr.linux.no/source/include/asm-i386/hw_irq.h?v=2.4.21#L175) on
the process specific kernel stack, which is the current stack at that
time, as current stack is switched from user space stack of process to
kernel space stack.

After pushing this number on stack this calls the do_IRQ() function
which actually first acquires the IRQ specific lock then acknowledges
the interrupt by setting the EOI bit on PIC and also make some changes
to the interrupt status (check the code of do_IRQ function at
http://lxr.linux.no/source/arch/i386/kernel/irq.c?v=2.4.21#L563). 

Once it is done it calls the handle_IRQ_event() function which actually
first disables the IRQ line by masking it on PIC and then re-enable the
interrupts by calling __sti() function. After doing this all the
handlers are called one by one and then while returning from this
function we again disables the interrupts as the calling functions
expects that.

Cheers !!
Gaurav



On Fri, 2004-10-01 at 17:23, mbrennan@xxxxxxxx wrote:
> Hello!
> 
> I'm reading Understanding the Linux Kernel, and I'm trying to
understand
> interrupts and exceptions properly. I wonder if I have understanded
this
> correctly, this is how I think it works, and I would appreciate if
someone
> could confirm that its right.
> 
> So, is this correct?
> 
> Linux's interrupts are interleaved, ie. they can be nested. That must
mean
> that interrupts are enabled when handling interrupts. Now the thing
that
> confuses me a little is that Linux uses interrupt gates, which clears
the
> IF flag, and disables interrupts. But it seems like Linux sets the IF
flag
> again before the actual handler. Is this to protect the code before
the
> handler from being interrupted? If so, why is this neccesary?
> 
> When interrupts are disabled by masking the maskable interrupts, does
that
> mean that the CPU ignores the signal on the INTR pin. And when a IRQ
is
> masked on the PIC, does that mean that the PIC doesn't send any
interrupt
> to the CPU when that IRQ is raised?
> In other words, the IF flag makes the CPU ignore all maskable
interrupts,
> while masking a particular IRQ, it prevents the interrupt from
reaching
> the CPU.
> 
> When executing an interrupt handler, maskable interrupts are enabled
but
> the IRQ of the interrupt is masked out. Other interrupts may interrupt
the
> execution, but not the same as the one currently executed?
> 
> Thank you!
> 
> /Michael
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux