CPU Performance

Performance

Define.

$$
\text{Performance}=\frac{1}{\text{Execution Time}}
$$

X is $n$ time faster than Y

Equals to:

$$
\frac{\text{Performance}{x}}{\text{Performance}{y}}=\frac{\text{Execution Time}{y}}{\text{Execution Time}{x}}=n
$$

Measuring Execution Time

  • Elapsed time
    • Total response time, including all aspects
      • Processing, I/O, OS overhread, idle time
    • Determines system performance
  • CPU time
    • Time spent processing a given job
      • Discounts I/O time, other jobs’ shares
    • Comprises user CPU time and system CPU time
    • Different programs are affected differently by CPU and system performance

CPU Clocking

Operation of digital hardware governed by a constant-rate clock.

![[images/Pasted image 20251126135609.png]]

  • Clock period: Clock Cycle Time
  • Clock frequency: Clock Rate

CPU Time

$$
\text{CPU\ Time}
=\text{CPU Clock\ Cycles} \times \text{Clock\ Cycle\ Time}
=\frac{\text{CPU Clock\ Cycles}}{\text{Clock\ Rate}}
$$

  • CPU Clock Cycles:所有指令所需时钟周期数量
  • Clock Cycle Time:一个时钟周期时间
  • Clock Rate:时钟频率

其中:$\text{Clock Cylce Time} = \frac{1}{\text{Clock Rate}}$

To improve performance:

  • Reducing CPU clock cycles
  • Increasing clock rate


用到了:

  • $\text{CPU Time}=\text{Clock Cycles}\times \text{Clock Cycle Time}=\frac{\text{Clock Cycles}}{\text{Clock Rate}}$

CPI

CPI: Cycles Per Instruction

$$
\text{CPU Clock\ Cycles}=\text{Instruction\ Count} \times \text{CPI}
$$

$$
\text{CPU Time}=\text{Instrcution Count}\times\text{CPI}\times\text{Clock Cycle Time}
=\frac{\text{Instrcution Count}\times\text{CPI}}{\text{Clock Cycle Time}}
$$

  • Instruction Count(IC):指令条数,determined by program, ISA and compiler
  • CPI(Cycles Per Instruction):每条指令平均所需时钟周期数量,determined by CPU hardware

ISA:指令集架构

If different instrcution classes take different numbers of cycles:

$$
\text{Clock Cycles}=\Sigma^{n}{i=1}(\text{CPI}{i}\times\text{IC}_{i})
$$

Weighted average CPI:

$$
\text{CPI}=\frac{\text{Clock Cycles}}{\text{IC}}=\Sigma^{n}{i=1}(\text{CPI}{i}\times\frac{\text{IC}_i}{\text{IC}})
$$

Consider three different processors P1, P2, and P3 executing the same instruction  set. P1 has a 3 GHz clock rate and a CPI of 1.5. P2 has a 2.5 GHz clock rate and a CPI  of 1.0. P3 has a 4.0 GHz clock rate and has a CPI of 2.2.

a. Which processor has the highest performance expressed in instructions per second?

b. If the processors each execute a program in 10 seconds, find the number of cycles and the number of instructions.

c. We are trying to reduce the execution time by 30% but this leads to an increase of 20% in the CPI. What clock rate should we have to get this time reduction?

With same IC.

processor clock rate CPI CPU Cycle Time Instructions Per Second
P1 $3\times 10^{9}$ 1.5 $\frac{1.5\times IC}{3\times 10^{9}}=IC\times 5\times 10^{-8}$ $3\times 10^{9}/1.5=2\times 10^{9}$
P2 $2.5\times 10^{9}$ 1.0 $\frac{1.0\times IC}{2.5\times 10^{9}}=IC\times 4\times 10^{-8}$ $2.5\times 10^{9}/1.0=2.5\times 10^{9}$
P3 $4\times 10^{9}$ 2.2 $\frac{2.2\times IC}{4\times 10^{9}}=IC\times 5.5\times 10^{-8}$ $4\times 10^{9}/2.2=1.818\times 10^{9}$

a. P2 has the highest performance.

b.

  • $\text{number of cycles}=\text{clock rate}\times \text{seconds}$
  • $\text{number of instruction}=\text{Instructions Per Second}\times\text{seconds}$

for $seconds = 10$:

