public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@openvz.org>
To: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>
Cc: ming.m.lin@intel.com, eranian@google.com, peterz@infradead.org,
	Cyrill Gorcunov <gorcunov@openvz.org>
Subject: [rfc 2/3] perf, x86: P4 PMU - Fix unflagged overflows handling v4
Date: Wed, 24 Nov 2010 01:46:03 +0300	[thread overview]
Message-ID: <20101123224800.485217113@openvz.org> (raw)
In-Reply-To: 20101123224601.766827604@openvz.org

[-- Attachment #1: perf-x86-p4-nmi-4 --]
[-- Type: text/plain, Size: 3356 bytes --]

Jason pointed out that kgdb no longer works with new
nmi-watchdog. Don found that P4 PMU reads CCCR register
instead of counter itself (in attempt to catch unflagged
event).

Testing high bit of counter didn't resolve the situation
in a complete way, the kgdb became working but perf top
still fails.

Lets read the all valuable bits from the counter and check them
for being oveflowed.

At least this patch eliminates wrong read operation though
perf top failure still requires to be investigated.

v2: Call checking_wrmsrl only if needed.
v3: Check the valuable bits.
v4: Leave p4_pmu_clear_cccr_ovf early if P4_CCCR_OVF flag is set.

Reported-by: Jason Wessel <jason.wessel@windriver.com>
Reported-by: Don Zickus <dzickus@redhat.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Lin Ming <ming.m.lin@intel.com>
CC: Stephane Eranian <eranian@google.com>
CC: Peter Zijlstra <peterz@infradead.org>
---

Don, I know this one still doesn't improve the situation on real p4 cpu
with perf top if nmi-watchdog enabled, but at least lets put it public
for more wide review, maybe some idea will appear :)

 arch/x86/include/asm/perf_event_p4.h |    3 +++
 arch/x86/kernel/cpu/perf_event_p4.c  |   28 +++++++++++++++-------------
 2 files changed, 18 insertions(+), 13 deletions(-)

Index: linux-2.6.git/arch/x86/include/asm/perf_event_p4.h
=====================================================================
--- linux-2.6.git.orig/arch/x86/include/asm/perf_event_p4.h
+++ linux-2.6.git/arch/x86/include/asm/perf_event_p4.h
@@ -20,6 +20,9 @@
 #define ARCH_P4_MAX_ESCR	(ARCH_P4_TOTAL_ESCR - ARCH_P4_RESERVED_ESCR)
 #define ARCH_P4_MAX_CCCR	(18)
 
+#define ARCH_P4_CNTRVAL_BITS	(40)
+#define ARCH_P4_CNTRVAL_MASK	((1ULL << ARCH_P4_CNTRVAL_BITS) - 1)
+
 #define P4_ESCR_EVENT_MASK	0x7e000000U
 #define P4_ESCR_EVENT_SHIFT	25
 #define P4_ESCR_EVENTMASK_MASK	0x01fffe00U
Index: linux-2.6.git/arch/x86/kernel/cpu/perf_event_p4.c
=====================================================================
--- linux-2.6.git.orig/arch/x86/kernel/cpu/perf_event_p4.c
+++ linux-2.6.git/arch/x86/kernel/cpu/perf_event_p4.c
@@ -753,19 +753,21 @@ out:
 
 static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc)
 {
-	int overflow = 0;
-	u32 low, high;
+	u64 v;
 
-	rdmsr(hwc->config_base + hwc->idx, low, high);
-
-	/* we need to check high bit for unflagged overflows */
-	if ((low & P4_CCCR_OVF) || !(high & (1 << 31))) {
-		overflow = 1;
-		(void)checking_wrmsrl(hwc->config_base + hwc->idx,
-			((u64)low) & ~P4_CCCR_OVF);
+	/* an official way for overflow indication */
+	rdmsrl(hwc->config_base + hwc->idx, v);
+	if (v & P4_CCCR_OVF) {
+		wrmsrl(hwc->config_base + hwc->idx, v & ~P4_CCCR_OVF);
+		return 1;
 	}
 
-	return overflow;
+	/* it might be unflagged overflow */
+	rdmsrl(hwc->event_base + hwc->idx, v);
+	if (!(v & ARCH_P4_CNTRVAL_MASK))
+		return 1;
+
+	return 0;
 }
 
 static void p4_pmu_disable_pebs(void)
@@ -1152,9 +1154,9 @@ static __initconst const struct x86_pmu 
 	 */
 	.num_counters		= ARCH_P4_MAX_CCCR,
 	.apic			= 1,
-	.cntval_bits		= 40,
-	.cntval_mask		= (1ULL << 40) - 1,
-	.max_period		= (1ULL << 39) - 1,
+	.cntval_bits		= ARCH_P4_CNTRVAL_BITS,
+	.cntval_mask		= ARCH_P4_CNTRVAL_MASK,
+	.max_period		= (1ULL << (ARCH_P4_CNTRVAL_BITS - 1)) - 1,
 	.hw_config		= p4_hw_config,
 	.schedule_events	= p4_pmu_schedule_events,
 	/*


  parent reply	other threads:[~2010-11-23 22:48 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-23 22:46 [rfc 0/3] perf,x86: p4 pmu series Cyrill Gorcunov
2010-11-23 22:46 ` [rfc 1/3] perf, x86: P4 PMU - describe config format Cyrill Gorcunov
2010-11-26 10:57   ` Stephane Eranian
2010-11-26 11:14     ` Cyrill Gorcunov
2010-11-26 11:32       ` Cyrill Gorcunov
2010-11-26 11:35         ` Stephane Eranian
2010-11-26 11:58           ` Cyrill Gorcunov
2010-11-26 12:46             ` Stephane Eranian
2010-11-26 13:04               ` Cyrill Gorcunov
2010-11-26 13:06                 ` Peter Zijlstra
2010-11-26 13:47                   ` Cyrill Gorcunov
2010-11-26 13:10                 ` Stephane Eranian
2010-11-26 13:50                   ` Cyrill Gorcunov
2010-11-26 13:54                     ` Stephane Eranian
2010-11-26 15:27                       ` Cyrill Gorcunov
2010-11-26 16:22                         ` Stephane Eranian
2010-11-26 17:16                           ` Cyrill Gorcunov
2010-11-26 18:05                             ` Stephane Eranian
2010-11-26 20:11                               ` Cyrill Gorcunov
2010-11-26 12:48   ` Stephane Eranian
2010-11-26 12:59     ` Peter Zijlstra
2010-11-26 13:07       ` Stephane Eranian
2010-11-26 13:07       ` Cyrill Gorcunov
2010-11-23 22:46 ` Cyrill Gorcunov [this message]
2010-11-23 22:46 ` [rfc 3/3] perf, x86: P4 PMU -- export ABI part of event config to userspace Cyrill Gorcunov
2010-11-24  8:32   ` Peter Zijlstra
2010-11-24  8:48     ` Cyrill Gorcunov
2010-11-24  9:02       ` Peter Zijlstra
2010-11-24  9:39         ` Cyrill Gorcunov
2010-11-24 11:46           ` Cyrill Gorcunov

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=20101123224800.485217113@openvz.org \
    --to=gorcunov@openvz.org \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.m.lin@intel.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /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