Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49c022e6 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar
Browse files

sched: Clean up rebalance_domains() load-balance interval calculation



Instead of the possible multiple-evaluation of num_online_cpus()
in rebalance_domains() that Linus reported, avoid it altogether
in the normal case since it's implemented with a Hamming weight
function over a cpu bitmask which can be darn expensive for those
with big iron.

This also makes it cleaner, smaller and documents the code.

Reported-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1301991265.2225.12.camel@twins>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent b2a8b4b8
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -6331,6 +6331,9 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
		break;
		break;
#endif
#endif
	}
	}

	update_max_interval();

	return NOTIFY_OK;
	return NOTIFY_OK;
}
}


+12 −4
Original line number Original line Diff line number Diff line
@@ -3820,6 +3820,17 @@ void select_nohz_load_balancer(int stop_tick)


static DEFINE_SPINLOCK(balancing);
static DEFINE_SPINLOCK(balancing);


static unsigned long __read_mostly max_load_balance_interval = HZ/10;

/*
 * Scale the max load_balance interval with the number of CPUs in the system.
 * This trades load-balance latency on larger machines for less cross talk.
 */
static void update_max_interval(void)
{
	max_load_balance_interval = HZ*num_online_cpus()/10;
}

/*
/*
 * It checks each scheduling domain to see if it is due to be balanced,
 * It checks each scheduling domain to see if it is due to be balanced,
 * and initiates a balancing operation if so.
 * and initiates a balancing operation if so.
@@ -3849,10 +3860,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)


		/* scale ms to jiffies */
		/* scale ms to jiffies */
		interval = msecs_to_jiffies(interval);
		interval = msecs_to_jiffies(interval);
		if (unlikely(!interval))
		interval = clamp(interval, 1UL, max_load_balance_interval);
			interval = 1;
		if (interval > HZ*num_online_cpus()/10)
			interval = HZ*num_online_cpus()/10;


		need_serialize = sd->flags & SD_SERIALIZE;
		need_serialize = sd->flags & SD_SERIALIZE;