Skip to content

Commit 1c792db

Browse files
Suresh SiddhaIngo Molnar
authored andcommitted
sched, nohz: Introduce nohz_flags in 'struct rq'
Introduce nohz_flags in the struct rq, which will track these two flags for now. NOHZ_TICK_STOPPED keeps track of the tick stopped status that gets set when the tick is stopped. It will be used to update the nohz idle load balancer data structures during the first busy tick after the tick is restarted. At this first busy tick after tickless idle, NOHZ_TICK_STOPPED flag will be reset. This will minimize the nohz idle load balancer status updates that currently happen for every tickless exit, making it more scalable when there are many logical cpu's that enter and exit idle often. NOHZ_BALANCE_KICK will track the need for nohz idle load balance on this rq. This will replace the nohz_balance_kick in the rq, which was not being updated atomically. Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20111202010832.499438999@sbsiddha-desk.sc.intel.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 5b680fd commit 1c792db

3 files changed

Lines changed: 40 additions & 24 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ void wake_up_idle_cpu(int cpu)
575575

576576
static inline bool got_nohz_idle_kick(void)
577577
{
578-
return idle_cpu(smp_processor_id()) && this_rq()->nohz_balance_kick;
578+
int cpu = smp_processor_id();
579+
return idle_cpu(cpu) && test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu));
579580
}
580581

581582
#else /* CONFIG_NO_HZ */
@@ -6840,7 +6841,7 @@ void __init sched_init(void)
68406841
rq->avg_idle = 2*sysctl_sched_migration_cost;
68416842
rq_attach_root(rq, &def_root_domain);
68426843
#ifdef CONFIG_NO_HZ
6843-
rq->nohz_balance_kick = 0;
6844+
rq->nohz_flags = 0;
68446845
#endif
68456846
#endif
68466847
init_rq_hrtick(rq);

‎kernel/sched/fair.c‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,18 +4889,15 @@ static void nohz_balancer_kick(int cpu)
48894889
return;
48904890
}
48914891

4892-
if (!cpu_rq(ilb_cpu)->nohz_balance_kick) {
4893-
cpu_rq(ilb_cpu)->nohz_balance_kick = 1;
4894-
4895-
smp_mb();
4896-
/*
4897-
* Use smp_send_reschedule() instead of resched_cpu().
4898-
* This way we generate a sched IPI on the target cpu which
4899-
* is idle. And the softirq performing nohz idle load balance
4900-
* will be run before returning from the IPI.
4901-
*/
4902-
smp_send_reschedule(ilb_cpu);
4903-
}
4892+
if (test_and_set_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu)))
4893+
return;
4894+
/*
4895+
* Use smp_send_reschedule() instead of resched_cpu().
4896+
* This way we generate a sched IPI on the target cpu which
4897+
* is idle. And the softirq performing nohz idle load balance
4898+
* will be run before returning from the IPI.
4899+
*/
4900+
smp_send_reschedule(ilb_cpu);
49044901
return;
49054902
}
49064903

@@ -4964,6 +4961,8 @@ void select_nohz_load_balancer(int stop_tick)
49644961
}
49654962
return;
49664963
}
4964+
4965+
set_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
49674966
} else {
49684967
if (!cpumask_test_cpu(cpu, nohz.idle_cpus_mask))
49694968
return;
@@ -5079,8 +5078,9 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle)
50795078
struct rq *rq;
50805079
int balance_cpu;
50815080

5082-
if (idle != CPU_IDLE || !this_rq->nohz_balance_kick)
5083-
return;
5081+
if (idle != CPU_IDLE ||
5082+
!test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
5083+
goto end;
50845084

50855085
for_each_cpu(balance_cpu, nohz.idle_cpus_mask) {
50865086
if (balance_cpu == this_cpu)
@@ -5091,10 +5091,8 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle)
50915091
* work being done for other cpus. Next load
50925092
* balancing owner will pick it up.
50935093
*/
5094-
if (need_resched()) {
5095-
this_rq->nohz_balance_kick = 0;
5094+
if (need_resched())
50965095
break;
5097-
}
50985096

50995097
raw_spin_lock_irq(&this_rq->lock);
51005098
update_rq_clock(this_rq);
@@ -5108,7 +5106,8 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle)
51085106
this_rq->next_balance = rq->next_balance;
51095107
}
51105108
nohz.next_balance = this_rq->next_balance;
5111-
this_rq->nohz_balance_kick = 0;
5109+
end:
5110+
clear_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu));
51125111
}
51135112

51145113
/*
@@ -5129,10 +5128,17 @@ static inline int nohz_kick_needed(struct rq *rq, int cpu)
51295128
int ret;
51305129
int first_pick_cpu, second_pick_cpu;
51315130

5132-
if (time_before(now, nohz.next_balance))
5131+
if (unlikely(idle_cpu(cpu)))
51335132
return 0;
51345133

5135-
if (idle_cpu(cpu))
5134+
/*
5135+
* We may be recently in ticked or tickless idle mode. At the first
5136+
* busy tick after returning from idle, we will update the busy stats.
5137+
*/
5138+
if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu))))
5139+
clear_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu));
5140+
5141+
if (time_before(now, nohz.next_balance))
51365142
return 0;
51375143

51385144
first_pick_cpu = atomic_read(&nohz.first_pick_cpu);
@@ -5196,7 +5202,7 @@ void trigger_load_balance(struct rq *rq, int cpu)
51965202
likely(!on_null_domain(cpu)))
51975203
raise_softirq(SCHED_SOFTIRQ);
51985204
#ifdef CONFIG_NO_HZ
5199-
else if (nohz_kick_needed(rq, cpu) && likely(!on_null_domain(cpu)))
5205+
if (nohz_kick_needed(rq, cpu) && likely(!on_null_domain(cpu)))
52005206
nohz_balancer_kick(cpu);
52015207
#endif
52025208
}

‎kernel/sched/sched.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ struct rq {
371371
unsigned long last_load_update_tick;
372372
#ifdef CONFIG_NO_HZ
373373
u64 nohz_stamp;
374-
unsigned char nohz_balance_kick;
374+
unsigned long nohz_flags;
375375
#endif
376376
int skip_clock_update;
377377

@@ -1064,3 +1064,12 @@ extern void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq);
10641064
extern void unthrottle_offline_cfs_rqs(struct rq *rq);
10651065

10661066
extern void account_cfs_bandwidth_used(int enabled, int was_enabled);
1067+
1068+
#ifdef CONFIG_NO_HZ
1069+
enum rq_nohz_flag_bits {
1070+
NOHZ_TICK_STOPPED,
1071+
NOHZ_BALANCE_KICK,
1072+
};
1073+
1074+
#define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags)
1075+
#endif

0 commit comments

Comments
 (0)