|
| 1 | +From: Jim Huang <jserv@ccns.ncku.edu.tw> |
| 2 | +Subject: [PATCH] tiny: sched: gate deadline.c behind CONFIG_SCHED_DEADLINE_CLASS |
| 3 | + |
| 4 | +Linux 7.0 deleted the historical CONFIG_SCHED_DEADLINE gate; deadline.c |
| 5 | +is now unconditionally included via build_policy.c. On a NOMMU image |
| 6 | +that never sets SCHED_DEADLINE policy (BusyBox CHRT applet is off, no |
| 7 | +init script issues sched_setattr with policy=6), the file is ~10.5KB of |
| 8 | +dead .text plus its DL bandwidth/server bookkeeping. |
| 9 | + |
| 10 | +Re-introduce a knob without resurrecting the old name. |
| 11 | +CONFIG_SCHED_DEADLINE_CLASS defaults to y so mainline behavior is |
| 12 | +preserved; setting it to n wraps the body of deadline.c in #ifdef and |
| 13 | +provides a minimal stub class plus stubs for every externally-called |
| 14 | +helper. The stub class is registered via DEFINE_SCHED_CLASS(dl) so it |
| 15 | +lands in the __dl_sched_class linker section between stop and rt -- |
| 16 | +core.c::sched_class_above() BUG_ON checks at sched_init pass. Only |
| 17 | +.pick_task is implemented (returns NULL); all other callbacks remain |
| 18 | +NULL because they fire only for tasks already in the class, and |
| 19 | +__checkparam_dl() rejects every attribute set so no task can ever join. |
| 20 | + |
| 21 | +External-API stubs match include/linux/sched/deadline.h and |
| 22 | +kernel/sched/sched.h declarations: |
| 23 | + |
| 24 | + Class chain: |
| 25 | + dl_sched_class -- empty class with pick_task=NULL |
| 26 | + Init paths (called from core.c, fair.c, topology.c): |
| 27 | + init_dl_bw / init_dl_rq / init_dl_entity |
| 28 | + init_sched_dl_class / sched_init_dl_servers |
| 29 | + Sysctl/global validation (called from rt.c sysctl handler): |
| 30 | + sched_dl_global_validate / sched_dl_do_global |
| 31 | + Syscall path (sched_setattr / sched_getattr): |
| 32 | + sched_dl_overflow -- returns -EPERM, blocks DL admission |
| 33 | + __checkparam_dl -- returns false, blocks DL attribute sets |
| 34 | + __setparam_dl / __getparam_dl / dl_param_changed |
| 35 | + CPU hotplug / cpuset: |
| 36 | + dl_cpuset_cpumask_can_shrink -- cpuset shrink validation |
| 37 | + DL server (used by fair.c to back SCHED_OTHER bandwidth): |
| 38 | + dl_server_init / _start / _stop / _update / _update_idle |
| 39 | + __dl_server_attach_root / dl_server_apply_params |
| 40 | + Bandwidth scaling helper: |
| 41 | + dl_scaled_delta_exec -- returns delta_exec unchanged |
| 42 | + Globals visible to topology.c / cgroup code: |
| 43 | + dl_cookie / dl_bw_visited |
| 44 | + Bandwidth-management helpers used by core.c / cpuset: |
| 45 | + dl_bw_deactivate / dl_bw_alloc / dl_bw_free |
| 46 | + |
| 47 | +The DL-server feature backs CFS bandwidth via a deadline entity per |
| 48 | +runqueue. When the class is disabled, any attempt to program a DL |
| 49 | +server fails with -EOPNOTSUPP instead of pretending to succeed; the |
| 50 | +build disables the scheduler cgroup bandwidth knobs accordingly. |
| 51 | + |
| 52 | +Measured on Cortex-M4 nommu mps2-an386 (linux-7.0): SCHED_DEADLINE_CLASS=n |
| 53 | +drops 10,530 bytes / 81 symbols from .text per nm --size-sort. |
| 54 | + |
| 55 | +--- |
| 56 | + init/Kconfig | 13 +++++++++ |
| 57 | + kernel/sched/deadline.c | 60 ++++++++++++++++++++++++++++++++++++ |
| 58 | + 2 files changed, 73 insertions(+) |
| 59 | + |
| 60 | +diff --git a/init/Kconfig b/init/Kconfig |
| 61 | +--- a/init/Kconfig |
| 62 | ++++ b/init/Kconfig |
| 63 | +@@ -933,6 +933,19 @@ config SCHED_PROXY_EXEC |
| 64 | + This option enables proxy execution, a mechanism for mutex-owning |
| 65 | + tasks to inherit the scheduling context of higher priority waiters. |
| 66 | + |
| 67 | ++config SCHED_DEADLINE_CLASS |
| 68 | ++ bool "SCHED_DEADLINE earliest-deadline-first scheduling class" |
| 69 | ++ default y |
| 70 | ++ help |
| 71 | ++ Build kernel/sched/deadline.c, which implements the SCHED_DEADLINE |
| 72 | ++ policy (EDF + Constant Bandwidth Server) and the deadline-server |
| 73 | ++ bandwidth backing for SCHED_OTHER. |
| 74 | ++ |
| 75 | ++ Say N on size-constrained NOMMU images that never set SCHED_DEADLINE |
| 76 | ++ policy and need every byte back. __checkparam_dl rejects all DL |
| 77 | ++ attribute sets; sched_setattr with policy=6 returns -EPERM. Any |
| 78 | ++ later attempt to program a DL server fails with -EOPNOTSUPP. |
| 79 | ++ |
| 80 | + endmenu |
| 81 | + |
| 82 | + # |
| 83 | +diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c |
| 84 | +--- a/kernel/sched/deadline.c |
| 85 | ++++ b/kernel/sched/deadline.c |
| 86 | +@@ -20,6 +20,8 @@ |
| 87 | + #include <uapi/linux/sched/types.h> |
| 88 | + #include "sched.h" |
| 89 | + #include "pelt.h" |
| 90 | ++ |
| 91 | ++#ifdef CONFIG_SCHED_DEADLINE_CLASS |
| 92 | + |
| 93 | + /* |
| 94 | + * Default limits for DL period; on the top end we guard against small util |
| 95 | +@@ -3841,3 +3843,64 @@ void print_dl_stats(struct seq_file *m, int cpu) |
| 96 | + { |
| 97 | + print_dl_rq(m, cpu, &cpu_rq(cpu)->dl); |
| 98 | + } |
| 99 | ++ |
| 100 | ++#else /* !CONFIG_SCHED_DEADLINE_CLASS */ |
| 101 | ++ |
| 102 | ++#include <linux/sched/deadline.h> |
| 103 | ++ |
| 104 | ++/* |
| 105 | ++ * Stub deadline scheduling class. No task ever joins SCHED_DEADLINE |
| 106 | ++ * because __checkparam_dl rejects every attribute set, so all callbacks |
| 107 | ++ * except pick_task are unreachable and remain NULL. pick_task is the |
| 108 | ++ * one method the chain walk in pick_next_task_balance / pick_next_task |
| 109 | ++ * invokes unconditionally per class; returning NULL forwards control to |
| 110 | ++ * the next class (rt -> fair -> idle). |
| 111 | ++ */ |
| 112 | ++ |
| 113 | ++static struct task_struct *pick_task_dl_stub(struct rq *rq, struct rq_flags *rf) |
| 114 | ++{ |
| 115 | ++ return NULL; |
| 116 | ++} |
| 117 | ++ |
| 118 | ++DEFINE_SCHED_CLASS(dl) = { |
| 119 | ++ .pick_task = pick_task_dl_stub, |
| 120 | ++}; |
| 121 | ++ |
| 122 | ++u64 dl_cookie; |
| 123 | ++ |
| 124 | ++bool dl_bw_visited(int cpu, u64 cookie) { return false; } |
| 125 | ++int dl_bw_deactivate(int cpu) { return 0; } |
| 126 | ++int dl_bw_alloc(int cpu, u64 dl_bw) { return 0; } |
| 127 | ++void dl_bw_free(int cpu, u64 dl_bw) { } |
| 128 | ++ |
| 129 | ++void init_dl_bw(struct dl_bw *dl_b) { } |
| 130 | ++void init_dl_rq(struct dl_rq *dl_rq) { } |
| 131 | ++void init_dl_entity(struct sched_dl_entity *dl_se) { } |
| 132 | ++void __init init_sched_dl_class(void) { } |
| 133 | ++void sched_init_dl_servers(void) { } |
| 134 | ++ |
| 135 | ++int sched_dl_global_validate(void) { return 0; } |
| 136 | ++void sched_dl_do_global(void) { } |
| 137 | ++int sched_dl_overflow(struct task_struct *p, int policy, |
| 138 | ++ const struct sched_attr *attr) { return -EPERM; } |
| 139 | ++void __setparam_dl(struct task_struct *p, const struct sched_attr *attr) { } |
| 140 | ++void __getparam_dl(struct task_struct *p, struct sched_attr *attr) { } |
| 141 | ++bool __checkparam_dl(const struct sched_attr *attr) { return false; } |
| 142 | ++bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr) |
| 143 | ++{ return false; } |
| 144 | ++int dl_cpuset_cpumask_can_shrink(const struct cpumask *cur, |
| 145 | ++ const struct cpumask *trial) { return 1; } |
| 146 | ++s64 dl_scaled_delta_exec(struct rq *rq, struct sched_dl_entity *dl_se, |
| 147 | ++ s64 delta_exec) { return delta_exec; } |
| 148 | ++ |
| 149 | ++void dl_server_init(struct sched_dl_entity *dl_se, struct rq *rq, |
| 150 | ++ dl_server_pick_f pick_task) { } |
| 151 | ++void dl_server_start(struct sched_dl_entity *dl_se) { } |
| 152 | ++void dl_server_stop(struct sched_dl_entity *dl_se) { } |
| 153 | ++void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec) { } |
| 154 | ++void dl_server_update_idle(struct sched_dl_entity *dl_se, s64 delta_exec) { } |
| 155 | ++void __dl_server_attach_root(struct sched_dl_entity *dl_se, struct rq *rq) { } |
| 156 | ++int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, |
| 157 | ++ u64 period, bool init) { return -EOPNOTSUPP; } |
| 158 | ++ |
| 159 | ++#endif /* CONFIG_SCHED_DEADLINE_CLASS */ |
0 commit comments