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

Similar documents
INPUT/OUTPUT ORGANIZATION

Lecture 23. I/O, Interrupts, exceptions

INPUT/OUTPUT ORGANIZATION

QUIZ Ch.6. The EAT for a two-level memory is given by:

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

Interrupt-Driven Input/Output

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

Input / Output. School of Computer Science G51CSA

Input/Output Programming

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

Unit 5. Memory and I/O System

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

INPUT-OUTPUT ORGANIZATION

Computer System Overview

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

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

Design and Implementation Interrupt Mechanism

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

8086 Interrupts and Interrupt Responses:

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

PC Interrupt Structure and 8259 DMA Controllers

ECE 485/585 Microprocessor System Design

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

INPUT/OUTPUT ORGANIZATION

Organisasi Sistem Komputer

Chapter 5 Input/Output. I/O Devices

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

Review: Hardware user/kernel boundary

Computer Organization (Input-output)

Interrupt/Timer/DMA 1

6 Direct Memory Access (DMA)

Control unit. Input/output devices provide a means for us to make use of a computer system. Computer System. Computer.

ECE 341. Lecture # 19

CS370 Operating Systems

CS370 Operating Systems

CPUs. Input and output. Supervisor mode, exceptions, traps. Co-processors. Computers as Components 4e 2016 Marilyn Wolf

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

CSE 410. Operating Systems

Unit 2 : Computer and Operating System Structure

Computer System Overview. Chapter 1

231 Spring Final Exam Name:

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

1. Define Peripherals. Explain I/O Bus and Interface Modules. Peripherals: Input-output device attached to the computer are also called peripherals.

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

Input Output (IO) Management

Digital Input and Output

UC Santa Barbara. Operating Systems. Christopher Kruegel Department of Computer Science UC Santa Barbara

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

EEL 4744C: Microprocessor Applications. Lecture 7. Part 2. M68HC12 Interrupt. Dr. Tao Li 1

Q.1 Explain Computer s Basic Elements

COEN-4720 Embedded Systems Design Lecture 4 Interrupts (Part 1) Cristinel Ababei Dept. of Electrical and Computer Engineering Marquette University

I/O Management Intro. Chapter 5

Introduction to Operating Systems. Chapter Chapter

Computer System Overview

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Common Computer-System and OS Structures

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

INPUT-OUTPUT ORGANIZATION

Computer Systems Overview

Chapter 1 Computer System Overview

October, Saeid Nooshabadi. Overview COMP 3221

INTERRUPTS in microprocessor systems

Interrupts Peter Rounce - room 6.18

CSCI-GA Operating Systems I/O. Hubertus Franke

Input/Output. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Introduction to Operating Systems. Chapter Chapter

The Embedded Computing Platform

EN1640: Design of Computing Systems Topic 07: I/O

Introduction to Operating. Chapter Chapter

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

Chapter 5 Input/Output Organization. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Lecture-51 INTEL 8259A Programmable Interrupt Controller

EECS 373 Design of Microprocessor-Based Systems

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

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

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION

ECE331: Hardware Organization and Design

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

Top-Level View of Computer Organization

Eastern Mediterranean University School of Computing and Technology INPUT / OUTPUT

Embedded System Design

Computer Architecture CS 355 Busses & I/O System

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

Design with Microprocessors

Microprocessor Architecture

CSCI-375 Operating Systems

Recap from last class

Chapter 8. Input Output Organization

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

I/O Devices. I/O Management Intro. Sample Data Rates. I/O Device Handling. Categories of I/O Devices (by usage)

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

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

BASIC COMPUTER ORGANIZATION. Operating System Concepts 8 th Edition

Week 11 Programmable Interrupt Controller

FINALTERM EXAMINATION Fall 2008 CS501- Advance Computer Architecture (Session - 1) Marks: 75

Digital System Design Using Verilog. - Processing Unit Design

GUJARAT TECHNOLOGICAL UNIVERSITY MASTER OF COMPUTER APPLICATION SEMESTER: III

Running Applications

