A car assembly line does not wait for one car to be finished before it starts the next. While the first car is being painted, the second is being fitted with an engine and the third is on the chassis. The same overlapping of work is used inside a processor, and it is called pipelining.

The Pipeline Idea

Pipelining divides a process into a number of sub-operations, called segments or stages, each handled by its own dedicated hardware. The result of one segment is passed to the next through a register. Several tasks are then in different segments at the same moment, and after the first result appears, a new result emerges at every clock cycle.

Definition: Pipeline. A technique in which a task is split into sequential segments, each performed by separate hardware, so that several tasks are processed at the same time in different segments.

Space-Time Diagram

A space-time diagram shows which task is in which segment during each clock cycle. The first task takes four cycles, and the second and third complete one cycle after it, so three tasks finish in six cycles.

Speed-Up

For a pipeline with k segments, n tasks and a clock period tp, the time to finish all the tasks is (k + n - 1) × tp. Without a pipeline each task takes tn = k × tp, and n tasks take n × tn. The speed-up is S = n × tn / ((k + n - 1) × tp). When n is very large, S approaches tn / tp, which equals k for equal segments.

Table 4.2: Time for n tasks in a k-segment pipeline

Quantity Non-pipelined Pipelined
Time for the first task k x tp k x tp
Time for n tasks n x k x tp (k + n - 1) x tp
Maximum speed-up 1 Approaches k

Example 4.2: Speed-up of a pipeline

Problem: A 4-segment pipeline has a clock period of 20 ns. Without a pipeline a task takes 80 ns. Find the speed-up for 100 tasks.

Solution:

  1. Pipelined time = (4 + 100 - 1) × 20 = 103 × 20 = 2060 ns.
  2. Non-pipelined time = 100 × 80 = 8000 ns.
  3. Speed-up = 8000 / 2060.

Result: The speed-up is about 3.88, close to the maximum of 4.

k, n, tp, tn = 4, 100, 20, 80
t_pipe = (k + n - 1) * tp
print(t_pipe, n * tn, round(n * tn / t_pipe, 2))

Output

2060 8000 3.88

Common mistakes

  • Believing that a pipeline makes a single task faster. It increases throughput.
  • Using k × n instead of k + n - 1 for the time of the pipelined tasks.
  • Ignoring the delay of the interface registers between segments.

Key takeaways

  • A pipeline splits a task into segments that work at the same time.
  • Time for n tasks in a k-segment pipeline is (k + n - 1) clock periods.
  • The speed-up approaches k as n becomes large.
  • Pipelining improves throughput, not the time of one task.

Practice questions

  1. What is a segment of a pipeline?
  2. How many clock cycles does a 5-segment pipeline need for 10 tasks?
  3. What does a space-time diagram show?

Answers to the practice questions

  1. One stage of the pipeline, with its own hardware, that performs a sub-operation.
  2. 5 + 10 - 1 = 14.
  3. Which task is in which segment during each clock cycle.

Sources

  • Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit IV