Presentation on theme: "1 SYSC3001 Operating Systems and Data Bases n From calendar: u Management of CPU (scheduling) processes, memory, disk, and files. u Implications of concurrency."— Presentation transcript:
1 SYSC3001 Operating Systems and Data Bases n From calendar: u Management of CPU (scheduling) processes, memory, disk, and files. u Implications of concurrency. u Concurrent programming, including interprocess communications in distributed systems. u Data base models and query languages.
2 Computer Systems Overview n Basically Chapter 1 in textbook n Need some basic understanding of computer organization and hardware: u processor u memory u I/O devices n “Left as an exercise”
Chapter 2: Operating Systems Overview n What is an Operating System? n Services provided by an OS n Evolution of the OS n Desired Hardware Features to support the OS n Multiprogramming n Time Sharing Systems n Difficulties of the OS Design n Achievements of the OS n System Structure of the OS n Modern OS 3
4 Operating System n Is a program that controls the execution of application programs u Tells the CPU when to execute other programs u Uses the hardware efficiently n Is an interface between the user and hardware u Masks the details of the hardware to application programs u Hence OS must deal with hardware details u Make the system convenient to use
5 Layers and Views The OS typically is further divided into multiple layers.
Operating Systems Definitions n Resource manager: manages and allocates resources (CPU, memory, I/O, software processes) n Control program: control the execution of user programs n Kernel: the one program running at all times (all else being application programs) 6
7 Services Provided by the OS n Facilities for Program creation u editors, compilers, linkers, and debuggers n Program execution u loading in memory, I/O and file initialization n Access to I/O and files u deals with the specifics of I/O and file formats n System access u Protection in access to resources and data u Resolves conflicts for resource contention
8 Services Provided by the OS n Error Detection u internal and external hardware errors F memory error F device failure u software errors F arithmetic overflow F access forbidden memory locations u Inability of OS to grant request of application n Error Response u simply report error to the application u Retry the operation u Abort the application
9 Services Provided by the OS n Accounting u collect statistics on resource usage u monitor performance (e.g., response time) u used for system parameter tuning to improve performance u useful for anticipating future enhancements u used for billing users (on multiuser systems)
Quiz What is an OS? A. Application program B. Interface between user programs C. Resource manager D. Kernel 2.Name two OS services. 10
11 Evolution of the Operating System n Must adapt to hardware upgrades and new types of hardware. Examples: u Character vs. graphic terminals u Introduction of paging hardware n Must offer new services, e.g., Internet support n The need to change the OS software on a regular basis u modular construction with clean interfaces u object oriented methodology
12 Simple Batch Systems n First generation OS (mid-50s) n Main objective is to maximize utilization n The user submits a job (written on card or tape) to a computer operator n The computer operator places a batch of several jobs on a input device n The OS, the monitor, manages the execution of each program in the batch u Monitor mostly is in main memory and available for execution, Resident Monitor u Monitor utilities are loaded when needed
13 The Monitor n Monitor reads in jobs one at a time from the input device n Monitor places a job in the user program area n A monitor instruction branches to the start of the user program n Execution of user program continues until: u end-of-program occurs u error occurs n Causes the CPU to fetch its next instruction from Monitor
14 Job Control Language (JCL) n Is the special type language to provide instructions to the monitor u what compiler to use u what data to use n Example of job format: u $JOB shows a new job $FTN loads the compiler and transfers control to it $LOAD loads the object code (in place of compiler) $RUN transfers control to user program $JOB $FTN... FORTRAN program... $LOAD $RUN... Data... $END
15 Job Control Language (JCL) During user program execution: n Each read (or input) instruction (in user program) causes one line of input data to be read n Causes an input routine to be invoked u checks for not reading a JCL line u skips to the next JCL line at completion of user program
16 Simple Batch OS n Alternates execution between a user program and the monitor program n Relies on available hardware to effectively alternate execution from various parts of memory
17 Desirable Hardware Features n Memory protection u do not allow the memory area containing the monitor to be altered by user programs n Timer u prevents a job from monopolizing the system u an interrupt occurs when time expires
18 Desirable Hardware Features n Privileged instructions u can be executed only by the monitor u an interrupt occurs if a program tries these instructions n Interrupts u provides flexibility for relinquishing control to and regaining control from user programs
Transfer of Control via Interrupts 19
20 Main Problem with Batch Systems - System Utilization Example
21 Multiprogrammed Batch Systems n I/O operations are exceedingly slow (compared to instruction execution) n A program containing even a very small number of I/O operations will spend most of its time waiting for them n Hence: poor CPU usage when only one program is present in memory
22 Multiprogrammed Batch Systems n If memory can hold several programs, then CPU can switch to another one whenever a program is awaiting for an I/O to complete n This is multitasking (multiprogramming)
23 Requirements for Multiprogramming n Hardware support: u I/O interrupts and (possibly) DMA F in order to execute instructions while I/O device is busy u Memory management F several ready-to-run jobs must be kept in memory u Memory protection (data and programs) n Software support from the OS: u Scheduling (which program is to be run next) u To manage resource contention and concurrency
24 Example: three jobs are submitted n Almost no contention for resources n All 3 can run in minimum time in a multitasking environment (assuming JOB2/3 have enough CPU time to keep their I/O operations active) n Total memory size is 256M bytes. JOB1 JOB2JOB3 Type of jobHeavy computeHeavy I/OHeavy I/O Duration 5 min.15 min.10 min. Memory req.50M100 M80 M Need disk?NoNoYes Need terminalNoYesNo Need printer?NoNoYes
25 Advantages of Multiprogramming UniprogrammingMultiprogramming Processor use17%33% Memory use33%67% Disk use33%67% Printer use33%67% Elapsed time30 min.15 min. Throughput rate6 jobs/hr12 jobs/hr Mean response time18 min.10 min.
26 Time Sharing Systems (TSS) n Batch multiprogramming does not support interaction with users n TSS extends multiprogramming to handle multiple interactive jobs n Processor’s time is shared among multiple users n Multiple users simultaneously access the system through terminals
27 Time Sharing Systems (TSS) n Because of slow human reaction time, a typical user needs 2 sec of processing time per minute n Then (about) 30 users should be able to share the same system without noticeable delay in the computer reaction time n The file system must be protected (multiple users…)
28 Difficulties with OS Design n Improper synchronization u ensure a program waiting for an I/O device receives the signal n Failed mutual exclusion u must permit only one program at a time to perform a transaction on a portion of data n Deadlock u It might happen that 2 or more programs wait endlessly after each other to perform an operation.
29 An example of deadlock n Program A wants to copy from disk1 to disk2 and takes control of disk1 n Program B wants to copy from disk2 to disk1 and takes control of disk2 n Program A must wait that program B releases disk2 and program B must wait that program A releases disk1 n Program A and B may wait forever
Quiz 2-2 n What is multiprogramming? n Multiprogramming vs. uniprogramming u Main advantage? u Challenges? n True of False u Time sharing systems (TSS) are multiprogramming u Multiprogramming systems are TSS n Batch multiprogramming vs. TSS u Key objective u Source of directives to OS 30
31 Major Achievements of OS n Operating Systems are among the most complex pieces of software ever developed n To meet the difficult requirements of multiprogramming and time sharing, there have been 5 major achievements by OS: u Processes and threads u Memory management u Information protection and security u Scheduling and resource management u System structure
32 Process n Introduced to obtain a systematic way of monitoring and controlling pgm execution n A process is an executable program with: u associated data (variables, buffers…) u execution context: i.e., all the information that F the CPU needs to execute the process content of the processor registers F the OS needs to manage the process: priority of the process the event (if any) after which the process is waiting other data (that we will introduce later)
n Fundamental to the structure of operating systems A process can be defined as: a program in execution an instance of a running program the entity that can be assigned to, and executed on, a processor a unit of activity characterized by a single sequential thread of execution, a current state, and an associated set of system resources
34 A simple implementation of processes n The process index register contains the index into the process list of the currently executing process (B) n A process switch from B to A consist of storing (in memory) B’s context and loading (in CPU registers) A’s context n A data structure that provides flexibility (to add new features)
n The OS has five principal storage management responsibilities: process isolation automatic allocation and management support of modular programming protection and access control long-term storage
36 Memory Management n The key contribution is virtual memory n It allows programs to address memory from a logical point of view without regard to the amount that is physically available n While a program is running only a portion of the program and data is kept in (real) memory n Other portions are kept in blocks on disk u the user has access to a memory space that is larger than real memory
37 Virtual Memory Concepts
38 Virtual Memory n All memory references made by a program are to virtual memory which can be either u a linear address space u a collection of segments (variable-length blocks) n The hardware (mapper) must map virtual memory address to real memory address n If a reference is made to a virtual address not in memory, then u (1) a portion of the content of real memory is swapped out to disk u (2) the desired block of data is swapped in
39 File System n Implements long-term store (often on disk) n Information stored in named objects called files u a convenient unit of access and protection for OS n Files (and portions) may be copied into virtual memory for manipulation by programs
40 Security and Protection n Access control to resources u forbid intruders (unauthorized users) to enter the system u forbid user processes to access resources which they are not authorized to
41 Scheduling and Resource Management n Differential responsiveness u discriminate between different classes of jobs n Fairness u give equal and fair access to all processes of the same class n Efficiency u maximize throughput, minimize response time, and accommodate as many users as possible
42 Key Elements for Scheduling n OS maintains queues of processes waiting for some resource u Short term queue of processes in memory ready to execute F The dispatcher (short term scheduler) decides who goes next u Long term queue of new jobs waiting to use the system F OS must not admit too many processes u A queue for each I/O device consisting of processes that want to use that I/O device
43 Key Elements for Scheduling (cont’d)
44 System Structure n Because of it’s enormous complexity, we view the OS system as a series of levels n Each level performs a related subset of functions n Each level relies on the next lower level to perform more primitive functions n Well defined interfaces: one level can be modified without affecting other levels n This decomposes a problem into a number of more manageable sub problems
45 Characteristics of Modern Operating Systems n New design elements were introduced recently n New hardware development u multiprocessor machines u high-speed networks u faster processors and larger memory n New software / application needs u multimedia applications u Internet and Web access u Client/Server applications
46 Microkernel architecture n Only a few essential functions in the kernel u primitive memory management (address space) u Interprocess communication (IPC) u basic scheduling n Other OS services are provided by processes running in user mode (servers) u device drivers, file system, virtual memory… n More flexibility, extensibility, portability… n A performance penalty by replacing service calls with message exchanges between process...
47 Multithreading n A process is a collection of one or more threads that can run simultaneously n Useful when the application consists of several tasks that do not need to be serialized n Gives the programmer a greater control over the timing of application-related events n All threads within the same process share the same data and resources and a part of the process’s execution context n It is easier to create or destroy a thread or switch among threads (of the same process) than to do these with processes
48 Distributed Systems n Distributed operating systems u Provides the illusion of a single main memory space and single secondary memory space
49 Symmetric Multiprocessing (SMP) n A computer with multiple processors n Each processor can perform the same functions and share same main memory and I/O facilities (symmetric) n The OS schedule processes/threads across all the processors (real parallelism) n Existence of multiple processors is transparent to the user. n Incremental growth: just add another CPU (at least in theory). n Robustness: a single CPU failure does not halt the system, only the performance is reduced.
50 Example of parallel execution on SMP
Quiz n Name the main difference between multiprogramming and multiprocessing n True or False n Multiprocessing generally implies multiprogramming n Multiprogramming generally implies multiprocessing
Quiz n Micorkernel systems: a. What extra “weight” (features) do they usually remove? b. What are the main advantages? c. What is the main cost?
n Virtualization u enables a single PC or server to simultaneously run multiple operating systems or multiple sessions of a single OS u a machine can host numerous applications, including those that run on different operating systems, on a single platform u host operating system can support a number of virtual machines (VM) each has the characteristics of a particular OS and, in some versions of virtualization, the characteristics of a particular hardware platform