kernel_explainer/
scheduler.rs1pub fn scheduler_description(policy: &str) -> String {
3 match policy {
4 "normal" | "other" | "SCHED_OTHER" => {
6 "Normal time-sharing scheduler (CFS) — balanced for general workloads".to_string()
7 }
8 "batch" | "SCHED_BATCH" => {
10 "Batch scheduler — optimized for non-interactive, CPU-intensive jobs".to_string()
11 }
12 "idle" | "SCHED_IDLE" => {
14 "Idle scheduler — only runs when the CPU would otherwise be idle".to_string()
15 }
16 "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}