CPE 315/353/357
Professor Stearns
SPIM Input Polling - Timing Calculation

Reference: Section A.8 of Patterson and Hennessy

When a programmer uses I/O polling to read characters from the keyboard, the polling code might look something like this:

# set Receiver control register address
          lui  $a1, 0xffff           
  
# wait for the character to arrive in Receiver data - use polling
wait:     lw   $t1, 0($a1)
          andi $t2, $t1, 1
          beq  $t2, $0, wait

# get the character from Receiver data
          lw   $t8, 4($a1)
          j    wait

The pseudo-code for this operation:
loop forever
    Is there a character in Receiver data?
    No - wait until a character is there
    Yes - get the character
end loop

Early computer architects noticed that polling wasted a lot of instructions. As an example, assume you have programmed a 150 mips CPU to read the input from a keyboard operator who can enter 60 words a minute.

The CPU reads 60 words per min ÷ 60 sec per min × 5 char per word = 5 char/sec

For each input character, the polling loop runs for 1/5 sec = 200 msec per char.

In 200 msec, the CPU executes 150 × 10 6 inst per sec ÷ 5 = 30 million instructions.

Since the polling loop contains 3 instructions, it loops 10 million times between each keystroke! There must something more productive for the CPU to do. Even for a fast device like a disk, the polling method wastes a lot of instructions. Try the same calculation for a disk drive I/O transfer.


Last updated on 11/1/01