Slide 1Perflab: Current StatusLast TimeLast Time: Symbol ResolutionLast Time: RelocationLast Time: Loading ExecutableTodayControl FlowAltering the Control FlowExceptional Control FlowExceptionsInterrupt VectorsAsynchronous Exceptions (Interrupts)Synchronous ExceptionsTrap Example: Opening FileFault Example: Page FaultFault Example: Invalid Memory ReferenceException Table IA32 (Excerpt)TodayProcessesConcurrent ProcessesUser View of Concurrent ProcessesContext Switchingfork: Creating New ProcessesUnderstanding forkFork Example #1Fork Example #2Fork Example #3Fork Example #4Fork Example #4exit: Ending a processZombiesZombie ExampleNonterminating Child Examplewait: Synchronizing with Childrenwait: Synchronizing with Childrenwait() Examplewaitpid(): Waiting for a Specific Processexecve: Loading and Running Programsexecve: Exampleexecl and exec Familyexec: Loading and Running ProgramsSummarySummary (cont.)Carnegie MellonIntroduction to Computer Systems15-213/18-243, spring 200914th Lecture, Mar. 3rdInstructors: Gregory Kesden and Markus PüschelCarnegie MellonPerflab: Current Statushttps://autolab.cs.cmu.edu/15213-s09/autolab.plCarnegie MellonLast TimeOptimization for the memory hierarchyLinkingSymbol resolution: Associate each symbol reference with exactly one definitionRelocation: Merge all .o files into one executableObject filesRelocatable object files (.o)ExecutablesShared object file (.so)ELF formatELF headerSegment header table(required for executables).text section.rodata section.bss section.symtab section.rel.txt section.rel.data section.debug sectionSection header table.data sectionCarnegie MellonLast Time: Symbol ResolutionSymbolsGlobalExternalLocalSymbolsStrongWeakextern int buf[]; static int *bufp0 = &buf[0];static int *bufp1;void swap(){ int temp; bufp1 = &buf[1]; temp = *bufp0; *bufp0 = *bufp1; *bufp1 = temp;}swap.cExternal LocalGlobalLinker knowsnothing of tempCarnegie MellonLast Time: Relocationmain()main.oint *bufp0=&buf[0]swap()swap.oint buf[2]={1,2}Headersmain()swap()System codeint *bufp0=&buf[0]int buf[2]={1,2}System dataMore system codeint *bufp1System dataRelocatable Object Files Executable Object File.text.text.data.text.data.text.data.bss .symtab.debug.dataUninitialized data.bssSystem codeCarnegie MellonLast Time: Loading ExecutableELF headerProgram header table(required for executables).text section.data section.bss section.symtab.debugSection header table(required for relocatables)0Executable Object FileKernel virtual memoryMemory-mapped region forshared librariesRun-time heap(created by malloc)User stack(created at runtime)Unused0%esp (stack pointer)Memoryinvisible touser codebrk0xc00000000x080480000x40000000Read/write segment(.data, .bss)Read-only segment(.init, .text, .rodata)Loaded from the executable file.rodata section.line.init section.strtabCarnegie MellonTodayExceptional Control FlowProcessesCarnegie MellonControl Flow<startup>inst1inst2inst3…instn<shutdown>Processors do only one thing:From startup to shutdown, a CPU simply reads and executes (interprets) a sequence of instructions, one at a timeThis sequence is the CPU’s control flow (or flow of control)Physical control flowTimeCarnegie MellonAltering the Control FlowUp to now: two mechanisms for changing control flow:Jumps and branchesCall and returnBoth react to changes in program stateInsufficient for a useful system: Difficult to react to changes in system state data arrives from a disk or a network adapterinstruction divides by zerouser hits Ctrl-C at the keyboardSystem timer expiresSystem needs mechanisms for “exceptional control flow”Carnegie MellonExceptional Control FlowExists at all levels of a computer systemLow level mechanismsExceptions change in control flow in response to a system event (i.e., change in system state)Combination of hardware and OS softwareHigher level mechanismsProcess context switchSignalsNonlocal jumps: setjmp()/longjmp()Implemented by either:OS software (context switch and signals)C language runtime library (nonlocal jumps)Carnegie MellonExceptionsAn exception is a transfer of control to the OS in response to some event (i.e., change in processor state)Examples: div by 0, arithmetic overflow, page fault, I/O request completes, Ctrl-CUser Process OSexceptionexception processingby exception handler• return to I_current•return to I_next•abortevent I_currentI_nextCarnegie Mellon012...n-1Interrupt VectorsEach type of event has a unique exception number kk = index into exception table (a.k.a. interrupt vector)Handler k is called each time exception k occursExceptionTablecode for exception handler 0code for exception handler 1code forexception handler 2code for exception handler n-1...Exception numbersCarnegie MellonAsynchronous Exceptions (Interrupts)Caused by events external to the processorIndicated by setting the processor’s interrupt pinHandler returns to “next” instructionExamples:I/O interruptshitting Ctrl-C at the keyboardarrival of a packet from a networkarrival of data from a diskHard reset interrupthitting the reset buttonSoft reset interrupthitting Ctrl-Alt-Delete on a PCCarnegie MellonSynchronous ExceptionsCaused by events that occur as a result of executing an instruction:TrapsIntentionalExamples: system calls, breakpoint traps, special instructionsReturns control to “next” instructionFaultsUnintentional but possibly recoverable Examples: page faults (recoverable), protection faults (unrecoverable), floating point exceptionsEither re-executes faulting (“current”) instruction or abortsAbortsunintentional and unrecoverableExamples: parity error, machine checkAborts current programCarnegie MellonTrap Example: Opening FileUser calls: open(filename, options)Function open executes system call instruction intOS must find or create file, get it ready for reading or writingReturns integer file descriptor0804d070 <__libc_open>: . . . 804d082: cd 80 int $0x80 804d084: 5b pop %ebx . . .User Process OSexceptionopen filereturnsintpopCarnegie MellonFault Example: Page FaultUser writes to memory locationThat portion (page) of user’s memory is currently on diskPage handler must load page into physical memoryReturns to faulting instructionSuccessful on
View Full Document