Need help in understanding x86 syscall
I had this question. As per my understanding, in the Linux system call implementation on x86 architecture the call flows like this int 0x80 -> syscall -> sys_call_vector(taken from the table)-> return from interrupt service routine.
Now I had the doubt that if the the syscall implementation is very large will the scheduling and other interrupts be blocked for the whole time till the process returns from the ISR (because in an ISR by default the interrupts are disabled unless “sti” is called explicitly)? That’s appears to be too long for the scheduling or other interrupts to be blocked? Am I missing something here?
Thanks
Ukil
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Quoted 6 lines · Ukil a
I had this question. As per my understanding, in the Linux system call implementation on x86 architecture the call flows like this int
0x80-> syscall ->sys_call_vector(taken from the table)-> return from interrupt service routine.
Quoted 8 lines
Now I had the doubt that if the the syscall implementation is very large will the scheduling and other interrupts be blocked for the whole time till the process returns from the ISR (because in an ISR by default the interrupts are disabled unless “sti” is called explicitly)? That’s appears to be too long for the scheduling or other interrupts to be blocked? Am I missing something here?
This is where interrupt is not a good term for syscall. It is really a trap. An interrupt is an outside source that stops the CPU from doing what it was doing to go do something else (asynchronous event). A trap is something that the CPU calls on itself to do something else (synchronous event). So when a network packet comes in, the NIC sends an interrupt request (request since the CPU may not immediately handle it), and when the CPU is ready (interrupts on) it will stop what it is doing and handle the network packet.
When you do a system call, it is a trap. Quoting the Intel manual:
The difference between an interrupt gate and a trap gate is as follows. If an interrupt or exception handler is called through an interrupt gate, the processor clears the interrupt enable (IF) flag in the EFLAGS register to prevent subsequent interrupts from interfering with the execution of the handler. When a handler is called through a trap gate, the state of the IF flag is not changed.
So when you go into the kernel through a trap (system call) interrupts are still on if they were on to begin with, which is the case when coming from user mode. But when you come into the kernel through a real interrupt, then interrupts are off.
Also note that if you have preemption disabled, the system call will _not_ do any scheduling unless it explicitly calls schedule. If you turn on voluntary preempt, it will call schedule at various spots in the kernel that might call schedule anyway. If you turn on full preemption, then the process can be scheduled out anywhere in the kernel unless it explicitly says it doesn't want to (preempt_disable or spin_lock).
-- Steve
Quoted 7 lines · Ukil a
I had this question. As per my understanding, in the Linux system call implementation on x86 architecture the call flows like this int
0x80-> syscall ->sys_call_vector(taken from the table)-> return from interrupt service routine.
Almost. There are two entry points, the one you describe above, and the sysenter entry point.
Quoted 9 lines
Now I had the doubt that if the the syscall
implementation is very large will the scheduling and
other interrupts be blocked for the whole time till
the process returns from the ISR (because in an ISR by
default the interrupts are disabled unless “sti” is
called explicitly)? That’s appears to be too long for
the scheduling or other interrupts to be blocked? Am I missing something here?
There are 3 types of gates you can use to service interrupts / faults on i386. Task gates are used where complex state changes are required, and an assured state is needed, such as doublefault and NMI handlers. Interrupt gates are used where interrupts must be disabled during initial processing, such as the page fault gate. Trap gates are used when interrupts may be allowed, and do not clear the interrupt flag.
On Linux, syscall vector int 0x80 is a trap gate, which means interrupts are not disabled. The sysenter handler is very special; SYSENTER does disable interrupts, so if you look at sysenter_entry, one of the first things it will do is re-enable interrupts as soon as the stack is sane. Thus, interrupts are enabled by default during system call processing unless explicitly disabled.
Your analysis of what would happen otherwise is quite correct.
Zach