Re: system call overheads

Brian Gerst (bgerst@quark.vpplus.com)
Thu, 14 Jan 1999 05:48:17 -0500


Robert Fish wrote:
> I have scoured the web trying to find out what happens in the
> time between an application issuing the "int 0x80" instruction and the
> execution of the system call handler (system_call in
> /usr/src/linux/arch/i386/kernel/entry.S).
>
> What happens before the kernel side (system_call) handler gets called ???

Essentially what happens is that the processor executes an interrupt
gate. It loads the gate descriptor from the Interrupt Descriptor Table
(requires memory access), validates the code segment and stack segment
values stored within, pushes some registers onto the kernel stack
(usually, esp, ss, eflags, cs, and eip, depending on which mode the
processor was in before the int), then jumps to the address defined in
the gate descriptor (system_call).

Later Pentium Pro's, Pentium II's, and K6's support a new instruction
called sysenter (syscall on the K6), which allow a faster entry into
ring 0, based on the assumptions that user mode and kernel mode code and
stack segments are flat (base=0, limit=4GB). Linux since early 2.1.x
has had this type of memory layout. This skips alot of the overhead
involved with using an interrupt or call gate, as the segments are not
validated (they are assumed to be correct as set up by the OS), and
nothing is pushed onto the stack. The new cs, ss, and eip are stored in
an MSR inside the cpu, so no memory access is need to get those like
with a gate.

Some good places to look for information on this:
http://www.sandpile.org
http://developer.intel.com/design/pentiumii/manuals
http://www.amd.com/K6/k6docs

I am experimenting with syscall support on my K6 and hope to have some
experimental patches available in the near future. From what I've seen
of syscall and sysenter, the two are similar enough that my patches
should be easily modified for sysenter support.

-- 

Brian Gerst

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/