C SC 340 Lecture 1: OS Overview Part 1
[ previous | schedule | next ]
Much OS processing is interrupt driven. An interrupt is an event to which the system responds. Examples of events that cause interrupt:
Each type of interrupt has service routine. Addresses of service routines stored in interrupt vector for fast access -- device and/or interrupt type used as index into vector.
The IBM-PC architecture has specific implementations of interrupt vectors and the associated interrupt request lines (IRQ). See e.g. Webopedia for definitions.
When interrupt occurs:
You are familiar with most of the major storage device types: registers, main memory, magnetic disks, optical disks, magnetic tape. Only the first two of these can be directly accessed by the CPU.
Caching
Cache memory refers to a technique rather than a technology. Caching is the temporary storage of information in a faster device to get faster access.
memory cache a.k.a. RAM cache resides between the CPU and main memory. Level-1 cache is built into the processor chip itself. Level-2 cache has historically been placed elsewhere on the motherboard but is now being incorporated onto the processor chip as well.
disk cache is RAM memory used to cache data for disk operations. The RAM may reside either on the disk device or be a portion of main memory.
Storage hierarchy
You may be familiar the storage hierarchy from previous courses (CSC 100 or 330). This is a ranking of storage devices based on several factors: access speed, capacity, cost per bit, and volatility. Here are some examples:
When user process needs to perform I/O, it issues a system call. OS sets the device controller registers accordingly, and device begins work on the operation. When operation is complete, device controller issues interrupt. What should CPU do in the meantime? What should user process do in the meantime? Note that I/O operation is initiated by user system call, completed by controller interrupt.
Assume that while a user process is awaiting I/O, the OS turns its attention to other processes or interrupts (asynchronous I/O). Since several such operations may be pending, OS needs a table to track them. Device status table has an entry for each device, and each entry points to a list of pending requests (containing user, operation, address, #bytes, etc). As each is completed, controller issues interrupt and interrupt handler updates the request list and associated user process.
I/O still requires a lot of CPU attention to transfer data between device buffer and main memory, so a technique called Direct Memory Access (DMA) was developed. Allows this transfer to occur directly w/o CPU intervention; a DMA controller replaces CPU as the "middle man".
A related but distinct technology is memory-mapped I/O. This is technique of reserving main memory address ranges to represent device registers. Allows CPU and device to communicate by reading/writing to main memory. Most well-known example is video.
Any resource sharing can lead to problems. Even on single-user system with only one user process and OS running. What kind of problems?
One protection technique is dual-mode operation. At any instant, the CPU is operating in either user mode or supervisor (privileged, kernel) mode. Indicates whether instruction is carried out on behalf of user or OS. Then define certain instructions, called privileged instructions, that can be carried out only when system in supervisor mode. If CPU sees privileged instruction and mode bit is set to user, issue trap to OS. This allows critical operations to be performed only by the OS. Must assure that user cannot take control while mode bit set to supervisor.
I/O is done this way -- system provides routines called system calls that the user can put in the program, and while the system call is being executed, the mode is changed to supervisor and the I/O operation is performed then the mode is changed back to user before returning.
Another protection technique protects memory space through the use of base register and limit register through which any user memory request must be filtered. Each user has exclusive rights to its logically contiguous address space. Base register contains lowest address of this space and limit register contains size of this space. So memory request must be no less than base register content and less than base+limit. User request outside this range triggers trap to OS. Only OS can set values of base and limit registers.
CPU is protected from infinite user control through the use of timers. When user process gets control of CPU, OS sets timer. If user still in control when timer goes off, OS can replace it.