Cycles Per Instruction (CPI)
What you'll learn: You'll understand how to measure the average number of clock cycles needed to execute each instruction in a processor and what factors affect this metric.
The Core Idea
CPI (Cycles Per Instruction) is a performance metric that tells you how many clock cycles, on average, are required to complete one instruction. It's the bridge between your processor's clock speed and its actual instruction throughput.
In an ideal pipelined processor, CPI would equal 1.0—every clock cycle completes one instruction. In reality, CPI is almost always higher due to various delays and stalls.
Calculating CPI
The basic formula is straightforward:
CPI = Total Clock Cycles / Instructions Executed
For example, if a program takes 5,000 cycles to execute 4,000 instructions:
CPI = 5,000 / 4,000 = 1.25 cycles per instruction
What Influences CPI in Pipelined Processors?
Several factors push CPI above the ideal 1.0:
- Pipeline stalls from hazards: Data hazards, structural hazards, and control hazards all force the pipeline to insert bubbles, wasting cycles
- Cache misses: When data or instructions aren't in cache, the processor must wait many cycles for memory access
- Branch mispredictions: Wrong predictions require flushing the pipeline and restarting with the correct path
- Multi-cycle instructions: Some instructions (like division) take longer than one cycle even in the execution stage
Think of CPI like a factory's efficiency rating. A perfectly efficient assembly line produces one product per time unit (CPI = 1), but delays, retooling, and errors increase the average time per product.
Key Takeaway: CPI measures the average cycles per instruction and directly impacts processor performance; reducing CPI through better hazard management, prediction, and caching is crucial for high-performance computing.