KonkurStudy
همه کارت‌ها

CPU Scheduling: Metrics & Algorithms

Short-term scheduling picks the next ready process for the CPU; you must know each algorithm's preemption behavior plus the standard time metrics (turnaround, waiting, response).

کارت مفهوم کنکور ارشد مهندسی کامپیوتر

اهمیت
۰/۵

What CPU scheduling decides

When several processes are ready but only some cores are free, the OS short-term scheduler chooses which ready process runs next. A program is a stream of CPU bursts separated by I/O bursts; the scheduler only ever schedules the CPU bursts. A scheduler is non-preemptive if a process keeps the CPU until it finishes or voluntarily blocks (I/O or exit), and preemptive if the OS can forcibly take the CPU away (on a timer interrupt or the arrival of a higher-priority job).

The four time metrics

For a process with arrival time aia_i, first time it gets the CPU sis_i, completion time cic_i, and total CPU burst bib_i:

Metric Definition Formula
Turnaround time total time in the system Ti=ci−aiT_i = c_i - a_i
Waiting time time spent ready but not running Wi=Ti−biW_i = T_i - b_i
Response time until first CPU service Ri=si−aiR_i = s_i - a_i
Throughput jobs finished per unit time # completedelapsed time\dfrac{\#\text{ completed}}{\text{elapsed time}}

Averages are taken over all processes, e.g. W‾=1n∑iWi\overline{W} = \tfrac{1}{n}\sum_i W_i. Throughput and CPU utilization are system-wide; the rest are per-process.

The classic algorithms

Algorithm Preemptive? Picks Note
FCFS / FIFO no earliest arrival simple; suffers the convoy effect
SJF no shortest next burst optimal W‾\overline{W}; needs burst length
SRTF yes shortest remaining time preemptive SJF
Priority either highest priority risk of starvation (fix: aging)
Round Robin yes next in queue, quantum qq fair; good response time
Rate Monotonic yes shortest period (real-time, fixed priority) preempts lower-rate tasks

SJF minimizes average waiting time among non-preemptive schedulers, but it requires knowing burst lengths in advance, so it is mostly a theoretical bound. Round Robin trades a little throughput for bounded response time: small qq improves responsiveness but adds context-switch overhead.

Mini-example (non-preemptive FCFS)

Three jobs arrive at t=0t=0 in order P1,P2,P3P_1,P_2,P_3 with bursts 24,3,324, 3, 3.

FCFS runs P1[0-24], P2[24-27], P3[27-30]P_1[0\text{-}24],\ P_2[24\text{-}27],\ P_3[27\text{-}30], so waiting times are 0,24,270, 24, 27 and W‾=0+24+273=17\overline{W} = \tfrac{0+24+27}{3} = 17. Reordering shortest-first (SJF) as P2,P3,P1P_2,P_3,P_1 gives waits 0,3,60,3,6 and W‾=3\overline{W}=3 — the convoy effect that a long job at the front inflates everyone's wait.

Multicore throughput

With kk identical cores and total CPU work ∑ibi\sum_i b_i, the makespan (time to finish a batch) is bounded below by ∑ibi/k\sum_i b_i / k. This bound is achievable when each process's I/O wait can be perfectly overlapped by another process's CPU burst, keeping every core 100%100\% busy — then I/O time hides completely behind computation.

Exam trick: Watch the preemption word. "Strict-priority and non-preemptive" points to FCFS — Rate Monotonic is strict fixed-priority but preemptive, and SJF has a preemptive variant (SRTF), so both fail. For a multicore batch with a matched CPU/I/O ratio, the answer is just (total CPU work) / (number of cores), not the naive sum of all burst-plus-wait times.

فرمول‌های کلیدی

Turnaround & waiting time
Ti=ci−ai,Wi=Ti−biT_i = c_i - a_i, \qquad W_i = T_i - b_i

Turnaround is completion minus arrival; waiting subtracts the actual CPU burst from turnaround.

Average waiting time
W‾=1n∑i=1nWi\overline{W} = \frac{1}{n}\sum_{i=1}^{n} W_i

Mean over all n processes; minimized by SJF among non-preemptive schedulers.

Multicore makespan lower bound
M≥1k∑i=1nbiM \ge \frac{1}{k}\sum_{i=1}^{n} b_i

With k identical cores, the batch finish time is at least total CPU work over k; tight when I/O waits overlap others' CPU bursts.

#cpu-scheduling#fcfs#fifo#round-robin#priority-scheduling#non-preemptive#rate-monotonic#turnaround-time#waiting-time#response-time#throughput#makespan#multicore

سوالات تمرینی