--- tags: 作業系統 --- # 作業系統 ch5 scheduling select next precess -> dispatcher module -> context switch (kernal mode) dispatcher latency: time between stop one process and start another running (including context switch) time quantum:a small unit of CPU time --- - FCFS: convey effect - SJF (Shortest-Job-First): nonpreemptive, type of priority(time) - SRTF (Shortest-remaining-time-first): SJF && preemptive - RR (Round Robin):preemptive, better response (time quantum > context switch time) - Priority --- ### determine next CPU burst time: next_predict_t = x(actual_t) + (1-x)(prior_predict_t) --- ### Process type - batch(批次): 大量 && 不急 -> background (RR) - interactive:互動 && 即時 -> foreground (FCFS) --- ## Single CPU ### Multi-Level - Multi-Level queue: process cann't move between queues - Multi-level feedback queue: process can move between queues(method to determine process enter which queue) ### schedule between queue - Fixed-priority (foreground -> background) - Time slice (80% foreground) ### Thread scheduling - support thread schedule, not process - user-mode - run on LWP(light-weight-process) - process contention scope (PCS): threads 在同一個 process 爭取 LWP - kernal-mode - system-contention-scope(SCS): 爭取 CPU --- ## Multiple-Processor ( Multi-core ) - processor affinity: process perfer the same CPU to avoid transfer data time - load balancing (push - if overload、pull - idle) ### hardware type - homogeneous: each CPU is the same - heterogeneous: (<->homogeneous) ### software type - asymmetric: only one CPU can execute kernal process - symmetric(SMP): each CPU can run user and kernal process --- ## Real-Time CPU Scheduling [ note ] - Interrupt latency: time between interrupt arrivial and run ISR(interpute service routine) ![](https://i.imgur.com/15Qpc09.jpg) - conflict: (inside dispatch latency) 準備 ISR 所需要的資源 ![](https://i.imgur.com/VYqQEft.png) - preemptive && priority-based * interrupt latency -> dispatcher latency type - software real-time system: priority high, not sure complete before deadline - hardware real-time system: make sure complete before deadline process change way (p: periodic, d: deadline, t: processing time) - rate montonic scheduling (period time) - earlist deadline first scheduling (deadline) --- ## Pthread - PTHREAD_SCOPE_PROCESS: PCS scheduling(user mode) - PTHREAD_SCOPE_SYSTEM: SCS scheduling(kernal mode) - 受 OS 所限制