1 / 28

Introduction to Computer Science Chapter 10. Operating Systems

Introduction to Computer Science Chapter 10. Operating Systems. Lynn Choi Korea University. What is an Operating System?. A program that acts as an intermediary between the user and the computer hardware. Provides a virtual machine that is easier to program than the raw hardware

Melvin
Télécharger la présentation

Introduction to Computer Science Chapter 10. Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computer ScienceChapter 10. Operating Systems Lynn Choi Korea University

  2. What is an Operating System? • A program that acts as an intermediary between the user and the computer hardware. • Provides a virtual machine that is easier to program than the raw hardware Applications Operating System Hardware • Provide an environment in which a user can execute programs in a convenient and efficient manner • What if you don’t have an operating system? • Source code -> compiler -> object code -> hardware • How do you get object code onto the hardware? • How do you print out the answer? • How do you interface HDD and open a file? Virtual Machine Interface Physical Machine Interface

  3. OS Functions • OS has two general functions: • Standard services • Provide standard services that everyone needs • Manages computer hardware • Provides easy of use for applications/users • Examples: standard IO libraries, window systems • Coordinator • Allows multiple applications/users to work together in efficient and fair ways • Resource sharing and efficient use of resources • Prevent errors and improper user of the computer by controlling the execution of user programs • Examples: concurrency, memory protection, share IO devices

  4. Abstract View of System Components

  5. Operating System from Different Viewpoints • User’s view • PC’s operating system • Designed mostly for easy of use, and partly for performance • Not much attention to resource utilization • Mainframe or minicomputer’s operating system • Multiple users are sharing the same computer through terminals • Designed primarily to maximize resource utilization • Workstations and servers • Users have dedicated resources but they also share resources such as networking, servers, print servers etc. • Designed to compromise individual usability and resource utilization • Handheld devices • Designed to provide a user-friendly interface, and performance/energy • System’s view • Resource allocator – manages and allocates resources • With numerous conflicting requests, OS must decide how to allocate them to specific user/program • Control program – controls the execution of user programs and operations of I/O devices to prevent errors and improper user of the computer

  6. Process Concept • Process • Informally, a process is a program in execution • A system includes a collection of processes: user processes and system processes • A process generally includes (or represented by) • PC (program counter) • CPU Registers • Text section • Data section (static data, stack, heap) • Process versus program • Program • Passive entity – an executable file stored on disk • Becomes a process when the executable file is loaded into memory • Process • Active entity – program in execution with a program counter specifying the next instruction to execute • Two processes may be associated with the same program • Several Internet Explorer processes • Although text sections are equivalent, the PC, registers, and the data sections vary

  7. Process in Memory MIPS Memory Map

  8. Process State • 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 processor • Terminated: The process has finished execution • These names may vary across operating systems.

  9. Process Control Block (PCB) • Each process is represented in the operating system by a process control block (PCB), which consists of the following information. • Process state – new, running, ready, waiting, etc. • Program counter – the address of the next instruction to be executed • CPU registers • General purpose registers, stack pointers, index registers, condition codes etc. • CPU scheduling information • Process priority, pointers to scheduling queues, and other scheduling parameters • Memory-management information • Base address of page tables • Accounting information • The amount of CPU time used, time limits, account numbers, etc. • I/O status information • The list of IO devices allocated, a list of open files, etc.

  10. Context Switch • When CPU switches to another process, • The system must save the state of the old process (called context save), and • Load the saved state for the new process (called context restore) • Context switching occurs • As time slice expires (as a result of CPU scheduling) • Exceptions (fault, trap, abort), External interrupts • System calls (user mode to system mode and vice versa)

  11. CPU Switch From Process to Process

  12. Process Scheduling • Process execution alternates sequences of CPU and IO bursts • Process scheduling • Select one from the ready processes and allocates the CPU • Can improve CPU utilization, throughput, response time, etc. • CPU scheduling decisions may take place when a process: • Switches from running to waiting state (i.e. I/O request) • Switches from running to ready state (i.e. interrupt) • Switches from waiting to ready (i.e. completion of I/O) • Terminates

  13. Process Scheduling • Nonpreemptive scheduling • The currently executing process gives up the CPU voluntarily • Preemptive scheduling • The operating system decides to favor another process, preempting the currently executing process • Scheduling Criteria • CPU utilization – keep the CPU as busy as possible • Throughput – # of processes completed per time unit • Turnaround time – the amount of time to execute a particular process • Waiting time – the amount of time a process has been waiting in the ready queue • Response time – the amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) • It is more important to minimize the variance in the response time than to minimize the average response time • Maximize CPU utilization/Throughput, minimize turnaround time/waiting time/response time

  14. CPU Scheduling Algorithms First-Come, First-Served (FCFS or FIFO) Processes are moved to the CPU in the order in which they arrive in the running state Shortest Job Next Process with shortest estimated running time in the ready state is moved into the running state first Round Robin Each process runs for a specified time slice and moves from the running state to the ready state to await its next turn if not finished

  15. First-Come, First-Served Assuming the processes all arrived at the same time, what is the average turn- around time? What is the average waiting time?

  16. Shortest Job Next What is the average turn- around time? What is the average waiting Time?

  17. Round Robin Every process is treated the same! Time slice (quantum) The amount of time each process receives before being preempted and returned to the ready state to allow another process its turn

  18. Round Robin Suppose the time slice is 50 • Every process is treated the same! • Time slice (quantum) • The amount of time each process receives before being preempted and returned to the ready state to allow another process its turn What is the average turnaround time? We cannot judge one algorithm is better than the other based on one example

  19. Virtual vs. Physical Address • Virtual address (also referred as logical address) • An address generated by the CPU • An address seen by the programmer • When a program is compiled, a reference to a variable is assigned a logical address. • Virtual address space: the set of all virtual addresses generated by a program • If you use 32bit virtual address, the maximum size of virtual address space is 4GB • Physical address • The address of main memory (physical memory) and caches • Physical address space: the set of all physical addresses • It is the size of physical memory you have in your PC. • The maximum size of physical address space is determined by the size of physical address. • Address binding • The mapping of a virtual address to a physical address • When the program is loaded into memory, each logical address is mapped to a specific physical address.

  20. Memory Management • The main memory must accommodate both the operating system and various user processes • The OS must allocate parts of the main memory to OS and other processes in an efficient way • Two approaches • Contiguous allocation versus noncontiguous allocation • With contiguous memory allocation • Each process is contained in a single contiguous section of memory • Main memory is usually divided into two partitions: • Resident operating system • User processes • Memory mapping and protection • Relocation register + limit register can be used to protect user processes from each other, and from changing operating-system code and data • Relocation register contains value of smallest physical address • Limit register contains the range of logical addresses

  21. A base and a limit register define a logical address space

  22. HW support for relocation and limit registers

  23. Contiguous Allocation • Multiple-partition method • Fixed size partitions • Divide memory into several fixed-sized partitions • Each partition may contain exactly one process • Variable size partitions • Divide memory into several variable size partitions • Hole – a contiguous block of free memory • When a process arrives, it is allocated memory from a hole large enough to accommodate it OS OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process10 process 2 process 2 process 2 process 2

  24. Dynamic Storage-Allocation Problem • First-fit: Allocate the first hole that is big enough • Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. • Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. How to satisfy a request of size n from a list of free holes First-fit and best-fit generally performs better than worst-fit in terms of speed and storage utilization!

  25. Fragmentation • External Fragmentation – There is enough total memory space to satisfy a request, but the available spaces are not contiguous • Occurs if variable size partitions (i.e. segmentation) are used • Can reduce external fragmentation by compaction • Shuffle memory contents to place all free memory together in one large block • Internal Fragmentation – The allocated memory may be slightly larger than requested memory; this size difference is internal to a partition, but is not being used • Occurs if fixed size partitions (i.e. paging) are used

  26. Paging • Noncontiguous allocation • The virtual address space of a process can be noncontiguous in the physical address space • Two approaches • Paging: divide virtual address space into fixed size partitions called pages • Segmentation: divide virtual address space into variable size partitions called segments • Paging • Divide virtual memory into blocks of same size called (virtual) pages • Divide physical memory into fixed-sized blocks called (physical) page frames • Page size is between 512B ~ 16MB • To run a program of size n pages, need to find n free frames • Frame table • OS needs to keep track of free and allocated page frames • Page table • OS needs to keep track of virtual to physical address mappings for each process

  27. Paging • Fragmentation • Internal fragmentation – on average, one half page per process • No external fragmentation • Page size • Small page – decrease internal fragmentation • Large page – decrease the number of entries in the page table • Generally page sizes have grown over time as processes and main memory become larger • Paging clearly separates user’s view of memory from the actual physical memory • Each virtual address generated by the CPU is translated to a physical address by hardware (MMU or TLB) and operating system (page table) • This mapping is hidden from the user and controlled by the operating system • Protection: each user process has no way of addressing memory outside of its address space • Its page table includes only the pages that the process owns

  28. Paging • Demand paging • Bring in a page on a page miss • Page table entry (PTE) contains • Virtual page number, Physical page frame number (translation) • Valid bit (valid entry or not) • Presence bit (memory or disk) • Reference bits (used for page replacement) • Dirty bit (write back to disk or not) • Access control: read/write/execute (protection) • Privilege level (protection) • Other page attributes: cacheable, etc.

More Related