sched: Fix missing sched tunable recalculation on cpu add/remove

Based on Peter Zijlstras patch suggestion this enables recalculation of
the scheduler tunables in response of a change in the number of cpus. It
also adds a max of eight cpus that are considered in that scaling.

Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1259579808-11357-2-git-send-email-ehrhardt@linux.vnet.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
Christian Ehrhardt 2009-11-30 12:16:46 +01:00 committed by Ingo Molnar
parent 57785df5ac
commit 0bcdcf28c9
2 changed files with 33 additions and 14 deletions

View file

@ -814,6 +814,7 @@ const_debug unsigned int sysctl_sched_nr_migrate = 32;
* default: 0.25ms * default: 0.25ms
*/ */
unsigned int sysctl_sched_shares_ratelimit = 250000; unsigned int sysctl_sched_shares_ratelimit = 250000;
unsigned int normalized_sysctl_sched_shares_ratelimit = 250000;
/* /*
* Inject some fuzzyness into changing the per-cpu group shares * Inject some fuzzyness into changing the per-cpu group shares
@ -1814,6 +1815,7 @@ static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares)
#endif #endif
static void calc_load_account_active(struct rq *this_rq); static void calc_load_account_active(struct rq *this_rq);
static void update_sysctl(void);
static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu) static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
{ {
@ -7028,22 +7030,23 @@ cpumask_var_t nohz_cpu_mask;
* *
* This idea comes from the SD scheduler of Con Kolivas: * This idea comes from the SD scheduler of Con Kolivas:
*/ */
static void update_sysctl(void)
{
unsigned int cpus = min(num_online_cpus(), 8U);
unsigned int factor = 1 + ilog2(cpus);
#define SET_SYSCTL(name) \
(sysctl_##name = (factor) * normalized_sysctl_##name)
SET_SYSCTL(sched_min_granularity);
SET_SYSCTL(sched_latency);
SET_SYSCTL(sched_wakeup_granularity);
SET_SYSCTL(sched_shares_ratelimit);
#undef SET_SYSCTL
}
static inline void sched_init_granularity(void) static inline void sched_init_granularity(void)
{ {
unsigned int factor = 1 + ilog2(num_online_cpus()); update_sysctl();
const unsigned long limit = 200000000;
sysctl_sched_min_granularity *= factor;
if (sysctl_sched_min_granularity > limit)
sysctl_sched_min_granularity = limit;
sysctl_sched_latency *= factor;
if (sysctl_sched_latency > limit)
sysctl_sched_latency = limit;
sysctl_sched_wakeup_granularity *= factor;
sysctl_sched_shares_ratelimit *= factor;
} }
#ifdef CONFIG_SMP #ifdef CONFIG_SMP

View file

@ -35,12 +35,14 @@
* run vmstat and monitor the context-switches (cs) field) * run vmstat and monitor the context-switches (cs) field)
*/ */
unsigned int sysctl_sched_latency = 5000000ULL; unsigned int sysctl_sched_latency = 5000000ULL;
unsigned int normalized_sysctl_sched_latency = 5000000ULL;
/* /*
* Minimal preemption granularity for CPU-bound tasks: * Minimal preemption granularity for CPU-bound tasks:
* (default: 1 msec * (1 + ilog(ncpus)), units: nanoseconds) * (default: 1 msec * (1 + ilog(ncpus)), units: nanoseconds)
*/ */
unsigned int sysctl_sched_min_granularity = 1000000ULL; unsigned int sysctl_sched_min_granularity = 1000000ULL;
unsigned int normalized_sysctl_sched_min_granularity = 1000000ULL;
/* /*
* is kept at sysctl_sched_latency / sysctl_sched_min_granularity * is kept at sysctl_sched_latency / sysctl_sched_min_granularity
@ -70,6 +72,7 @@ unsigned int __read_mostly sysctl_sched_compat_yield;
* have immediate wakeup/sleep latencies. * have immediate wakeup/sleep latencies.
*/ */
unsigned int sysctl_sched_wakeup_granularity = 1000000UL; unsigned int sysctl_sched_wakeup_granularity = 1000000UL;
unsigned int normalized_sysctl_sched_wakeup_granularity = 1000000UL;
const_debug unsigned int sysctl_sched_migration_cost = 500000UL; const_debug unsigned int sysctl_sched_migration_cost = 500000UL;
@ -1890,6 +1893,17 @@ move_one_task_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
return 0; return 0;
} }
static void rq_online_fair(struct rq *rq)
{
update_sysctl();
}
static void rq_offline_fair(struct rq *rq)
{
update_sysctl();
}
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
/* /*
@ -2035,6 +2049,8 @@ static const struct sched_class fair_sched_class = {
.load_balance = load_balance_fair, .load_balance = load_balance_fair,
.move_one_task = move_one_task_fair, .move_one_task = move_one_task_fair,
.rq_online = rq_online_fair,
.rq_offline = rq_offline_fair,
#endif #endif
.set_curr_task = set_curr_task_fair, .set_curr_task = set_curr_task_fair,