2. List the five interrupt pins available in INTR, TRAP, RST 7.5, RST 6.5, RST 5.5.

Transcription:

I/O - input/output system components: CPU, memory, and bus -- now add I/O controllers and peripheral devices CPU Cache CPU must perform all transfers to/from simple controller, e.g., CPU reads byte from buffer in memory and stores it in controller's data register then stores a write-to-device command in the controller's command register +==================================================+ bus memory I/O buffer controller data status command controller data status command device device

I/O - input/output controller registers data register - holds data byte going to/from device status register - holds bits indicating if device is ready, error, etc. command register - bit for read, bit for write, etc. (may be combined with the status register)

I/O - input/output access to controller registers either by: memory-mapped I/O isolated I/O - special instructions (e.g., IN, OUT, INS, OUTs) are required, use port numbers as addresses of the controller registers

I/O - input/output memory-mapped I/O one address space is divided into two parts. Some addresses refer to physical memory locations. Other addresses actually reference peripherals. registers respond to main memory addresses (typically high memory), so you can use normal load/store instructions to access The I/O addresses are shared by many peripherals. memory I/O Some devices may need several I/O addresses memory

I/O - input/output memory-mapped I/O control address data CPU Memory Hard Disk CD-ROM Network Displa 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. The device only responds when its address appears on the address bus.

I/O - input/output isolated I/O supports separate address spaces for memory and I/O devices, with special instructions (e.g. IN, OUT, INS, OUTs) that access the I/O space. use port numbers as addresses of the controller registers Regular instructions like MOV reference RAM. The special instructions such as IN, Out access a separate I/O address space

I/O - input/output differences between memory-mapped I/O and memorymapped I/O Isolated I/O Isolated I/O uses separate address space for memory and I/O devices. Limited instructions can be used (e.g. IN, OUT, INS, OUTS). The addresses for Isolated I/O devices are called ports. Memory Mapped I/O Memory mapped I/O uses same address bus to address memory and I/O devices Any instruction which references memory can be used to access I/O device (e.g. LDR, STR). Memory mapped I/O devices are treated as memory locations on the memory map. Efficient I/O operations due to use of separate bus Comparatively larger in size Uses complex internal logic Slower operations Inefficient I/O operations due to using single bus for data and addressing Smaller in size Common internal logic for memory and I/O devices Faster operations

Comparison of Memory-Mapped and Isolated I/) Memory-mapped I/O with a single address space is nice because the same instructions that access memory can also access I/O devices. With isolated I/O, special instructions are used to access devices. This is less flexible for programming

I/O - Transferring data between a device and Memory The second important question is how data is transferred between a device and memory. Programmed I/O Interrupt-driven I/O DMA I/O

I/O - Transferring data between a device and Memory Under programmed I/O, it is 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 most devices are slow compared to modern CPUs. The CPU is also involved as a middleman for the actual data transfer.

I/O - Transferring data Programmed I/O CPU sends read request to device Nor Ready CPU waits for device Ready CPU reads word from device CPU writes word to main memory No Done? Yes

I/O - input/output // write bytes from memory buffer to device */ /*** pseudo-code int count = N; char *addr = memory_buffer; char byte; do{ byte = *addr; while( io_device_status!= READY ) /* busy wait */ ; io_device_data = byte; io_device_command = WRITE; addr++; count--; }while( count > 0 );

I/O - input/output //defines may differ for real device) define(device_regs_base, 0xffff0000) define(device_ready, 0x80) // mask that defines ready bit in status reg. define(write_cmd, 0x1) // mask to set write command in command reg. define(data, 0) // offset of data reg. define(status, 4) // offset of status reg define(cmd, 8) // offset of command reg. ldr addr_reg, =buffer ldr count_reg, =buffer_size ldr device_reg_ptr, =DEVICE_REGS_BASE // memory-mapped i/o mov cmd_reg, WRITE_CMD loop: ldrub byte_reg, [addr_reg] // get data byte from buffer busy_wait: ldrub status_reg, [device_reg_ptr_r, STATUS] btst status_reg, DEVICE_READY // andcc to test ready bit beq busy_wait // branch if zero ready: strb strb byte_reg, [device_reg_ptr, DATA] // send data byte cmd_reg, [device_reg_ptr, CMD] // send write command add addr_reg, addr_reg, #1 sub count_reg, count_reg, #1 cmp count_reg, #0 bgt loop

