Lecture 23. I/O, Interrupts, exceptions

Similar documents
IT 252 Computer Organization and Architecture. Introduction to I/O

Input / Output. School of Computer Science G51CSA

I/O - input/output. system components: CPU, memory, and bus -- now add I/O controllers and peripheral devices. CPU Cache

Chapter 3. Top Level View of Computer Function and Interconnection. Yonsei University

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

Computer System Overview. Chapter 1

Computer System Overview

Systems Architecture II

Computer System Overview

Unit 1. Chapter 3 Top Level View of Computer Function and Interconnection

5.b Principles of I/O Hardware CPU-I/O communication

Chapter 1 Computer System Overview

Computer Organization (Input-output)

Generic Model of I/O Module Interface to CPU and Memory Interface to one or more peripherals

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

Input/Output Problems. External Devices. Input/Output Module. I/O Steps. I/O Module Function Computer Architecture

Computer Systems Overview

Bus System. Bus Lines. Bus Systems. Chapter 8. Common connection between the CPU, the memory, and the peripheral devices.

ECE 485/585 Microprocessor System Design

Review: Hardware user/kernel boundary

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

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

Operating Systems. Lecture 09: Input/Output Management. Elvis C. Foster

What are Exceptions? EE 457 Unit 8. Exception Processing. Exception Examples 1. Exceptions What Happens When Things Go Wrong

Chapter 1 Computer System Overview

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

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

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

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

Computer Architecture CS 355 Busses & I/O System

ECE468 Computer Organization and Architecture. OS s Responsibilities

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION

Organisasi Sistem Komputer

CSC 2405: Computer Systems II

Chapter 7 : Input-Output Organization

Computer Organization ECE514. Chapter 5 Input/Output (9hrs)

OPERATING SYSTEMS CS136

Chapter 1 Computer System Overview

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

I/O Design, I/O Subsystem, I/O-Handler Device Driver, Buffering, Disks, RAID January WT 2008/09

Running Applications

Chapter 3 - Top Level View of Computer Function

Introduction to Operating. Chapter Chapter

COSC 243. Input / Output. Lecture 13 Input/Output. COSC 243 (Computer Architecture)

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

Hardware, Modularity, and Virtualization CS 111

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

Module 6: INPUT - OUTPUT (I/O)

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

INPUT-OUTPUT ORGANIZATION

Introduction to Operating Systems. Chapter Chapter

Introduction to Operating Systems. Chapter Chapter

COMP I/O, interrupts, exceptions April 3, 2016

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

19: I/O. Mark Handley. Direct Memory Access (DMA)

lecture 21 Input / Output (I/O) 3 - system bus and memory (lectures revisited) - system bus and interrupts - exceptions (lecture 12 revisited)

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

Chapter 5 - Input / Output


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

Input / Output. Kevin Webb Swarthmore College April 12, 2018

ECE331: Hardware Organization and Design

Programmed I/O Interrupt-Driven I/O Direct Memory Access (DMA) I/O Processors. 10/12/2017 Input/Output Systems and Peripheral Devices (02-2)

Modes of Transfer. Interface. Data Register. Status Register. F= Flag Bit. Fig. (1) Data transfer from I/O to CPU

CS 104 Computer Organization and Design

CS510 Operating System Foundations. Jonathan Walpole

BASIC COMPUTER ORGANIZATION. Operating System Concepts 8 th Edition

Computer Architecture and Organization (CS-507)

Assembly Language. Lecture 2 - x86 Processor Architecture. Ahmed Sallam

Interrupt/Timer/DMA 1

5 Computer Organization

-Device. -Physical or virtual thing that does something -Software + hardware to operate a device (Controller runs port, Bus, device)

Example Networks on chip Freescale: MPC Telematics chip

A+ Guide to Managing and Maintaining Your PC. How Hardware and Software Work Together

Eastern Mediterranean University School of Computing and Technology INPUT / OUTPUT

CS152 Computer Architecture and Engineering Lecture 20: Busses and OS s Responsibilities. Recap: IO Benchmarks and I/O Devices

8086 Interrupts and Interrupt Responses:

POLITECNICO DI MILANO. Exception handling. Donatella Sciuto:

Input/Output Systems

