-
PerformanceComputer Science/Computer Architecture and Organization 2021. 3. 25. 21:35
CPU Performance
시간은 컴퓨터 성능 측정에 있어서 중요한 수단이다. 시간을 나타내는 방법은 다양한데, wall clock time, response time 또는 elapsed time와 같은 표현은 디스크 엑세스, 메모리 엑세스, input/output, 운영체제 overhead등을 포함해서, 테스크가 시작부터 끝까지 걸린 총 시간을 나타낸다. CPU time (CPU execution time)은 CPU가 한 작업을 위해 쓰여진 시간으로, I/O이나 다른 프로그램을 돌린 시간은 측정되지 않는다. 조금더 들어가보면, user CPU time (프로그램에 쓰여진 시간)과 system CPU time (운영체제에 쓰여진 시간)으로 나눠질 수 있다.
언제 하드웨어가 가동되는지 알려주는 time interval을 clock cycle 또는 clock rate를 통해서 알 수 있고, 아래 식을 이용하면, 프로그램을 돌리기 위해 드는 시간 (CPU execution time for a program)을 계산 할 수 있다.
CPU Execution Time = CPU Clock Cycle * Clock Cycle Time = CPU Clock Cycle / Clock Rate
아래 예시 문제를 풀어보자.
Our favorite program runs in 10 seconds on computer A, which has a 2 GHz clock. We are trying to help a computer designer build a computer, B, which will run this program in 6 seconds. Th e designer has determined that a substantial increase in the clock rate is possible, but this increase will aff ect the rest of the CPU design, causing computer B to require 1.2 times as many clock cycles as computer A for this program. What clock rate should we tell the designer to target?
2GHz clock 의 Clock rate의 CPU를 가진 컴퓨터 A가 10초만에 프로그램을 돌렸는데 컴퓨터 B는 6초만에 해결했다는 조건이다.
컴퓨터 A의 CPU time은 10이였고, 2GHz 의 clock rate를 가졌기때문에, 1초에 2 * 10^9 의 cycle을 도는 CPU이다. 식을 이용해 CPU clock cycle을 구해주면, 20 * 10^9 cycles 라는 결과가 나온다. 그렇다면, 이 값을 가지고 B의 Clock rate를 구해야하는데, 조건에서 컴퓨터 B는 1.2배 더 많은 Clock Cycle을 필요로 한다고 했기 때문에 CPU clock cycle은 1.2 * 20 * 10^9 가 된다.
위와같이 주어진 값으로 계산하게 되면, 최종적으로 4 * 10^9 cycles/second, 즉 4GHz cycle rate를 구 할 수 있다. Clock rate가 컴퓨터B가 훨씬 더 효율적이었기 때문에, 4초 더 빠르게 처리할 수 있었다.
Instruction Performance
위에서 계산했던 것에는 프로그램당 필요한 instructions의 갯수가 포함되어있지 않다. CPU Clock Cycle은 프로그램에 포함된 Instruction의 갯수에 Instruction에 필요한 clock cycle의 평균값을 곱해서 계산되어야하는데, 여기서 평균값을 CPI, Clock Cycle per Instruction이라고 한다. 그렇기 때문에, Instruction count를 포함해서 CPU time을 아래와같이 더 자세하게 나타낼 수 있다.
CPU time = Instruction Count * CPI * Clock Cycle Time = Instruction Count * CPI / Clock Rate
아래 예시 문제를 보자.
Suppose we have two implementations of the same instruction set architecture. Computer A has a clock cycle time of 250 ps and a CPI of 2.0 for some program, and computer B has a clock cycle time of 500 ps and a CPI of 1.2 for the same program. Which computer is faster for this program and by how much?
컴퓨터 A는 어떤 프로그램에 대한 clock cycle이 250 ps 이고, CPI 가 2.0 이다. 컴퓨터 B는 clock cycle time이 500 ps 이고 CPI 가 1.2 이다. 이때, 어떤 컴퓨터가 얼마나 더 빠른지에 대한 문제이다. 일단, ps (picosecond)는 아주 미세한 초 단위이다. 아래에서 보여진것처럼 1/1,000,000,000,000 초이다.
두 컴퓨터 각각의 CPU Clock Cycle은 아래와 같이 나타낼 수 있다 (I는 Instruction 갯수를 나타낸다).
CPU Clock Cycles A = I * 2.0 CPU Clock Cycles B = I * 1.2
컴퓨터 A와 B의 CPU time을 계산해보면, 아래와 같다.
CPU time A = CPU Clock Cycles A * Clock cycle time A = (I * 2.0) * 250 ps = 500 * I ps CPU time B = CPU Clock Cycles B * Clock cycle time B = (I * 1.2) * 500 ps = 600 * I ps
보여지다싶이, A가 B보다 빠른것을 알 수 있다. 비율을 계산하자면,
600/500 = 1.2
즉, 1.2배 빠르다고 말할 수 있다.
하드웨어가 1.2배 빠르다고 해서 무조건 빠른것은 아니다. 소프트웨어안에 코드도 효율적으로 짜여져야 빠른 시간안에 효율적으로 처리될 수 있다. 아래 문제는 그 코드의 효율성을 CPI를 이용해서 비교해보는 문제이다.
코드 1 은, 2 + 1 + 2 = 5개의 instructions을, 코드 2는 4 + 1 + 1 의 6개의 instructions을 처리해야한다. 총 Clock Cycle을 계산해보면 아래와 같다
CPU Clock Cycles 1 = (2 * 1) + (1 * 2) + (2 * 3) = 10 cycles CPU Clock Cycles 2 = (4 * 1) + (2 * 1) + (3 * 1) = 9 cycles
6개의 instructions을 처리하는데도, code 2가 1보다 빠른것을 보여준다. CPI를 계산해보면,
CPI 1 = 10 cycles / 5 instructions = 2.0 CPI 2 = 9 cycles / 6 instructions = 1.5
CPI에서 보여지는것처럼 Code2가 1보다 적은 clock cycle을 필요로 하는데, 그 이유는 CPI가 더 낮기 때문이다.
앞에서 보여지는것처럼, 프로그래밍을 할 때, 좋은 알고리즘은 똑같은 동작을 하더라도 적은 cycle을 사용할 수 있는 프로그램을 만든다. 알고리즘은 Instruction Count 그리고 CPI에 영향을 준다. 알고리즘 이외에도 어떤 Programming Language를 쓰는지에 따라서, 컴파일러에 따라서, 또는 Instruction set architecture에 따라서, Instruction count, CPI 그리고 clock rate에도 영향을 줄 수 있다.
마지막으로 아래 문제를 풀어보자
A given application written in Java runs 15 seconds on a desktop processor. A new Java compiler is released that requires only 0.6 as many instructions as the old compiler. Unfortunately, it increases the CPI by 1.1. How fast can we expect the application to run using this new compiler?
A의 정보를 이용해 Clock Cycle Time을 구해준 후, B의 총 시간을 구해주면 된다.
CPU Time = Instruction Count * CPI * Clock Cycle Time 15 seconds = InsA * CPIA * Clock Cycle Time Clock Cycle Time = 15 seconds / (InsA * CPIA) TimeB = (0.6 * InsA) * (1.1 * CPIA) * Clock Cycle Time = (0.6 * InsA) * (1.1 * CPIA) * (15 seconds / (InsA * CPIA)) = 0.6 * 1.1 * 15 seconds = 9.9 seconds
Reference
David A. Patterson and John L. Hennessy. 2013. Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (5th. ed.). Morgan Kaufmann Publishers Inc., San Francisco, CA, USA.
www.nasdaq.com/articles/time-relative%3A-where-trade-speed-matters-and-where-it-doesnt-2019-05-30
'Computer Science > Computer Architecture and Organization' 카테고리의 다른 글
컴퓨터의 언어, MIPS (0) 2021.04.03 Power의 벽, GHz가 높은 CPU가 좋은 CPU인가? (0) 2021.03.27 Processors and Memory (0) 2021.03.21 아이패드를 해부해보자 (사진으로만) (0) 2021.03.17 컴퓨터 구조와 장치, 그리고 Pixel (0) 2021.03.16