Cycles per instruction explained

In computer architecture, cycles per instruction (aka clock cycles per instruction, clocks per instruction, or CPI) is one aspect of a processor's performance: the average number of clock cycles per instruction for a program or program fragment.[1] It is the multiplicative inverse of instructions per cycle.

Definition

The average of Cycles Per Instruction in a given process is defined by the following weighted average:

CPI:=

\Sigmai(ICi)(CCi)
IC

=

\Sigmai(ICiCCi)
\Sigmai(ICi)

Where

ICi

is the number of instructions for a given instruction type

i

,

CCi

is the clock-cycles for that instruction type and

IC=\Sigmai(ICi)

is the total instruction count. The summation sums over all instruction types for a given benchmarking process.

Explanation

Let us assume a classic RISC pipeline, with the following five stages:

  1. Instruction fetch cycle (IF).
  2. Instruction decode/Register fetch cycle (ID).
  3. Execution/Effective address cycle (EX).
  4. Memory access (MEM).
  5. Write-back cycle (WB).

Each stage requires one clock cycle and an instruction passes through the stages sequentially. Without pipelining, in a multi-cycle processor, a new instruction is fetched in stage 1 only after the previous instruction finishes at stage 5, therefore the number of clock cycles it takes to execute an instruction is five (CPI = 5 > 1). In this case, the processor is said to be subscalar. With pipelining, a new instruction is fetched every clock cycle by exploiting instruction-level parallelism, therefore, since one could theoretically have five instructions in the five pipeline stages at once (one instruction per stage), a different instruction would complete stage 5 in every clock cycle and on average the number of clock cycles it takes to execute an instruction is 1 (CPI = 1). In this case, the processor is said to be scalar.

With a single-execution-unit processor, the best CPI attainable is 1. However, with a multiple-execution-unit processor, one may achieve even better CPI values (CPI < 1). In this case, the processor is said to be superscalar. To get better CPI values without pipelining, the number of execution units must be greater than the number of stages. For example, with six executions units, six new instructions are fetched in stage 1 only after the six previous instructions finish at stage 5, therefore on average the number of clock cycles it takes to execute an instruction is 5/6 (CPI = 5/6 < 1). To get better CPI values with pipelining, there must be at least two execution units. For example, with two executions units, two new instructions are fetched every clock cycle by exploiting instruction-level parallelism, therefore two different instructions would complete stage 5 in every clock cycle and on average the number of clock cycles it takes to execute an instruction is 1/2 (CPI = 1/2 < 1).

Examples

Example 1

For the multi-cycle MIPS, there are five types of instructions:

If a program has:

then, the CPI is:

CPI=

5 x 50+4 x 25+4 x 15+3 x 8+3 x 2
100

=4.4

Example 2

[2] A 400MHz processor was used to execute a benchmark program with the following instruction mix and clock cycle count:

Instruction TYPEInstruction countClock cycle count
Integer Arithmetic450001
Data transfer320002
Floating point150002
Control transfer80002

Determine the effective CPI, MIPS (Millions of instructions per second) rate, and execution time for this program.

CPI=

45000 x 1+32000 x 2+15000 x 2+8000 x 2
100000

=

155000
100000

=1.55

400MHz=400,000,000Hz

since:

MIPS\propto1/CPI

and

MIPS\proptoclockfrequency

Effectiveprocessorperformance=MIPS=

clockfrequency
CPI

x {

1
1Million
}

=

400,000,000
1.55 x 1000000

=

400
1.55

=258MIPS

Therefore:

Executiontime(T)=CPI x Instructioncount x clocktime=

CPI x InstructionCount
frequency

=

1.55 x 100000
400 x 1000000

=

1.55
4000

=0.0003875sec=0.3875ms

See also

Notes and References

  1. Book: Computer Organization and Design: The Hardware/Software Interface. registration. Patterson. John L.. Hennessy. 1994. 9781558602816.
  2. Advanced Computer Architecture by Kai Hwang, Chapter 1, Exercise Problem 1.1