Click here to load reader

Operating Systems Lecture Notes Introduction Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002

  • View
    230

  • Download
    1

Embed Size (px)

Text of Operating Systems Lecture Notes Introduction Matthew Dailey Some material © Silberschatz,...

  • Operating Systems Lecture NotesMatthew DaileySome material Silberschatz, Galvin, and Gagne, 2002Introduction

  • Operating SystemsThe software that turns a hunk of electronics into something you can use.This semester, we will learn how OSs work.As users, this helps us get more out of any OS.As programmers, this helps usbuild our own large end-user applicationsexploit the special features of particular OSs

  • OutlinePurpose of operating systemsHistory of operating systemsInterrupts and system callsReadings: Silberschatz et al., chapters 1-3

  • Purpose of Operating Systems

  • Purpose of Operating SystemsThe OS is an intermediary between the systems hardware and its users.Also called the kernel: the one program always running

  • Purpose of Operating SystemsGoal of an OS: to provide a convenient and efficient environment for executing programs.When there is more than one program or user, an additional goal is to provide a safe environment.Programs should not be able to interfere with other programs.Users should not be able to interfere with other users programs or data.

  • Purpose of Operating Systems Purpose of an OS also depends onwhat hardware is being used.who the users are.User/programmer point of viewWe dont want to know all the details of the hardware.The OS provides a simple abstract system model.System point of viewResources (CPU time, memory, IO devices, etc) need to be managed.The OS is a resource allocator.

  • History of Operating Systems

  • History of Operating SystemsEarly days: mainframe batch systemsUsers would submit a job:Stack of punch cardsIncludes the program, input data, and control instructionsOperator would organize jobs and run in batchesOne program resident in memory at any timeSlow operators / card readers / output devices mean CPU underutilizedThe computers main memory address spaceoperatingsystemuser programarea (onlyONE program)Memory location 0Memory location 512K

  • History of Operating Systems: Multiprogramming

    Multiprogrammed Systems:Keep more than one running job in memoryWhen one job waits for IO, switch to a different job

    Increases CPU utilizationoperatingsystemjob 1Memory location 0Memory location 512Kjob 2job 3job 4The computers main memory address space

  • History of Operating Systems: MultiprogrammingMultiprogramming allows time sharingMultiple simultaneous users interacting with the systemCPU switches between jobs fast enough for interactive useProcess execution state diagram:

    RUNNINGREADYBLOCKEDIO RequestIO CompletionKernel Selection

  • History of Operating Systems: Multiprogramming Multiprogramming increased efficiency and time sharing increases convenience. BUTA single process might monopolize CPU or memory.One process might overwrite anothers memory.If total memory exceeds system memory, backing store is required.System state (program counter, registers, etc) needs to be saved and restored on every context switch.Result: added complexity thats why we need this course!

  • History of Operating Systems: Virtual memoryVirtual MemoryPrograms see one large block of memory, possibly bigger than actual system memory.Program memory references get translated into real hardware addresses. Not all of a programs memory has to be resident at once. Simpler abstract model for the programmer. Requires hardware support for address translation. Requires backing store.

  • History of Operating Systems: Types of computer systemsDesktop systems:Initially simple, with batch operation e.g. MS-DOSEvolved multiprogramming and time sharing in 80s and 90sEvolved graphical user interfacesMaximal convenience for user; efficiency secondaryMultiprocessor systems:More than one CPU to divide the workloadSymmetric multiprocessing: all CPUs run same OSAsymmetric multiprocessing: master CPU assigns individual tasks to slave CPUsIncreasingly common in network servers and even desktops

  • History of Operating Systems: Types of computer systemsDistributed systems:Multiple standalone systems interconnected for cooperationClient-server systems place shared resources on centralized serversPeer-to-peer systems allow ad-hoc cooperation between individualsReal-time systems:Systems with rigid time requirementse.g. must process images coming from a camera at 30 HzKernel delays must be bounded. Disks are a bad ideaCommon in robots, automobiles, appliances, etc.

  • History of Operating Systems: Types of computer systemsMany different system models have evolved over time, driven byHardware costsEfficiencyConvenience for the user

  • Interrupts and system calls

  • Von Neumann Architecture, Modern Style

  • Von Neumann Architecture, Modern StyleCPU and device controllers operate independently, and are connected by a shared bus to shared memory.

    The memory controller synchronizes access to memory.

  • InterruptsMost modern systems are interrupt-driven.If nothing is happening (no programs are ready to run, no IO devices are waiting for service, and no users are making requests),then the system sits idle, waiting for an event.Events are signaled by interrupts.Hardware interrupts: usually triggered when a device enables a line on the system bus, e.g. IRQn on i386Software interrupts (also called traps):Software errors (divide by 0, invalid memory access)System calls (requests for service by the kernel)[Trap is a metaphor for falling through a door from user space execution to kernel mode execution.]

  • InterruptsWhen a hardware interrupt occurs,CPU stops what it is doing and transfers control to an interrupt service routine (ISR)May be different ISRs for different types of interrupts. The list of ISR locations is called the interrupt vector.Example: the Intel 386 architecture contains 16 interrupt lines (IRQ0-IRQ15), requiring a 16-element interrupt vector.After servicing the interrupt, the CPU returns to what it was previously doing. This requires save and restore of process context (program counter, registers, etc.).

  • Interrupts during I/OFor a single process accessing output device:Process generates output but continues.Transfer begins. When done, IO device signals an interrupt.CPU switches to ISR, services the interrupt, then returns to the user process.

  • ProtectionProtection architecture: with resource sharing, processes and their data must be protected from other processes.Also, errors detected by hardware (e.g. divide by 0) should not crash the system. Instead trap to the kernel:Kernel logs an error message, dumps process memory, and so on.Kernel frees resources associated with the bad process and continues normal system operation.

  • ProtectionHardware support for protection: Dual Mode.Some systems use two modes, e.g. USER and MONITOR mode (aka PRIVILEDGED mode).Most modern CPUs support modes.A trap causes a switch from user to monitor mode.When kernel completes the system call or error handler, it switches back to user mode before giving control to a user process.

  • I/O protectionSystem callsequence for I/OSYSTEM MEMORYsystem call routine:Check access privilegesJump to routine for system call nread routine:perform the readreturn control to userRESIDENTMONITORUSERPROGRAMsystem call n (e.g. a read)(1) Trap toMonitor(2) Performthe I/O(3) Returncontrolto user

  • I/O protectionTypically, all I/O operations are privileged.User program requesting I/OIssues a system callSystem call generates a software interrupt (trap)Trap causes bit flip to MONITOR mode and ISR to runKernel ISR checks whether user process has permission to access the requested device.If legal, executes (or queues) the request then flips the mode bit back to user mode.WHY?

  • System callsSystem calls: the main interface between user programs and the kernel.Available as special assembly language instructions or high-level language function calls.In Unix, documented in man page section 2

  • System callsSystem call categories:Process control (creation, deletion, suspension, load, execute, get/set attributes, wait, allocate memory)File management (creation, deletion, open, close, read, write, seek, get/set attributes)Information maintenance (time-of-day, system data)Communications (create channel, delete channel, send, receive, transfer, attach)Most systems use message passing and/or shared memory for IPC

  • System callsSyscall interface between user processes and kernel (in Unix):

  • Operating System Structures: System callsSequence of system calls for cp hw1.pdf hw2.pdf:execve(): morph the child process into a cp instanceSetup: many calls to get OS info, read DLLs into memory, etc.stat(hw1.pdf) to get file information and statusstat(hw2.pdf)open(hw1.pdf) to open the fileopen(hw2.pdf)read() get a block of data from first filewrite() write the block of data to the second file(repeat many times)close() first fileclose() second file

  • What have we learned?What the OS does for us.How the modern OS evolved.Basic computer architecture: interrupts.How the OS services user programs via system calls.

    Convenience and efficiency are sometimes at odds, and some systems stress one over the other. Mainframs, for example, stress efficiency, but are not convenient. PCs running Microsoft Windows are very convenient to use, but not always efficient.Convenience and efficiency are sometimes at odds, and some systems stress one over the other. Mainframes, for example, stress efficiency, but are not convenient. PCs running Microsoft Windows are very convenient to use, but not always efficient.By abstract system model, we mean that users and programmers should not be bogged down with the details of the particular hardware they are using. An example is in a

Search related