Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Similar documents
Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Process Description and Control. Chapter 3

CSE 153 Design of Operating Systems

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Instruction Set Architecture of MIPS Processor

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Process Description and Control. Chapter 3

Process Description and Control. Chapter 3

Major Requirements of an OS

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Anne Bracy CS 3410 Computer Science Cornell University

Four Components of a Computer System. Operating System Concepts 7 th Edition, Jan 12, 2005

Operating Systemss and Multicore Programming (1DT089)

Computer Systems II. First Two Major Computer System Evolution Steps

CSE 153 Design of Operating Systems Fall 18

Lec 22: Interrupts. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

Processes. Dr. Yingwu Zhu

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CS 550 Operating Systems Spring Interrupt

3.1 Introduction. Computers perform operations concurrently

Process Description and Control

IT 540 Operating Systems ECE519 Advanced Operating Systems

The Kernel Abstraction. Chapter 2 OSPP Part I

Process Scheduling Queues

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Operating System Concepts

Announcement. Exercise #2 will be out today. Due date is next Monday

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

Anne Bracy CS 3410 Computer Science Cornell University

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

Operating Systems. Lecture 3- Process Description and Control. Masood Niazi Torshiz

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Chapter 9: Virtual-Memory Management. Operating System Concepts 8 th Edition,

! The Process Control Block (PCB) " is included in the context,

Chapter 1: Introduction. Operating System Concepts 8 th Edition,

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

The Operating System (OS) MicroComputer Engineering OperatingSystem slide 1!

Operating System Control Structures

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

The Kernel Abstraction

Announcements Processes: Part II. Operating Systems. Autumn CS4023

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Lecture 11: Interrupt and Exception. James C. Hoe Department of ECE Carnegie Mellon University

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

Chap 4, 5: Process. Dongkun Shin, SKKU

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Processes. Sanzheng Qiao. December, Department of Computing and Software

Process Description and Control

