Skip to content

Commit 4defea8

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
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: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/n/tip-8tnwb92asqj7xajqqoty4gel@git.kernel.org Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent bc1738f commit 4defea8

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎arch/x86/kernel/cpu/perf_event.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,25 @@ static bool __perf_sched_find_counter(struct perf_sched *sched)
574574

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

577+
/* Prefer fixed purpose counters */
578+
if (x86_pmu.num_counters_fixed) {
579+
idx = X86_PMC_IDX_FIXED;
580+
for_each_set_bit_cont(idx, c->idxmsk, X86_PMC_IDX_MAX) {
581+
if (!__test_and_set_bit(idx, sched->state.used))
582+
goto done;
583+
}
584+
}
577585
/* Grab the first unused counter starting with idx */
578586
idx = sched->state.counter;
579-
for_each_set_bit_cont(idx, c->idxmsk, X86_PMC_IDX_MAX) {
587+
for_each_set_bit_cont(idx, c->idxmsk, X86_PMC_IDX_FIXED) {
580588
if (!__test_and_set_bit(idx, sched->state.used))
581-
break;
589+
goto done;
582590
}
583-
sched->state.counter = idx;
584591

585-
if (idx >= X86_PMC_IDX_MAX)
586-
return false;
592+
return false;
593+
594+
done:
595+
sched->state.counter = idx;
587596

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

0 commit comments

Comments
 (0)