Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

1 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
Carnegie Mellon 1 Exceptional Control Flow: Exceptions and Processes /18-243: Introduction to Computer Systems 13 th Lecture, June 15, 2011 Instructors:
University of Washington Today Midterm grades posted  76. HW 3 due Lab 4 fun! 1.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 3 – Process Concepts Outline 3.1 Introduction 3.1.1Definition of Process 3.2Process States:
University of Washington Today Finish up cache-aware programming example Processes  So we can move on to virtual memory 1.
University of Washington Today Move on to … 1. University of Washington Hmm… Lets look at this again Disk Main Memory L2 unified cache L1 I-cache L1 D-cache.
Processes Topics Process context switches Creating and destroying processes CS 105 “Tour of the Black Holes of Computing!”
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Exceptional Control Flow Part I September 22, 2008 Topics Exceptions Process context switches Creating and destroying processes class11.ppt ,
OS Spring’03 Introduction Operating Systems Spring 2003.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes class14.ppt CS 123.
Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes.
Introduction to Interrupts
Exceptions, Interrupts & Traps
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
1 Program and OS interactions: Exceptions and Processes Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaron.
Fabián E. Bustamante, Spring 2007 Exceptional Control Flow Part I Today Exceptions Process context switches Creating and destroying processes Next time.
Exceptional Control Flow Part I March 4, 2004 Topics Exceptions Process context switches Creating and destroying processes class16.ppt “The course.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Carnegie Mellon 1 Exceptional Control Flow: Exceptions and Processes : Introduction to Computer Systems 13 th Lecture, Oct. 7, 2014 Instructors:
CSC 2405 Computer Systems II Exceptions Mini-Lecture Traps & Interrupts.
Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes class16.ppt.
Exceptional Control Flow Topics Exceptions except1.ppt CS 105 “Tour of the Black Holes of Computing”
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Exceptional Control Flow I March 12, 2002
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Carnegie Mellon 1 CMSC os1: OS and Exceptions Chapter 8.1 Instructors: Haryadi Gunawi Henry Hoffmann Matthew Wachs.
Computer Organization & Design 计算机组成与设计
Exceptional Control Flow
CS 3214 Computer Systems Lecture 9 Godmar Back.
Operating Systems CMPSC 473
Exceptional Control Flow & Processes
Exceptional Control Flow
Exceptions and Processes
Microprocessor Systems Design I
Exceptional Control Flow
Protection of System Resources
Exceptional Control Flow
Chapter 3 – Process Concepts
Exceptional Control Flow Oct 24, 2000
Overview of today’s lecture
Exceptional Control Flow Part I
Exceptional Control Flow
Instructors: Anthony Rowe, Seth Goldstein and Gregory Kesden
Exceptional Control Flow: System Calls, Page Faults etc.
Exceptional Control Flow
Exceptional Control Flow I
Exceptional Control Flow Part I Mar. 11, 2003
Exceptional Control Flow Part I
Exceptions Control Flow
CS 105 “Tour of the Black Holes of Computing!”
Processes Prof. Ikjun Yeom TA – Mugyo
Exceptions and Processes
Exceptional Control Flow
CS201 - Lecture 17 Exceptions
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
System Control Flow and Processes CSE 351 Winter 2018
CS510 Operating System Foundations
Architectural Support for OS
Exceptional Control Flow & Processes October 2, 2008
Interrupts and System Calls
Presentation transcript:

Exceptional Control Flow Processes Today

Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets) a sequence of instructions, one at a time This sequence is the CPU’s control flow (or flow of control) inst 1 inst 2 inst 3 … inst n Physical control flow Time

Altering the Control Flow Up to now: two mechanisms for changing control flow: Jumps and branches Call and return Both react to changes in program state Insufficient for a useful system: Difficult to react to changes in system state data arrives from a disk or a network adapter instruction divides by zero user hits Ctrl-C at the keyboard System timer expires System needs mechanisms for “exceptional control flow”