Today: Computer System Overview (Stallings, chapter ) Next: Operating System Overview (Stallings, chapter ,

CS370 Operating Systems

Processes. CS3026 Operating Systems Lecture 05

Processes, PCB, Context Switch

Architectural Support for Operating Systems

Operating Systems. Lecture 05

Process Description and Control

CS 322 Operating Systems Practice Midterm Questions

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

TCSS 422: OPERATING SYSTEMS

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Syscalls, exceptions, and interrupts, oh my!

Interrupts Peter Rounce

Chapter 8: Virtual Memory. Operating System Concepts

Exceptions and Interrupts

Traps, Exceptions, System Calls, & Privileged Mode

OPERATING SYSTEMS: Lesson 4: Process Scheduling

Chapter 1: Introduction. Operating System Concepts 9 th Edit9on

CS 326: Operating Systems. Process Execution. Lecture 5

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

SMD149 - Operating Systems

CSE 120 Principles of Operating Systems

COS 318: Operating Systems

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong

CSC 539: Operating Systems Structure and Design. Spring 2006

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

Distributed Systems Operation System Support

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

CSE 120 Principles of Operating Systems

Exceptions and Processes

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 1 Solution Due 3:15 PM, Wednesday, 2/1/17

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Page 1, 5/4/99 8:22 PM

CS370 Operating Systems

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

CS 5460/6460 Operating Systems

Frequently asked questions from the previous class survey

Operating Systems and Interrupts/Exceptions

POLITECNICO DI MILANO. Exception handling. Donatella Sciuto:

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

CS399 New Beginnings. Jonathan Walpole

Hardware OS & OS- Application interface

CS370 Operating Systems

csci3411: Operating Systems

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Transcription:

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management Boris Grot School of Informatics University of Edinburgh

Class party! When: Friday, Dec 1 @ 8pm Where: Bar 50 on Cowgate Inf2C Computer Systems - 2017-2018. Boris Grot 3

Previous lecture: Virtual memory Solves two problems: Capacity (physical memory is limited) Safety (physical memory must be shared by multiple programs and the OS) Virtual vs physical address space Each program sees a full 32-bit address space Actual physical memory managed by the OS Address translation Page table all translations, but slow (in memory) TLB recent entries only, but fast (cache) Inf2C Computer Systems - 2017-2018. Boris Grot 4

Exceptions definition Exceptional events that interrupt normal program flow and require attention of the CPU outside of the running program External ( interrupts ) Not caused by program execution E.g., I/O interrupt (e.g., network packet arrived) Internal ( traps ) Caused by program execution E.g. illegal instruction, arithmetic overflow, TLB miss Inf2C Computer Systems - 2017-2018. Boris Grot 5

Intentional exceptions Use exception mechanism to request some OS functions e.g., I/O (e.g., print to screen), memory allocation MIPS: user program uses syscall instruction Cause register ($v0) is set with a special value to identify the syscall exception OS exception handler invoked when instruction executes Parameters are passed to the OS through agreed upon registers (usually $a0, $a1,..) Linux: library call Inf2C Computer Systems - 2017-2018. Boris Grot 6

Syscall example The following will print the integer in register $t0 to the screen. li $v0, 1 # service 1 is print integer add $a0, $t0, $zero # load integer into $a0 syscall Inf2C Computer Systems - 2017-2018. Boris Grot 7

Exception mechanism Step 1: Save the address of current instruction into a special register, the exception program counter (EPC) Note: must return to the interrupted instruction (not PC+4) Step 2: Transfer control to the OS at a known address (i.e., exception handler PC) Step 3: Handle the exception Deal with the cause of the exception All registers must be preserved, similar to a procedure call Step 4: Return to user program execution Handler restores user program s registers and jumps back using EPC Relies on special instruction eret Inf2C Computer Systems - 2017-2018. Boris Grot 8

Finding the exception handler Approach 1: Jump to a predefined address (e.g., 0x800000180 in MARS) Use the Cause register to then branch to the right handler (e.g., print int, read string, exit program) Works well for syscall cause register explicitly set Approach 2 Directly jump to a specific handler depending on the exception (vectored interrupt) Eg: Undefined opcode: 0x8000 0000 Overflow: 0x8000 0020 : 0x8000 0040 Inf2C Computer Systems - 2017-2018. Boris Grot 9

Handling the exception Determine action required By inspecting the Cause register or by virtue of being at the right handler (e.g., undefined opcode) If restartable: Take corrective action, then use EPC to return to program Otherwise: Terminate program and report error using EPC, cause, For a critical time while the interrupt is being handled, other interrupts should not happen Otherwise the EPC, Cause will be overwritten This is forced by masking interrupts à by setting the exception level (EXL) bit in the status register Inf2C Computer Systems - 2017-2018. Boris Grot 10

Protecting system resources The OS must guarantee safe and orderly access to critical system resources Hardware (processor, networking, I/O) Program memory (including page tables) The OS is the ultimate arbiter of what s allowed TLB miss à OK (but must access page table to service) Arithmetic overflow à may be OK (depends on what we re doing) Illegal opcode à not OK (kill the program) Exceptions are used to hand control over to the OS Need a separate mechanism to limit capabilities of user programs Inf2C Computer Systems - 2017-2018. Boris Grot 11

Kernel vs. User Mode Protection Exceptions (including system calls) are handled by the OS CPU has two modes of operation: user and kernel (OS) Current mode identified by a bit in a special status register Privileged instructions only executed in kernel mode E.g. accessing I/O devices, handling page table accesses and TLB updates, halt or reset the processor or change its voltage Kernel mode can only be entered through an exception User programs cannot jump to OS instruction space eret instruction sets mode back to previous mode Inf2C Computer Systems - 2017-2018. Boris Grot 12

Advantages of Dual Mode architecture Guarantees that control is transferred to OS when user programs attempt to perform potentially dangerous tasks Allows OS to ensure that programs do not interfere with each other e.g., each program is able to get its share of physical memory Allows OS to ensure that programs do not have access to resources for which they do not have permission e.g., files, another program s memory Ensures that user programs do not have indefinite control of the processor Time-sharing of the CPU Inf2C Computer Systems - 2017-2018. Boris Grot 13

Time-Sharing the CPU Problem: I/O takes too long processor idle User programs can crash or monopolize the CPU (either unintentionally or maliciously) Solution: Multiplex or time-share the CPU and other resources among several user processes Switch from one process to another when it performs I/O, or when its time allocation (time slice) expires Process: a program in execution [Silberschatz, Galvin, Gagne] Inf2C Computer Systems - 2017-2018. Boris Grot 14

Multi-tasking Single-task system: waiting for I/O processor idle process running system call for I/O process running I/O completion (interrupt) Multi-tasking system: OS interrupt handler running OS interrupt handler running process 1 running system call for I/O process 2 running Process 1 running I/O completion Inf2C Computer Systems - 2017-2018. Boris Grot 15

Managing Processes Processes are managed by the OS kernel Kernel: the core of the operating system that controls all software and hardware resources First to be loaded when the computer boots Manages interrupts, processes, memory, I/O The kernel s scheduler chooses which process to run next from the pool of active processes New processes can be explicitly created by the user, or implicitly by another process (through forking) Original process parent New process child Inf2C Computer Systems - 2017-2018. Boris Grot 16

Process States States: READY I/O COMPLETION BLOCKED RUNNING: process is currently running in the CPU READY: process is not running, but could run if brought into CPU BLOCKED: process is not able to run because it is waiting for I/O to finish DISPATCH Transitions: TIMEOUT RUNNING I/O REQUEST I/O REQUEST: process initiates I/O I/O COMPLETION: I/O finishes DISPATCH: OS moves process into CPU and it starts executing TIMEOUT: process s timeslice is over Inf2C Computer Systems - 2017-2018. Boris Grot 17

Process States Step 1: process calls (or traps into) the OS, or interrupt occurs (e.g. because of timer) Step 2: OS s dispatcher performs context switch: Process s context is saved (registers, PC, etc) in process control block (PCB) Dispatcher chooses new process to run Processes states are updated PCB: OS data structure containing each process s information: Process id (PID) Process state (blocked, running, etc) Process priority Process permissions Etc Inf2C Computer Systems - 2017-2018. Boris Grot 18

Suspending and Resuming Processes Problem: Might not have enough physical memory for all processes Some processes have higher priority and must get more processor & memory resources (e.g., high-res game) Solution: Processes can be swapped out from memory to disk Such processes are moved into an inactive state 2 new process states PCB of inactive processes are still kept in OS memory Inactive processes are resumed by swapping in the data from disk back to memory Inf2C Computer Systems - 2017-2018. Boris Grot 19

Suspending and Resuming Processes I/O COMPLETION READY DISPATCH BLOCKED ACTIVE STATES TIMEOUT I/O REQUEST RESUME RUNNING RESUME SUSPEND SUSPEND INACTIVE STATES SUSPENDED READY SUSPENDED BLOCKED I/O COMPLETION Inf2C Computer Systems - 2017-2018. Boris Grot 20