An I/O interrupt is

Download Report

Transcript An I/O interrupt is

IKI20210
Pengantar Organisasi Komputer
Kuliah No. 19: I/O, Interupsi
Sumber:
1. Hamacher. Computer Organization, ed-4.
2. Materi kuliah CS61C/2000 & CS152/1997, UCB.
20 November 2002
Bobby Nazief ([email protected])
Johny Moningka ([email protected])
bahan kuliah: http://www.cs.ui.ac.id/~iki20210/
1
What is the alternative to polling?
° Wasteful to have processor spend most of its time
“spin-waiting” for I/O to be ready
° Wish we could have an unplanned procedure call
that would be invoked only when I/O device is
ready
° Solution: use interrupt mechanism to help I/O.
Interrupt program when I/O ready, return when
done with data transfer
2
I/O Interrupt
° An I/O interrupt is like a subroutine call except:
• An I/O interrupt is “asynchronous”
• More information needs to be conveyed
° An I/O interrupt is asynchronous with respect to
instruction execution:
• I/O interrupt is not associated with any instruction, but it can
happen in the middle of any given instruction
• I/O interrupt does not prevent any instruction from completion
3
Interrupt Driven Data Transfer
Memory
(1) I/O
interrupt
add
sub
and
or
(2) save PC
user
program
(3) interrupt
service addr (4)
read
store
(5) ...
jr
interrupt
service
routine
4
Instruction Set Support for I/O Interrupt
° Save the PC for return
• AVR uses the stacks
° Where go when interrupt occurs?
• AVR defines:
- Locations 0x000 – 0x002 for external interrupts
- Locations 0x003 – 0x00C for internal interrupts
° Determine cause of interrupt?
• AVR uses vectored interrupt, which associates the location of the
interrupt service routine (see above) with the device that causes it
5
Benefit of Interrupt-Driven I/O
° 400 clock cycle overhead for each transfer, including
interrupt. Find the % of processor consumed if the
hard disk is only active 5% of the time.
° Interrupt rate = polling rate
• Disk Interrupts/sec = 8 MB/s /16B
= 500K interrupts/sec
• Disk Transfer Clocks/sec = 500K * 400
= 200,000,000 clocks/sec
• % Processor for during transfer: 250*106/500*106= 40%
° Disk active 5%  5% * 40%  2% busy
Determined by disk’s activity, whereas in Pollingdriven I/O the Processor will be busy polling 40% of
the time even if the disk is not active
6
Multiple Devices/Interrupts
° Which I/O device caused exception?
• Needs to convey the identity of the device generating the interrupt
° Can avoid interrupts during the interrupt routine?
• In general, interrupts are disabled whenever one is being serviced;
interrupts will be enabled after the service is completed
• What if more important interrupt occurs while servicing this
interrupt?
° Who keeps track of status of all the devices, handle
errors, know where to put/supply the I/O data?
• In general, these is one of the tasks of Operating System
7
Device Identification
Device 1
CPU
INTR1
Device 2
INTR2
Device N
INTRn
wired-OR
° The Interrupting Device may provide its identity
through:
• Interrupt-Request (IRQ) bit in its Status Register, which will be
evaluated one-by-one by the processor (polling)
• Sending special code the the processor over the bus (vectored
interrupt)
8
Prioritized Interrupt
Device 1
INTA1
Device 2
Device N
INTR1
CPU
° An Interrupt Service Routine may be interrupted by
other, higher-priority interrupt
9
Daisy Chain Scheme
Device 1
Highest
Priority
Device N
Lowest
Priority
Device 2
INTA
CPU
Release
INTR
wired-OR
° Advantage: simple
° Disadvantages:
• Cannot assure fairness:
A low-priority device may be locked out indefinitely
10
Exceptions
° Interrupt is only a subset of Exception
• Exception: signal marking that something “out of the ordinary”
has happened and needs to be handled
° Interrupt: asynchronous exception
• Unrelated with instruction being executed
° Trap: synchronous exception
•
•
•
•
Related with instruction being executed
To recover from errors: Illegal Instruction, Divide By Zero, …
To debug a program
To provide privilege (for Operating System)
11
4 Responsibilities leading to OS
° The I/O system is shared by multiple programs
using the processor
° Low-level control of I/O device is complex because
requires managing a set of concurrent events and
because requirements for correct device control
are often very detailed
° I/O systems often use interrupts to communicate
information about I/O operations
° Would like I/O services for all user programs under
safe control
12
4 Functions OS must provide
° OS guarantees that user’s program accesses only the
portions of I/O device to which user has rights (e.g., file
access)
° OS provides abstractions for accessing devices by
supplying routines that handle low-level device
operations
° OS handles the exceptions generated by I/O devices
(and arithmetic exceptions generated by a program)
° OS tries to provide equitable access to the shared I/O
resources, as well as schedule accesses in order to
enhance system performance
13
OS Interrupt Services
OSINIT
Set interrupt vectors
Time-slice clock  SCHEDULER
Trap  OSSERVICES
VDT interrupts  IODATA
SCHEDULER
OSSERVICES
IODATA
…
…
OSSERVICES Examine stack to determine requested operation
Call appropriate routine
PC
SCHEDULER Save current context
Select a runnable process
Restore saved context of new process
Push new values for PS and PC on stack
Return from interrupt
14
I/O ROUTINES & DEVICE DRIVER
IOINIT
Set process status to Blocked
Initialize memory buffer address pointer
Call device driver to initialize device & enable
interrupts in the device interface (VDTINIT)
Return from subroutine
IODATA
Poll devices to determine source of interrupt
Call appropriate device driver (VDTDATA)
If END = 1, then set process status to Runnable
Return from interrupt
VDTINIT
Initialize device interface
Enable interrupts
Return from subroutine
VDTDATA
Check device status
If ready, then transfer character
If character = CR, then set END = 1;
else set END = 0
Return from subroutine
15
Things to Remember
° I/O gives computers their 5 senses
° I/O speed range is million to one
° Processor speed means must synchronize with I/O
devices before use
° Polling works, but expensive
• processor repeatedly queries devices
° Interrupts works, more complex
• devices causes an exception, causing
OS to run and deal with the device
° I/O control leads to Operating Systems
16