480 likes | 499 Views
COSC 4P13. Operating Systems : Design and Implementation. Course Description(1). The Goals for this course Understand UNIX Understand Operating Systems Prerequisites: COSC 2P13 : Introduction to Operating Systems COSC 2P91 : Procedural Programming
E N D
COSC 4P13 Operating Systems : Design and Implementation
Course Description(1) • The Goals for this course • Understand UNIX • Understand Operating Systems • Prerequisites: • COSC 2P13 : Introduction to Operating Systems • COSC 2P91 : Procedural Programming • COSC 1P12 : Computer Organization and Assembly Language
Course Description(2) • An intensive study of computer operating system design • Multiprogramming • Time-sharing • Real-time processing • Job and task control • Synchronization of concurrent processes and processors • Resource scheduling • Protection • Management of hierarchical storage.
How to study this course • Read and remember • Read the book, remember the concepts and commands • Think • Think operating systems as natural administrative agents • Practice • Coding with UNIX, use and understand of UNIX commands and get the results
The Textbook Used • Uresh Vahalia, UNIX Internals: The New Frontiers, Prentice Hall, 1996 • Why we use this book? • UNIX is one of the popular operating systems of the world. • If you understand UNIX, you can understand other operating systems.
References • William Stallings, Operating Systems,4th Ed., Prentice Hall,2000 • A. Tanenbaum, Modern Operating Systems, 2nd ed. Prentice Hall 2001 • Kay A. Robbins and Steven Robbins, Practical UNIX Programming, Prentice Hall,1996 • W. R. Stevens, Advanced Programming in the UNIX Environment, Addison Wesley, 1992
Operating System Overview • Computer System • Computer Hardware • Components • Registers • Instruction execution • Interrupt • Memory Hierarchy and I/O • Operating System • Services of OS • Major Achievements • Characteristics of Modern OS
End User Programmer Operating- System Designer Computer System Application Programs Utilities Operating-System Computer Hardware
Computer Hardware • Processor • Main Memory • referred to as real memory or primary memory • volatile • I/O modules • secondary memory devices • communications equipment • terminals • System interconnection • communication among processors, memory, and I/O modules
Computer Components:top-level view Memory • MAR - Memory Address Register • address for next read or write • MBR - Memory Buffer Register • data to be written into memory • receives data read from memory • I/OAR - I/O Address • specifies a particular I/O device • I/OBR - I/O Buffer • exchange of data between an I/O module and the processor . . . CPU Instruction PC MAR Instruction Instruction . IR MBR . I/O AR Data I/O BR Data Data I/O Module Data . . . . . Buffers
I/O Module Structure • Data to/from system bus are buffered in data register(s) • Status/Control register(s) • I/O logic interact with CPU via control bus • Contains logic specific to the interface of each device
Processor Registers • User-visible registers • Data Registers • Address Registers • index register • segment pointer • stack pointer • Condition Codes or Flags • Control and Status Registers • Program Counter (PC) • Instruction Register (IR) • Program Status Word (PSW)
Instruction Execution • Processor executes instructions in a program • Instructions are fetched from memory one at a time Fetch Cycle Execute Cycle Fetch Next Instruction Execute Instruction START HALT
Instruction Fetch and Execute • The processor fetches the instruction from memory • Program counter (PC) holds address of the instruction to be fetched next • Program counter is incremented after each fetch
Instruction Register • Fetched instruction is placed here • Types of instructions • Processor-memory • transfer data between processor and memory • Processor-I/O • data transferred to or from a peripheral device • Data processing • arithmetic or logic operation on data • Control • alter sequence of execution
Interrupts • An interruption of the normal processing of processor • Improves processing efficiency • Allows the processor to execute other instructions while an I/O operation is in progress • A suspension of a process caused by an event external to that process and performed in such a way that the process can be resumed
Classes of Interrupts • Program • arithmetic overflow • division by zero • execute illegal instruction • reference outside user’s memory space • Timer • I/O • Hardware failure
Instruction Cycle with Interrupts Fetch Cycle Execute Cycle Interrupt Cycle Interrupts Disabled Execute Instruction Check for Interrupt: Process Interrupt Fetch Next Instruction START Interrupts Enabled HALT
Interrupt Handler • A program that determines nature of the interrupt and performs whatever actions are needed • Control is transferred to this program • Generally part of the operating system
Interrupt Cycle • Processor checks for interrupts • If no interrupts fetch the next instruction for the current program • If an interrupt is pending, suspend execution of the current program, and execute the interrupt handler
Device controller or other system hardware issues an interrupt Save remainder of process state information Processor finishes execution of current instruction Processor signals acknowledgment of interrupt Process interrupt Processor pushes PSW and PC onto control stack Restore process state information Processor loads new PC value based on interrupt Restore old PSW and PC Simple Interrupt Processing
Interrupts improve CPU usage • I/O pgm prepares the I/O module and issues the I/O command (eg: to printer) • I/O pgm branches to user pgm • User code gets executed during I/O operation (eg: printing): no waiting • User pgm gets interrupted (x) when I/O operation is done and branches to interrupt handler to examine status of I/O module • Execution of user code resumes
Multiple interrupts: sequential order • Disable interrupts during an interrupt • Interrupts remain pending until the processor enables interrupts • After interrupt handler routine completes, the processor checks for additional interrupts
Multiple Interrupts: priorities • Higher priority interrupts cause lower-priority interrupts to wait • Causes a lower-priority interrupt handler to be interrupted • Example: when input arrives from communication line, it needs to be absorbed quickly to make room for more input
Cache/Main-Memory Structure Memory Address Slot Number Tag Block 0 0 1 1 2 Block (k words) 2 3 C - 1 Block Length (k words) (b) Cache Block 2n - 1 Word Length (a) Main Memory
Cache Design • Cache size • Block size • Mapping function • Replacement algorithm
I/O Techniques • Programmed I/O • Interrupt-Driven I/O • Direct Memory Access
Programmed I/O Insert Read command to I/O Module • I/O module performs the action, not the processor • Sets appropriate bits in the I/O status register • No interrupts occur • Processor is kept busy checking status CPU I/O Read Status of I/O Module I/O CPU Not Ready Error Condition Check Status Ready Read word from I/O Module I/O CPU Write word into memory CPU Memory No Done? Yes Next Instruction
Interrupt-Driven I/O Insert Read command to I/O Module • Processor is interrupted when I/O module ready to exchange data • Processor is free to do other work • No needless waiting • Consumes a lot of processor time because every word read or written passes through the processor CPU I/O Do something else Read Status of I/O Module Interrupt I/O CPU Error Condition Check Status Ready Read word from I/O Module I/O CPU Write word into memory CPU Memory No Done? Yes Next Instruction
Direct Memory Access Issue Read block command to I/O module • Transfers a block of data directly to or from memory • An interrupt is sent when the task is complete • The processor is only involved at the beginning and end of the transfer CPU DMA Do something else Read status of DMA module Interrupt DMA CPU Next Instruction
Operating System • Making computing power available to users by controlling the hardware • a program that controls execution of application programs • an interface between the user and hardware • Directs the processor in the use of system resources • Directs the processor when executing other programs
Services Provided by the OS • Facilities for Program creation • editors, compilers, linkers, and debuggers • Program execution • loading in memory, I/O and file initialization • Access to I/O and files • deals with the specifics of I/O and file formats • System access • Protection of access to resources and data • Resolves conflicts for resource contention
Error Detection internal and external hardware errors memory error device failure software errors arithmetic overflow access forbidden memory locations Inability of OS to grant request of application Error Response simply report error to the application Retry the operation Abort the application Services Provided by the OS
Services Provided by the OS • Accounting • collect statistics on resource usage • monitor performance (eg: response time) • used for system parameter tuning to improve performance • useful for anticipating future enhancements • used for billing users (on multiuser systems)
Operating System as a Resource Manager Computer System Memory I/O Controller Operating System Software I/O Controller . . Programs and Data . I/O Controller . . . Processor Processor OS Programs Data
Ability to Evolve • Must be able to adapt to hardware upgrades and new types of hardware. Examples: • Character vs graphic terminals • Introduction of paging hardware • Must be able to offer new services, eg: internet support
Major Achievements • Processes • Memory Management • Information protection and security • Scheduling and resource management • System structure
Memory Management • Process isolation • Automatic allocation and management • Support for modular programming • Protection and access control • Long-term storage
Virtual Memory • Allows programmers to address memory from a logical point of view • While program is running portions of the program and data are kept in blocks on disk
File System • Implements long-term store • Information stored in named objects called files
Categories of Security and Protection • Access control • regulate user access to the system • Information flow control • regulate flow of data within the system and its delivery to users • Certification • proving that access and flow control perform according to specifications
Scheduling and Resource Management • Fairness • give equal and fair access to all processes • Differential responsiveness • discriminate between different classes of jobs • Efficiency • maximize throughput, minimize response time, and accommodate as many uses as possible
Characteristics of Modern Operating Systems • Microkernel architecture • assigns only a few essential functions to the kernel • address space • interprocess communication (IPC) • basic scheduling
Characteristics of Modern Operating Systems • Multithreading • process • is divided into threads that can run simultaneously • Process is a collection of one or more threads • Thread • dispatchable unit of work • executes sequentially and is interruptable
Characteristics of Modern Operating Systems • Symmetric multiprocessing • there are multiple processors • these processors share the same main memory and I/O facilities • All processors can perform the same functions
Characteristics of Modern Operating Systems • Distributed operating systems • provides the illusion of a single main memory • used for distributed file system
Characteristics of Modern Operating Systems • Object-oriented design • used for adding modular extensions to a small kernel • enables programmers to customize an operating system without disrupting system integrity