OPERATING SYSTEMS 1 龚玲 lgong@sjtu.edu.cn
OPERATING SYSTEMS 龚玲 lgong@sjtu.edu.cn 1
REVIEW o Interrupt o Dual Mode o System Calls vs.APIs o Multiprogramming/Concurrency ohttp://wenku.baidu.com/course/study/77fldcccda38376ba flfae94#665ea0c7aa00b52acfc7ca94
REVIEW Interrupt Dual Mode System Calls vs. APIs Multiprogramming/Concurrency http://wenku.baidu.com/course/study/77f1dcccda38376ba f1fae94#665ea0c7aa00b52acfc7ca94
INTERRUPT TIMELINE CPU user process executing L I/O interrupt processing l/O idle device transferring 1/0 transfer V/O transfer request done request done
INTERRUPT TIMELINE
COMMON FUNCTIONS OF INTERRUPTS o Interrupt transfers control to the interrupt service routine generally,through the interrupt vector, which contains the addresses of all the service routines. o Interrupt architecture must save the address of the interrupted instruction. o Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt. o A trap is a software-generated interrupt caused either by an error or a user request. o An operating system is interrupt driven
COMMON FUNCTIONS OF INTERRUPTS Interrupt transfers control to the interrupt service routine generally, through the interrupt vector, which contains the addresses of all the service routines. Interrupt architecture must save the address of the interrupted instruction. Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt. A trap is a software-generated interrupt caused either by an error or a user request. An operating system is interrupt driven
OPERATING-SYSTEM OPERATIONS o Interrupt driven by hardware o Software error or request creates exception or trap Division by zero,request for operating system service o Other process problems include infinite loop, processes modifying each other or the operating system
OPERATING-SYSTEM OPERATIONS Interrupt driven by hardware Software error or request creates exception or trap Division by zero, request for operating system service Other process problems include infinite loop, processes modifying each other or the operating system
INTERRUPT HANDLING o The operating system preserves the state of the CPU by storing registers and the program counter. o Determines which type of interrupt has occurred: ·polling vectored interrupt system o Separate segments of code determine what action should be taken for each type of interrupt user process user mode user process executing calls system call return from system call (mode bit=1) kernel trap return mode bit =0 mode bit =1 kernel mode execute system call (mode bit =0)
INTERRUPT HANDLING The operating system preserves the state of the CPU by storing registers and the program counter. Determines which type of interrupt has occurred: polling vectored interrupt system Separate segments of code determine what action should be taken for each type of interrupt
OPERATING SYSTEM STRUCTURE o Multiprogramming needed for efficiency Single user cannot keep CPU and I/O devices busy at all times Multiprogramming organizes jobs (code and data)so CPU always has one to execute A subset of total jobs in system is kept in memory One job selected and run via job scheduling When it has to wait (for I/O for example),OS switches to another job
OPERATING SYSTEM STRUCTURE Multiprogramming needed for efficiency Single user cannot keep CPU and I/O devices busy at all times Multiprogramming organizes jobs (code and data) so CPU always has one to execute A subset of total jobs in system is kept in memory One job selected and run via job scheduling When it has to wait (for I/O for example), OS switches to another job
OPERATING SYSTEM STRUCTURE (CONT.) Timesharing (multitasking)is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing Response time should be 1 second Each user has at least one program executing in memory →process If several jobs ready to run at the same timeCPU scheduling If processes don't fit in memory,swapping moves them in and out to run Virtual memory allows execution of processes not completely in memory
OPERATING SYSTEM STRUCTURE (CONT.) Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing Response time should be < 1 second Each user has at least one program executing in memory process If several jobs ready to run at the same time CPU scheduling If processes don’t fit in memory, swapping moves them in and out to run Virtual memory allows execution of processes not completely in memory
MEMORY LAYOUT FOR MULTIPROGRAMMED SYSTEM 0 operating system job 1 job2 job 3 job 4 512M
MEMORY LAYOUT FOR MULTIPROGRAMMED SYSTEM
CONCURRENCY o What problem does concurrent mechanism solve? o Why use concurrent mechanism?
CONCURRENCY What problem does concurrent mechanism solve? Why use concurrent mechanism?