C833 of 55
0 XP
  1. Hook
  2. Problems

C8 · Problem set 6

Problem set 6: interrupts, input and output, linking and performance

These problems use lessons 25 to 32: interrupts and exceptions, privilege modes and system calls, polling, interrupts and DMA for moving data, critical sections and atomic instructions, linking and startup code, measuring performance, and what the compiler does. Unless a problem says otherwise, each instruction takes one cycle and a UART byte is 10 bit times.

Check

An interrupt costs 12 cycles of hardware entry, then its handler saves and restores 4 registers (one sw and one lw each), does 30 instructions of work and ends with mret. Interrupts arrive 20000 times a second on a 16 MHz processor.

(a)

How many cycles does each interrupt take?

(b)

What percentage of the processor's time do the interrupts use?

Check

A timer interrupt handler moves TIMECMP forward by 1000 cycles each time, on a 48 MHz clock.

(a)

How many interrupts a second does that give?

(b)

How long is it between interrupts?

Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.

Check

A device sends 20-byte messages over a 57600-baud UART.

(a)

How many bytes a second can the UART carry?

(b)

How long does one message take?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Check

Firmware polls a sensor's status register every 10 µs, each poll costing 20 cycles on a 32 MHz clock.

(a)

What percentage of the processor's time does polling use?

(b)

What is the worst-case delay before a new reading is noticed?

Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.

Check

An ADC delivers 500000 samples a second. Each interrupt costs 80 cycles on a 168 MHz processor.

(a)

With an interrupt per sample, what percentage load would that be? (Over 100% means impossible.)

(b)

With DMA in blocks of 128, what is the interrupt load?

Check

A DMA controller moves 64 kB over a 16-bit bus at 25 million transfers a second.

(a)

What is the bus bandwidth?

(b)

How long does the transfer take, using the whole bus?

Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.

Check

A build reports 28 kB of .text, 2 kB of .rodata, 3 kB of .data and 8 kB of .bss, with 1 kB set aside for the stack.

(a)

How much flash does it need?

(b)

How much RAM does it need?

Check

la t0, table is at 0080 and table is at 1388.

(a)

What is the auipc immediate?

(b)

What is the addi immediate?

Check

A program runs 10 million instructions on processor A (CPI 1.2, 80 MHz). Recompiled for processor B, it needs 0.8 as many instructions, at CPI 1.4 and 120 MHz.

(a)

How long does it take on A?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

(b)

How many times faster is B?

Check

A fraction 0.65 of a program's time is in a routine that gets 3 times faster.

(a)

What is the overall speedup?

(b)

What percentage of the new running time is spent outside the routine?

Check

Of a program's instructions, 0.45 are ALU (1 cycle), 0.25 are loads that hit in a cache (2 cycles) and the rest branches (1 cycle). A fraction 0.1 of the loads miss and take 50 extra cycles each.

(a)

What is the average CPI?

(b)

What MIPS rate does that give at 100 MHz?

Check

A microcontroller draws 40 mW at 16 MHz and averages CPI 1.5. A task runs 20 million instructions.

(a)

How long does the task take?

Write units the way you normally would: 1.5 s and 1500 ms are the same answer.

(b)

How much energy does it use?

Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.

Practice

Keep practicing

16 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.