Topic 4 : IO Devices - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

Topic 4 : IO Devices

Description:

A magnetic disk consists of one or more circular metal plates coated with a ... that the DMA device either gains outright control (and the processor idles) or ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 43
Provided by: compLa
Category:

less

Transcript and Presenter's Notes

Title: Topic 4 : IO Devices


1
Topic 4 I/O Devices Networks
  • Interacting with I/O Devices
  • Reference G L pp 170-172
  • (note that most of the material isnt in G L)

2
Recap on Magnetic Disks
  • A magnetic disk consists of one or more circular
    metal plates coated with a material which can be
    magnetised.
  • There may be more than one of these plates
    mounted on a common spindle.

3
Magnetic Disks ... contd.
  • The disks rotate continuously.
  • Information is stored on the disk using a set of
    read/write heads.

4
Data Layout on Magnetic Disks (1)
  • As the disk rotates, the read/write heads trace
    out a circular path or track on each surface.
  • On disks with more than one plate, the heads
    trace out a cylinder.

5
Data Layout on Magnetic Disks (2)
  • Each track is divided up into a fixed number of
    sectors.
  • Each sector holds a fixed number of bytes of
    information.
  • The specification of how many tracks, how many
    sectors, sector size etc. is called the disk
    format.

6
Techniques for Accessing I/O Devices
  • Explicit read/write operations (isolated I/O).
  • Can provide optimised performance
  • Or, use a technique called memory-mapped I/O.
  • no i/o instructions
  • each device has an associated memory address
  • when we manipulate that address we are actually
    manipulating the device

7
Performance Mismatch
  • There is a speed mismatch between I/O devices and
    computers.
  • Problem how to avoid slowing down the computer
    to the speed of the device.
  • Solution introduce a degree of autonomy into the
    device and allow the computer to get on with
    other tasks.

8
Data and Status Registers
  • In early machines there would be blocking read
    and write instructions.
  • Computer would block until the transfer was
    complete.
  • Since I/O devices are very slow in comparison to
    computers this is wasted time.

9
Data and Status Registers ... contd.
  • We can introduce some autonomy into the device by
    providing it with a data register capable of
    holding one character and a status register.
  • The device sets the status register to signify
    that it has a character waiting.
  • cf Modem

10
Data and Status Registers ... contd.
  • Sequence of instructions to get a character.

start the device by clearing its status
register repeat test the status register until
the status register has been set copy the
character from the data register into the acc.
  • This doesnt take advantage of the devices
    autonomy.

11
Improving Efficiency
  • To take advantage of the devices autonomy we
    need to do some useful work inside the test loop.
  • However, when the device has finished we want to
    find out as soon as possible.
  • This means placing lots of tests for multiple
    devices throughout our code.
  • The devices we wish to check may change.
  • Since we want to find out about the devices
    completion ASAP most of the instructions we
    execute will be redundant.

12
Interrupts
  • The solution is to provide support in the form of
    interrupts.
  • The status registers of all the devices are
    continually checked.
  • If a status register changes, jump to
    instructions to deal with the interrupt.
  • This sequence of instructions is called an
    interrupt service routine (ISR).

13
Causes of Interrupts
  • Example causes of interrupts include
  • devices completing I/O.
  • clocks.
  • power failure.
  • illegal instructions and addresses.
  • data conditions (e.g. divide by zero).

14
Implementing Interrupts
  • Need to store the contents of the program counter
    so we can resume execution at the right point.
  • Need to store some state, e.g. the accumulator.
  • Need to determine what caused the interrupt.

15
Implementing Interrupts
  • Assign some storage to be associated with each
    interrupt (called the interrupt vector).
  • When an interrupt occurs
  • store the program counter
  • jump to the address specified
  • The last instruction of the interrupt service
    routine can then be an indirect jump through the
    stored address.

16
Example Layout of Interrupt Software
10 100 keyboard 11 0 current PC will be
written here
100 STA SAVEK save the accumulator 101 transfe
r the data register to the accumulator 102 store
the accumulator in a suitable place 103 LDA
SAVEK restore the accumulator 104 JUMP _at_11
17
Example Layout of Interrupt Software
10
100
100 STA SAVEK 101 transfer.... 102 store the
...... 103 LDA SAVEK 104 JUMP _at_11
11
18
Example Layout of Interrupt Software
10
100
100 STA SAVEK 101 transfer.... 102 store the
...... 103 LDA SAVEK 104 JUMP _at_11
11
Current PC
37
19
Example Layout of Interrupt Software
10
100
100 STA SAVEK 101 transfer.... 102 store the
...... 103 LDA SAVEK 104 JUMP _at_11
11
37
Current PC
100
20

