Commit 1983a922a1bc843806b9a36cf3a370b242783140

Authored by Christian Ehrhardt
Committed by Ingo Molnar
1 parent 0bcdcf28c9

sched: Make tunable scaling style configurable

As scaling now takes place on all kind of cpu add/remove events a user
that configures values via proc should be able to configure if his set
values are still rescaled or kept whatever happens.

As the comments state that log2 was just a second guess that worked the
interface is not just designed for on/off, but to choose a scaling type.
Currently this allows none, log and linear, but more important it allwos
us to keep the interface even if someone has an even better idea how to
scale the values.

Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1259579808-11357-3-git-send-email-ehrhardt@linux.vnet.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 5 changed files with 61 additions and 2 deletions Side-by-side Diff

include/linux/sched.h
... ... @@ -1902,13 +1902,22 @@
1902 1902 extern unsigned int sysctl_sched_shares_ratelimit;
1903 1903 extern unsigned int sysctl_sched_shares_thresh;
1904 1904 extern unsigned int sysctl_sched_child_runs_first;
  1905 +
  1906 +enum sched_tunable_scaling {
  1907 + SCHED_TUNABLESCALING_NONE,
  1908 + SCHED_TUNABLESCALING_LOG,
  1909 + SCHED_TUNABLESCALING_LINEAR,
  1910 + SCHED_TUNABLESCALING_END,
  1911 +};
  1912 +extern enum sched_tunable_scaling sysctl_sched_tunable_scaling;
  1913 +
1905 1914 #ifdef CONFIG_SCHED_DEBUG
1906 1915 extern unsigned int sysctl_sched_migration_cost;
1907 1916 extern unsigned int sysctl_sched_nr_migrate;
1908 1917 extern unsigned int sysctl_sched_time_avg;
1909 1918 extern unsigned int sysctl_timer_migration;
1910 1919  
1911   -int sched_nr_latency_handler(struct ctl_table *table, int write,
  1920 +int sched_proc_update_handler(struct ctl_table *table, int write,
1912 1921 void __user *buffer, size_t *length,
1913 1922 loff_t *ppos);
1914 1923 #endif
... ... @@ -7033,7 +7033,20 @@
7033 7033 static void update_sysctl(void)
7034 7034 {
7035 7035 unsigned int cpus = min(num_online_cpus(), 8U);
7036   - unsigned int factor = 1 + ilog2(cpus);
  7036 + unsigned int factor;
  7037 +
  7038 + switch (sysctl_sched_tunable_scaling) {
  7039 + case SCHED_TUNABLESCALING_NONE:
  7040 + factor = 1;
  7041 + break;
  7042 + case SCHED_TUNABLESCALING_LINEAR:
  7043 + factor = cpus;
  7044 + break;
  7045 + case SCHED_TUNABLESCALING_LOG:
  7046 + default:
  7047 + factor = 1 + ilog2(cpus);
  7048 + break;
  7049 + }
7037 7050  
7038 7051 #define SET_SYSCTL(name) \
7039 7052 (sysctl_##name = (factor) * normalized_sysctl_##name)
kernel/sched_debug.c
... ... @@ -309,6 +309,12 @@
309 309 print_rq(m, rq, cpu);
310 310 }
311 311  
  312 +static const char *sched_tunable_scaling_names[] = {
  313 + "none",
  314 + "logaritmic",
  315 + "linear"
  316 +};
  317 +
312 318 static int sched_debug_show(struct seq_file *m, void *v)
313 319 {
314 320 u64 now = ktime_to_ns(ktime_get());
... ... @@ -333,6 +339,10 @@
333 339 P(sysctl_sched_features);
334 340 #undef PN
335 341 #undef P
  342 +
  343 + SEQ_printf(m, " .%-40s: %d (%s)\n", "sysctl_sched_tunable_scaling",
  344 + sysctl_sched_tunable_scaling,
  345 + sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
336 346  
337 347 for_each_online_cpu(cpu)
338 348 print_cpu(m, cpu);
... ... @@ -21,6 +21,7 @@
21 21 */
22 22  
23 23 #include <linux/latencytop.h>
  24 +#include <linux/sched.h>
24 25  
25 26 /*
26 27 * Targeted preemption latency for CPU-bound tasks:
... ... @@ -36,6 +37,18 @@
36 37 */
37 38 unsigned int sysctl_sched_latency = 5000000ULL;
38 39 unsigned int normalized_sysctl_sched_latency = 5000000ULL;
  40 +
  41 +/*
  42 + * The initial- and re-scaling of tunables is configurable
  43 + * (default SCHED_TUNABLESCALING_LOG = *(1+ilog(ncpus))
  44 + *
  45 + * Options are:
  46 + * SCHED_TUNABLESCALING_NONE - unscaled, always *1
  47 + * SCHED_TUNABLESCALING_LOG - scaled logarithmical, *1+ilog(ncpus)
  48 + * SCHED_TUNABLESCALING_LINEAR - scaled linear, *ncpus
  49 + */
  50 +enum sched_tunable_scaling sysctl_sched_tunable_scaling
  51 + = SCHED_TUNABLESCALING_LOG;
39 52  
40 53 /*
41 54 * Minimal preemption granularity for CPU-bound tasks:
... ... @@ -251,6 +251,8 @@
251 251 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
252 252 static int min_wakeup_granularity_ns; /* 0 usecs */
253 253 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
  254 +static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
  255 +static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
254 256 #endif
255 257  
256 258 static struct ctl_table kern_table[] = {
... ... @@ -304,6 +306,18 @@
304 306 .mode = 0644,
305 307 .proc_handler = &proc_dointvec,
306 308 },
  309 + {
  310 + .ctl_name = CTL_UNNUMBERED,
  311 + .procname = "sched_tunable_scaling",
  312 + .data = &sysctl_sched_tunable_scaling,
  313 + .maxlen = sizeof(enum sched_tunable_scaling),
  314 + .mode = 0644,
  315 + .proc_handler = &proc_dointvec_minmax,
  316 + .strategy = &sysctl_intvec,
  317 + .extra1 = &min_sched_tunable_scaling,
  318 + .extra2 = &max_sched_tunable_scaling,
  319 + },
  320 +
307 321 {
308 322 .ctl_name = CTL_UNNUMBERED,
309 323 .procname = "sched_shares_thresh",