計算機結構 2

作者:   發佈於:  

要決定一個程式之執行時間,有下列因素;

其關係式為:

Clock Rate IPS = ------------ CPI

IC IC * Clock Rate ExecTime = ----- = ----------------- IPS CPI

任何部份因素都無法斷定系統的效能好壞,因此:

To retain the value of an individual instruction for its other four stages, the value read from instruction memory must be saved in a register. Similar arguments apply to every pipeline stage, so we must place registers between any two stages on the pipline datapath. Such register is called "Pipeline Register".

對一個指令而言,為了要在其他四個階段也都能夠讀取到指令本身的內容,於第 一個階段讀取 Instruction Memory 所得之值必定要存於某個暫存器之中。而每 一個 stage 也都有此需求。是故,在 pipeline datapath 上之 stage 分界處 必定要擺放若干長度的暫存器,即稱為「Pipeline Register」。

Pipeline Hazard 有三種:

由於部份功能單元沒有管線化,或是所需之資源沒有複製足夠多份,使oCPU 無 法支援某些次序指令的執行。

發生在會修改 Program Counter 的指令(Jump/Branch/else) 是最影響效能的 Hazard。解決方法有四種:

  1. flush the pipeline 2. branch predict taken 2. branch predict not taken 4. dealyed branch.

  2. Data Hazard

"不符合組語語意"

在連續數個指令都存取同一個暫存器時可能會發生的 Race Condition。會造成 執行時 read/write 指令的順序與在組語之中的順序不同。Data Hazard 又分為 RAW, WAW, WAR 三種,其中以 RAW 最為常見,又,在 Pipeline stage 長度恆 定的情況之下,很少會發 WAW 與 WAR data hazard。唯一的解決方式是 Forwarding,可是即是 Forwarding 也無法完全不 stall pipeline 就解決問題。

現假設有兩個指令 i 與 j ,且 i 在 j 之前執行。假設 Pipeline 為 MIPS : IF, ID, ALU, MEM ,WB。

"j 的讀取在 i 的寫入之前完成。"

假設 i 與 j 之指令如下:

i: ADD R1, R2, R3 j: SUB R4, R1, R5

i 將新的值寫入 R1 , 所以 j 應當要讀取到 i 剛剛所寫入的新值才行。 但若將 Pipeline 排起來看:

1 2 3 4 5 6 i IF ID ALU MEM WB j IF ID ALU MEM WB

會發現 i 之寫入是在時間點 5 的地方, j 之讀取是在時間點 3 的地方。因 此 ``j 的讀取會比 i 的寫入先被執行到''。如此一來,j 所讀到的 R1 其實不 是 i 所寫入的值。

"j 的寫入 在 i 的讀取 之前完成"

考慮修改過的 MIPS Pipeline:

i:SW R1, 0(R2) IF ID EX MEM1 MEM2 WB j:ADD R2, R3, R4 IF ID EX WB

MEM2 與 WB 是在同一個時刻進行的。如果 WB 之動作在前半進行,而 MEM2 在 後半進行,那麼 R2 便會先被寫入新的值,SW 所參考到的記憶體位址便會是錯 誤的位址。

" j 的寫入 在 i 的寫入 之前完成"

1 2 3 4 5 6 i:LW R1, 0(R2) IF ID EX MEM1 MEM2 WB j:ADD R1, R2, R3 IF ID EX WB

j 的 WB 在時刻 5 ,而 i 的 WB 在時刻 6,所以最後 R1 的值會是 i 指令所 寫入的。

A routine is not loaded until it is called. All routines are kept on disk in a rellocatable format. The advantage of dynamic loading is that an unused route is never loaded. It doesn't requite special support from the operation system.

所有的常式在用到之前都不會被載入。在磁碟上,常式是以一種 rellopcatable 的格式儲存著。OS 並不需要替 Dynamic loding 提供特殊的支援C

All process use the same language library executed only once copy of the library code. Such feature can be extended to library updates, libraries could be updated to a newer version without relinking with user programs. It needs some help from OS because the library code has only one copy in some process' address space which is proctected from accessing by other processes and OS is the only entity that can check and grant the access.

D) 作為依據,如此即可完全決定兩兩程序之間的次序。(這個次序 即是進入 Mutex Section 的依據)