Docsity

I/O Device Interface: Polling, Interrupts, and DMA in Systems Architecture II - Prof. Will, Study notes of Computer Science

Toggle sidebar
bg1
Lec 10 Systems Architecture II 1
Systems Architecture II
Lecture 10: Interfacing I/O Devices to Memory, Processor,
and Operating System *
Jeremy R. Johnson
Anatole D. Ruslanov
William M. Mongan
*This lecture was derived from material in the text (Secs. 8.5-8.7).
Some or all figures from Computer Organization and Design: The Hardware/Software
Approach, Third Edition, by David Patterson and John Hennessy, are copyrighted
material (COPYRIGHT 2004 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS
RESERVED).
Contributions from Mary Jane Irwin ( www.cse.psu.edu/~mji )
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download I/O Device Interface: Polling, Interrupts, and DMA in Systems Architecture II - Prof. Will and more Study notes Computer Science in PDF only on Docsity!

Lec 10

Systems Architecture II

Systems Architecture II

Lecture 10: Interfacing I/O Devices to Memory, Processor,

and Operating System


Jeremy R. Johnson Anatole D. Ruslanov

William M. Mongan

*This lecture was derived from material in the text (Secs. 8.5-8.7). Some or all figures from Computer Organization and Design: The Hardware/SoftwareApproach, Third Edition, by David Patterson and John Hennes

s

y, are copyrighted

material (COPYRIGHT 2004 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTSRESERVED).

Contributions from Mary Jane Irwin (

www.cse.psu.edu/~mji

)

Lec 10

Systems Architecture II

Introduction

Objective: To learn how an I/O device communicates with auser program?

How is a user I/O request transformed into a device command andcommunicated to the device?

How is data actually transferred to or from a memory location?

What is the role of the operating system?

Topics

Role of the OS

Giving commands to the I/O system

I/O commands

Memory mapped I/O

Communicating with the processor

polling

interrupts

Transferring data between a device and memory

Direct Memory Access (DMA)

Designing an I/O system

Lec 10

Systems Architecture II

I/O and the Operating System

The operating system acts as the interface between the I/Ohardware and the program requesting I/O

To protect the shared I/O resources, the user program is not allowed tocommunicate directly with the I/O device

Thus OS must be able to give commands to I/O devices,handle interrupts generated by I/O devices, provide equitableaccess to the shared I/O resources, and schedule I/O requeststo enhance system throughput

I/O interrupts result in a transfer of processor control to the supervisor(OS) process

Lec 10

Systems Architecture II

Functions of the OS

The OS guarantees that a user’s program accesses only theportions of an I/O device to which the user has rights.

The OS provides abstractions for accessing devices bysupplying routines that handle low-level device operations.

The OS handles the interrupts generated by I/O devices.

The OS tries to provide equitable access to the shared I/Oresources, as well as schedule accesses in order toenhance system throughput.

Lec 10

Systems Architecture II

Giving Commands to I/O Devices

Dedicated I/O instructions (e.g. Intel 80x86)

command and device number specified in the instruction

processor communicates the device address via a set of wiresincluded as part of the I/O bus

illegal to execute while in user mode

Memory-mapped I/O

Portions of the address space are assigned to I/O devices

commands and data are written to special addresses

data and status info read from special addresses

Memory system ignores operation (determined by address)

I/O controller, sees the operation, and transmits it to the device

Lec 10

Systems Architecture II

Communication of I/O Devices and

Processor

How the processor directs the I/O devices

Special I/O instructions

Must specify both the device and the command

Memory-mapped I/O

Portions of the high-order memory address space are assigned to each I/Odevice

Read and writes to those memory addresses are interpreted as commands to the I/O devices

Load/stores to the I/O address space can only be done by the OS

How the I/O device communicates with the processor

Polling – the processor periodically checks the status of an I/O device todetermine its need for service

Processor is totally in control – but does all the work

Can waste a lot of processor time due to speed differences

Interrupt-driven I/O – the I/O device issues an interrupts to the processorto indicate that it needs attention

Lec 10

Systems Architecture II

Overhead of Polling

Determine impact of polling on three different devices:

Assume 400 cycles for polling operation and a 500 MHz clock

