sched: reintroduce the sched_min_granularity tunable

we lost the sched_min_granularity tunable to a clever optimization
that uses the sched_latency/min_granularity ratio - but the ratio
is quite unintuitive to users and can also crash the kernel if the
ratio is set to 0. So reintroduce the min_granularity tunable,
while keeping the ratio maintained internally.

no functionality changed.

[ mingo@elte.hu: some fixlets. ]

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by Peter Zijlstra and committed by Ingo Molnar b2be5e96 2cb8600e

+41 -13
+5 -1
include/linux/sched.h
··· 1460 1460 1461 1461 #ifdef CONFIG_SCHED_DEBUG 1462 1462 extern unsigned int sysctl_sched_latency; 1463 - extern unsigned int sysctl_sched_nr_latency; 1463 + extern unsigned int sysctl_sched_min_granularity; 1464 1464 extern unsigned int sysctl_sched_wakeup_granularity; 1465 1465 extern unsigned int sysctl_sched_batch_wakeup_granularity; 1466 1466 extern unsigned int sysctl_sched_child_runs_first; 1467 1467 extern unsigned int sysctl_sched_features; 1468 1468 extern unsigned int sysctl_sched_migration_cost; 1469 + 1470 + int sched_nr_latency_handler(struct ctl_table *table, int write, 1471 + struct file *file, void __user *buffer, size_t *length, 1472 + loff_t *ppos); 1469 1473 #endif 1470 1474 1471 1475 extern unsigned int sysctl_sched_compat_yield;
+1 -1
kernel/sched_debug.c
··· 211 211 #define PN(x) \ 212 212 SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x)) 213 213 PN(sysctl_sched_latency); 214 - PN(sysctl_sched_nr_latency); 214 + PN(sysctl_sched_min_granularity); 215 215 PN(sysctl_sched_wakeup_granularity); 216 216 PN(sysctl_sched_batch_wakeup_granularity); 217 217 PN(sysctl_sched_child_runs_first);
+28 -7
kernel/sched_fair.c
··· 35 35 const_debug unsigned int sysctl_sched_latency = 20000000ULL; 36 36 37 37 /* 38 + * Minimal preemption granularity for CPU-bound tasks: 39 + * (default: 1 msec, units: nanoseconds) 40 + */ 41 + const_debug unsigned int sysctl_sched_min_granularity = 1000000ULL; 42 + 43 + /* 44 + * is kept at sysctl_sched_latency / sysctl_sched_min_granularity 45 + */ 46 + const_debug unsigned int sched_nr_latency = 20; 47 + 48 + /* 38 49 * After fork, child runs first. (default) If set to 0 then 39 50 * parent will (try to) run first. 40 51 */ 41 52 const_debug unsigned int sysctl_sched_child_runs_first = 1; 42 - 43 - /* 44 - * Minimal preemption granularity for CPU-bound tasks: 45 - * (default: 2 msec, units: nanoseconds) 46 - */ 47 - const_debug unsigned int sysctl_sched_nr_latency = 20; 48 53 49 54 /* 50 55 * sys_sched_yield() compat mode ··· 217 212 * Scheduling class statistics methods: 218 213 */ 219 214 215 + #ifdef CONFIG_SCHED_DEBUG 216 + int sched_nr_latency_handler(struct ctl_table *table, int write, 217 + struct file *filp, void __user *buffer, size_t *lenp, 218 + loff_t *ppos) 219 + { 220 + int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos); 221 + 222 + if (ret || !write) 223 + return ret; 224 + 225 + sched_nr_latency = DIV_ROUND_UP(sysctl_sched_latency, 226 + sysctl_sched_min_granularity); 227 + 228 + return 0; 229 + } 230 + #endif 220 231 221 232 /* 222 233 * The idea is to set a period in which each task runs once. ··· 245 224 static u64 __sched_period(unsigned long nr_running) 246 225 { 247 226 u64 period = sysctl_sched_latency; 248 - unsigned long nr_latency = sysctl_sched_nr_latency; 227 + unsigned long nr_latency = sched_nr_latency; 249 228 250 229 if (unlikely(nr_running > nr_latency)) { 251 230 period *= nr_running;
+7 -4
kernel/sysctl.c
··· 235 235 #ifdef CONFIG_SCHED_DEBUG 236 236 { 237 237 .ctl_name = CTL_UNNUMBERED, 238 - .procname = "sched_nr_latency", 239 - .data = &sysctl_sched_nr_latency, 238 + .procname = "sched_min_granularity_ns", 239 + .data = &sysctl_sched_min_granularity, 240 240 .maxlen = sizeof(unsigned int), 241 241 .mode = 0644, 242 - .proc_handler = &proc_dointvec, 242 + .proc_handler = &sched_nr_latency_handler, 243 + .strategy = &sysctl_intvec, 244 + .extra1 = &min_sched_granularity_ns, 245 + .extra2 = &max_sched_granularity_ns, 243 246 }, 244 247 { 245 248 .ctl_name = CTL_UNNUMBERED, ··· 250 247 .data = &sysctl_sched_latency, 251 248 .maxlen = sizeof(unsigned int), 252 249 .mode = 0644, 253 - .proc_handler = &proc_dointvec_minmax, 250 + .proc_handler = &sched_nr_latency_handler, 254 251 .strategy = &sysctl_intvec, 255 252 .extra1 = &min_sched_granularity_ns, 256 253 .extra2 = &max_sched_granularity_ns,