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

Commit 4defea85 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar
Browse files

perf, x86: Prefer fixed-purpose counters when scheduling



This avoids a scheduling failure for cases like:

  cycles, cycles, instructions, instructions (on Core2)

Which would end up being programmed like:

  PMC0, PMC1, FP-instructions, fail

Because all events will have the same weight.

Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-8tnwb92asqj7xajqqoty4gel@git.kernel.org


Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent bc1738f6
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -574,17 +574,26 @@ static bool __perf_sched_find_counter(struct perf_sched *sched)

	c = sched->constraints[sched->state.event];

	/* Prefer fixed purpose counters */
	if (x86_pmu.num_counters_fixed) {
		idx = X86_PMC_IDX_FIXED;
		for_each_set_bit_cont(idx, c->idxmsk, X86_PMC_IDX_MAX) {
			if (!__test_and_set_bit(idx, sched->state.used))
				goto done;
		}
	}
	/* Grab the first unused counter starting with idx */
	idx = sched->state.counter;
	for_each_set_bit_cont(idx, c->idxmsk, X86_PMC_IDX_MAX) {
	for_each_set_bit_cont(idx, c->idxmsk, X86_PMC_IDX_FIXED) {
		if (!__test_and_set_bit(idx, sched->state.used))
			break;
			goto done;
	}
	sched->state.counter = idx;

	if (idx >= X86_PMC_IDX_MAX)
	return false;

done:
	sched->state.counter = idx;

	if (c->overlap)
		perf_sched_save_state(sched);