processor number of cycles number of instruction
P1 $3\times 10 ^{10}$ $3\times 10^{9}/1.5=2\times 10^{10}$
P2 $2.5\times 10 ^{10}$ $2.5\times 10^{9}/1.0=2.5\times 10^{10}$
P3 $4\times 10 ^{10}$ $4\times 10^{9}/2.2=1.818\times 10^{10}$

c. assume that the clock rate we should have is $cr_{\text{new}}$

We have:

$$
\begin{array}{l}
\text{CPU Time}{\text{new}}=\text{CPU Time}{\text{old}}\times 70%
\newline
\text{CPI}{\text{new}}=\text{CPI}{\text{old}}\times 120%
\end{array}
$$

And:

$$\text{CPU Time}=\frac{\text{CPI}}{\text{CPU Rate}}$$

So we get:

$$
cr_{\text{new}}=\frac{\text{CPI}{\text{new}}}{\text{CPU Time}{\text{new}}}
=\frac{\text{CPI}{\text{old}}\times 120%}{\text{CPU Time}{\text{old}}\times 70%}
=cr_{\text{old}}\times\frac{12}{7}
$$

Power

$$
\text{Power}=\text{Capacitive\ Load}\times\text{Voltage}^{2}\times\text{Frequency}
$$

  • capacitive load refers to the total capacitance that must be charged and discharged every time a signal switches (i.e., changes logic state) in the circuit

Multiprocessors

Assume for arithmetic, load/store, and branch instructions, a processor has CPIs of  1, 12, and 5, respectively. Also assume that on a single processor a program requires the execution of 2.56E9 arithmetic instructions, 1.28E9 load/store instructions, and 256 million branch instructions. Assume that each processor has a 2 GHz clock frequency.

Assume that, as the program is parallelized to run over multiple cores, the number of  arithmetic and load/store instructions per processor is divided by 0.7 x p (where p is  the number of processors) but the number of branch instructions per processor remains the same.

Find the total execution time for this program on 1, 2, 4, and 8 processors, and show the relative speedup of the 2, 4, and 8 processor result relative to the single processor result.

Instruction CPI IC(single processor) IC(multiprocessors) Clock Rate
arithmetic 1 $2.56\times 10^{9}$ $\frac{2.56}{0.7\times p}\times 10^{9}$ $2\times 10^{9}$
load/store 12 $1.28\times 10^{9}$ $\frac{1.28}{0.7\times p}\times 10^{9}$ $2\times 10^{9}$
branch 5 $0.256\times 10^{9}$ $0.256\times 10^{9}$ $2\times 10^{9}$

$p$ is in $(1,2,4,8)$

for $p=1$: use signle precessor

$$
\begin{array}{l}
\text{CPU Time}{1}=\frac{\Sigma^{3}{i=1}(\text{IC}{i}\times\text{CPI}{i})}{\text{Clock Rate}}
\newline
=\frac{(2.56\times1+1.28\times12+0.256\times5)\times 10^{9}}{2\times10^{9}}
\newline
=9.6(s)
\end{array}
$$

for $p=2$: use multiprocessors

$$
\begin{array}{l}
\text{CPU Time}{2}=\frac{\Sigma^{3}{i=1}(\text{IC}{i}\times\text{CPI}{i})}{\text{Clock Rate}}
\newline
=\frac{(\frac{2.56\times 1}{0.7\times 2}+
\frac{1.28\times 12}{0.7\times 2}+
0.256\times 5)\times 10^{9}}{2\times10^{9}}
\newline
=7.04(s)
\end{array}
$$

for $p=4$: use multiprocessors

$$
\begin{array}{l}
\text{CPU Time}{4}=\frac{\Sigma^{3}{i=1}(\text{IC}{i}\times\text{CPI}{i})}{\text{Clock Rate}}
\newline
=\frac{(\frac{2.56\times 1}{0.7\times 4}+
\frac{1.28\times 12}{0.7\times 4}+
0.256\times 5)\times 10^{9}}{2\times10^{9}}
\newline
=3.84(s)
\end{array}
$$

for $p=8$: use multiprocessors

$$
\begin{array}{l}
\text{CPU Time}{2}=\frac{\Sigma^{3}{i=1}(\text{IC}{i}\times\text{CPI}{i})}{\text{Clock Rate}}
\newline
=\frac{(\frac{2.56\times 1}{0.7\times 8}+
\frac{1.28\times 12}{0.7\times 8}+
0.256\times 5)\times 10^{9}}{2\times10^{9}}
\newline
=2.24(s)
\end{array}
$$