Skip to main content

kernel_explainer/
scheduler.rs

1// Scheduler policy → plain English (SCHED_OTHER, SCHED_FIFO, ...).
2pub fn scheduler_description(policy: &str) -> String {
3    match policy {
4        // Generic/normal time-sharing (CFS)
5        "normal" | "other" | "SCHED_OTHER" => {
6            "Normal time-sharing scheduler (CFS) — balanced for general workloads".to_string()
7        }
8        // Background/batch work
9        "batch" | "SCHED_BATCH" => {
10            "Batch scheduler — optimized for non-interactive, CPU-intensive jobs".to_string()
11        }
12        // Very low priority
13        "idle" | "SCHED_IDLE" => {
14            "Idle scheduler — only runs when the CPU would otherwise be idle".to_string()
15        }
16        // Realtime policies
17        "fifo" | "SCHED_FIFO" => {
18            "Realtime FIFO — fixed-priority, first-in/first-out scheduling".to_string()
19        }
20        "rr" | "SCHED_RR" => {
21            "Realtime round-robin — fixed-priority, time-sliced scheduling".to_string()
22        }
23        "deadline" | "SCHED_DEADLINE" => {
24            "Realtime deadline — tasks scheduled to meet explicit deadlines".to_string()
25        }
26        other => format!("Scheduler policy: {}", other),
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::scheduler_description;
33
34    #[test]
35    fn describes_known_policies() {
36        let s = scheduler_description("SCHED_OTHER");
37        assert!(s.contains("Normal time-sharing"));
38
39        let s = scheduler_description("SCHED_BATCH");
40        assert!(s.contains("Batch scheduler"));
41
42        let s = scheduler_description("SCHED_FIFO");
43        assert!(s.contains("Realtime FIFO"));
44    }
45
46    #[test]
47    fn falls_back_for_unknown() {
48        let s = scheduler_description("weird_policy");
49        assert!(s.contains("weird_policy"));
50    }
51}