Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 19: I/O, Interupsi 20 November 2002 Bobby Nazief Johny Moningka

Similar presentations


Presentation on theme: "1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 19: I/O, Interupsi 20 November 2002 Bobby Nazief Johny Moningka"— Presentation transcript:

1 1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 19: I/O, Interupsi 20 November 2002 Bobby Nazief (nazief@cs.ui.ac.id) Johny Moningka (moningka@cs.ui.ac.id) bahan kuliah: http://www.cs.ui.ac.id/~iki20210/ Sumber: 1. Hamacher. Computer Organization, ed-4. 2. Materi kuliah CS61C/2000 & CS152/1997, UCB.

2 2 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

3 3 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

4 4 Interrupt Driven Data Transfer (1) I/O interrupt (2) save PC (3) interrupt service addr Memory add sub and or user program read store... jr interrupt service routine (4) (5)

5 5 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

6 6 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*10 6 /500*10 6 = 40% °Disk active 5%  5% * 40%  2% busy  Determined by disk’s activity, whereas in Polling- driven I/O the Processor will be busy polling 40% of the time even if the disk is not active

7 7 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

8 8 Device Identification CPU Device 1 Device N Device 2 INTR1 °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) INTRn INTR2 wired-OR

9 9 Prioritized Interrupt CPU Device 1 Device N Device 2 INTA1 INTR1 °An Interrupt Service Routine may be interrupted by other, higher-priority interrupt

10 10 Daisy Chain Scheme °Advantage: simple °Disadvantages: Cannot assure fairness: A low-priority device may be locked out indefinitely CPU Device 1 Highest Priority Device N Lowest Priority Device 2 INTA Release INTR wired-OR

11 11 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)

12 12 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

13 13 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

14 14 OS Interrupt Services OSINITSet interrupt vectors Time-slice clock  SCHEDULER Trap  OSSERVICES VDT interrupts  IODATA OSSERVICESExamine stack to determine requested operation Call appropriate routine SCHEDULERSave current context Select a runnable process Restore saved context of new process Push new values for PS and PC on stack Return from interrupt SCHEDULER OSSERVICES IODATA … … PC

15 15 I/O ROUTINES & DEVICE DRIVER IOINITSet 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 IODATAPoll devices to determine source of interrupt Call appropriate device driver (VDTDATA) If END = 1, then set process status to Runnable Return from interrupt VDTINITInitialize device interface Enable interrupts Return from subroutine VDTDATACheck device status If ready, then transfer character If character = CR, then set END = 1; else set END = 0 Return from subroutine

16 16 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


Download ppt "1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 19: I/O, Interupsi 20 November 2002 Bobby Nazief Johny Moningka"

Similar presentations


Ads by Google