<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Nick Piggin &lt;nickpiggin@yahoo.com.au&gt;


Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 kernel/sched.c |  125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+)

diff -puN kernel/sched.c~sched2-sched-domain-sysctl kernel/sched.c
--- devel/kernel/sched.c~sched2-sched-domain-sysctl	2005-07-26 00:38:38.000000000 -0700
+++ devel-akpm/kernel/sched.c	2005-07-26 00:38:38.000000000 -0700
@@ -45,6 +45,7 @@
 #include &lt;linux/perfctr.h&gt;
 #include &lt;linux/kthread.h&gt;
 #include &lt;linux/seq_file.h&gt;
+#include &lt;linux/sysctl.h&gt;
 #include &lt;linux/syscalls.h&gt;
 #include &lt;linux/times.h&gt;
 #include &lt;linux/acct.h&gt;
@@ -4724,6 +4725,129 @@ static void migrate_dead_tasks(unsigned 
 }
 #endif /* CONFIG_HOTPLUG_CPU */
 
+#if defined(CONFIG_DEBUG_KERNEL) &amp;&amp; defined(CONFIG_SYSCTL)
+static struct ctl_table sd_ctl_dir[] = {
+	{1, "sched_domain", NULL, 0, 0755, NULL, },
+	{0,},
+};
+
+static struct ctl_table sd_ctl_root[] = {
+	{1, "kernel", NULL, 0, 0755, sd_ctl_dir, },
+	{0,},
+};
+
+static char *sched_strdup(char *str)
+{
+	int n = strlen(str)+1;
+	char *s = kmalloc(n, GFP_KERNEL);
+	if (!s)
+		return NULL;
+	return strcpy(s, str);
+}
+
+static struct ctl_table *sd_alloc_ctl_entry(int n)
+{
+	struct ctl_table *entry =
+		kmalloc(n * sizeof(struct ctl_table), GFP_KERNEL);
+	BUG_ON(!entry);
+	memset(entry, 0, n * sizeof(struct ctl_table));
+	return entry;
+}
+
+static void set_table_entry(struct ctl_table *entry, int ctl_name,
+			const char *procname, void *data, int maxlen,
+			mode_t mode, proc_handler *proc_handler)
+{
+	entry-&gt;ctl_name = ctl_name;
+	entry-&gt;procname = procname;
+	entry-&gt;data = data;
+	entry-&gt;maxlen = maxlen;
+	entry-&gt;mode = mode;
+	entry-&gt;proc_handler = proc_handler;
+}
+
+static struct ctl_table *
+sd_alloc_ctl_domain_table(struct sched_domain *sd)
+{
+	struct ctl_table *table;
+	table = sd_alloc_ctl_entry(14);
+
+	set_table_entry(&amp;table[0], 1, "min_interval", &amp;sd-&gt;min_interval,
+		sizeof(long), 0644, proc_doulongvec_minmax);
+	set_table_entry(&amp;table[1], 2, "max_interval", &amp;sd-&gt;max_interval,
+		sizeof(long), 0644, proc_doulongvec_minmax);
+	set_table_entry(&amp;table[2], 3, "busy_idx", &amp;sd-&gt;busy_idx,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[3], 4, "idle_idx", &amp;sd-&gt;idle_idx,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[4], 5, "newidle_idx", &amp;sd-&gt;newidle_idx,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[5], 6, "wake_idx", &amp;sd-&gt;wake_idx,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[6], 7, "forkexec_idx", &amp;sd-&gt;forkexec_idx,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[7], 8, "busy_factor", &amp;sd-&gt;busy_factor,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[8], 9, "imbalance_pct", &amp;sd-&gt;imbalance_pct,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[9], 10, "cache_hot_time", &amp;sd-&gt;cache_hot_time,
+		sizeof(long long), 0644, proc_doulongvec_minmax);
+	set_table_entry(&amp;table[10], 11, "cache_nice_tries", &amp;sd-&gt;cache_nice_tries,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[11], 12, "per_cpu_gain", &amp;sd-&gt;per_cpu_gain,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	set_table_entry(&amp;table[12], 13, "flags", &amp;sd-&gt;flags,
+		sizeof(int), 0644, proc_dointvec_minmax);
+	return table;
+}
+
+static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
+{
+	struct sched_domain *sd;
+	int domain_num = 0, i;
+	struct ctl_table *entry, *table;
+	char buf[32];
+	for_each_domain(cpu, sd)
+		domain_num++;
+	entry = table = sd_alloc_ctl_entry(domain_num + 1);
+
+	i = 0;
+	for_each_domain(cpu, sd) {
+		snprintf(buf, 32, "domain%d", i);
+		entry-&gt;ctl_name = i + 1;
+		entry-&gt;procname = sched_strdup(buf);
+		entry-&gt;mode = 0755;
+		entry-&gt;child = sd_alloc_ctl_domain_table(sd);
+		entry++;
+		i++;
+	}
+	return table;
+}
+
+static struct ctl_table_header *sd_sysctl_header;
+static void init_sched_domain_sysctl(void)
+{
+	int i, cpu_num = num_online_cpus();
+	char buf[32];
+	struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
+
+	sd_ctl_dir[0].child = entry;
+
+	for (i = 0; i &lt; cpu_num; i++, entry++) {
+		snprintf(buf, 32, "cpu%d", i);
+		entry-&gt;ctl_name = i + 1;
+		entry-&gt;procname = sched_strdup(buf);
+		entry-&gt;mode = 0755;
+		entry-&gt;child = sd_alloc_ctl_cpu_table(i);
+	}
+	sd_sysctl_header = register_sysctl_table(sd_ctl_root, 0);
+}
+#else
+static void init_sched_domain_sysctl(void)
+{
+}
+#endif
+
 /*
  * migration_call - callback that gets triggered when a CPU is added.
  * Here we can start up the necessary migration thread for the new CPU.
@@ -5810,6 +5934,7 @@ void __init sched_init_smp(void)
 	unlock_cpu_hotplug();
 	/* XXX: Theoretical race here - CPU may be hotplugged now */
 	hotcpu_notifier(update_sched_domains, 0);
+	init_sched_domain_sysctl();
 }
 #else
 void __init sched_init_smp(void)
_
</pre></body></html>