INTRO TO OPERATING SYSTEMS
INTRO TO OPERATING SYSTEMS CS 333
Popular in Course
verified elite notetaker
Popular in ComputerScienence
This 48 page Class Notes was uploaded by Orrin Rutherford on Tuesday September 1, 2015. The Class Notes belongs to CS 333 at Portland State University taught by Jonathan Walpole in Fall. Since its upload, it has received 24 views. For similar materials see /class/168271/cs-333-portland-state-university in ComputerScienence at Portland State University.
Reviews for INTRO TO OPERATING SYSTEMS
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/01/15
CS 333 Introduction to Operating Systems Class 2 OSRelated Hardware amp Software The Process Concept Jonathan Walpole Computer Science Portland State University Lecture 2 overview OSRelafed Hardware amp Software Complico rions in real sys rems Brief in rroduc rion To memor pro fec on and reoca on vm ua memory amp MM Us I0amp Inferrupfs The process abstraction Process scheduling Process s ro res Process hierarchies Process sys rem calls in Unix Why its not quite that simple u The basic model introduced in lecture 1 still applies but the following issues tend to complicate implementation in real systems z Pipelined CPUs z Superscalar39 CPUs z MultiIevel memor39y hierarchies z Vir39tual memory 4 Complexity of devices and buses Pipelined CPUs Fetch Decode Execute unit unit unit Execu rion of current ins rr39uc rion performed in parallel wi rh decode of nex r instruction and fe rch of The one offer Tha r Superscalar39 CPUs Fetch unit Decode unit Execute unit Fetch unit Holding buffer Decode unit Execute unit Execute unit What does this mean for the OS a Pipelined CPUs 4 more complexity in taking a snapshot of the state of a running application more expensive to Suspend and resume applications a Superscalar CPUs even more complexity in capturing state of a running application even more expensive to suspend and reSume applications support from hardware is useful ie precise interrupts a More details but fundamentally the same task a The BLITZ CPU is not pipelined or superscalar BLITZ has precise interrupts The memory hierarchy El El D ZGHz processor 9 05 ns clock cycle Datainstruction cache access time 9 05ns 10 ns This is where The CPU looks firsT Memory This fasT is veryexpensive i Size 64 kB 1MB Too small for whole program 7 Main memory access Time 9 60 ns Slow bu r cheap Size 512 MB 168 Magnetic disk 9 10 ms 200 Gbyfes Figure 114 The Memory Hierarchy Terminology review metric units Exp Explicit Pre x Exp Explicit Pre x 103 0001 milli 103 1000 Kilo 10 5 0000001 micro 105 1000000 Mega 10 Q 0000000001 nano 109 1000000000 Giga 10 12 0000000000001 pico 1012 1000000000000 Tera 10 15 0000000000000001 femto 1015 1 000000000000000 Peta 10 18 00000000000000000001 atto 1018 1 OO0000000000000000 Exa 10121 00000000000000000000001 zepto 1021 1000000000000000000000 Zetta 10 24 00000000000000000000000001 yocto 1024 1000000000000000000000000 Yotta The me rr39ic prefixes Who manages the memory hierarchy a Movement of data from main memory to cache is under hardware control cache 39ne5 loaded on demand automatically Placement and replacement policy fixed by hardware a Movement of data from cache to main memory can be affected by OS instructions for flushing the cache 4 can be used to maintain consistency of main memory a Movement of data among lower levels of the memory hierarchy is under direct control of the 05 virtual memory page faults file system calls OS implications of a memory hierarchy a How do you kee the contents of memory consistent across layers 0 the hierarchy a How do you allocate space at layers of the memory hierarchy quotfairlyquot across different applications a How do you hide the latency of the slower subsystems Main memory Disk a How do you protect one application39s area of memory from other applications a How do you reocafe an application in memory How does We programmer know where fIe program w ufmofey reso e m memory Memory protection and relocation a Memory protection the basic ideas virtual vs physical addresses address range in each application starts at 0 Possible solution with base and limit registers base register used to convert each virtual address to a physical address before main memory is accessed address is compared to a limit register to keep memory references within bounds Relocation by changing the base register value Base amp Limit Registers single amp multiple Address UAIIIIIIII Limit r User program and data Base 4 User program and data Operating System a Registers when program 2 is running Reglsters 4 Limite when Program 1 User 2 data is running A 33592 Limit 2 r 33592 User1 data Limit1 Limit1 User program Base1 gt 33561 Operating System b Memory protection and relocation a Memory protection the basic ideas virtual vs physical addresses address range in each application starts at 0 Possible solution with base and limit registers base register used to convert each virtual address to a physical address before main memory is accessed address is compared to a limit register to keep memory references within bounds Relocation by changing the base register value Paged virtual memory same basic concept but more powerful and complex Virtual memory and MMUs a Memory management unit MMU z hardware provided equivalent of multiple base registers at the granularity of pages of memory say 2kB ie lots of them supports relocation at page granularity by replacing high order address bits z applications need not occupy contiguous physical memory a Memory protection limit registers don39t work in this context perpage and perapplication protection registers a Relocation and protection checking occur at CPU speed What about IO devices Monitor Hard Keyboard dizllsf zlle disk drive 1 l lll Floppy Hard Video Keyboard CPU Memory controller controller coggrsclfller cost39rs jler Bus A simplified view of a computer system Structure of a large Pentium system Cache bus Local bus Leve2 cache CPU PCI b dge Memory bus Main 39 I memory PCI bus 1 gt ISA IDE Available bridge H dlSk PCI slot A k Itor ISA bus A H l39l H k quot Ll Ll quot Sound Modem Printer Available How do programs interact with devices a Why protect access to devices by accessing them indirectly via the 05 a Devices vs device controllers vs device drivers 4 device drivers are part of the 05 ie Software programs call the 05 which calls the device driver a Device drivers interact with device controllers either using special IO instructions or by reading writing controller registers that appear as memory locations Device controllers are hardware They communicate with device drivers via interrupts How do devices interact with programs a Interrupts Disk drive 3 CPU Interrupt DISK controller controller I Current instruction I Next instruction 3 Return 1 Interrupt lid MM 1 J 2 Dispatch to handler Interrupt handler Different types of interrupts I Timer interrupts z Allows OS to keep control after calling app39 code z One way to keep track of time 10 interrupts 4 Keyboard mouse disks network etc I u Hardware failures I Program generated traps amp faults z Programming errors seg faults divide by zero etc z System calls like read write gettimeofday System calls a System calls are the mechanism by which programs communicate with the 05 u Implemented via a TRAP instruction u Example UNIX system calls open read write close ki11 signa1 fork wait exec getpid 1ink unlink mount chdir setuid getuid chown 20 The inner workings of a system call Process usercode read file buffer 11 Procedure readfi1e buff 1 readfi1e buff 1 read LOAD r1 SP2 LOAD r2 SP4 LOAD r3 SP6 TRAP ReadCall 21 Steps in making a read system call Address OxFFFFFFFF r User space Kernel space Operating system Library procedure read Increment SP User program ampbuffer calling read 1 Push Sys call handler Dispatch 22 What about disks and file storage Readwrite head 1 per surface Surface 7 Surface 6 Surface 5 Surface 4 39 Surface 3 Direction of arm motion Surface 2 Surface 1 Surface 0 S rr39uc rur39e of a disk drive 23 Disks and file storage u Manipulating the disk device is complicated 4 hide some of the complexity behind disk controller disk device driver a Disk blocks are not a very userfriendly abstraction for storage z contiguous allocation may be difficult for large data items z how do you manage administrative information a One application should not automatically be able to access another application39s storage 4 05 needs to provide a file systemquot 24 File systems Root directory Students Faculty Robber t ProfWhite File system an abstraction above disk blocks 25 What about networks a Network interfaces are just another kind of shared deviceresource u Need to hide complexity z send and receive primitives packets interrupts etc z protocol layers U Need to protect the device z access via the 05 u Need to allocate resources fairly 4 packet scheduling 26 The Process Concept 27 The Process Concept a Process a program in execution z Program description of how to perform an activity instructions and static data values 4 Process a snapshot of a program in execution memory program instructions static and dynamic data values CPU state registers PC SP etc operating system state open files accounting statistics etc 28 Process address space a Each process runs in iTs own virTual memory address space ThaT consisTs of Sfack space used for funcTion and sysTem calls Da7 a space variables boTh sTaTic and dynamic allocaTion TeXf The program code usually read only stack Address space data text a Invoking The same program mulTiple Times resulTs in The creaTion of mulTiple disTincT address spaces 29 Switching among multiple processes a Program instructions operate on operands in memory and temporarily in registers Memory I Load A1 R1 I Dmm Load A2 R2 Progl I C036 Add R1 R2 R3 COde I Store R3 A3 I Prog2 Progl A h 1 Data Prog2 CPU Progl has CPU Prog2 is suspended 30 Switching among multiple processes u Saving all the information about a process allows a process to be temporarily suspended and later resumed from the same point Memory CPU I Prog2 Progl I Code ALU Code I P 1 I Prog2 mg Data OS suspends Progl Progl Prog2 State State Switching among multiple processes u Saving all the information about a process allows a process to be temporarily suspended and later resumed Memory CPU I Prog2 Progl I Code ALU Code I P 1 I Prog2 mg Data Data 7 OS resumes Prog2 32 Switching among multiple processes a Program instructions operate on operands in memory and in registers Memory Progl Code Pro g 1 Data Prog2 Code Load A1 R1 Load A2 R2 Prog2 Data Sub R1 R2 R3 Store R3 A3 CPU Prog2 has CPU Progl is suspended 33 Why use the process abstraction One program counter Four program counters Process switch Process Time gt a b c a Multiprogramrning of four programs in the same address space a Conceptual model of 4 independent sequential processes a Only one program active at any instant 34 The role of the scheduler Processes Scheduler u Lowest layer of processstructured OS z handles interrupts amp scheduling of processes a Sequential processes only exist above that layer 35 Process states 1 Process blocks for input 2 Scheduler picks another process 3 Scheduler picks this process 4 Input becomes available Blocked a Possible process states z running 4 blocked z ready 36 How do processes get created Principal events that cause process creation El El El El System initialization Initiation of a batch job User request to create a new process Execution of a process creation system call from another process 37 Process hierarchies a Parent creates a child process z special system calls for communicating with and waiting for child processes 4 each process is assigned a unique identifying number or process ID PID a Child processes can create their own child processes z Forms a hierarchy z UNIX calls this a quotprocess groupquot z Windows has no concept of process hierarchy all processes are created equal 38 How do processes terminate Conditions which terminate processes El El El El Normal exit voluntary Error exit voluntary Fatal error involuntary Killed by another process involuntary 39 Process creation in UNIX a All processes have a unique process id gem0 0 gefppb O system calls allow processes to get their information a Process creation for0 system call creates a copy of a process and returns in both processes but with a different return value exec replaces an address space with a new program a Process Termination signaling sync0 k39s stem calls allow a process to be terminated or ave specific signals sent to it 40 Example process creation in UNIX csh pid 22 pid fork if pid 0 childm xec else parent wait Process creation in UNIX example csh pid 22 csh pid 24 pid fork if pid 0 childm exec else parent wait pid fork if pid 0 childm exec else parent wait 42 Process creation in UNIX example csh pid 22 csh pid 24 pid fork if pid 0 childm exec else parent wait pid fork if pid 0 childm exec else parent wait 43 Process creation in UNIX example csh pid 22 csh pid 24 pid fork if pid 0 childm exec else parent wait pid fork if pid 0 childm exec else parent wait M Process creation in UNIX example csh pid 22 pid fork if pid 0 childm xec else parent wait ls pid 24 ls program main look up dir What other process state does the OS manage Process management Registers Program counter Program status word Stack pointer Process state Priority Scheduling parameters Process ID Parent process Process group Signals Time when process started CPU time used Children39s CPU time Time of next alarm Memory management Pointer to text segment Pointer to data segment Pointer to stack segment File management Floot directory Working directory File descriptors User ID Group ID Example fields of a process table entry 46 What about the 05 a Is the 05 a process a It is a program in execution after all a Does it need a process control block a Who manages its state when its not running 47 What to do before next class a Reading for next week39s class pages 117128 a Finish project 1 Introduction to BLITZ 48
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'