1 / 46

OS 期中考複習

OS 期中考複習. 資工碩一 林昱宏 kenobi@networklab.csie.ncu.edu.tw. CH 1. Main purposes of operating system Multiprogramming Time-Sharing Systems Parallel Systems Symmetric multiprocessing (SMP) Asymmetric multiprocessing (ASMP) Real-Time Systems Distributed Systems.

edythe
Download Presentation

OS 期中考複習

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OS 期中考複習 資工碩一 林昱宏 kenobi@networklab.csie.ncu.edu.tw

  2. CH 1 • Main purposes of operating system • Multiprogramming • Time-Sharing Systems • Parallel Systems • Symmetric multiprocessing (SMP) • Asymmetric multiprocessing (ASMP) • Real-Time Systems • Distributed Systems

  3. Main purposes of operating system • 作為 user 與 hardware 之間的溝通介面,讓 user 易於使用電腦。 • 提供讓 user program 易於執行之環境 • 管理並分配資源,讓資源公平且有效地被利用。 • 監督 process 的執行,防止不當之執行對系統造成重大之危害。

  4. Multiprogramming • Def:單一 CPU 的系統中允許多個 process 同時執行 • 目的:提昇 CPU utilization,避免 CPU idle • 作法:透過 CPU scheduling,當某 process 執行期間,若因故被迫暫停(如:wait for I/O complete),則OS 可將 CPU 切換給其他 process 使用。 • Multiprogrammingv.s. Multiprocessor

  5. Time-Sharing Systems • Def:屬於 Multiprogramming 的一種,透過 RR(Round-Robin) 的 CPU scheduling 策略,使每個 user 以為各自有一套專屬的系統。 • 各 user 以 interactive 的方式與系統溝通 • 強調 user 之間的公平性及較短的 response time • 各 user 可共享 memory space、I/O device

  6. Parallel Systems • 又稱 Multiprocessor systems 或 tightly coupled systems • 同一部機器中具有多顆CPU,並具下列特徵: • 彼此共享 memory、bus、I/O device • 通常受同一個 OS 及 clock 控制 • 各 processor 之間的溝通採 share memory 方式 • 支援 parallel computing,即同一時間可有多個 process或 thread 在不同的 processor 上執行,以增進 throughput • 可再分成兩類 • Symmetric multiprocessing (SMP) • Asymmetric multiprocessing (ASMP)

  7. Real-time System • Def:對於工作完成的時間有極嚴格的限制,若未能於規定的時間內完成,系統即屬失敗。如:工廠自動化生產、軍事防衛 • Hard real-time system:採用 RAM 或 ROM,不使用secondary storage,不使用 virtual memory,保證工作能在時間內完成。 • Soft real-time system:讓即時的 process 有高優先權,支援 priority scheduling,不能有aging 機制,UNIX 有支援。

  8. Distributed System • Def:每部機器有自己的 CPU,每個 CPU 有自己的 memory space、I/O device • 各個 CPU 不一定受到相同的 clock rate 或 OS 控制 • 各 CPU (或機器) 之間彼此以網路或高速 bus 連接

  9. CH2 • Interrupt • I/O Interrupts • Direct Memory Access (DMA) • Storage-device Hierarchy • Hardware Resource Protection • Dual-Mode Operation • I/O Protection • Memory Protection • CPU Protection

  10. Interrupt • Interrupt 發生後,OS 的處理程序: • 暫停目前 process 執行,並保存其當時執行的狀態 • 根據 interrupt ID 查詢 interrupt vector,取出對應的 Interrupt Service Routine (ISR) 之起始位址。 • 執行 ISR • 恢復原先被中斷的 process

  11. I/O Interrupts • User process 發出 I/O request 後,控制權何時交回給user process,有兩種模式: • Synchronous I/O:等待 I/O 完成後才交回控制權 • Asynchronous I/O:啟動 I/O 後即刻交回控制權

  12. DMA ( Direct Memory Access ) • Def:由 DMA controller 負責 I/O device 與 Memory間的資料傳輸,傳送過程不需 CPU 的參與監督,可提高 CPU utilization。主要用於大量資料傳輸,如 Disk block data 的傳送。 • 每個 block 產生一次 interrupt,而非每 byte。

  13. Storage-device Hierarchy 速度快 容量小 大 慢

  14. Dual-Mode Operation • 系統必須提供2種運作模式:user mode、monitor mode • User mode:user program 運作之狀態,不允許執行privileged instruction,否則會引起 Trap,OS 會強迫process 終止。 • Monitor mode:OS 的 system process 運作之狀態,user program 不允許在此 mode 執行,可執行 privileged instruction。 • 利用 mode bit 來區分 user mode 或 monitor mode,並將所有僅能在 monitor mode 執行的指令設為privileged instruction。

  15. I/O Protection • 目的 • 防止 user program 直接使用 I/O device service user program 必須對 OS 提出 I/O request,再由 OS 控制 I/O 運作,並將 I/O result 告知 user program。 • 方法 • 將所有 I/O 指令設為特權指令,user 必須透過 OS 來執行 I/O 指令。

  16. Memory Protection • 目的 • 防止 user program 去更改 OS 所在區域的 memory 內容,例如:interrupt vector、ISR • 方法 • 利用 base 及 limit Register 來紀錄各 process 的起始位置及大小。透過存取位址與 B、B+L 之比較,確保 memory 之 protection。 • 修改 B 及 L Register 的指令要設為 privileged instruction。

  17. CPU Protection • 目的 • 防止 user program 無限期霸佔 CPU 的狀況發生。 • 方法 • OS 要規定一個使用 CPUtime 的最大值 (time slice),並利用 timer 記錄,counter隨時間遞減,當counter為 0 即發出 time-out 中斷通知 OS,OS 會強迫此 process 釋放CPU。 • 設定/修改 timer 運作的指令需設為特權指令。

  18. CH3 • System Components • System Calls • Virtual Machine

  19. System Components • Process Management • Main-Memory Management • File Management • I/O-System Management • Secondary-Storage Management • Networking • Protection System • Command-Interpreter System

  20. System Calls (1/3) • Def:作為 user program 執行時與 OS 溝通之介面。當 user program 執行時需要 OS 提供服務,會發出 system call 通知 OS,OS 會執行對應的 service routine 以完成服務請求。

  21. System Calls (2/3) • System call 的參數如何傳遞給 OS • 用 register 保存這些參數,速度快,但不適用於參數個數太多之情況。 • 將參數保存在 memory 中的 block (或 table) 中,同時用一個 register 紀錄此 table 的起始位址。 • 利用 system stack,保存參數時將其 push 到 stack,system call 執行時再 pop 取得參數。

  22. System Calls (3/3) • System call 種類 • Process control • File manipulation • Device manipulation • Information maintenance • Communication

  23. Virtual Machine • Def:透過 軟體模擬的技術,copy 出一份與底層 hardware 一模一樣的功能介面。 • 優點: • 對於 OS 的測試與開發是一個很好的負載平台 • 同一部機器上可以執行多套不同的 OS • 具有安全性 • 缺點:實作困難 • JVM

  24. Mechanism v.s. Policy • Mechanisms determine how to do something • 怎麼做? • Policies decide what will be done. • 做什麼?

  25. CH4 • Diagram of Process State • Process Control Block (PCB) • Schedulers • Long-term scheduler • Short-term scheduler • Context Switch

  26. Diagram of Process State

  27. Process Control Block (PCB) • 目的:OS 為執行 process management,所以將 process 相關的資訊建立一個集合表示,即為 PCB

  28. Schedulers • Long-term scheduler (job scheduler) • 執行頻率不高 • 可控制 multiprogramming degree • 調和 I/O bound 與 CPU bound job 之比例 • Short-term scheduler (CPU scheduler) • 從記憶體中那些欲執行的process 中,根據它們的優先權,挑出一個process來執行 • 執行頻率很高 • Medium-term Scheduler • 有時候從記憶體中撤除的process 又可重新送入到記憶體之中,並能在被撤除之處恢復繼續執行,這種架構稱為調換(Swapping),process 由中期排程程式來將其調換出來,隨後在調換進去

  29. Context Switch • 定義:當 CPU 從執行中的 process 切換給另一個 process 執行之前,OS 要先保存舊有 process 的執行狀態(如:program counter、CPU register…等PCB中的內容),並且載入新 process 的執行狀態,此一過程稱為context switch。

  30. Communication • Direct Communication • send (P, message) • receive(Q, message) • Indirect Communication • mailbox

  31. CH5 • Thread • Thread Benefits • Thread V.S Process • User and Kernel Threads • Multithreading Models • Many-to-One • One-to-One • Many-to-Many

  32. Thread • 又稱 Light weight process (LWP) • 同一 process 中的 thread 彼此共享 • Code section • Data section • OS resource

  33. Thread Benefit • Responsiveness • Resource Sharing • Economy • Utilization of Multiprocessor Architectures

  34. Thread V.S Process

  35. User and Kernel Threads • User threads • Def:implemented by a thread library at user level. • 優點:fast to create and manage • 缺點:if the kernel is single threaded, then….. • Kernel threads • Def:Supported directly by OS • 缺點:slower to create and manage • 優點:if a thread performs a blocking system call, the kernel can schedule another thread in the application for execution.

  36. Many-to-One Model 若某個thread執行暫停系統的呼叫, 整個行程就會被暫停 One-to-One Model 可能造程應用程式額外的負擔 ,數量大多受限制 Many-to-Many Model Multithreading Models

  37. CH6 • Scheduling Criteria • Scheduling Algorithms

  38. Scheduling Criteria • CPU utilization:CPU 的使用率 • Throughput:單位時間內完成的工作數 • Turnaround time:從 process 進入系統到完成工作 • Waiting time:process 在 ready Queue 中等待的時間 • Response time:從 user request 交付進入系統,到系統產生第一個回應的時間

  39. Scheduling Algorithms • First-Come, First-Served (FCFS) Scheduling • Shortest-Job-First (SJR) Scheduling • Non-Preemptive • Preemptive • Priority Scheduling • Round Robin (RR) • Multilevel Queue • Multilevel Feedback Queue

  40. Scheduling AlgorithmsFirst-Come, First-Served (FCFS) Scheduling • Def:arrival time 愈早的 process,愈優先取得 CPU 的控制權。 • 排班效益最差,即Avg. waiting time 或 turnaround time 最長 • Convoy effect(護衛效應) • 較短工作的行程一直等待在較長工作的行程之後。 • 簡單易製作、fair、no starvation、non-preemptive • 計算題

  41. Scheduling AlgorithmsShortest-Job-First Scheduling • Def:process 之CPU burst time 愈小,愈優先取得CPU的控制權。 • 排班效益最佳Avg. waiting time 或 turnaround time 最短 • Unfair、starvation、non-preemptive • 計算題

  42. Scheduling AlgorithmsPriority Scheduling • Def:具有較高優先權的 process 愈先取得 CPU。 • 排班效益最佳。 • Unfair、Starvation • 計算題

  43. Scheduling AlgorithmsRound-Robin Scheduling • Def:通常用在 Time-sharing system,OS 會規定一個CPU time quantum,若 process 取得 CPU 後未能在此quantum 內完成工作,則需放棄 CPU 等待下一輪。 • Fair、No starvation、Preemptive • Time quantum too large -> FCFS • 計算題

  44. Scheduling AlgorithmsMultilevel Queue Scheduling • Def:進一步將單一 ready Queue 分成許多不同優先權等級的 ready Queue。 • 各個 Queue 可有自己的 scheduling algo. • Process不能在各 Queue 之間移動 • Unfair、Starvation、Preemptive

  45. Scheduling AlgorithmsMultilevel Feedback-Queue Scheduling • Def:允許 process 在不同的 Queue 之間移動。 • 作法:類似aging,每隔固定時間,將所有 process 上移到上一層的 Queue 中。 • Unfair、No Starvation、Preemptive

  46. 各排班法則比較

More Related