IAE Academy

GATE 2023 CS Q.34: solution and answer

GATE 2023 · CSQ.34 · 1 mark · NAT

A keyboard connected to a computer is used at a rate of 1 keystroke per second. The computer system polls the keyboard every 10 ms (milli seconds) to check for a keystroke and consumes 100 μs (micro seconds) for each poll. If it is determined after polling that a key has been pressed, the system consumes an additional 200 μs to process the keystroke. Let denote the fraction of a second spent in polling and processing a keystroke.

In an alternative implementation, the system uses interrupts instead of polling. An interrupt is raised for every keystroke. It takes a total of 1 ms for servicing an interrupt and processing a keystroke. Let denote the fraction of a second spent in servicing the interrupt and processing a keystroke.

The ratio is ______. (Rounded off to one decimal place)

See the question in the paper

Answer and solution

ANSWER

The ratio T1/T2 = 10.2

Official answer: 10.2Source: Official answer key, GATE 2023 CS (IIT Kanpur)

  1. Since the keystroke rate is 1 per second, analyze a 1-second interval, in which exactly one keystroke occurs.

  2. Polling: the system polls every 10 ms, so in 1 second (1000 ms) there are 1000/10 = 100 polls.

  3. Each poll costs 100 μs, so total polling cost = 100 × 100 μs = 10,000 μs (= 10 ms).

  4. Since one keystroke occurs in this second, an additional 200 μs is spent processing it once detected.

  5. Total time spent on polling and processing in one second = 10,000 μs + 200 μs = 10,200 μs.

  6. T1 = 10,200 μs / 1,000,000 μs (1 second in μs) = 0.0102.

  7. Interrupt-driven: one interrupt occurs per second (matching the keystroke rate), and each interrupt costs a total of 1 ms = 1000 μs for servicing and processing.

  8. T2 = 1000 μs / 1,000,000 μs = 0.001.

  9. Ratio T1/T2 = 0.0102 / 0.001 = 10.2.

KEY IDEA

Compute the total time spent per second under each scheme (polling overhead + one keystroke-processing event per second, versus one interrupt-service event per second), express each as a fraction of a second, and take the ratio.

WATCH OUT FOR

Forgetting to add the 200 μs keystroke-processing time to the polling cost (giving T1 = 0.01, ratio 10.0), or forgetting that the 200 μs is added only once per second (since only one keystroke occurs per second), not per poll.

From the GATE 2023 CS paper. Every question of this paper · Download the full paper · All 8 I/O, interrupts & DMA questions, with notes

More I/O, interrupts & DMA questions