Faculty of Science FINAL EXAMINATION

Chapter 2 Data Manipulation

I/O Systems. Jo, Heeseung

CPS104 Computer Organization and Programming Lecture 18: Input-Output. Outline of Today s Lecture. The Big Picture: Where are We Now?

What Operating Systems Do An operating system is a program hardware that manages the computer provides a basis for application programs acts as an int

Lecture 1 Introduction (Chapter 1 of Textbook)

Module 11: I/O Systems

Computer Architecture

EECS 373 Design of Microprocessor-Based Systems

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

Assembly Language. Lecture 2 x86 Processor Architecture

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

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

MICROPROCESSOR MEMORY ORGANIZATION

Interconnecting Components

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

CSE 451: Operating Systems Winter I/O System. Gary Kimura

Storage, Networks, and Other Peripherals

Digital System Design

ECE 571 Advanced Microprocessor-Based Design Lecture 3

Computer and Hardware Architecture I. Benny Thörnberg Associate Professor in Electronics

Transcription:

Lecture 23 I/O, Interrupts, exceptions 1

A Timely Question. Most modern operating systems pre-emptively schedule programs. If you are simultaneously running two programs A and B, the O/S will periodically switch between them, as it sees fit. Specifically, the O/S will: Stop A from running Copy A s register values to memory Copy B s register values from memory Start B running How does the O/S stop program A? 2

I/O Programming, Interrupts, and Exceptions Most I/O requests are made by applications or the operating system, and involve moving data between a peripheral device and main memory. There are two main ways that programs communicate with devices. Memory-mapped I/O Isolated I/O There are also several ways of managing data transfers between devices and main memory. Programmed I/O Interrupt-driven I/O Direct memory access Interrupt-driven I/O motivates a discussion about: Interrupts Exceptions and how to program them 3

Communicating with devices Most devices can be considered as memories, with an address for reading or writing. Many instruction sets often make this analogy explicit. To transfer data to or from a particular device, the CPU can access special addresses. Here you can see a video card can be accessed via addresses 3B0-3BB, 3C0-3DF and A0000-BFFFF. There are two ways these addresses can be accessed. 4

Memory-mapped I/O With memory-mapped I/O, one address space is divided into two parts. Some addresses refer to physical memory locations. Other addresses actually reference peripherals. For example, an Apple IIe had a 16-bit address bus which could access a whole 64KB of memory. Addresses C000-CFFF in hexadecimal were not part of memory, but were used to access I/O devices. All the other addresses did reference main memory. The I/O addresses are shared by many peripherals. In the Apple IIe, for instance, C010 is attached to the keyboard while C030 goes to the speaker. Some devices may need several I/O addresses. Memory I/O Memory FFFF D000 C000 0000 5

Programming memory-mapped I/O Control Address Data CPU Memory Hard disks CD-ROM Network Display To send data to a device, the CPU writes to the appropriate I/O address. The address and data are then transmitted along the bus. Each device has to monitor the address bus to see if it is the target. The Apple IIe main memory ignores any transactions whose address begins with bits 1100 (addresses C000-CFFF). The speaker only responds when C030 appears on the address bus. 6

Isolated I/O Another approach is to support separate address spaces for memory and I/O devices, with special instructions that access the I/O space. For instance, 8086 machines have a 32-bit address space. Regular instructions like MOV reference RAM. The special instructions IN and OUT access a separate 64KB I/O address space. Main memory FFFFFFFF 00000000 I/O devices 0000FFFF 00000000 7

Comparing memory-mapped and isolated I/O Memory-mapped I/O with a single address space is nice because the same instructions that access memory can also access I/O devices. For example, issuing MIPS sw instructions to the proper addresses can store data to an external device. With isolated I/O, special instructions are used to access devices. This is less flexible for programming. May have advantages for bandwidth/throughput (memory and I/O busses separate) 8

Transferring data with programmed I/O The second important question is how data is transferred between a device and memory. Under programmed I/O, it s all up to a user program or the operating system. The CPU makes a request and then waits for the device to become ready (e.g., to move the disk head). Buses are only 32-64 bits wide, so the last few steps are repeated for large transfers. A lot of CPU time is needed for this! If the device is slow the CPU might have to wait a long time as we will see, most devices are slow compared to modern CPUs. The CPU is also involved as a middleman for the actual data transfer. Not ready CPU sends read request to device CPU waits for device Ready CPU reads word from device CPU writes word to main memory (This CPU flowchart is based on one from Computer Organization and Architecture by William Stallings.) No Done? Yes 9

