Kernel Interrupts – Do System Calls Interrupt CPU Like Hardware Interrupts?

interruptkernel

I'm trying to get a deeper understanding of how system calls and hardware interrupts are implemented, and something that keeps confusing me is how they differ with respect to how they're handled. For example, I am aware that one way a system call (at least used to) be initiated is through the x86 INT 0x80 instruction.

  1. Does the processor handle this the exact same way as if, say, a hardware peripheral would have interrupted the CPU? If not, at what point do they differ? My understanding is they both index the IDT, just with different indices in the vector.

  2. In that same sense, my understanding is there's this idea of a softirq to handle the "bottom half" processing, but I only see this form of "software interrupt" in reference to being enqueued to run by physical hardware interrupts. Do system call "software interrupts" also trigger softirqs for processing? That terminology confuses me a bit as well, as I've seen people refer to system calls as "software interrupts" yet softirqs as "software interrupts" as well.

Best Answer

INT 0x80h is an old way to call kernel services (system functions). Currently, syscalls are used to invoke these services as they are faster than calling the interrupt. You can check this mapping in kernel's Interrupt Descriptor Table idt.c and in line 50 in the irq_vectors.h file.

The important bit that I believe answers your question is the header of that last file, where you can see how interrupt requests (IRQs) are organized.

 This is the general layout of the IDT entries: 
   Vectors   0 ...  31 : system traps and exceptions - hardcoded events
   Vectors  32 ... 127 : device interrupts
   Vector  128         : legacy int80 syscall interface
   Vectors 129 ... INVALIDATE_TLB_VECTOR_START-1 except 204 : device interrupts
   Vectors INVALIDATE_TLB_VECTOR_START ... 255 : special interrupts

It really does not matter if it is by electrical means or software means. Whenever an interrupt is triggered, the kernel looks for its ID in the IDT and runs (in kernel mode) the associated interrupt handler. As they have to be really fast, they normally set some info to be handled later on by a softirq or a tasklet. Read chapter 2 (fast read...) of the Unreliable Guide To Hacking The Linux Kernel

Let me recommend also reading this really good and thorough answer at stackoverflow to Intel x86 vs x64 system call question, where INT 0x80h, sysenter and syscall are put in context...

I wrote my own (so very modest and still under construction) self learning page about interrupts and signals to help me understand the relation of signals and traps with interrupts (for instance SIGFPE - divide by zero).