Skip to contentSkip to conversation

Fix xenoprof counter overflow check

PATCH In review Niraj Tolia 2 participants 5 messages Jan 6, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix xenoprof counter overflow check

# HG changeset patch
# User Niraj Tolia <[email protected]>
# Date 1231217146 28800
# Node ID eb1ad7bbdaf3ae553a6bf319180b5880f5ac4307
# Parent 8417ddc981b407753f966c568ef8c7b673d8d22a
Xenoprof patch to fix the counter overflow check for CPUs with counter width > 32

I had to port this patch from mainline Linux where it can be found at
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=7c64ade53a6f977d73f16243865c42ceae999aea

xen/arch/x86/oprofile/op_model_ppro.c +4 -5
diff -r 8417ddc981b4 -r eb1ad7bbdaf3 xen/arch/x86/oprofile/op_model_ppro.c
@@ -25,9 +25,8 @@
 #define NUM_COUNTERS 2
 #define NUM_CONTROLS 2
 
-#define CTR_READ(l,h,msrs,c) do {rdmsr(msrs->counters[(c)].addr, (l), (h));} while (0)
 #define CTR_WRITE(l,msrs,c) do {wrmsr(msrs->counters[(c)].addr, -(u32)(l), -1);} while (0)
-#define CTR_OVERFLOWED(n) (!((n) & (1U<<31)))
+#define CTR_OVERFLOWED(n) (!((n) & (1ULL<<31)))
 
 #define CTRL_READ(l,h,msrs,c) do {rdmsr((msrs->controls[(c)].addr), (l), (h));} while (0)
 #define CTRL_WRITE(l,h,msrs,c) do {wrmsr((msrs->controls[(c)].addr), (l), (h));} while (0)
@@ -98,7 +97,7 @@ static int ppro_check_ctrs(unsigned int 
                            struct op_msrs const * const msrs,
                            struct cpu_user_regs * const regs)
 {
-	unsigned int low, high;
+	u64 val;
 	int i;
 	int ovf = 0;
 	unsigned long eip = regs->eip;
@@ -107,8 +106,8 @@ static int ppro_check_ctrs(unsigned int 
 	for (i = 0 ; i < NUM_COUNTERS; ++i) {
 		if (!reset_value[i])
 			continue;
-		CTR_READ(low, high, msrs, i);
-		if (CTR_OVERFLOWED(low)) {
+		rdmsrl(msrs->counters[i].addr, val);
+		if (CTR_OVERFLOWED(val)) {
 			xenoprof_log_event(current, regs, eip, mode, i);
 			CTR_WRITE(reset_value[i], msrs, i);
 			ovf = 1;
#1 lore raw
Quoted 8 lines · Niraj Tolia

# HG changeset patch
# User Niraj Tolia <[email protected]>
# Date 1231217146 28800
# Node ID eb1ad7bbdaf3ae553a6bf319180b5880f5ac4307
# Parent 8417ddc981b407753f966c568ef8c7b673d8d22a
Xenoprof patch to fix the counter overflow check for CPUs with counter width > 32

Quoted 5 lines

I had to port this patch from mainline Linux where it can be found at
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;
h=7c64ade53a6f977d73f16243865c42ceae999aea

This patch can't possibly build, and is pointless anyway since the overflow width check is still hardcoded to 32 bits in CTR_OVERFLOWED().

-- Keir

#2 lore raw
Quoted 12 lines · Keir Fraser
Quoted 10 lines · Niraj Tolia

# HG changeset patch
# User Niraj Tolia <[email protected]>
# Date 1231217146 28800
# Node ID eb1ad7bbdaf3ae553a6bf319180b5880f5ac4307
# Parent 8417ddc981b407753f966c568ef8c7b673d8d22a
Xenoprof patch to fix the counter overflow check for CPUs with counter width > 32

I had to port this patch from mainline Linux where it can be found at

Quoted 7 lines

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff
;

Quoted 3 lines

h=7c64ade53a6f977d73f16243865c42ceae999aea

This patch can't possibly build, and is pointless anyway since the overflow

While the mainline patch won't build, the one attached definitely does. That said, I see your point about the overflow. Now I need to figure out why this broken patch actually enables xenoprof to work on my Intel Xeon. The only reason would be the switch from CTR_READ() (which uses rdmsr() internally) to rdmsrl() but let me dig into it.

Cheers,
Niraj

Quoted 5 lines

width check is still hardcoded to 32 bits in CTR_OVERFLOWED().

-- Keir

Signature · 2 lines
Niraj Tolia, Researcher, HP Labs
http://www.hpl.hp.com/personal/Niraj_Tolia/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 5 lines · Niraj Tolia

While the mainline patch won't build, the one attached definitely does. That said, I see your point about the overflow. Now I need to figure out why this broken patch actually enables xenoprof to work on my Intel Xeon. The only reason would be the switch from CTR_READ() (which uses rdmsr() internally) to rdmsrl() but let me dig into it.

The patch absolutely did not build. There were still references to local variables ('low' and 'high') that you removed the definitions of.

-- Keir

#4 lore raw
Quoted 5 lines · Keir Fraser
Quoted 1 line · Niraj Tolia

While the mainline patch won't build, the one attached definitely does.

That

Quoted 1 line

said, I see your point about the overflow. Now I need to figure out why

Quoted 9 lines

this

Quoted 2 lines

broken patch actually enables xenoprof to work on my Intel Xeon. The only reason would be the switch from CTR_READ() (which uses rdmsr()

internally) to

Quoted 1 line

rdmsrl() but let me dig into it.

The patch absolutely did not build. There were still references to local variables ('low' and 'high') that you removed the definitions of.

Ah. My patch was generated against xen-3.3-testing.hg. I just noticed that the same function has a number of changes in xen-unstable and would cause a build failure. Sorry about that.

Niraj

Quoted 5 lines

-- Keir

Signature · 2 lines
Niraj Tolia, Researcher, HP Labs
http://www.hpl.hp.com/personal/Niraj_Tolia/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel