較特別的資料

屬資工基本

  • Chapter 1

如何解決(避免)CPU idle time太長

形成原因及解決策略

1.人為set-up time過長

Sol: "Automatic Job Sequence" → "Resident(駐留) Monitor"

2.I/O Device之operating speed太慢,造成CPU需等待I/O operation完成才往下執行 ∴CPU idle time過久

Sol:

A.用較快速的Device介入CPU與慢速的I/O Device之間 1.Off-Line 2.Buffering 3. Spooling

B.讓CPU always busy → Multiprogramming System

 

Spooling(Simultaneous Peripheral Operation On-Line processing)

Spooling為device介入CPU的方式~DMA便有用到spooling概念的技術

這樣就能分辨出有別於polling

 http://nixchun.pixnet.net/blog/post/7989495

 

DF:

 

在Disk上可依不同I/O Device切成n區的Spooling Area,對於輸入而言,input device可先行將處理資料送到spooling area, 當CPU從此Area取出Data進行運算同時,input device亦同時將下一波欲處理的Data送到spooling area 同理,輸出時亦同 

Spooling vs Buffering(不同處)

spooling允許某工作的CPU computation與其他工作的I/O operations overlay execution

Buffering與允許自身的CPU computation與I/O operation overlay execution 「Buffering限定在user memory space中」(假設條件)

 

系統類型(System Types)

單點

multi-programming

time-share

multi-processor

multi-tasking

 

Multi programming

目的就是讓CPU不要idle,提高CPU utilization~

允許系統(or memory)內存在多個process(處理程序)同時執行,透過CPU scheduling技術,當某個process取得CPU執行時,若因為某些事情發生(eg. wait for I/O complete, resource not available, etc.)而無法往下執行時,則OS可將CPU切換給其他process使用,如此一來,CPU在各個processes切換,則CPU總是Busy

多個process同時執行,mode有兩種 Concurrent(並行) Parallel(平行)

 

Time share

是Multiprogramming的一種,在CPU排班法則方面,其使用RR(Round-Robin)法則, 【即OS規定一個CPU time quantum,若process在取得CPU後,未能於quantum內完成工作,則必須被迫放棄CPU,等待下一次輪迴。】 對每個user皆是公平的

 

Distributed System(分散式系統)

1.Multiprocessor(或Multiprocessing)多顆處理器系統→又稱Tightly-Coupled System(緊密耦合)

2.Distributed System,舊版的Loosely-Coupled Distributed System(鬆散耦合)

=每部機器(或每個processor)有自己的local memory,此外,具下列特點: 通常不受同一clock及OS控制 各processors之間的溝通大都採"Message passing"方式 各機器彼此之間以Network(or 高速bus)相互連接

 

Clustered System

1.Asymmetric clustering

2.Symmetric clustering

 

real time

on-line

 

Computing Environments

1.Traditional computing

2.Web-Based Computing

3.Embedded Computing

 

 

  • Chapter 2

CPU與I/O運作之間的溝通

  1. Busy waiting I/O(polling(詢問) I/O)(programmed I/O) I/O Device(DISK) 很慢
  2. Interrupt I/O 慢
  3. DMA(Direct Memory Access) 現在使用*DMA controller與CPU採Interleaving(交替)使用memory resource,一般稱為"cycle straling"技術cycle straling 

Interrupt討論

1.interrupt的種類:

A.硬體1.External interrupt(HW) CPU以外的周邊元件所發出的 eg. I/O complete、I/O error、machine check

2.Internal interrupt(HW) CPU本身所引發的 eg. stack overflow、illegal command(非法指令執行)、divided by zero(除以0)...

B.軟體

Software interrupt 當user program執行時,若需要OS提供服務,則發出此類中斷通知OS執行對應的service routine eg. system call、trap

 

interrupt發生後,OS的處理程序

Step:

  1. 暫停目前process的執行,並保存當時執行狀況
  2. 根據interrupt ID查詢interrupt vector,取出對應的Interrupt Service Routine(ISR)起始位址
  3. Jump to ISR的initial address,執行該ISR
  4. ISR complete
  5. OS恢復原先中斷前的process執行

I/O結構

Def: 當process發出I/O request以後,控制權如何交回給process?          有兩種mode:

  1. Synchronous I/O I/O運作完成後才交回
  2. Asynchronous I/O 不等I/O完成,即刻交回

不一樣中斷(trap)

Interrupt與Trap之比較

  1. Interrupt:Hardware generated interrupt eg. I/O device發出"I/O complete"中斷
  2. TrapSoftware generated interrupt 用途: 1.user program需要OS提供Service時發出 2. Catch up arithematic error

 

