# Chap. 01 - Computer Abstractions and Technology > 課程內容 : 清華大學開放式課程 黃婷婷教授 > 參考書目 : Computer Organization and Design: The Hardware/Software Interface (5th), David A. Patterson, John L. Hennessy > > 其他科目內容請參見 [[Here]](https://hackmd.io/@ChenZE/By4SOO6Jyl) ## 1. The computer revolution ### 1.1 Moore's law (摩爾定律) > 每 1.5 年(18個月),單一晶片(chip)中的電晶體(transistor)數量會成長 2 倍 ## 2. Abstraction ### 2.1 Below our program 電腦中運行的程式(program)通常由三個部分組成 * Application software : 應用程式 * 通常是以 high-level language (Ex: C)編寫 * System software : 將應用程式與底層的硬體連接,目的是要幫助 app 做事情 * Complier * Operating system * Hardware 而程式碼也分成三個等級 * high-level language (高階語言) * 更接近人類問題的描述方式 * 提供更好的生產力與可攜性 * 透過 complier 編譯成組合語言 * assembly language (組合語言) * 指令的描述方式 * 透過 assembler 組譯成機器語言 * machine language * 由一堆 0 與 1 的 binary bit 組成 * 將指令解碼提供給硬體設備 ### 2.2 Inside the CPU CPU 的內部由三個元件組成 * Datapath(資料路徑) * 主要執行運算以及資料處理存取的地方 * 通常由一系列的小元件構成 Ex: register, ALU, ... * Control unit(控制單元) * 依據指令來指揮 datapath, memory, I/O 等硬體的運作 * Cache memory * SRAM memory * 可以看成是一種較小且較快的記憶體,但只存在 CPU 晶片中 ![S__2146325](https://hackmd.io/_uploads/S1Z8vpXQR.jpg) ## 3. Technology ### 3.1 Performance **Definition** * Resoinse time * How long it takes to do a task * 表示「多久完成」 * Throughout * Total work done per unit time * 表示「單位時間內完成的工作量」 以上兩者主要會受到 processor(處理器)的世代不同或是數量不同而有所差異,此處主要聚焦在 response time **Measuring executing time** * Elapsed time * 整體的 response time(包含 I/O, idle 等的處理時間) * CPU time * 處理單一任務的時間 * 由 user CPU time + system CPU time 組成 **Relative performance(相對效能)** Define $$ \text{Performance}=\frac{1}{\text{Execution time}} $$ 意即,效能與執行的時間成反比。如果表示「X 的效能是 Y 的 N 倍」,則 $$ \frac{\text{Performance}_x}{\text{Performance}_y}=\frac{\text{Execution time}_y}{\text{Execution time}_x}=n $$ **處理器的效能評估** 習慣上會以 CPU clocking 來評估處理器的效能。clock 可視為一個由硬體所產生的訊號,這個訊號可以用來控制 data transfer 以及 computation * Clock period (i.e., 週期) * 單一 clock cycle 所需的時間(單位: 秒) * Clock frequency (i.e., 頻率) * 每秒的 clock cycle 數量(單位: 赫茲) ![S__2170882](https://hackmd.io/_uploads/B1q9ih6m0.jpg) CPU 執行時間的定義如下 : $$ \begin{aligned} \text{CPU time} &= \text{CPU clock cycles} \times \text{clock cycle time}\\ &= \frac{\text{CPU clock cycles}}{\text{clock rate}} \end{aligned} $$ 因為速率與頻率是相同概念,所以 $$ \frac{1}{\text{clock rate}} = \text{clock period} = \frac{\text{sec}}{\text{clock cycle}} $$ 舉例 : Computer A : 2 GHz clock, 10s CPU time Design another computer B * aim for 6s CPU time * can do fast, but causes $1.2 \times$ clock cycles How fast must computer B clock be ? ![S__2170883](https://hackmd.io/_uploads/BkCLMTamR.jpg) **程式效能評估** * CPI : clock per instruction * 一個 instruction 要多少的 clock cycles * Instruction count 主要由程式、ISA、編譯器所決定 $$ \begin{aligned} \text{clock cycles} &= \text{instruction count} \times \text{CPI}\\ \text{CPU time} &= \frac{\text{clock cycles}}{\text{clock rate}}\\ &=\frac{\text{instruction count} \times \text{CPI}}{\text{clock rate}} \end{aligned} $$ 舉例 : * Computer A * cycle time : 250 * CPI : 2 * Computer B * cycle time : 500 * CPI : 1.2 * sams ISA (program 產生的東西用相同的 ISA 來執行) Which is faster ? How much ? ![S__2170884](https://hackmd.io/_uploads/HJ15d6a70.jpg)