COS 318: Operating Systems Overview
Total Page:16
File Type:pdf, Size:1020Kb
9/16/19 Important Times u PreCepts: COS 318: Operating Systems l Mon: 7:30-8:20pm, 104 CS building l Tues: 7:30-8:20pm, 105 CS building l This week (TODAY and TOMORROW): Overview • Tutorial on Assembly programming and kernel debugging u ProjeCt 1 Jaswinder Pal Singh and a Fabulous Course Staff l Design review: Computer SCienCe Department • Next Mon/Tues: 3:00–7:00 pm (Signup online), 010 Friend PrinCeton University l Project 1 due: Sunday 9/29 at 11:55pm (http://www.Cs.prinCeton.edu/courses/cos318/) u Immediate To-Do: l Make sure you have your projeCt partner 2 Today Hardware of A TypiCal Computer u Overview of OS funCtionality CPU . CPU u Overview of OS components u InteraCting with the OS Memory Chipset u Booting a Computer I/O bus ROM Network 3 4 1 9/16/19 An Overview of HW FunCtionality Software in a TypiCal Computer u Executing the machine code (CPU, cache, memory) l instruCtions for ALU, branch, memory operations Memory CPU l instruCtions for communiCating with I/O deviCes Applications . u Performing I/O operations . Libraries, Runtime Systems l I/O deviCes and the CPU can exeCute conCurrently Operating System l Every deviCe controller is in charge of one device type CPU BIOS l Every deviCe controller has a local buffer ROM l CPU moves data btwn main memory and loCal buffers l I/O is btwn deviCe and loCal buffer of deviCe Controller OS l DeviCe Controller uses interrupt to inform CPU it is done Apps Network u Protection Data l Timer, paging (e.g. TLB), mode bit (e.g., kernel/user ) 6 TypiCal Unix OS StruCture TypiCal Unix OS StruCture User funCtion Calls written by programmers and Application Application compiled by programmers. Libraries User level Libraries Kernel level Portable OS Layer Portable OS Layer Machine-dependent layer Machine-dependent layer 7 8 2 9/16/19 TypiCal Unix OS StruCture QuiCk Review: How AppliCation is Created • Written by elves foo.c gcC foo.s as foo.o • ObjeCts pre-compiled • Defined in headers bar.C gcC bar.s as bar.o ld a.out Application • Input to linker • Invoked like funCtions • May be “resolved” when libC.a … Libraries program is loaded u gcC can compile, assemble, and link together u Compiler (part of gcC) Compiles a program into assembly Portable OS Layer u Assembler Compiles assembly Code into reloCatable object file u Linker links object files into an executable Machine-dependent layer u For more information: l Read man page of a.out, elf, ld, and nm l Read the doCument of ELF 9 10 AppliCation: How it’s exeCuted What an exeCutable appliCation looks like u On Unix, “loader” does the job u Four segments 2n -1 l Read an exeCutable file l Code/Text – instruCtions Stack l Layout the Code, data, heap and stack l Data – global variables l DynamiCally link to shared libraries l Stack l Prepare for the OS kernel to run the appliCation l Heap u Why: l Separate Code and data? AppliCation Heap *.o, *.a ld a.out loader l Have staCk and heap go towards eaCh other? Shared Initialized data library Code 0 11 12 3 9/16/19 Responsibilities for the segments TypiCal Unix OS StruCture u StaCk l Layout by ? l AlloCated/deallocated by ? l Local names are absolute/relative? u Heap Application l Who sets the starting address? l AlloCated/deallocated by ? Libraries l How do appliCation programs manage it? u Global data/Code l Who alloCates? Portable OS Layer “Guts” of system calls l Who defines names and referenCes? l Who translates referenCes? Machine-dependent layer l Who reloCates addresses? l Who lays them out in memory? 13 14 Must Support Multiple AppliCations Multiple AppliCation ProCesses u In multiple windows l Browser, shell, powerpoint, word, … Application Application Application u Use Command line to run multiple appliCations … ‘ ’ % ls –al | grep ^d Libraries Libraries Libraries % foo & % bar & Portable OS Layer Machine-dependent layer 15 16 4 9/16/19 OS ServiCe Examples TypiCal Unix OS StruCture u Examples that are not provided at user level l System Calls: file open, Close, read and write l Control the CPU so that users won’t cause problems • while ( 1 ) ; Application • Bootstrap l Protection: • System initialization • Interrupt and exCeption • Keep user programs from Crashing OS Libraries • I/O deviCe driver • Keep user programs from Crashing eaCh other • Memory management u Examples that are provided at user level • Mode switChing • ProCessor management l Read time of day Portable OS Layer l ProteCted user-level aCtivities Machine-dependent layer 17 18 Today OS Components u Overview of OS funCtionality u ResourCe manager for eaCh HW resourCe l CPU: proCessor management u Overview of OS components l RAM: memory management u InteraCting with the OS l Disk: file system and secondary-storage management u Booting a Computer l I/O deviCe management (keyboards, mouse, …) u Additional serviCes: l networking l window manager (GUI) l command-line interpreters (e.g., shell) l resource alloCation and aCCounting l protection • Keep user programs from Crashing OS • Keep user programs from Crashing eaCh other 20 5 9/16/19 ProCessor Management Memory Management u Goals u Goals l Overlap between I/O and CPU I/O CPU Register: 1x computation l Support for programs to run CPU I/O and to be written more easily L1 cache: 2-4x l Time sharing l Allocation and management l Multiple CPU alloCation CPU L2 cache: ~10x u Issues l Transfers from and to secondary storage L3 cache: ~50x l Do not waste CPU resourCes CPU u Issues l Synchronization and mutual I/O DRAM: ~200-500x exClusion CPU l EffiCiency & Convenience Disks: ~30M x l Fairness and deadlock CPU l Fairness l Protection CPU ArChive storage: >1000M x 22 23 File System I/O DeviCe Management u Goals: u Goals l Manage disk bloCks l InteraCtions between l Map between files and disk bloCks User 1 . User n deviCes and appliCations u TypiCal file system Calls User 1 . User n l Ability to plug in new l Open a file with authentiCation File system services deviCes l Read/write data in files u l Close a file Issues Library support File . File u Issues l Diversity of deviCes, third- l Reliability party hardware Driver Driver l Safety l EffiCiency I/O I/O l EffiCienCy l Fairness device . device l Manageability l Protection and sharing 24 25 6 9/16/19 Window Systems Summary u Goals u Overview of OS funCtionality l InteraCting with a user l Layers of abstraction l InterfaCes to examine and l ServiCes to appliCations manage apps and the system l ResourCe management u Issues u Overview of OS Components l Inputs from keyboard, mouse, l Processor management touCh sCreen, … l Memory management l Display output from appliCations l I/O deviCe management and systems l File system l Where is the Window System? l Window system • All in the kernel (Windows) • All at user level l … • Split between user and kernel (Unix) 26 27 Today How the OS is Invoked u Overview of OS funCtionality u ExCeptions u Overview of OS components l Normal or program error: faults, traps, aborts u InteraCting with the OS l Special software generated: INT 3 l MaChine-check exCeptions u Booting a Computer u Interrupts l Hardware (by external deviCes) l Software: INT n u System Calls u See Intel doCument volume 3 for details 28 29 7 9/16/19 Interrupts Interrupt and ExCeptions (1) u Raised by external events Vector # Mnemonic Description Type u Interrupt handler is in kernel 0: 0 #DE Divide error (by zero) Fault u Eventually resume the 1: 1 #DB Debug Fault/trap Interrupt … 2 NMI interrupt Interrupt interrupted proCess handler u A way to i: 3 #BP Breakpoint Trap i+1: 4 #OF Overflow Trap l SwitCh CPU to another … process 5 #BR BOUND range exceeded Trap l Overlap I/O with CPU N: 6 #UD Invalid opcode Fault 7 #NM Device not available Fault l Handle other long-latenCy events 8 #DF Double fault Abort 9 Coprocessor segment overrun Fault 10 #TS Invalid TSS (Task State Segment). Kernel/HW bug. 30 31 Interrupt and ExCeptions (2) System Calls Vector # Mnemonic Description Type u Operating system API 11 #NP Segment not present Fault l InterfaCe between an appliCation and the operating 12 #SS Stack-segment fault Fault system kernel 13 #GP General protection Fault u Categories of system Calls 14 #PF Page fault Fault l Process management l Memory management 15 Reserved Fault l File management 16 #MF Floating-point error (math fault) Fault l DeviCe management 17 #AC Alignment check Fault l CommuniCation 18 #MC Machine check Abort 19-31 Reserved 32-255 User defined Interrupt 32 33 8 9/16/19 How many system Calls? System Call MeChanism u 6th Edition Unix: ~45 u Assumptions l User Code Can be arbitrary u POSIX: ~130 l User Code Cannot modify kernel User User u FreeBSD: ~130 memory program program u Linux: ~250 u Design Issues return call l User makes a system Call with u Windows 7: > 900 parameters l The Call meChanism switChes entry code to kernel mode Kernel in l ExeCute system Call protected memory l Return with results 34 35 OS Kernel: Trap Handler Interrupt, trap and syscall vector Interrupt u Table set up by OS kernel; pointers to Code to run service on different events HW Device Syscall table routines Interrupt Processor Interrupt Register Vector Table System Call System ServiCe System HW exceptions dispatcher services handleTimerInterrupt() { SW exceptions ..