C8 Computer organization · Practice
Problem set 6: interrupts, input and output, linking and performance
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
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?
Check
A 48 MHz core takes 8 cycles to enter an interrupt handler; its longest critical section is 60 cycles.
(a)
What is the worst-case interrupt latency?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
How much of that is the critical section?
Check
A main loop of 6 instructions has a 2-instruction window between reading a shared counter and writing it back. 400 timer ticks, each adding to the counter in a handler, land at random points.
(a)
What share of the handler's updates are lost?
(b)
About how many updates are lost?
Check
Inlining removes the 6-instruction call overhead from a 4-instruction function called 10000 times on a 200 MHz core (one instruction a cycle).
(a)
How many instructions does it save?
(b)
How much time is that?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A data logger on a 200 MHz processor makes 2000 system calls a second at 150 cycles of overhead each, and also updates a counter shared between two cores whose cache line takes 120 ns per handoff.
(a)
What percentage of one core goes to system-call overhead?
(b)
At most how many million times per second can the two cores together update the shared counter?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C8