I/O - input/output consider 24 ppm printer, with 5,000 characters per page = 120,000 chars/min = 2000 chars/sec = 0.0005 sec/char = 0.5 ms/char for a 3.6 GHz processor (= 3.6 B cycles/sec), the cycle time is approx. 0.28 ns, thus 560,000 cycles in 0.5 ms, and thus 560,000 cycles between characters if the busy wait loop takes 100 cycles per iteration (of which most will be required for the latency of the load inst. accessing the device status register), the busy wait loop requires 5,600 iterations between characters 1 success in 5,600 iterations => not an efficient use of the CPU (CPU spends 99.9+% of its time waiting)

I/O - input/output programmed I/O (cont'd) /*** read bytes from device to memory buffer pseudo-code int count = N; char *addr = memory_buffer; char byte; do{ io_device_command = READ; while( io_device_status!= READY ) /* busy wait */ ; byte = io_device_data; *addr = byte; addr++; count--; }while( count > 0 ); */

I/O - input/output /* defines may differ for real device */ define(device_regs_base, 0xffff0000) define(device_ready, 0x80) // mask that defines ready bit in status reg. define(read_cmd, 0x2) // mask to set read command in command reg. define(data, 0) // offset of data reg. define(status, 4) // offset of status reg. define(cmd, 8) // offset of command reg. ldr addr_reg, =buffer ldr count_reg =buffer_size ldr device_reg_ptr =device_regs_base mov cmd_reg, READ_CMD // memory-mapped i/o loop: strb cmd_reg, [device_reg_ptr, CMD] // send read command busy_wait: ldrub status_reg, [device_reg_ptr, STATUS] btst status_reg, DEVICE_READY // andcc to test ready bit beq busy_wait // branch if zero ready: ldrub byte_reg, [device_reg_ptr, DATA] // get data byte strb byte_reg, [addr_reg] // put in buffer add addr_reg, addr_reg, #1 sub count_reg, count_reg, #1 cmp count_reg, #0 bgt loop

Interrupt-driven I/O An interrupt is the automatic transfer of software execution in response to a hardware event that is asynchronous with the current software execution. This hardware event is called a trigger. The hardware event can either be a busy to ready transition in an external I/O device (like the UART input/output) or an internal event (like bus fault, memory fault, or a periodic timer). When the hardware needs service, signified by a busy to ready state transition, it will request an interrupt by setting its trigger flag.

Interrupt-driven I/O CPU can do something else while controller and device are busy; the controller grabs the CPU's attention when needed by causing what is essentially an unplanned procedure call CPU Cache +=============================================+ bus memory buffer ISR int. vector table controller data status command device controller data status command device interrupt request line (INTR) interrupt ack line (INTA) controllers that can interrupt, raise request signal on bus when CPU responds with an acknowledgement, the controller places some type of identification on the bus

Interrupt-driven I/O we rely on an external interrupt from the controller to signal that the device is ready (i.e., that the previous I/O operation is complete); this will cause the currently executing program to stop and the processor to enter the OS and start executing an interrupt service routine (ISR) -- sometimes called an interrupt handler (IH) there are also internal interrupts (sometimes called exceptions) for divide by zero, unaligned memory accesses, memory protection errors, etc.

Interrupt-driven I/O moreover, to protect the OS, calls to the OS must be made by a special instruction that causes an interrupt - called SVC (supervisor call) on IBM mainframes, INT on x86. an interrupt must save a return address and information on the processor state to allow the interrupted program to be resumed later => save the program counter (PC) and processor state register (PSR) an interrupt switches execution mode to an OS-only mode by changing a mode bit (or bits) in the PSR

Interrupt-driven I/O there are typically interrupt control bits in the controller's command register, and interrupt enable bits (either a priority level or a bit mask) in the PSR - the processor typically disables interrupts (at least at that level and lower) whenever an ISR starts the entry point address to the interrupt service routine (ISR) is typically provided by a table of such addresses in low memory; for I/O the entry is chosen according to the interrupt code placed on bus by controller

Interrupt-driven I/O 0 addr of ISR for type 0 4 8 c addr of ISR for type 1 addr of ISR for type 2 addr of ISR for type 3 code for type 3 int return from interrupt interrupt vector table (IVT) interrupt service routine (ISR)

Interrupt-driven I/O a special return from interrupt instruction at end of ISR switches back to previous processor state and restores saved PC the fetch-execute cycle is extended to check for interrupts after each instruction - the hardware response to an interrupt acts like procedure call if interrupt requested by device and if CPU has interrupts enabled note that the ISR is a software routine - and that instructions in the ISR are fetched, decoded, and executed, just like any other program

Interrupt-driven I/O PC - program counter, contains address of next instruction PSR - processor status register, contains: processor execution mode (kernel/user) interrupt enable/permission (can be single bit, mask, or priority code condition codes IVT - interrupt vector table, contains entry-point addresses for ISRs ISR - interrupt service routine

Interrupt-driven I/O fetch decode +---+-------+------------+-------... ---------------+ execute load execute add execute store return from interrupt (restore PC and PSR) + no +--+---------+------- ----+------... ---------------+ if interrupt requested and interrupts are enabled yes 1) save PC and PSR 2) switch execution mode to kernel (OS-only) 3) disable/restrict further interrupts 4) load new PC from IVT (interrupt vector table)

