Académique Documents
Professionnel Documents
Culture Documents
Efficiency issues
Main difference is that the system call executes code the OS (in supervisor mode) How to communicate parameters and return value between the program and the OS?
Return:
pop state off stack and reload registers push return value onto stack jump to next instruction of caller (as read from stack)
Issue hardware TRAP instruction sets mode bit from USER to SUPERVISOR
jumps to fixed address in OS
OS pops syscall number and parameters (from stack) OS calls appropriate system call function
pushes return value onto processs stack
Process pops syscall return value from stack and gets on with its business
Interrupts
Recall that the OS can be invoked in two ways - syscalls (traps) and interrupts Interrupts are similar to TRAP instructions, except they are triggered by hardware, not by the currently running process An interrupt might occur at almost any point in a running process
the process isnt expecting it, and so isnt saving its parameters, etc returning from an interrupt means restarting from at an arbitrary point in the process
Serving an interrupt
A process is happily running along Suddenly, a hardware interrupt occurs
clock tick, I/O, illegal instruction, etc.
Hardware forces jump to fixed address in OS address space (called an Interrupt Service Routine)
pushes current state onto system stack pushes interrupt ID onto system stack
Upon completion, OS calls scheduler / dispatcher to select and load user process
maybe the original one, maybe someone else
Examples of Interrupts
Clock pulse
every so often (say, 50 times per second) reinvoke the scheduler
Illegal instruction
send signal to (or terminate) process that issued instruction
Blocking system calls are an efficient mechanism for a process to wait for some event (I/O, inter-process synchronization)
user-mode busy loops are a bad way to wait!
Schedulers might favor the currently running process to avoid context switch overhead
build in hysteresis but not too much - avoid starvation
a thread of execution
the current state operating on these resources
This is nice, but it means that if you want to change threads, you have to go to the OS
requires context switch to change processes this is a shame, because some applications logically consist of more than one thread but need only one grouping of resources
Multithreaded applications
Important property: one address space, no need to enforce resource separation between threads
not arbitrary code
Examples:
networked web server
serves several clients at once
web browser
load different pages simultaneously
Basic idea: a dispatcher that is called when a thread is ready to relinquish control to another thread
manages stack pointer, program counter can switch state between threads