Computer System Architecture: CPU Performance Formula

2020年2月4日 4405点热度 2人点赞 0条评论
内容目录

Computer System Architecture: CPU Performance Formula

Basic Knowledge

CPU Time: The time a program runs on the CPU. (Excluding I/O time)

Clock Frequency: The frequency of the internal main clock of the CPU, indicating how many cycles can be completed in one second.

For example, a frequency of 4.1 GHz means that it can complete 4.1 × 109 clock cycles per second.

Clock Cycle: The clock cycle, also known as the oscillation period, is defined as the inverse of the clock frequency. The clock cycle is the most basic and smallest time unit in a computer. Within one clock cycle, the CPU completes only the most basic action.

Clock Cycle = 1 / Frequency, for example, 1 / 4.1 × 109.

The shorter the clock cycle of the CPU, the better the CPU performance.

Instruction Cycle: The time taken to fetch and execute an instruction.

Clock Cycles of a Program

CPU Time = Number of Clock Cycles Required to Execute Program * Clock Cycle Time

Formula

Instruction Cycle: The time taken to fetch and execute an instruction;

Cycles per Instruction (CPI): The average number of clock cycles consumed per instruction.

CPI = Number of Clock Cycles Required to Execute Program / Number of Instructions Executed

Rearranging the formula gives us:

Number of Clock Cycles Required to Execute Program = CPI * Number of Instructions Executed
CPU Time / Clock Cycle Time = CPI * Number of Instructions Executed
CPU Time = CPI * Number of Instructions Executed * Clock Cycle Time

We define IC: Number of Instructions Executed, so:

CPU Time = CPI * IC * Clock Cycle Time
CPU Time = (CPI * IC) / Clock Frequency

CPIi: The number of clock cycles required for the i-th instruction;

ICi: The number of times the i-th instruction is executed during program execution;

i represents the index.

Since there are many instructions in the CPU instruction set, we need to calculate the average time consumed by each instruction and the number of times each instruction is executed.

The total CPU time is the sum of the CPU times for all individual instructions.

CPUi = (CPIi * ICi) / Clock Frequency

Therefore, the summary of formulas is as follows:

(ICi / IC) reflects the proportion of the i-th instruction in the program.

Example Problem

First, calculate the CPI before improvement. Currently, we have FP instructions (25%) and non-FP instructions (75%), along with their respective CPI values.

In Scheme One, the improvement level equals (CPI before improvement - CPI after improvement).

Since we can also determine the overall proportion of FPSQR, Scheme One does not need to include FR.

If you don't understand, let me explain.

The overall CPI is 2.
Before improvement, the CPI for FPSQR is 20*2% = 0.4,
The CPI for other instructions + the CPI for FRSQR = 2; The CPI for other instructions = 1.6;
After improvement, the CPI for FPSQR is 2*2% = 0.04.
This improves by 0.36.
The CPI after improvement requires time 1.6 + the CPI for improved FRSQR = 1.64.

Strategies for Optimizing Processor Performance

Three factors affect CPU performance: clock frequency, CPI, and the number of instructions.

Reducing the number of instructions can make the CPU simpler, use fewer registers, and make the system code simpler. For example, RISC-V. As lower-level instructions reduce, the upper-level code, such as operating systems and assembly programs, will also increase.

However, due to the varying frequencies of different instructions and the number of data accesses within each cycle, designing the CPU must take into account optimizing the execution speed of instructions and allocating more resources to frequently accessed instructions, such as X86.

痴者工良

高级程序员劝退师

文章评论