Skip to content

Commit a4064fb

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/fair: Add NOHZ stats balancing
Teach the idle balancer about the need to update statistics which have a different periodicity from regular balancing. Suggested-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 4550487 commit a4064fb

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

kernel/sched/fair.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9053,6 +9053,7 @@ static struct {
90539053
cpumask_var_t idle_cpus_mask;
90549054
atomic_t nr_cpus;
90559055
unsigned long next_balance; /* in jiffy units */
9056+
unsigned long next_stats;
90569057
} nohz ____cacheline_aligned;
90579058

90589059
static inline int find_new_ilb(void)
@@ -9087,9 +9088,8 @@ static inline void set_cpu_sd_state_busy(void)
90879088
* nohz_load_balancer CPU (if there is one) otherwise fallback to any idle
90889089
* CPU (if there is one).
90899090
*/
9090-
static void kick_ilb(void)
9091+
static void kick_ilb(unsigned int flags)
90919092
{
9092-
unsigned int flags;
90939093
int ilb_cpu;
90949094

90959095
nohz.next_balance++;
@@ -9099,7 +9099,7 @@ static void kick_ilb(void)
90999099
if (ilb_cpu >= nr_cpu_ids)
91009100
return;
91019101

9102-
flags = atomic_fetch_or(NOHZ_KICK_MASK, nohz_flags(ilb_cpu));
9102+
flags = atomic_fetch_or(flags, nohz_flags(ilb_cpu));
91039103
if (flags & NOHZ_KICK_MASK)
91049104
return;
91059105

@@ -9129,7 +9129,7 @@ static void nohz_balancer_kick(struct rq *rq)
91299129
struct sched_domain_shared *sds;
91309130
struct sched_domain *sd;
91319131
int nr_busy, i, cpu = rq->cpu;
9132-
bool kick = false;
9132+
unsigned int flags = 0;
91339133

91349134
if (unlikely(rq->idle_balance))
91359135
return;
@@ -9148,11 +9148,14 @@ static void nohz_balancer_kick(struct rq *rq)
91489148
if (likely(!atomic_read(&nohz.nr_cpus)))
91499149
return;
91509150

9151+
if (time_after(now, nohz.next_stats))
9152+
flags = NOHZ_STATS_KICK;
9153+
91519154
if (time_before(now, nohz.next_balance))
9152-
return;
9155+
goto out;
91539156

91549157
if (rq->nr_running >= 2) {
9155-
kick = true;
9158+
flags = NOHZ_KICK_MASK;
91569159
goto out;
91579160
}
91589161

@@ -9165,7 +9168,7 @@ static void nohz_balancer_kick(struct rq *rq)
91659168
*/
91669169
nr_busy = atomic_read(&sds->nr_busy_cpus);
91679170
if (nr_busy > 1) {
9168-
kick = true;
9171+
flags = NOHZ_KICK_MASK;
91699172
goto unlock;
91709173
}
91719174

@@ -9175,7 +9178,7 @@ static void nohz_balancer_kick(struct rq *rq)
91759178
if (sd) {
91769179
if ((rq->cfs.h_nr_running >= 1) &&
91779180
check_cpu_capacity(rq, sd)) {
9178-
kick = true;
9181+
flags = NOHZ_KICK_MASK;
91799182
goto unlock;
91809183
}
91819184
}
@@ -9188,16 +9191,16 @@ static void nohz_balancer_kick(struct rq *rq)
91889191
continue;
91899192

91909193
if (sched_asym_prefer(i, cpu)) {
9191-
kick = true;
9194+
flags = NOHZ_KICK_MASK;
91929195
goto unlock;
91939196
}
91949197
}
91959198
}
91969199
unlock:
91979200
rcu_read_unlock();
91989201
out:
9199-
if (kick)
9200-
kick_ilb();
9202+
if (flags)
9203+
kick_ilb(flags);
92019204
}
92029205

92039206
void nohz_balance_exit_idle(unsigned int cpu)
@@ -9389,7 +9392,9 @@ static void rebalance_domains(struct rq *rq, enum cpu_idle_type idle)
93899392
static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
93909393
{
93919394
/* Earliest time when we have to do rebalance again */
9392-
unsigned long next_balance = jiffies + 60*HZ;
9395+
unsigned long now = jiffies;
9396+
unsigned long next_balance = now + 60*HZ;
9397+
unsigned long next_stats = now + msecs_to_jiffies(LOAD_AVG_PERIOD);
93939398
int update_next_balance = 0;
93949399
int this_cpu = this_rq->cpu;
93959400
unsigned int flags;
@@ -9449,6 +9454,8 @@ static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
94499454
if (flags & NOHZ_BALANCE_KICK)
94509455
rebalance_domains(this_rq, CPU_IDLE);
94519456

9457+
nohz.next_stats = next_stats;
9458+
94529459
/*
94539460
* next_balance will be updated only when there is a need.
94549461
* When the CPU is attached to null domain for ex, it will not be

0 commit comments

Comments
 (0)