OS 筆記
operating systems three easy pieces筆記
IO運作模式和Hw resources protection
Introduce
- IO 運作方式
- polling
- interrupted
- DMA
- Interrupt 機制處理程序與種種類
- Hardware resources protection
- 基礎建設
- Dual Mode 運作
- Privileged instruction 特權指令
- protection
- IO protection
- Memory protection
- Cpu protection
- 基礎建設
IO 運作模式
Pooling IO (訊問是IO)
- Def: 又稱 Busy-waiting IO or Programmed IO
- Step
- 執行中的process對Os發出IO request (e.g. Disk read)
- 執行中的process會被Block, wait uintil IO complete(不一定)
- OS取得CPU執行相關的System calls,已完成IO services
- CPU設定IO command給 device controller
- device controller 控制 IO device 進行real IO operation
- CPU 可以切給其他process使用
- 然而CPU在執行其他process過程中耗費大量CPU time用於polling IO device controller 資訊,已確認剛交付的IO運作完成與否
- 並為全部用在process execution 上因此CPU utilzation低且process throughput 不高
Interrupted IO (中斷式IO)
- Step 如1~5如同polling IO
- CPU 切給另一個Process執行且IO Device也正在執行IO運作
- 當IO運作完成,IO Device controller 會發出 IO complete Interrupt 通知OS
- OS 收到interrupt 後會先暫停目前process執行並保存期狀態
- OS 會查詢interrupt vector判定何種中斷發生,並找出對應的Interrupt Service Routine(ISR 或 interrupt handler ) 位址
- Jump to ISR
- 等待ISR完成後return contril to kernel, kernel notify wait process 其IO 完成
- OS恢復中斷之前得prcess執行,或交由CPU scheduler決定下一個執行的process
- 優點
- CPU 無需耗費大量的time在polling IO Device controller上,而是更專注用在process execution 上
- CPU utilzation較高,產能throughput提升,imporve the system performance
- 缺點
- Interrupt 處理也需耗費cpu time,,所以IO運作時間不長時polling IO也許更有利
- 如果interrupt發生頻率極大的頻繁,則CPU utilzation 會很低,因此performance很差
- CPU time人須用於Data 在IO Device 與 Memory上的傳輸,過程監督
- CPU time 此時位在process execution上
DMA (Direct Memory Access)
-
Def: DMA controller 負責IO Device 與memory 之間的資料傳輸,過程不用CPU 參與監督
-
優點
- CPU 有更多時間在process execution上, cpu utilzation相對更高,此外適用於高速Block-Transfer oriented之IO Device
- 中斷發生頻率相對較低
- 缺點
- DMA controller 設計會讓硬體設計更複雜,需要增加額外Bus
- DMA 必須用到memory 和 bus而這會和cpu 產生衝突,資源的爭奪
- DMA controller 一班採用interleaving(交錯)or cycle stealing 技術,與CPU輪番使用memory