Skip to content

Commit b7031a0

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/fair: Add NOHZ_STATS_KICK
Split the NOHZ idle balancer into doing two separate actions: - update blocked load statistic - actually load-balance Since the latter requires the former, ensure this happens. For now always tag both bits at the same time. Prepares for a future where we can toggle only the STATS bit. Suggested-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> 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 a22e47a commit b7031a0

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

kernel/sched/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static inline bool got_nohz_idle_kick(void)
583583
{
584584
int cpu = smp_processor_id();
585585

586-
if (!(atomic_read(nohz_flags(cpu)) & NOHZ_BALANCE_KICK))
586+
if (!(atomic_read(nohz_flags(cpu)) & NOHZ_KICK_MASK))
587587
return false;
588588

589589
if (idle_cpu(cpu) && !need_resched())
@@ -593,7 +593,7 @@ static inline bool got_nohz_idle_kick(void)
593593
* We can't run Idle Load Balance on this CPU for this time so we
594594
* cancel it and clear NOHZ_BALANCE_KICK
595595
*/
596-
atomic_andnot(NOHZ_BALANCE_KICK, nohz_flags(cpu));
596+
atomic_andnot(NOHZ_KICK_MASK, nohz_flags(cpu));
597597
return false;
598598
}
599599

kernel/sched/fair.c

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9082,8 +9082,8 @@ static void nohz_balancer_kick(void)
90829082
if (ilb_cpu >= nr_cpu_ids)
90839083
return;
90849084

9085-
flags = atomic_fetch_or(NOHZ_BALANCE_KICK, nohz_flags(ilb_cpu));
9086-
if (flags & NOHZ_BALANCE_KICK)
9085+
flags = atomic_fetch_or(NOHZ_KICK_MASK, nohz_flags(ilb_cpu));
9086+
if (flags & NOHZ_KICK_MASK)
90879087
return;
90889088
/*
90899089
* Use smp_send_reschedule() instead of resched_cpu().
@@ -9202,8 +9202,6 @@ static void rebalance_domains(struct rq *rq, enum cpu_idle_type idle)
92029202
int need_serialize, need_decay = 0;
92039203
u64 max_cost = 0;
92049204

9205-
update_blocked_averages(cpu);
9206-
92079205
rcu_read_lock();
92089206
for_each_domain(cpu, sd) {
92099207
/*
@@ -9298,20 +9296,27 @@ static void rebalance_domains(struct rq *rq, enum cpu_idle_type idle)
92989296
* In CONFIG_NO_HZ_COMMON case, the idle balance kickee will do the
92999297
* rebalancing for all the CPUs for whom scheduler ticks are stopped.
93009298
*/
9301-
static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
9299+
static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
93029300
{
9303-
int this_cpu = this_rq->cpu;
9304-
struct rq *rq;
9305-
int balance_cpu;
93069301
/* Earliest time when we have to do rebalance again */
93079302
unsigned long next_balance = jiffies + 60*HZ;
93089303
int update_next_balance = 0;
9304+
int this_cpu = this_rq->cpu;
9305+
unsigned int flags;
9306+
int balance_cpu;
9307+
struct rq *rq;
93099308

9310-
if (!(atomic_read(nohz_flags(this_cpu)) & NOHZ_BALANCE_KICK))
9311-
return;
9309+
if (!(atomic_read(nohz_flags(this_cpu)) & NOHZ_KICK_MASK))
9310+
return false;
93129311

9313-
if (idle != CPU_IDLE)
9314-
goto end;
9312+
if (idle != CPU_IDLE) {
9313+
atomic_andnot(NOHZ_KICK_MASK, nohz_flags(this_cpu));
9314+
return false;
9315+
}
9316+
9317+
flags = atomic_fetch_andnot(NOHZ_KICK_MASK, nohz_flags(this_cpu));
9318+
9319+
SCHED_WARN_ON((flags & NOHZ_KICK_MASK) == NOHZ_BALANCE_KICK);
93159320

93169321
for_each_cpu(balance_cpu, nohz.idle_cpus_mask) {
93179322
if (balance_cpu == this_cpu || !idle_cpu(balance_cpu))
@@ -9339,7 +9344,9 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
93399344
cpu_load_update_idle(rq);
93409345
rq_unlock_irq(rq, &rf);
93419346

9342-
rebalance_domains(rq, CPU_IDLE);
9347+
update_blocked_averages(rq->cpu);
9348+
if (flags & NOHZ_BALANCE_KICK)
9349+
rebalance_domains(rq, CPU_IDLE);
93439350
}
93449351

93459352
if (time_after(next_balance, rq->next_balance)) {
@@ -9348,15 +9355,19 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
93489355
}
93499356
}
93509357

9358+
update_blocked_averages(this_cpu);
9359+
if (flags & NOHZ_BALANCE_KICK)
9360+
rebalance_domains(this_rq, CPU_IDLE);
9361+
93519362
/*
93529363
* next_balance will be updated only when there is a need.
93539364
* When the CPU is attached to null domain for ex, it will not be
93549365
* updated.
93559366
*/
93569367
if (likely(update_next_balance))
93579368
nohz.next_balance = next_balance;
9358-
end:
9359-
atomic_andnot(NOHZ_BALANCE_KICK, nohz_flags(this_cpu));
9369+
9370+
return true;
93609371
}
93619372

93629373
/*
@@ -9443,7 +9454,10 @@ static inline bool nohz_kick_needed(struct rq *rq)
94439454
return kick;
94449455
}
94459456
#else
9446-
static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
9457+
static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
9458+
{
9459+
return false;
9460+
}
94479461
#endif
94489462

94499463
/*
@@ -9464,7 +9478,11 @@ static __latent_entropy void run_rebalance_domains(struct softirq_action *h)
94649478
* load balance only within the local sched_domain hierarchy
94659479
* and abort nohz_idle_balance altogether if we pull some load.
94669480
*/
9467-
nohz_idle_balance(this_rq, idle);
9481+
if (nohz_idle_balance(this_rq, idle))
9482+
return;
9483+
9484+
/* normal load balance */
9485+
update_blocked_averages(this_rq->cpu);
94689486
rebalance_domains(this_rq, idle);
94699487
}
94709488

kernel/sched/sched.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,9 +2036,13 @@ extern void cfs_bandwidth_usage_dec(void);
20362036
#ifdef CONFIG_NO_HZ_COMMON
20372037
#define NOHZ_TICK_STOPPED_BIT 0
20382038
#define NOHZ_BALANCE_KICK_BIT 1
2039+
#define NOHZ_STATS_KICK_BIT 2
20392040

20402041
#define NOHZ_TICK_STOPPED BIT(NOHZ_TICK_STOPPED_BIT)
20412042
#define NOHZ_BALANCE_KICK BIT(NOHZ_BALANCE_KICK_BIT)
2043+
#define NOHZ_STATS_KICK BIT(NOHZ_STATS_KICK_BIT)
2044+
2045+
#define NOHZ_KICK_MASK (NOHZ_BALANCE_KICK | NOHZ_STATS_KICK)
20422046

20432047
#define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags)
20442048

0 commit comments

Comments
 (0)