Dual Mode(雙重模式)

需要硬體支援

系統運作的狀態主要分為兩種模式,1.Monitor mode2.user mode

主要是由mode bit區分,通常

0:表monitor mode : 主要是OS的system processes在執行

1:表user mode : user program可以執行的狀態

 

Priveledged Instruction(特權指令) (?應該資工會用)

  1. I/O instruction 
  2. 關於memory management所用之Register修改指令(base、limit register) 
  3. Timer設定指令 
  4. Enable, Disable Interrupt指令
  5.  Halt指令 
  6. change user mode to moniter mode指令

protection

 

I/O

Def: 防止user program對I/O Device不正常之使用

目的

∵I/O Device是重要的資源

不希望user program直接去控制I/O運作,造成資源不當分配,利用度低或危害系統

 

Memory 

1.Monitor Area Protection

   保護monitor所在的區域不被user program更改

2.Job與Job之間的Memory Protection(96清大 3.14)

Def: 防止user program企圖修改其它processes所在的Memory Area

作法: 利用base register及limit register記錄user program的起始位址及大小 對所有memory address存取執行下列檢查:

~圖 http://www.csie.ntnu.edu.tw/~swanky/os/chap2/Hardware_Address_Protection.png

 

CPU

  1. 目的: 防止user process無限期佔用CPU而不釋放 
  2. 作法: OS會規定一個使用CPU的最大時間值(Max time constraint),利用timer記錄此max值,隨著process的執行,timer的值會隨著時間遞減,直到timer值變成零為止,此時timer會發出time out中斷通知OS,則OS可以強制此process放棄CPU 此外,Timer設定之指令需設為特權指令

Timer用途

CPU Protection Time-sharing system製作(RR scheduling) DMA controller設定中counter(傳輸量)使用 計時器、系統時間(clock)

 

  • Chapter 3

OS User Interface

主要由Command Interpreter(命令解譯器)及System Call所組成

CLI (Command Line Interface) 

如果有圖~GUI (Graphics User Interface)

 

Command Interpreter(命令解譯器)

作為user與OS之間的溝通介面。

主要工作: 接收user commands 判斷command正確與否

=>若正確,則呼叫對應的Service routine(command routine)完成工作 結果回傳給(display to)user

 

設計上會遇到兩個issue(術語http://en.wikipedia.org/wiki/Issue_(computers)#Issue)

  1. Issue1:Command Interpreter是否要包含command service routines?有包含服務理所當然的 "慢" 
  2. Issue2:Command Interpreter與OS kernel module的關連程度?eg. UNIX的Shell與kernel是獨立的~ 優點:shell可以任意改變而不影響kernel

System Call(系統呼叫)

作為user program執行時與OS之間的溝通介面~

當user program需要OS提供服務時,藉由呼叫system call(伴隨trap to monitor mode)通知OS,OS可依據system call ID查表,啟動service routine執行,得到結果,再傳回給user program,完成服務請求

 

System Call種類:(P3-8~3-9)

  1. Process Control 
  2. File Management 
  3. Device Management 
  4. Information 
  5. Maintenance
  6. Communication

(有些為了教學會把OS的功能做似大總結memory process device information 不過還是主要依賴system call的功能 ~雖然以上是基礎~不過作引文)

 

system call的參數傳遞

法一:利用registers儲存參數

法二:將參數存在memory中的某個表格或Block,同時將此表格的起始位址存在一個register中,將此register傳給OS

(一跟二可以猜出好處壞處~SPEED)

法三:利用system stack保存參數

 

Virtual Machine


軟體模擬即:

  1. 利用CPU scheduling技術創造出有多顆CPU的假象
  2. 利用virtual memory技術創造出更多的記憶體空間
  3. 透過spooling技巧,提供多套I/O Device之功能

 


 

小結:

  1. Multiprogramming與MultiprocessesMultiprogramming不一定是MultiprocessesMultiprocesses一定是Multiprogramming
  2. Multiprogramming與Time sharingMultiprogramming不一定是Time sharingTime sharing一定是Multiprogramming
  3. Multiprogramming與Multiusers Multiprogramming不一定是Multiusers Multiusers一定是Multiprogramming 
  4. Real time與On-Line system Real time一定是On-Line system On-Line system不一定是Real time

 

Operating System Study Guide 

http://www.csie.ntnu.edu.tw/~swanky/os/index.htm

arrow
arrow
    全站熱搜

    方 發表在 痞客邦 留言(0) 人氣()