This is the 25th day of my participation in Gwen Challenge
Title 1
Suppose that the clock frequency of machine M is 4GHz, the number of instructions of user program P on M is 8×10^9, and the CPI is 1.25, what is the execution time of P on M? If the time from program P to the end of execution on machine M is 4 seconds, what percentage of CPU time is occupied by P?
Answer to question 1
CPI = Required Clock cycles/Number of instructions CPU execution time = Required clock cycles/Clock frequency P execution time on M = CPI x Number of instructions/Clock frequency = 1.25 x 8 x 10^9/4 x 10^9 =2.5s
The total time from the start of P execution to the end of execution is 4 seconds, of which 2.5 seconds is the actual execution time of P on the CPU. Other events may execute operating system programs or other user programs. The percentage is: 2.5/4 = 62.5%
Topic 2
Suppose A compiler generates two different instruction sequences S1 and S2 for A high-level language program, running on machine M with A clock frequency of 500MHz. The instruction types used in the target instruction sequence are A, B, C and D. The CPI of the four types of instructions on M and the number of various instructions used by the two instruction sequences are shown in the following table:
How many instructions do S1 and S2 have? What is the CPI? What are the number of clock cycles included? What are the execution times?
Answer to question 2
The number of instructions in S1 and S2 is 10 and 8 respectively
The CPI of S1 and S2 is:
S1:1 x2/10 + 2 x2/10 + 3 x2/10 + 10 = 4 x4/28/10 = 2.8
S2:1 x4/8 + 2 x1/8 + 3 + 4 x1 x2/8/8 = 16/8 = 2
Clock period = CPI * Number of instructions
The number of clock cycles contained in S1 and S2 is:
So S1:28; S2:16
CPU execution time = Number of clock cycles x time cycle
S1:28×1/500M = 56ns;
S2:16×1/500M = 32ns
Topic 3
Assume that the clock frequency of machine M is 1.2GHz, and the execution time of a program P on machine M is 12 seconds. When P is optimized, all multiply by 4 instructions are replaced by an instruction that moves 2 bits to the left, and the optimized program P ‘is obtained. Given that the CPI of the multiplication instruction on M is 5, the CPI of the left-shift instruction is 2, and the execution time of P is 1.2 times that of P ‘, how many multiplication instructions in P are replaced with left-shift instructions?
Answer to question 3
P ‘Execution time = P execution time / 1.2 = 10s
CPU execution time = contained clock period x clock period
CPI = Contained clock cycle/number of instructions
CPU execution time = Number of instructions x CPI/clock frequency
(12-10) s = n * (5-2) / 1.2g
N = 2 * 1.2g / 3 = 0.8g = 800M