Exceptional Control Flow Exists at all levels of a computer system Low level mechanisms Exceptions change in control flow in response to a system event (i.e., change in system state) Combination of hardware and OS software Higher level mechanisms Process context switch Signals Nonlocal jumps: setjmp()/longjmp() Implemented by either: OS software (context switch and signals) C language runtime library (nonlocal jumps)

Exceptions An 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-C User ProcessOS exception exception processing by exception handler return to I_current return to I_next abort event I_current I_next

n-1 Interrupt Vectors Each type of event has a unique exception number k k = index into exception table (a.k.a. interrupt vector) Handler k is called each time exception k occurs Exception handler runs in kernel mode User mode to kernel mode Makes use of kernel stack Exception table base register Exception Table code for exception handler 0 code for exception handler 1 code for exception handler 2 code for exception handler n-1... Exception numbers

Asynchronous Exceptions (Interrupts) Caused by events external to the processor Indicated by setting the processor’s interrupt pin Handler returns to “next” instruction Examples: I/O interrupts hitting Ctrl-C at the keyboard arrival of a packet from a network arrival of data from a disk Hard reset interrupt hitting the reset button Soft reset interrupt hitting Ctrl-Alt-Delete on a PC

Synchronous Exceptions Caused by events that occur as a result of executing an instruction: Traps Intentional Examples: system calls, breakpoint traps, special instructions Returns control to “next” instruction Faults Unintentional but possibly recoverable Results from an error condition Examples: page faults (recoverable), protection faults (unrecoverable), floating point exceptions Either re-executes faulting (“current”) instruction or aborts Aborts unintentional and unrecoverable Examples: parity error, machine check Aborts current program

Trap Example: Opening File User calls: open(filename, options) Function open executes system call instruction int OS must find or create file, get it ready for reading or writing Returns integer file descriptor 0804d070 : d082:cd 80 int $0x80 804d084:5b pop %ebx... User ProcessOS exception open file returns int pop

Fault Example: Page Fault User writes to memory location That portion (page) of user’s memory is currently on disk Page handler must load page into physical memory Returns to faulting instruction Successful on second try int a[1000]; main () { a[500] = 13; } 80483b7:c d d movl $0xd,0x8049d10 User ProcessOS exception: page fault Create page and load into memory returns movl

Fault Example: Invalid Memory Reference Page handler detects invalid address Sends SIGSEGV signal to user process User process exits with “segmentation fault” int a[1000]; main () { a[5000] = 13; } 80483b7:c e d movl $0xd,0x804e360 User ProcessOS exception: page fault detect invalid address movl signal process

Exception Table IA32 (Excerpt) Exception NumberDescriptionException Class 0Divide errorFault 13General protection faultFault 14Page faultFault 18Machine checkAbort OS-definedInterrupt or trap 128 (0x80)System callTrap OS-definedInterrupt or trap Check Table 6-1:

Today Exceptional Control Flow Processes

Definition: A process is an instance of a running program. One of the most profound ideas in computer science Not the same as “program” or “processor” Process provides each program with two key abstractions: Logical control flow Each program seems to have exclusive use of the CPU Private virtual address space Each program seems to have exclusive use of main memory How are these Illusions maintained? Process executions interleaved (multitasking) or run on separate cores Address spaces managed by virtual memory system

Concurrent Processes Two processes run concurrently (are concurrent) if their flows overlap in time Otherwise, they are sequential Examples (running on single core): Concurrent: A & B, A & C Sequential: B &C Process AProcess BProcess C Time

User View of Concurrent Processes Control flows for concurrent processes are physically disjoint in time However, we can think of concurrent processes are running in parallel with each other Time Process AProcess BProcess C

Context Switching Processes are managed by a shared chunk of OS code called the kernel Important: the kernel is not a separate process, but rather runs as part of some user process Control flow passes from one process to another via a context switch Process AProcess B user code kernel code user code kernel code user code context switch Time

Private virtual address space

fork : Creating New Processes int fork(void) creates a new process (child process) that is identical to the calling process (parent process) returns 0 to the child process returns child’s pid to the parent process Fork is interesting (and often confusing) because it is called oncebut returns twice pid_tpid = fork(); if (pid== 0) { printf("hello from child\n"); } else { printf("hello from parent\n"); }