From: Aubrey Li <aubrey...@linux.intel.com>

Short idle periods varies from different workload, make the switch
tunable
---
 include/linux/sched/sysctl.h |  1 +
 kernel/sched/idle.c          |  5 +++--
 kernel/sysctl.c              | 10 ++++++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
index 0f5ecd4..9771506 100644
--- a/include/linux/sched/sysctl.h
+++ b/include/linux/sched/sysctl.h
@@ -65,6 +65,7 @@ extern unsigned int sysctl_sched_autogroup_enabled;
 
 extern int sysctl_sched_rr_timeslice;
 extern int sched_rr_timeslice;
+extern unsigned int sysctl_fast_idle_threshold;
 
 extern int sched_rr_handler(struct ctl_table *table, int write,
                void __user *buffer, size_t *lenp,
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 3358db2..555b02d 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -287,6 +287,8 @@ static void cpuidle_generic(void)
        tick_nohz_idle_exit();
 }
 
+unsigned int sysctl_fast_idle_threshold = USEC_PER_SEC / HZ / 2;
+
 /*
  * Generic idle loop implementation
  *
@@ -295,7 +297,6 @@ static void cpuidle_generic(void)
 static void do_idle(void)
 {
        unsigned int predicted_idle_us;
-       unsigned int short_idle_threshold = jiffies_to_usecs(1) / 2;
        /*
         * If the arch has a polling bit, we maintain an invariant:
         *
@@ -309,7 +310,7 @@ static void do_idle(void)
 
        predicted_idle_us = cpuidle_predict();
 
-       if (likely(predicted_idle_us < short_idle_threshold))
+       if (likely(predicted_idle_us < sysctl_fast_idle_threshold))
                cpuidle_fast();
        else
                cpuidle_generic();
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8c8714f..0acf81d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -128,6 +128,7 @@ static int __maybe_unused four = 4;
 static unsigned long one_ul = 1;
 static int one_hundred = 100;
 static int one_thousand = 1000;
+static int one_tick_to_us = USEC_PER_SEC / HZ;
 #ifdef CONFIG_PRINTK
 static int ten_thousand = 10000;
 #endif
@@ -1201,6 +1202,15 @@ static struct ctl_table kern_table[] = {
                .extra2         = &one,
        },
 #endif
+       {
+               .procname       = "sched_fast_idle_threshold",
+               .data           = &sysctl_fast_idle_threshold,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &zero,
+               .extra2         = &one_tick_to_us,
+       },
        { }
 };
 
-- 
2.7.4

Reply via email to