162k views
2 votes
A system clocked at 1 GHz wants to read data from a hard disk. The hard disk needs some time to read the data and to prepare it for transmission. An interrupt routine requires 240 cycles each, polling requires 50 cycles each. The interrupt routine would be more efficient after how many polls.

User Gesgsklw
by
7.8k points

1 Answer

3 votes

Step-by-step explanation:

To determine when the interrupt routine would be more efficient than polling, we need to compare the time it takes for the interrupt routine and the time it takes for polling.

Let's assume that each cycle takes 1 nanosecond (ns) since the system clock is clocked at 1 GHz (1 GHz = 1 billion cycles per second, which means each cycle takes 1 nanosecond).

The interrupt routine requires 240 cycles, so the time it takes to complete the interrupt routine is 240 ns (240 cycles * 1 ns/cycle = 240 ns).

Polling requires 50 cycles per poll. So, the time it takes for one poll is 50 ns (50 cycles * 1 ns/cycle = 50 ns).

Now we need to find out after how many polls the cumulative time spent on polling exceeds the time taken by the interrupt routine.

Let's assume the number of polls is 'n'. The time spent on polling would be n * 50 ns.

So, the equation would be: n * 50 ns > 240 ns.

To solve this equation and find the value of 'n', we can divide both sides of the inequality by 50 ns:

n > 240 ns / 50 ns.

Simplifying the expression, we get:

n > 4.8.

Since 'n' represents the number of polls, it must be a whole number. Therefore, we round up to the nearest whole number.

So, the interrupt routine would be more efficient after 5 polls, as the cumulative time spent on polling (5 * 50 ns = 250 ns) exceeds the time taken by the interrupt routine (240 ns).

Therefore, after 5 polls, it would be more efficient to use the interrupt routine instead of polling.

User Lawree
by
8.3k points