Interrupts Peter Rounce

Similar documents
Interrupts Peter Rounce - room 6.18

Operating System Control Structures

Input / Output. School of Computer Science G51CSA

Input Output (IO) Management

Process Description and Control

The control of I/O devices is a major concern for OS designers

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

CSC227: Operating Systems Fall Chapter 1 INTERRUPTS. Dr. Soha S. Zaghloul

Major Requirements of an OS

Process Description and Control. Chapter 3

Process Description and Control

18-349: Introduction to Embedded Real-Time Systems

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

These three counters can be programmed for either binary or BCD count.

Virtual Memory Outline

CS 550 Operating Systems Spring Interrupt

Chapter 9: Virtual Memory

PC Interrupt Structure and 8259 DMA Controllers

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

1. Background. 2. Demand Paging

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

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

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

IT 540 Operating Systems ECE519 Advanced Operating Systems

Chapter 9: Virtual-Memory

Unit 3 and Unit 4: Chapter 4 INPUT/OUTPUT ORGANIZATION

Anne Bracy CS 3410 Computer Science Cornell University

Lecture 3: Concurrency & Tasking

Anne Bracy CS 3410 Computer Science Cornell University

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

操作系统概念 13. I/O Systems

Process Scheduling Queues

Hardware OS & OS- Application interface

Q.1 Explain Computer s Basic Elements

There are different characteristics for exceptions. They are as follows:

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Today s class. Finish review of C Process description and control. Informationsteknologi. Tuesday, September 18, 2007

Process- Concept &Process Scheduling OPERATING SYSTEMS

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

Efficiency and memory footprint of Xilkernel for the Microblaze soft processor

Computer Systems II. First Two Major Computer System Evolution Steps

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

Processes. Dr. Yingwu Zhu

8086 Interrupts and Interrupt Responses:

3.1 Introduction. Computers perform operations concurrently

CS370 Operating Systems

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

OPERATING SYSTEMS. Systems with Multi-programming. CS 3502 Spring Chapter 4

Programming Embedded Systems

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

HANDLING MULTIPLE DEVICES

CS 104 Computer Organization and Design

Page Replacement Algorithms

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 13: I/O Systems

INTERRUPTS in microprocessor systems

Module 12: I/O Systems

EE458 - Embedded Systems Exceptions and Interrupts

Syscalls, exceptions, and interrupts, oh my!

Silberschatz and Galvin Chapter 12

ECE332, Week 8. Topics. October 15, Exceptions. Hardware Interrupts Software exceptions

[08] IO SUBSYSTEM 1. 1

Interrupts in Zynq Systems

Chapter 12: I/O Systems

Chapter 13: I/O Systems

Chapter 12: I/O Systems. Operating System Concepts Essentials 8 th Edition

Chapter 13: I/O Systems

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

Interrupt/Timer/DMA 1

THE CPU SPENDS ALMOST ALL of its time fetching instructions from memory

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

Single thread Scheduler All processes called once each sample

Chapter 3 - Top Level View of Computer Function

OPERATING SYSTEM. Chapter 9: Virtual Memory

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

for Operating Systems Computer Systems Laboratory Sungkyunkwan University

Interfacing. Introduction. Introduction Addressing Interrupt DMA Arbitration Advanced communication architectures. Vahid, Givargis

Process Context & Interrupts. New process can mess up information in old process. (i.e. what if they both use the same register?)

Real-Time Programming

Topics. Interfacing chips

I/O AND DEVICE HANDLING Operating Systems Design Euiseong Seo

CSCE Introduction to Computer Systems Spring 2019

4) In response to the the 8259A sets the highest priority ISR, bit and reset the corresponding IRR bit. The 8259A also places

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

The K Project. Interrupt and Exception Handling. LSE Team. May 14, 2018 EPITA. The K Project. LSE Team. Introduction. Interrupt Descriptor Table

UNIT V INPUT OUTPUT ORGANIZATION

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

For more notes of DAE

Why use an Operating System? Operating System Definition

Computer Architecture 5.1. Computer Architecture. 5.2 Vector Address: Interrupt sources (IS) such as I/O, Timer 5.3. Computer Architecture

INPUT/OUTPUT ORGANIZATION

Chapter 13: I/O Systems

Chapter 13: I/O Systems. Chapter 13: I/O Systems. Objectives. I/O Hardware. A Typical PC Bus Structure. Device I/O Port Locations on PCs (partial)

Computer System Overview. Chapter 1

