CSE 380 Computer Operating SystemsWhat is an Operating System?Resource Abstraction and SharingPentium ArchitectureAbstractions in OSSharing of MemoryTimesharingChallenges in OSHow does OS work?Inside a CPUDifferent types of MemorySample Scenario 1Sample Scenario 1 (continued)Sample Scenario 2Sample Scenario 2 (continued)Brief History of Operating Systems1940's -- First Computers1950's -- Batch ProcessingTypical Batch System1960's -- Multiprogramming (timesharing)1970's - Minicomputers & Microprocessors1980's - Networking1990's and BeyondOperating System StructureOperating System Structure (1)Operating System Structure (2)Operating System Structure (3)Operating System Structure (4)Operating System Structure (5)1CSE 380Computer Operating SystemsInstructor: Insup LeeUniversity of PennsylvaniaFall 2003Lecture Note 1: Introduction2What is an Operating System?Operating systems provides an interface between hardware and user programs, and makes hardware usable3Resource Abstraction and SharingIt is an extended machine providing abstraction of the hardwareHides the messy details which must be performedPresents user with a virtual machine, easier to useIt is a resource managerTime on CPU is shared among multiple users/programsSpace in memory and on disks is shared among multiple users/programs4Pentium Architecture5Abstractions in OSHardwareDisksMemoryProcessorsNetworkMonitorKeyboardMouseOS abstractionFilesProgramsThreads / ProcessesCommunicationWindows and GUIInputLocator6Sharing of MemoryIssuesAllocation schemesProtection from each otherProtecting OS codeTranslating logical addresses to physicalSwapping programsWhat if physical memory is small: Virtual memoryProgram 2O S Program 3Free spaceProgram 17TimesharingAt any point, only one program can run on CPUContext switch: changing the program that has CPUWhen to switch (goal: to optimize the CPU usage)When a program terminatesWhen a program has run “long enough”When a program executes a system call or waits for I/OWhen an external interrupt arrives (e.g. mouse click)OS must do all the book-keeping necessary for context switch, with minimum number of instructionsP1 P1P2 P3OS OS OS OS8Challenges in OSPerformance is criticalHow to reduce the memory and time overhead due to OSSynchronization and deadlocks due to shared resourcesScheduling of multiple programsFairness, response time, real-time applicationsMemory management Virtual memory, paging, segmentationSecurity and ProtectionAuthorization, authentication, virusesInterrupt management and error handlingMarketability and backward compatibilityWhy can’t Microsoft still get rid of all bugs in Windows ?9How does OS work?OS gets control of the CPU repeatedlyLet’s look at two typical scenarios to get a glimpse of how things work (we will get a more accurate and detailed understanding as the course progresses)Basic knowledge about computer architecture is essential ! (Read Sec 1.4 to review CSE 240)10Inside a CPUState of a running programRegistersProgram counter (PC)Stack pointerProgram status word (PSW)Key distinction in PSW: user mode vs kernel (OS) modeKey instruction for OS calls: TRAP (switch to kernel mode)Many operations (such as accessing I/O devices) are possible only in the kernel mode11Different types of Memory Use of disks unavoidable (permanence and size)Access time is significantly slower for disks12Sample Scenario 1Consider a statement to read from a file in a user program PUser program stores parameters such as file-id, memory-address, number-of-bytes, and system-call number of read, and executes TRAP instruction to invoke OSHardware saves the state of current program, sets the mode-bit in PSW register in CPU to 1, and transfers control to a fixed location in OS codeOS maintains an internal file table that stores relevant information about all open files13Sample Scenario 1 (continued)OS read routine examines the parameters, checks for errors (e.g. file must be open), consults its file table, and determines the disk address from where data is to be retrieved then it sets up registers to initiate transfer by the disk controllerWhile disk controller is transferring data from disk to memory, OS can suspend current program, and switch to a different programWhen OS routine finishes the job, it stores the status code, and returns control to the user program P (hardware resets mode-bit)Note: Disk controller is accessed only by OS code (this is ensured by hardware protection)14Sample Scenario 2Consider an assignment x:=y in a program PCompiler assigns logical addresses, say Add1 and Add2, for program variables in P’s data spaceWhen P is loaded in memory, OS assigns a physical base address to store P and its dataCompiled code looks likeLoad (R, Add1); Store (R, Add2)While executing Load instruction the hardware translates the logical address Add1 to a physical memory location (this is done by Memory Management Unit MMU)15Sample Scenario 2 (continued)However, OS may not keep all of P in memory all the timeOS maintains an internal table, called page table, that keeps track of which blocks of P are in memoryIf Add1 is not in memory, MMU generates a page fault, and transfers control to OSOS examines the cause, and initiates a disk transfer to load in the relevant block of POS needs to decide memory allocation for the block to be fetched (page replacement algorithms)While this block is being fetched, P may be suspended using a context switch16Brief History of Operating Systems1940's -- First Computers1950's -- Batch Processing1960's -- Multiprogramming (timesharing)1970's -- Minicomputers & Microprocessors1980's -- Networking, Distributed Systems, Parallel (multiprocessor) Systems1990's and Beyond -- PCs, WWW, Mobile Systems, embedded systems171940's -- First ComputersComputer dedicated to one user/programmer at a time. Program loaded manually by programmer, using console switches. Debugging using console lights. Advantages:Interactive (user gets immediate response)Disadvantages:Expensive machine idle most of time, because people are slow.Programming & debugging are tedious.Each program must include code to operate peripherals -- error prone, device dependencies.Libraries of subroutines to drive peripherals are
View Full Document