Download Operating System Overview: CPU, I/O, Memory, and Disk Management and more Quizzes Electrical and Electronics Engineering in PDF only on Docsity! 1 ECE 3055 Quiz-2 Review Computer-System Operation • I/O devices and the CPU can execute concurrently. • Each device controller is in charge of a particular device type. • Each device controller has a local buffer. • CPU moves data from/to main memory to/from local buffers • I/O is from the device to local buffer of controller. • Device controller informs CPU that it has finished its operation by causing an interrupt. 2 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. 3 2 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 • “Trap” - a software driven interrupt 4 I/O Structure • Synchronous - After I/O starts, control returns to user program only upon I/O completion. – wait instruction idles the CPU until the next interrupt – wait loop (contention for memory access). – At most one I/O request is outstanding at a time, no simultaneous I/O processing (for a single “thread”) . • Asynchronous - After I/O starts, control returns to user program without waiting for I/O completion. – System call – request to the operating system to allow user to wait for I/O completion. – Device-status table contains entry for each I/O device indicating its type, address, and state. – Operating system indexes into I/O device table to determine device status and to modify table entry to include interrupt. 5 Dual-Mode Operation • Sharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly. • Provide hardware support to differentiate between at least two modes of operations. 1. User mode – execution done on behalf of a user. 2. Monitor mode (also supervisor mode or system mode) – execution done on behalf of operating system. monitor user Interrupt/fault set user mode 6 5 System Calls • System calls provide the interface between a running program and the operating system. – Generally available as assembly-language instructions. – Languages defined to replace assembly language for systems programming allow system calls to be made directly (e.g., C. Bliss, PL/360) • Three general methods are used to pass parameters between a running program and the operating system. – Pass parameters in registers. – Store the parameters in a table in memory, and the table address is passed as a parameter in a register. – Push (store) the parameters onto the stack by the program, and pop off the stack by operating system. 13 System Programs • System programs provide a convenient environment for program development and execution. The can be divided into: – File manipulation – Status information – File modification – Programming language support – Program loading and execution – Communications – Application programs • Most users’ view of the operation system is defined by system programs, not the actual system calls. 14 UNIX System Structure (GUI, Mouse & Keyboard Controllers) 15 6 Virtual Machines • A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware. • A virtual machine provides an interface identical to the underlying bare hardware. • The operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory. 16 Process Concept • An operating system executes a variety of programs: – Batch system – jobs – Time-shared systems – user programs or tasks • Textbook uses the terms job and process almost interchangeably. • Process – a program in execution; process execution must progress in sequential fashion. • A process includes: – program counter – stack – data section • As a process executes, it changes state – new: The process is being created. – running: Instructions are being executed. – waiting: The process is waiting for some event to occur. – ready: The process is waiting to be assigned to a process. – terminated: The process has finished execution. 17 Process Control Block (PCB) 18 7 Context Switch • When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. • Context-switch time is overhead; the system does no useful work while switching (frequently the major bottleneck in modern systems) • Time dependent on hardware support. 19 Threads • A thread (or lightweight process) is a basic unit of CPU utilization; it consists of: – program counter – register set – stack space • A thread shares with its peer threads its: – code section – data section – operating-system resources collectively know as a task. • A traditional or heavyweight process is equal to a task with one thread 20 • Responsiveness (Blocked and non-blocked) • Resource Sharing • Economy • Utilization of Multi-Proc. Architectures • User and Kernal-supported threads – Many-to-One – One-to-One – Many-to-Many Threads 21 10 Module 10: Virtual Memory • Background • Demand Paging • Performance of Demand Paging • Page Replacement • Page-Replacement Algorithms (Optimal, FIFO, LRU) • Allocation of Frames • Thrashing • Other Considerations • Demand Segmentation 28 • Virtual memory – separation of user logical memory from physical memory. – Only part of the program needs to be in memory for execution. – Logical address space can therefore be much larger than physical address space. – Need to allow pages to be swapped in and out. • Virtual memory can be implemented via: – Demand paging – Demand segmentation 29 Demand Paging • Bring a page into memory only when it is needed. – Less I/O needed – Less memory needed – Faster response – More users • Page is needed ⇒ reference to it – invalid reference ⇒ abort – not-in-memory ⇒ bring to memory 30 11 Page Fault • If there is ever a reference to a page, first reference will trap to OS ⇒ page fault • OS looks at another table to decide: – Invalid reference ⇒ abort. – Just not in memory. • Get empty frame. • Swap page into frame. • Reset tables, validation bit = 1. • Restart instruction: Least Recently Used – block move 31 Demand Paging Example • Memory access time = 1 microsecond • 50% of the time the page that is being replaced has been modified and therefore needs to be swapped out. • Swap Page Time = 10 msec = 10,000 usec EAT = (1 – p) x 1us + p (15000us) 1 + 15000 P (in usec) Obviously we would like P to be much less than 1 If P = 0.0001, then EAT = 1 + 1.5 = 2.5 usec 32 Module 11: File-System Interface • File Concept • Access Methods • Directory Structure • Protection • File-System Structure • Allocation Methods • Free-Space Management • Directory Implementation • Efficiency and Performance • Recovery 33 12 File Attributes • Name – only information kept in human-readable form. • Type – needed for systems that support different types. • Location – pointer to file location on device. • Size – current file size. • Protection – controls who can do reading, writing, executing. • Time, date, and user identification – data for protection, security, and usage monitoring. • Information about files are kept in the directory structure, which is maintained on the disk. 34 File Operations • create • write • read • reposition within file – file seek • delete • truncate • open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory. • close (Fi) – move the content of entry Fi in memory to directory structure on disk. 35 36 Two-Level Directory • Separate directory for each user. • Path name • Can have the same file name for different user • Efficient searching • No grouping capability