Determine fraction of CPU time consumed in the following 3 cases(assume that you poll often enough so that no data is lost and that thedevices are potentially always busy)

Mouse must be polled 30 times per second

Floppy disk transfers data to processor in 16-bit units and has atransfer rate of 50 KB/sec

Hard disk drive transfers data in 4 word chunks and can transfer at4 MB/sec

Lec 10

Systems Architecture II

Overhead of Polling

Mouse: 30 accesses per second

×

400 = 12,000 cycles per second for polling

Fraction of processor clock cycles = (

×

3

×

6

Floppy Drive:

25K

×

400 cycles per second for polling

Fraction of processor clock cycles = (

×

6

×

6

Hard Drive:

250K

×

400 cycles per second for polling

Fraction of processor clock cycles = (

×

6

×

6

sec /

accesses

K

access

polling /

bytes 2

sec /

KB

sec /

accesses

K

access

polling /

bytes

sec /

MB

Lec 10

Systems Architecture II

Interrupt-Driven Input

addsubandorbeq^ lbusb...jr

userprogram

1. inputinterrupt

inputinterruptserviceroutine

Processor

Receiver

Memory

Keyboard

memory

Lec 10

Systems Architecture II

Interrupt-Driven Input

userprogram

1. inputinterrupt

2.1 save state

Processor

Receiver

Memory

addsubandorbeq^ lbusb...jr

2.2 jump tointerruptservice routine

2.4 returnto user code

2.3 serviceinterrupt

inputinterruptserviceroutine

Keyboard

memory

Lec 10

Systems Architecture II

Interrupt-Driven I/O

An I/O interrupt is asynchronous wrt instruction execution

Is not associated with any instruction so doesn’t prevent any instructionfrom completing

You can pick your own convenient point to handle the interrupt

With I/O interrupts

Need a way to identify the device generating the interrupt

Can have different urgencies (so may need to be prioritized)

Advantages of using interrupts

Relieves the processor from having to continuously poll for an I/O event;user program progress is only suspended during the actual transfer of I/Odata to/from user memory space

Disadvantage – special hardware is needed to

Cause an interrupt (I/O device) and detect an interrupt and save thenecessary information to resume normal processing after servicing theinterrupt (processor)

Lec 10

Systems Architecture II

Overhead of Interrupt-Driven I/O

Assume hard disk drive transfers data in 4 word chunksand can transfer at 4 MB/sec

500 MHz clock

Overhead of transfer including interrupt is 500 cycles

Hard drive is transferring data only 5% of the time

Interrupt rate when the disk is busy is the same as polling

250K

×

×

6

cycles per second for disk

Fraction of processor clock cycles = (

×

6

×

6

Assuming that the disk is only transferring data 5% of thetime

Fraction of processor clock cycles = 25%

×

Compare to polling - the absence of overhead when the disk is notactive is the major advantage of an interrupt-driven interface

Lec 10

Systems Architecture II

Overhead of DMA

Assume hard disk drive transfers data in 4 word chunksand can transfer at 4 MB/sec

500 MHz clock

Assume transfer with DMA and initial DMA setup takes 1000 cycles

Overhead of interrupt at completion is 500 cycles

If the average transfer is 8KB, what fraction of the CPU is consumed ifthe disk is active 100% of the time (ignore processor/DMA controllerbus contention)

Each DMA transfer takes:

Cycles/sec for disk =

Fraction of processor clock cycles = (

×

3

×

6

sec

sec /

MB

KB

3 −

×

sec /

cycles

clock

transfer /

sec

transfer

500cycles/

3

3

×

×

−

Lec 10

Systems Architecture II

Issues with DMA

With DMA there is another path to memory

This provides difficulties with virtual memory and cache

Should physical or virtual addresses be used?

If virtual, the DMA unit must translate to physical addresses.

If physical must ensure that addresses don’t cross page boundaries(otherwise memory addresses would not be contiguous)

Can break transfer into a sequence of page size transfers

OS must not remap memory during DMA transfer

The value of a memory location as seen by DMA and the processormay differ

Stale data or coherency problem (value in cache different frommemory). Solved by routing through cache or cache flushing