Embedded Software TI2726 B. 4. Interrupts. Koen Langendoen. Embedded Software Group

INPUT/OUTPUT ORGANIZATION

Design and Implementation Interrupt Mechanism

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

Transcription:

Interrupts Peter Rounce P.Rounce@cs.ucl.ac.uk 22/11/2011 11-GC03 Interrupts 1

INTERRUPTS An interrupt is a signal to the CPU from hardware external to the CPU that indicates than some event has occured, e.g. data has arrived at an input interface. CPUs respond to an interrupt by switching from executing the instructions of the current program to executing instructions to handle the event that caused the interrupt. The interrupt mechanism provides an efficient way to detect the occurrence of an event. It is important to understand the implementation of interrupts and when they should or should not be used. Interrupts are a key element in the operation of most computer systems. 22/11/2011 11-GC03 Interrupts 2

Why interrupts? Polling is inefficient when data rates are low: - too many CPU cycles wasted executing instructions of polling loop. Polling is the wrong approach to handling events where the time of the occurrence of an event is uncertain or distant, i.e. 100s of clock cycles away. Start Read Status Register Start Read Status Register The occurrence of the event should be the trigger for CPU action, the CPU should not be checking for the event. Examples of similar systems: a knock on the door, the ringing of the telephone Buffer Full? Y Read Data from Data Port Buffer Empty? Y Write Data intodata Port 22/11/2011 11-GC03 Interrupts 3 End N End Example polling software on input and output interfaces N

Points to cover:- how is interrupt signal generated how are interrupts prioritised, if there are several at same time how does CPU identify event that generated interrupt how does CPU switch from to running software to deal with event how is it that program running at time of interrupt is not affected how does interrupt software exchange data with rest of system 22/11/2011 11-GC03 Interrupts 4

8-Bit Parallel Output Interface READ 8-Bit Parallel Input Interface READ Data Bus WRITE interrupt Data Reg Status Reg Output Data Input Data Flow Control Signals Data Reg Status Reg Data Bus interrupt Address Bus Select Signals Select Signals Address Bus When Rx acknowledges receipt of data the TX interrupt request is activated Writing new data into the Data Register or reading Status Register deactivates TX interrupt request Arrival of new data triggers activation of interrupt request Reading data from Data Register deactivates interrupt request 22/11/2011 11-GC03 Interrupts 5