Interrupt-driven I/O (nested interrupts) if the PC and PSR are saved on a stack (or in a set of registers), a high priority device can interrupt the execution of the ISR for a lower priority device disk ISR printer ISR printer ISR user program user program printer interrupt disk interrupt rti rti otherwise, the second interrupt is held pending until the first ISR finishes and executes its rti instruction; at that point, the rti briefly reestablishes user mode with interrupts enabled but immediately the highest-priority pending interrupt is accepted

DMA I/O DMA - direct memory access - extra registers and logic in the controller allow it to transfer a whole block of bytes without CPU involvement, interrupts the CPU after completion or after an error - address register - address of buffer in main memory, controller increments - count register - length of block, controller decrements

DMA I/O CPU Cache INTA INTR +=============================================+ bus memory I/O buffer data status command address count controller &buffer # in buffer device DMA controller can be bus master, so need to arbitrate for bus among DMA controllers and CPU extra logic in controller to implement loop: while( count > 0 ) { transfer byte at address; address++; count--; } interrupt once at end of buffer

Summary of I/O I/O methods CPU involvement #interrupts programmed I/O completely dedicated to the transfer none interrupt-driven I/O transfers each byte after each byte DMA I/O initially loads the address and count registers; gives transfer command one, at end of each block

Effect of Offloading CPU do { byte = *addr; while( status!= READY ); <= interrupt-driven I/O complete block io_device_data = byte; relieves CPU of transfer is io_device_command = WRITE; busy-wait loop offloaded onto addr++; DMA controller count--; } while( count > 0 );

Further Offloading of I/O from the CPU mainframe channel - provides for transfers of multiple blocks by traversing linked-list-like channel programs; interrupt only when end of channel program reached (or on error) a channel has the equivalent of a program counter channel PC each channel instruction is called a "channel command word" (CCW) r/w address count next r/w address count next each CCW has address and count fields to support a block additional fields indicate end of physical block, etc.

Further Offloading of I/O from the CPU CCWs can also provide scatter-gather scatter - read data from a single physical block on an I/O device and send different parts to multiple, noncontiguous I/O buffers in memory gather - read data from multiple, non-contiguous I/O buffers in memory and write a single physical block to the device I/O processors - offload I/O conversion, editing, etc