Sub topic 5
Speedup, Throughput, and Efficiency
Assume you know the CPU clock, instruction stages, registers, and basic ratio arithmetic. You should also understand simple instructions such as add, load, and branch.
Measuring pipeline performance
A pipeline overlaps different instructions in different stages. This improves throughput, which is the number of completed instructions per unit of time. It does not necessarily reduce the time needed by one instruction.
For a pipeline with k stages and n instructions, assuming no stalls:
- The first instruction completes after
kclock cycles. - Each later instruction completes one cycle after the previous instruction.
- Total cycles are
k + n - 1. - Steady-state throughput is approximately one instruction per clock cycle.
The clock period must be long enough for the slowest stage and its pipeline register:
clock period = maximum stage delay + pipeline-register delayThe pipeline-register delay is also called latch overhead. It limits the maximum clock frequency.
Speedup
Speedup compares the execution time without pipelining with the execution time using a pipeline:
speedup = non-pipelined time / pipelined timeIf the stage delays are d1, d2, ..., dk, then:
non-pipelined time = n × (d1 + d2 + ... + dk)
pipelined time = (k + n - 1) × clock periodFor a large number of instructions, the fill and drain terms become small. The speedup then approaches:
sum of stage delays / clock periodA perfectly balanced pipeline with no latch overhead can approach a speedup of k, but it cannot exceed that ideal limit.
Worked example
Consider five stages with delays of 60, 80, 70, 90, and 50 nanoseconds. The pipeline-register delay is 10 nanoseconds.
The clock period is:
max(60, 80, 70, 90, 50) + 10 = 100 nsFor 100 instructions:
- Non-pipelined time =
100 × 350 = 35,000 ns - Pipelined time =
(5 + 100 - 1) × 100 = 10,400 ns - Speedup =
35,000 / 10,400 = 3.37
The ideal five-stage speedup is 5, but the unequal stage delays, latch overhead, and pipeline fill reduce it.
def pipelined_time(stage_delays, latch_delay, n, stall_cycles=0):
clock = max(stage_delays) + latch_delay
k = len(stage_delays)
return (k + n - 1 + stall_cycles) * clock
def non_pipelined_time(stage_delays, n):
return n * sum(stage_delays)
delays = [60, 80, 70, 90, 50]
n = 100
tp = pipelined_time(delays, 10, n)
tn = non_pipelined_time(delays, n)
print(tp, tn, round(tn / tp, 2))Throughput and efficiency
After the pipeline is full, one instruction completes every 100 ns in this example:
throughput = 1 / 100 ns = 10 million instructions per secondLatency is the time for one instruction to travel through all stages. With five stages, the latency is 5 × 100 = 500 ns. A pipeline can therefore improve throughput while increasing the latency of an individual instruction.
For an ideal k-stage pipeline, efficiency is often defined as:
efficiency = actual speedup / ideal speedup
= actual speedup / kHere, efficiency is approximately 3.37 / 5 = 67.4%.
Exercise
A four-stage pipeline has a 20 ns clock period. How many cycles and how much time are needed for 10 instructions with no stalls?
Show answer
The cycle count is 4 + 10 - 1 = 13 cycles. The time is 13 × 20 = 260 ns.