Can you hear me now? Can you hear me now? Continually checking to see if a device is ready is called polling. It s not a particularly efficient use of the CPU. The CPU repeatedly asks the device if it s ready or not. The processor has to ask often enough to ensure that it doesn t miss anything, which means it can t do much else while waiting. An analogy is waiting for your car to be fixed. You could call the mechanic every minute, but that takes up all your time. A better idea is to wait for the mechanic to call you. Not ready CPU sends read request to device CPU waits for device Ready 10

Interrupt-driven I/O Interrupt-driven I/O attacks the problem of the processor having to wait for a slow device. Instead of waiting, the CPU continues with other calculations. The device interrupts the processor when the data is ready. The data transfer steps are still the same as with programmed I/O, and still occupy the CPU. CPU sends read request to device CPU does other stuff... CPU receives interrupt CPU reads word from device CPU writes word to main memory (Flowchart based on Stallings again.) No Done? Yes 11

Interrupts Interrupts are external events that require the processor s attention. Peripherals and other I/O devices may need attention. Timer interrupts to mark the passage of time. These situations are not errors. They happen normally. All interrupts are recoverable: The interrupted program will need to be resumed after the interrupt is handled. It is the operating system s responsibility to do the right thing, such as: Save the current state. Find and load the correct data from the hard disk Transfer data to/from the I/O device. 12

Exception handling Exceptions are typically errors that are detected within the processor. The CPU tries to execute an illegal instruction opcode. An arithmetic instruction overflows, or attempts to divide by 0. The a load or store cannot complete because it is accessing a virtual address currently on disk Virtual Memory! There are two possible ways of resolving these errors. If the error is un-recoverable, the operating system kills the program. Less serious problems can often be fixed by the O/S or the program itself. 13

How interrupts/exceptions are handled For simplicity exceptions and interrupts are handled the same way. When an exception/interrupt occurs, we stop execution and transfer control to the operating system, which executes an exception handler to decide how it should be processed. The exception handler needs to know two things. The cause of the exception (e.g., overflow or illegal opcode). What instruction was executing when the exception occurred. This helps the operating system report the error or resume the program. This is another example of interaction between software and hardware, as the cause and current instruction must be supplied to the operating system by the processor. 14

MIPS Interrupt Programming In order to receive interrupts, the software has to enable them. On a MIPS processor, this is done by writing to the Status register. Interrupts are enabled by setting bit zero. 1 1 MIPS has multiple interrupt levels Interrupts for different levels can be selectively enabled. To receive an interrupt, its bit in the interrupt mask (bits 8-15 of the Status register) must be set. In the Figure, interrupt level 15 is enabled. 15

MIPS Interrupt Programming When an interrupt occurs, the Cause register indicates which one. For an exception, the exception code field holds the exception type. For an interrupt, the exception code field is 0000 and bits will be set for pending interrupts. The register below shows a pending interrupt at level 15 1 0000 The exception handler is generally part of the operating system. 16

Direct memory access One final method of data transfer is to introduce a direct memory access, or DMA, controller. The DMA controller is a simple processor which does most of the functions that the CPU would otherwise have to handle. The CPU asks the DMA controller to transfer data between a device and main memory. After that, the CPU can continue with other tasks. The DMA controller issues requests to the right I/O device, waits, and manages the transfers between the device and main memory. Once finished, the DMA controller interrupts the CPU. CPU sends read request to DMA unit CPU does other stuff... CPU receives DMA interrupt (Flowchart again.) 17

Main memory problems System bus CPU & cache Memory DMA unit Hard disks CD-ROM Network As you might guess, there are some complications with DMA. Since both the processor and the DMA controller may need to access main memory, some form of arbitration is required. Who is the bus master at any given time? If the DMA unit writes to a memory location that is also contained in the cache, the cache and memory could become inconsistent. Can be done automatically by the cache controller, or by explicit CPU instructions invalidating part of the cache, or 18