I/O INT Interface INTERRUPT HARDWARE To I/O devices I/O INT Interface I/O INT Interface I 1 I 2 I 3 I n Interrupt Controller Interrupt Request Interrupt CPU I/O INT Interface Data Bus Decoder Address Bus Data Bus 1) I/O interface generates an interrupt request signal on some Tx or Rx event. 2) Interrupt Controller generates an interrupt request to CPU, when one or more inputs is active. 3) CPU reads Interrupt Controller to get number (vector) identifying the highest priority active interrupt request (priority in by input number, or rotating priority allocation: the vector identifies the highest priority interrupt device requiring service. [This is why the controller is shown with connections to the system busses:to read vector] 22/11/2011 11-GC03 Interrupts 6

CPU Activity in servicing an Interrupt Request When Interrupt Request becomes active, CPU completes current instruction, and then executes the following operations automatically:- CPU saves PC register & turns off interrupts CPU loads PC with new value CPU resumes instruction processing CPU switches to execute software in response to the interrupt. Software handles event that occurred, e.g. data received. This software is called the Interrupt Service Routine (ISR). At end of ISR, CPU continues the interrupted program. Alternatives: Once in the ISR, software can determine whether to return to the interrupted program, to suspend it or to close it down. ISR now executes to deal with event generating interrupt until... CPU resumes instruction processing of interrupted program at end of ISR CPU loads registers and PC with values saved at start of interrupt service, a special return-frominterrupt instruction is executed to re-enable interrupts 22/11/2011 11-GC03 Interrupts 7

Another way of viewing of Interrupt Servicing Instructions of program being executed by CPU Interrupt Service Routine (ISR) general structure Interrupt Request PC saved, PC loaded with new value further interrupts disabled PC reloaded Interrupts re-enabled Save CPU registers changed in ISR Handle event that caused interrupt, e.g. input data, output data acknowledged. Restore CPU registers saved at start of ISR Return-from-interrupt Instruction executed Interrupt is very like a hardware generated function call! Saving/restoring registers ensures state of interrupted program is not changed by interrupt servicing. stack is used to save state 22/11/2011 11-GC03 Interrupts 8

Where does new PC address come from? Non-vectored interrupts: new PC address is defined in CPU hardware, always go to same address: find source of event by polling IO interfaces slow! Vectored Interrupts: Vector read from controller is used to look up the address of software to handle interrupt, and placed in PC. This activity is done by the hardware. This allows CPU to get quickly to the software to handle the event. The interrupt table has to be set up by software. vector PC Interrupt table in memory MIPS uses Non-vectored interrupt, so ISR is found by software. 22/11/2011 11-GC03 Interrupts 9

Interrupt are very good for low frequency data. There is a large overhead in saving and restoring program state (registers & PC), which limits the maximum frequency of data that can be handled. 22/11/2011 11-GC03 Interrupts 10

How does ISR handle interrupt event? One way is to use circular buffers to queue data Input Device: Output Device: ISR puts input data on to tail of queue in circular buffer. Data producer program puts output data into tail of queue. data removed by consumer program from head of queue at convenient time data removed from head of queue by ISR and output 22/11/2011 11-GC03 Interrupts 11

Timer Device CPU writes count into count-down register and starts counting by writing into a control register in the timer. Register counted down by one on each clock rising edge. When count register reaches zero, interrupt generated and register reloaded. Clock Count-down register written over data bus by software: once written, the count will be restored once zero is reached. Timer looks like I/O device to CPU. Timer Device Control Register Count-down Register Decoder Address Bus Data Bus Interrupt Request Timer generates interrupts at regular time intervals. Instead of re-starting interrupted program after timer interrupt, operating system may suspend this program and switch to run another program. Thus, each program is executed for a time slice at regular intervals: this is how an operating system runs several programs at once. 22/11/2011 11-GC03 Interrupts 12

Switching processes on interrupt in an operating system environment, e.g. linux. Instructions of program X being executed by CPU Timer Interrupt Request Switch to running ISR Load program B state from program B stack ISR Instructions of program Y in memory as well. Save all program A state on its stack Switch to run program at end of ISR On any interrupt, but particularly on a timer interrupt, the operating can store the state of the interrupted program, i.e. the register contents, on the program stack. It can then resume the execution of a previously suspended program or even start the execution of a new program (usually called a process). In this way, the operating system can seem to be executing several processes at a time by running allowing one process to execute on the CPU for short period (a time slice ) before suspending the process and allowing another process to run. The ISRs are considered part of the operating system. A process can be suspended for a long while while awaiting some I/O activity to complete. 22/11/2011 11-GC03 Interrupts 13

Exceptions These are very similar to interrupts in many ways. Exceptions are caused by the current instruction being executed. Interrupts are always triggered outside the CPU and are caused by events that are being awaited e.g. an I/O transfer completing, a timer count elapsing. Exceptions are either triggered inside the CPU or is caused by an error condition on a transfer to memory or I/O interface. The last is signalled via BUS ERROR input to the CPU. Internal CPU exceptions are often error conditions, e.g. divide-by-zero exception, an address error (perhaps an odd address where an even one is expected) An exception is processed in an exactly similar way to an Interrupt except that the vector used to look up the vector table is generated by the CPU. Exceptions are generally triggered by software actions rather than hardware events. 22/11/2011 11-GC03 Interrupts 14

System Call Exception the exception that is an NOT an error Used in a computer with a protection system to allow a user program to call a particular service in the operating system to perform a privileged operation. Example services: open a file for reading or writing reading or writing data to an open file write data to the screen allocate some space on the heap. All these are activities for which could corrupt the system, breach security User Code:- Set up data on stack for service required Set identifier for service Execute system call instruction sc, trap system call exception generated; exception service routine for a system call executed When service completes the user program will continue as if a method/function/subroutine call had been made 22/11/2011 11-GC03 Interrupts 15

MIPS Operation On interrupt/exception: Hardware operations wait for completion of current instruction save pc to epc register (exception program counter register) set type of event in cause register load pc with address 80000080 restart execution MIPS Exceptions address error exception on load address error exception on load bus error on instruction fetch bus error on data load or store system call exception breakpoint exception reserved instruction exception arithmetic overflow exception Interrupt/Exception Service Routine resides at address 0x80000080 The ISR must discover the cause of the event and then execute software to deal with the event. It is the ISR responsibility to save the state (register values) of the interrupted program if this program is to be continued later. If interrupt occurred, then must discover what device generated it. 22/11/2011 11-GC03 Interrupts 16