Question 3:A given processor requires 2000 cycles to perform a context switch and start an interrupt handler (and the same number of cycles to switch back to the program that was running when the interrupt occurred), or 400 cycles to poll an I/O device. An I/O device attached to that processor makes 250 requests per second, each of which takes 10,000 cycles to resolve once the handler has been started. By default, the processor polls every 0.5 ms if it is not using interrupts. a. How many cycles per second does the processor spend handling I/O from the device if interrupts are used? b. How many cycles per second are spent on I/O if polling is used (include all polling attempts)? Assume the processor only polls during time slices when user programs are not running, so do not include any context-switch time in your calculation. c. How often would the processor have to poll for polling to take as many cycles per second as interrupt
Answer:
Given Data:
- Context switch for interrupt: 2000 cycles to switch to the interrupt handler and 2000 cycles to switch back.
- Total cycles for context switching for one interrupt: 2000 + 2000 = 4000 cycles.
- Cycles to resolve each I/O request: 10,000 cycles.
- I/O device requests per second: 250 requests.
- Cycles to poll an I/O device: 400 cycles.
- Polling interval: 0.5 ms (milliseconds).
Part (a): Cycles Spent Handling I/O if Interrupts are Used
Interrupt Handling Per Request:
- Cycles for context switching (to and from): 4000 cycles.
- Cycles to resolve each I/O request: 10,000 cycles.
- Total cycles per I/O request when using interrupts = 4000 cycles + 10,000 cycles = 14,000 cycles.
Total Requests Per Second:
- I/O device makes 250 requests per second.
Total Cycles Spent Per Second:
- Total cycles per second = 250 requests/second * 14,000 cycles/request
- Total cycles per second = 3,500,000 cycles/second.
So, the processor spends 3,500,000 cycles per second handling I/O from the device if interrupts are used.
Part (b): Cycles Spent on I/O if Polling is Used
Polling Interval:
- Polling every 0.5 ms means the processor polls 1000 times per second (since 1 second = 1000 ms, and 1000 ms / 0.5 ms = 2000 polls/second).
Cycles Per Polling Attempt:
- Each polling attempt takes 400 cycles.
Total Cycles for Polling Per Second:
- Total cycles per second for polling = 2000 polls/second * 400 cycles/poll
- Total cycles per second for polling = 800,000 cycles/second.
Handling I/O Requests:
- Each request takes 10,000 cycles to resolve, and there are 250 requests per second.
- Total cycles for handling I/O requests = 250 requests/second * 10,000 cycles/request
- Total cycles for handling I/O requests = 2,500,000 cycles/second.
Total Cycles Spent Per Second:
- Total cycles spent on I/O per second = Cycles for polling + Cycles for handling requests
- Total cycles per second = 800,000 cycles/second + 2,500,000 cycles/second
- Total cycles per second = 3,300,000 cycles/second.
So, the processor spends 3,300,000 cycles per second on I/O if polling is used.
Part (c): Polling Frequency to Match Interrupt Cycle Usage
To find the polling frequency that would result in the same number of cycles spent per second as when using interrupts:
Target Cycle Usage:
- From part (a), the cycles per second with interrupts are 3,500,000 cycles/second.
Current Polling Cost:
- Each polling attempt takes 400 cycles.
- Let be the polling frequency (polls per second).
Cycle Calculation:
- Total cycles for polling per second = .
- Total cycles for handling requests per second = 2,500,000 cycles/second.
Equation to Match Interrupt Cycle Usage:
Solve for :
So, the processor would have to poll 2500 times per second for polling to take as many cycles per second as interrupts.
Comments
Post a Comment