1 / 25

Chapter 10 Interrupt driven I/O

Chapter 10 Interrupt driven I/O. Review: Polling vs Interrupts. Who determines when the next data transfer occurs? Polling CPU keeps checking status register until new data arrives OR device ready for next data Simple to implement but can be inefficient

kareng
Download Presentation

Chapter 10 Interrupt driven I/O

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 10 Interrupt driven I/O

  2. Review: Polling vs Interrupts • Who determines when the next data transfer occurs? • Polling • CPU keeps checking status register until new data arrives OR device ready for next data • Simple to implement but can be inefficient • “Are we there yet? Are we there yet? Are we there yet?” • Interrupts • Device sends a special signal to CPU whennew data arrives OR device ready for next data • CPU can be performing other tasks instead of polling device. • Adds complexity, only useful if there is more than one task to do • Not usually an issue in modern computer • “Wake me when we get there.”

  3. Interrupt-Driven I/O • Interrupt generated by an external device: • Stops the currently executing program; • Starts processing instructions that perform the I/O • Resumes the stopped program as if nothing happened. • Why? • Polling consumes a lot of cycles,especially for rare events – these cycles can be usedfor more computation. • Example: Process previous input while collectingcurrent input. (See Example 8.1 in text.)

  4. Interrupt-Driven I/O • To implement an interrupt mechanism, we need: • A way for the I/O device to signal the CPU that aninteresting event has occurred. • A way for the CPU to test whether the interrupt signal is setand whether its priority is higher than the current program. • Generating Signal • Software sets "interrupt enable" bit in device register. • When ready bit is set and IE bit is set, interrupt is signaled. interrupt enable bit 0 15 14 13 ready bit KBSR interrupt signal to processor

  5. Priority • Every instruction executes at a stated level of urgency. • LC-3: 8 priority levels (PL0-PL7) • Example: • Payroll program runs at PL0. • Nuclear power correction program runs at PL6. • It’s OK for PL6 device to interrupt PL0 program,but not the other way around. • The priority level of the interrupting program must be strictly greater than currently executing program for interrupt to happen • Priority encoder selects highest-priority device, compares to current processor priority level, and generates interrupt signal if appropriate.

  6. Testing for Interrupt Signal • CPU looks at signal between STORE and FETCH phases. • If not set, continues with next instruction. • If set, transfers control to interrupt service routine. F NO D interrupt signal? YES EA Transfer to ISR OP EX S

  7. Interrupt-Driven I/O (Part 2) • Interrupts were introduced in Chapter 8. • External device signals it needs to be serviced. • Processor saves state and starts service routine. • When finished, processor restores state and resumes program. Interrupt is an unscripted subroutine call,triggered by an external event.

  8. Processor State • What state is needed to completely capture thestate of a running process? • Processor Status Register • Privilege [15], Priority Level [10:8], Condition Codes [2:0] • Program Counter • Pointer to next instruction to be executed. • Registers • All temporary state of the process that’s not stored in memory.

  9. Where/When to Save Processor State? • Memory allocated by interrupted service routine? • Programmer doesn’t know when interrupt might occur,so she can’t prepare by saving critical registers. • When resuming, need to restore state exactly as it was. • Memory allocated by interrupting service routine? • Must save state before invoking routine,so we wouldn’t know where. • Also, interrupts may be nested – that is, an interrupt service routine might also get interrupted! • Use a stack and special instructions / hardware! • Location of stack “hard-wired”. • Push state to save, pop to restore.

  10. Supervisor Stack • A special region of memory used as the stackfor interrupt service routines. • Initial Supervisor Stack Pointer (SSP) stored in Saved.SSP. • Another register for storing User Stack Pointer (USP):Saved.USP. • Saved.SSP, Saved.USP, and PSR are special purpose registers in the LC3 processor needed for interrupt handling • Want to use R6 as stack pointer. • So that our PUSH/POP routines still work. • When switching from User mode to Supervisor mode(as result of interrupt), save R6 to Saved.USP.

  11. Invoking the Service Routine – The Details 1,2 Swap stacks and save state • If Priv = 1 (user), Saved.USP = R6, then R6 = Saved.SSP. • Push PSR and PC to Supervisor Stack. • Set PSR[15] = 0 (supervisor mode). • Set PSR[10:8] = priority of interrupt being serviced. • Set PSR[2:0] = 0. • Set MAR = x01vv, where vv = 8-bit interrupt vectorprovided by interrupting device (e.g., keyboard = x80). • Load memory location (M[x01vv]) into MDR. • Set PC = MDR; now first instruction of ISR will be fetched. 3,4,5 Update PSR 6,7,8 Jump to interrupt handling code Note: This all happens between the STORE RESULT of the last user instruction andthe FETCH of the first ISR instruction.

  12. Returning from Interrupt • Special instruction – RTI – that restores state. • Pop PC from supervisor stack. (PC = M[R6]; R6 = R6 + 1) • Pop PSR from supervisor stack. (PSR = M[R6]; R6 = R6 + 1) • If PSR[15] = 1, R6 = Saved.USP.(If going back to user mode, need to restore User Stack Pointer.) • RTI is a privileged instruction. • Can only be executed in Supervisor Mode. • If executed in User Mode, causes an exception.(More about that later.)

  13. Example (1) Program A Saved.SSP / / / / / / / / / / / / ADD x3006 / / / / / / / / / / / / / / / / / / x3006 PC Executing ADD at location x3006 when Device B interrupts.

  14. Example (2) Program A ISR forDevice B x6200 / / / / / / / / / / / / ADD x3006 R6 x3007 PSR for A RTI x6210 / / / / / / x6200 PC Saved.USP = R6. R6 = Saved.SSP. Push PSR and PC onto stack, then transfer toDevice B service routine (at x6200).

  15. Example (3) Program A ISR forDevice B x6200 / / / / / / x6202 AND / / / / / / ADD x3006 R6 x3007 PSR for A RTI x6210 / / / / / / x6203 PC Executing AND at x6202 when Device C interrupts.

  16. Example (4) Program A ISR forDevice B x6200 R6 x6203 x6202 AND PSR for B ADD x3006 ISR forDevice C x3007 PSR for A RTI x6300 x6210 / / / / / / x6300 PC RTI x6315 Push PSR and PC onto stack, then transfer toDevice C service routine (at x6300).

  17. Example (5) Program A ISR forDevice B x6200 x6203 x6202 AND PSR for B ADD x3006 ISR forDevice C R6 x3007 PSR for A RTI x6300 x6210 / / / / / / x6203 PC RTI x6315 Execute RTI at x6315; pop PC and PSR from stack.

  18. Example (6) Program A ISR forDevice B Saved.SSP x6200 x6203 x6202 AND PSR for B ADD x3006 ISR forDevice C x3007 PSR for A RTI x6300 x6210 / / / / / / x3007 PC RTI x6315 Execute RTI at x6210; pop PSR and PC from stack.Restore R6. Continue Program A as if nothing happened.

  19. Exception: Internal Interrupt • When something unexpected happensinside the processor, it may cause an exception. • Examples: • Privileged operation (e.g., RTI in user mode) • Executing an illegal opcode • Divide by zero • Accessing an illegal address (e.g., protected system memory) • Handled just like an interrupt • Vector is determined internally by type of exception • Priority is the same as running program

  20. ExternalDMAAcknowledgement: Silbershatz et al

  21. Direct Memory Access • For movement of a block of data • To/from disk, network etc. • Why • Free up general purpose processor for more complex tasks • Save energy • Example code to copy data • Very simple, does not require full instruction set or general purpose registers • MoveData • LD R0, Source ; R0: pointer to data source • LD R1, Dest ; R1: pointer to data dest • LD R2, Size ; R2: counter • BRz Done ; • Loop LDR R3, R0, #0 ; load data from source • STR R3, R1, #0 ; store data in dest • ADD R0, R0, #1 ; increment source pointer • ADD R1, R1, #1 ; increment dest pointer • ADD R2, R2, #-1 ; decrement counter • BRp Loop ; more data to copy? • Done RET ;

  22. Direct Memory Access • Requires DMA controller • Special purpose processor • Bypasses CPU to transfer data directly between I/O device and memory • OS writes DMA command block into memory • Source and destination addresses • Read or write mode • Count of bytes • Writes location of command block to DMA controller • Bus mastering of DMA controller – grabs bus from CPU • Cycle stealing from CPU but still much more efficient • When done, interrupts to signal completion

  23. LC-3 Data Path

  24. Six Step Process to Perform DMA Transfer Interrupt when done

  25. Direct Memory Access Structure high-speed I/O devices Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention Only one interrupt is generated per block

More Related