Example Layout of Interrupt Software
10
100
100 STA SAVEK 101 transfer.... 102 store the
...... 103 LDA SAVEK 104 JUMP _at_11
11
37
Current PC
101 - 104
21
Example Layout of Interrupt Software
10
100
100 STA SAVEK 101 transfer.... 102 store the
...... 103 LDA SAVEK 104 JUMP _at_11
11
37
Current PC
37
22
Multiple Interrupts
  • This scheme is ok except.....
  • ..... need to define what happens if an
    interrupt occurs when we are already handling an
    interrupt.
  • One solution is to just have a flag which says we
    are already busy with an interrupt and all
    further interrupts are ignored.
  • However, some interrupts we cant afford to
    ignore e.g. clocks.
  • Therefore need a means of assigning priorities to
    interrupts.

23
Adding Priorities to Our Interrupt Scheme
  • We assign priorities to all sources of
    interrupts.
  • High priority devices (e.g. clocks) can interrupt
    low priority devices.
  • The main program runs at the lowest priority
    level.
  • To tell the processor which priority it is
    running at, introduce a new register to hold the
    current priority.

24
An Example Interrupt Vector With Priorities
10 100 keyboard 11 current PC will be
written here 12 2 priority of this
interrupt 13 current priority will be written
here 15 200 power failure 16 current PC
will be written here 17 7 priority of this
interrupt 18 current priority will be written
here
25
Maskable Interrupts
  • If we have multiple interrupts there will be
    times when we dont want to receive interrupts of
    a particular type.
  • Most processors allow two types of interrupts
    maskable and non-maskable (NMI).
  • The processor can be asked to ignore maskable
    interrupts.

26
Connecting Interrupts to the Processor
  • Simplest approach is to have a separate input pin
    for each device which can generate an interrupt.

Device 1
Device 2
Device 3
27
Connecting Interrupts to the Processor
  • A better (and more usual approach) is to have
    multiple devices connected to a single pin.
  • When an interrupt occurs the processor either
    polls the devices or the interrupt includes a
    vector number.

Device 1
Device 2
Device 3
28
Fast I/O Devices
  • Consider a disk which transfers several hundred
    thousand bytes a second.
  • Each byte requires an interrupt.
  • Solution is to use Direct Memory Access (DMA)
  • i/o operation specifies a section of memory and
    the number of bytes to read/write.
  • device reads/writes directly from/to this memory.
  • interrupt generated when complete transfer has
    been achieved.

29
An Example of DMA
  • disk_read (file_name, 150, 50)

148
Bytes to read
149
CPU
150
Destination
151
152
153
154
155
156
157
30
An Example of DMA
  • disk_read (file_name, 150, 50)

148
Bytes to read
50
149
CPU
150
150
Destination
151
152
153
154
155
156
157
31
An Example of DMA
  • disk_read (file_name, 150, 50)

148
Bytes to read
50
149
CPU
150
A
150
Destination
151
B
152
A
153
154
155
156
157
32
An Example of DMA
  • disk_read (file_name, 150, 50)

148
Bytes to read
50
149
CPU
150
A
150
Destination
151
B
152
A
153
C
B
154
Done
155
A
156
C
D
157
33
Bus Contention
  • A key issue with DMA is access to the system bus.
  • Contention between the DMA device and the
    processor has to be addressed.
  • Normal situation is that the DMA device either
    gains outright control (and the processor idles)
    or the device cycle steals and always has
    priority for the bus.

34
Direct Memory Access
  • Some DMA controllers have an internal buffer to
    reduce contention for the system bus.
  • This means the contents of the buffer has to be
    transferred into memory Most controllers cant
    do this and i/o at the same time.
  • Concept of interleaving.

35
Interleaving
0
7
6
1
2
5
4
3
36
Interleaving
0
7
3
4
1
6
2
5
37
Interleaving
0
5
2
3
6
7
4
1
38
Device Controllers
  • Controller must accept data from the system and
    control device to make it actually perform the
    i/o.
  • The interface between a device controller and the
    device itself is very low-level.
  • cf keyboard controller need to translate
    voltage to a seven bit ASCII code.
  • The interface between the controller and the
    system is at a higher level - usually through
    special registers and interrupts.
  • cf a video controller could have a special cursor
    register.

39
An Example Controller
  • The IBM PC floppy controller accepts 15 different
    commands such as READ, WRITE, RECALIBRATE etc.
  • Commands and parameters are passed using the
    registers.
  • While the command is being processed the CPU is
    free to do other work - an interrupt occurs when
    the command has been completed.

40
Device Drivers
  • Device drivers interface between device
    independent i/o software in the OS and device
    controllers.
  • For example, if a disk driver is asked to read
    block n it must...
  • start the floppy motor.
  • work out where on the disk the block is.
  • move the arm to the appropriate position.
  • initiate the read.
  • stop the motor after the operation.

41
Summary
  • Recapped on the construction of magnetic disks.
  • Problems of connecting i/o devices to a computer
    the performance mismatch.
  • Implementing interrupts.
  • DMA for fast I/O devices.
  • Interleaving.

42
Coming Next Week
  • Computer Networking.
Write a Comment
User Comments (0)
About PowerShow.com