Skip to content

Commit

Permalink
sched: check for SD_SERIALIZE atomically in rebalance_domains()
Browse files Browse the repository at this point in the history
Nothing really serious here, mainly just a matter of nit-picking :-/

From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
For CONFIG_SCHED_DEBUG && CONFIG_SYSCT configs, sd->flags can be altered
while being manipulated in rebalance_domains(). Let's do an atomic check.
We rely here on the atomicity of read/write accesses for aligned words.

Signed-off-by: Dmitry Adamushko <dmitry.adamushko@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Dmitry Adamushko authored and Ingo Molnar committed Jun 6, 2008
1 parent 6d299f1 commit d07355f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -3668,6 +3668,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
/* Earliest time when we have to do rebalance again */
unsigned long next_balance = jiffies + 60*HZ;
int update_next_balance = 0;
int need_serialize;
cpumask_t tmp;

for_each_domain(cpu, sd) {
Expand All @@ -3685,8 +3686,9 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
if (interval > HZ*NR_CPUS/10)
interval = HZ*NR_CPUS/10;

need_serialize = sd->flags & SD_SERIALIZE;

if (sd->flags & SD_SERIALIZE) {
if (need_serialize) {
if (!spin_trylock(&balancing))
goto out;
}
Expand All @@ -3702,7 +3704,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
}
sd->last_balance = jiffies;
}
if (sd->flags & SD_SERIALIZE)
if (need_serialize)
spin_unlock(&balancing);
out:
if (time_after(next_balance, sd->last_balance + interval)) {
Expand Down

0 comments on commit d07355f

Please sign in to comment.