The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>,
	Ingo Molnar <mingo@elte.hu>, Andi Kleen <andi@firstfloor.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 0/2] perf, x86: handle overlapping counters
Date: Tue, 22 Nov 2011 16:26:07 +0100	[thread overview]
Message-ID: <1321975567.14799.15.camel@twins> (raw)
In-Reply-To: <1321616122-1533-1-git-send-email-robert.richter@amd.com>

I stuck the below patch on top, afaict there is no reason to store
sched->state.counter when we fail, since in that case we pop a state or
go bust entirely, right?



---
Subject: perf, x86: Prefer Fixed purpose counters when scheduling
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
Date: Thu Nov 10 15:15:42 CET 2011

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>
---
 arch/x86/kernel/cpu/perf_event.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
Index: linux-2.6/arch/x86/kernel/cpu/perf_event.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/perf_event.c
+++ linux-2.6/arch/x86/kernel/cpu/perf_event.c
@@ -574,16 +574,25 @@ static bool __perf_sched_find_counter(st
 
 	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;
+	return false;
+
+done:
+	sched->state.counter = idx;
 
 	if (c->overlap)
 		perf_sched_save_state(sched);


  parent reply	other threads:[~2011-11-22 15:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-18 11:35 [PATCH v4 0/2] perf, x86: handle overlapping counters Robert Richter
2011-11-18 11:35 ` [PATCH v4 1/2] perf, x86: Implement event scheduler helper functions Robert Richter
2011-12-06  9:44   ` [tip:perf/core] " tip-bot for Robert Richter
2011-11-18 11:35 ` [PATCH v4 2/2] perf, x86: Fix event scheduler for constraints with overlapping counters Robert Richter
2011-12-06  9:45   ` [tip:perf/core] " tip-bot for Robert Richter
2011-11-18 15:10 ` [PATCH v4 0/2] perf, x86: handle " Peter Zijlstra
2011-11-18 16:32   ` Robert Richter
2011-11-22 15:26 ` Peter Zijlstra [this message]
2011-11-22 16:27   ` Robert Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1321975567.14799.15.camel@twins \
    --to=peterz@infradead.org \
    --cc=andi@firstfloor.org \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=robert.richter@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox