Course contentsShow
← Computer Science
Lesson 1153 of 2,87227. Pipelining and PerformanceFree lesson

Pipeline Fill and Drain

Understand pipeline startup and shutdown phases where the pipeline is not yet full or emptying out.

Pipeline Fill and Drain

What you'll learn: You'll understand the startup and shutdown phases of a pipeline, when it's not operating at full efficiency.

The Core Idea

When a CPU pipeline first starts executing instructions, it doesn't immediately reach peak throughput. Similarly, when the last instruction enters, the pipeline gradually empties. These transitional periods are called pipeline fill (startup) and pipeline drain (shutdown).

Think of an assembly line manufacturing cars. When the factory opens for the day, the first car enters station 1, but stations 2-5 sit idle. Only after the first car moves through each station does the entire line become fully productive. That initial period is the "fill" phase. At closing time, when no new cars enter, stations gradually become idle as the last cars finish—that's the "drain" phase.

Why This Matters

In a five-stage pipeline (Fetch, Decode, Execute, Memory, Write-back), the first instruction doesn't complete until all five stages have passed. During fill:

  • Cycle 1: Only stage 1 is active (1 instruction in flight)
  • Cycle 2: Stages 1-2 active (2 instructions)
  • Cycle 3: Stages 1-3 active (3 instructions)
  • Cycle 4: Stages 1-4 active (4 instructions)
  • Cycle 5: All stages active—pipeline is full!

Only after cycle 5 does the pipeline achieve its ideal throughput of one instruction per cycle.

During drain, the opposite happens: no new instructions enter, and stages become idle one by one until the last instruction completes.

Impact on Performance

These transitional phases reduce the average speedup from the theoretical maximum, especially for short instruction sequences. The pipeline isn't "free"—you pay a startup and shutdown cost.

Key Takeaway: Pipeline fill and drain are transitional phases where the pipeline operates below peak efficiency—critical for understanding real-world pipeline performance, not just ideal throughput.