Computer Organisation and Architecture · Pipelining Basics
Phase-Time Diagram and Clock Cycles for Multiple Instructions
Overview
Pipelining splits the CPU hardware into separate functional units, one per instruction phase, so that several instructions can be processed at the same time in different phases.
The phase-time diagram records which phase each instruction occupies in each clock cycle, and it is used to count the clock cycles needed and the number of instructions in flight at any moment.
Key concepts
- Pipelining: a technique to speed up instruction processing by splitting the CPU hardware into separate functional units, each dedicated to one phase of instruction execution, so that multiple instructions can be processed simultaneously (in parallel) at different phases.
- Phase-time diagram: a diagram showing, for each clock cycle (columns) and each instruction (rows), which phase the instruction is in.
It is used to count how many clock cycles are needed and how many instructions are in flight at any time. - Four phases: Instruction Fetch (IF), Instruction Decode (ID), Execute (EX), Write Back (WB). Each phase is handled by its own dedicated functional unit.
- Relative clock numbering: the clock at which execution starts is simply called clock 1, then 2, 3, ...; there is no absolute "first" clock.
- Diagram length: how many clocks to draw depends on the options given in the exam question — if an option is 15, draw up to clock 15; if 20, draw up to clock 20.
Here 12 clocks are drawn because 3 instructions would take 12 clocks in non-pipelined execution, and the aim is to compare how many instructions finish in those same 12 clocks.
How it works
- The CPU's combinational circuit is divided into smaller functional units, one unit per phase: one for instruction fetch, one for instruction decode, one for execute, one for write back.
This division is what creates the parallelism. - Dividing the CPU has penalties and trade-offs (studied later); the focus here is how instructions flow through the units.
- Clock 1: I1 is placed in the Instruction Fetch unit (the fetch unit fetches I1).
- Clock 2: I1 moves to Instruction Decode. The fetch unit is now idle, so instead of wasting it, start I2 in fetch. This is the parallelism and the advantage of pipelining: even while I1 is still being processed, I2 can begin.
- End of clock 2: I1 finishes decode and can start Execute; I2 finishes fetch and can start Decode.
- Clock 3: I1 in Execute, I2 in Decode, and the idle fetch unit starts I3. Now three instructions are being processed at the same time (earlier only one was).
- End of clock 3: I1 finishes Execute → goes to Write Back; I2 finishes Decode → goes to Execute; I3 finishes Fetch → goes to Decode.
- Clock 4: the fetch unit is again idle, so start I4 in Fetch. At this clock, four instructions (I1 in WB, I2 in EX, I3 in ID, I4 in IF) are being processed simultaneously — the power of pipelining.
In non-pipelined execution only one instruction would be processed at any time. - Continue filling: I2, I3, I4, I5, I6, I7, I8, I9 move through the stages one clock at a time. Assume only 9 instructions (I10, I11 are not executed).
- End of clock 4: I1 has finished (it needed exactly 4 clocks). End of clock 5: I2 finishes. End of clock 6: I3 finishes.
So the first instruction comes out after 4 clocks, and after that one instruction comes out every clock — the main aim of pipelining. - Drawing boxes around every entry is only for explanation and visibility; in the exam do not draw the boxes — it wastes time. Use boxes only while practising if you find it hard without them.
Formulas
-
= number of pipeline stages (here ); the first instruction exits after clocks.
-
: total clocks for instructions in an ideal -stage pipeline.
-
Throughput after the pipeline is filled = 1 instruction per clock.
-
4-stage pipeline phase-time diagram
Drawing the diagram…
- Shows the staggered IF/ID/EX/WB phases of nine instructions across clock cycles 1 to 12, with one instruction entering and one leaving each clock after fill.
Worked examples
4-stage pipeline (IF, ID, EX, WB), 9 instructions, ideal (no stalls)
Phase-time table (rows = instructions, columns = clock cycles 1 to 12; each cell shows the phase):
| Instr | C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10 | C11 | C12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| I1 | IF | ID | EX | WB | – | – | – | – | – | – | – | – |
| I2 | – | IF | ID | EX | WB | – | – | – | – | – | – | – |
| I3 | – | – | IF | ID | EX | WB | – | – | – | – | – | – |
| I4 | – | – | – | IF | ID | EX | WB | – | – | – | – | – |
| I5 | – | – | – | – | IF | ID | EX | WB | – | – | – | – |
| I6 | – | – | – | – | – | IF | ID | EX | WB | – | – | – |
| I7 | – | – | – | – | – | – | IF | ID | EX | WB | – | – |
| I8 | – | – | – | – | – | – | – | IF | ID | EX | WB | – |
| I9 | – | – | – | – | – | – | – | – | IF | ID | EX | WB |
Step-by-step reasoning:
- C1: I1 in IF.
- C2: I1 in ID; fetch unit idle → I2 in IF.
- C3: I1 in EX, I2 in ID, I3 in IF (3 instructions in flight).
- C4: I1 in WB, I2 in EX, I3 in ID, I4 in IF (4 instructions in flight — maximum).
- C5 onward: I1 has left; each clock one new instruction enters IF and one leaves WB.
- I1 exits at end of C4, I2 at end of C5, I3 at end of C6, ..., I9 at end of C12.
Results:
- First instruction exits after 4 clocks (= number of stages).
- After that, one instruction exits per clock.
- 9 instructions finish in clocks.
- In non-pipelined execution, 9 instructions would need clocks; speedup , approaching for large .
Comparison
| Aspect | Non-pipelined | Pipelined (4 stages) |
|---|---|---|
| Instructions processed at a time | Only 1 | Up to 4 (one per stage) |
| Clocks for first result | 4 | 4 |
| Clocks per instruction after fill | 4 | 1 |
| Clocks for 9 instructions | 36 | 12 |
Revision summary
- Pipelining = divide the CPU into functional units, one per phase (IF, ID, EX, WB), and let different instructions occupy different units in the same clock.
- Whenever a unit is idle, start the next instruction in it — that idle unit is the source of parallelism.
- Clock numbering is relative; the number of clocks to draw depends on the options given in the question.
- First instruction exits after clocks ( = number of stages);
thereafter one instruction exits per clock. - At steady state, 4 instructions are simultaneously in the pipeline (one per stage).
- Do not draw boxes around cells in the exam — it wastes time; boxes are only for explanation and practice.
Previous-year exam insights
- For a k-stage pipeline with unequal stage delays and inter-stage latch delay d, the clock period is max() + d, and the time for n instructions is (k + n - 1) × (max() + d).
Asked inGATE 2025GATE 2023 - When different instructions need different numbers of cycles in stages (or a stage is repeated), the phase-time diagram must be drawn instruction by instruction, respecting that an instruction cannot enter a stage before the previous instruction leaves it;
total cycles = last instruction's finish time, not k + n - 1.
Asked inGATE 2009GATE 2004GATE 1999ISRO 2009 - Speedup of an ideal k-stage pipeline over non-pipelined execution for n instructions is n·k / (k + n - 1), which tends to k as n → ∞;
efficiency = speedup / k and throughput = 1/clock period.
Asked inGATE 2023GATE 2025 - A reservation table marks which stages an instruction uses in which cycles; the forbidden latencies (collisions) are read from it, and the minimum average latency (MAL) is the smallest average number of clock cycles between successive initiations over all collision-free latency cycles; the throughput is 1/MAL initiations per cycle.
Asked inGATE 2015 - When multiple functional units of the same type are available, the minimum time is found by scheduling each unit as early as possible (list scheduling), so the bottleneck resource determines the total time: total ≈ (number of operations on the busiest unit) × (its latency), overlapped with dependencies.
Asked inGATE 2016 - Pipeline registers/latches add to every stage delay and must be included in the cycle time; also, the first output appears after k clock cycles, and after that one output per cycle only if there are no stalls (hazards, branches, or multi-cycle stages).
Asked inGATE 2025GATE 2023ISRO 2009