Skip to contentSkip to conversation

perf/x86: Use KERN_INFO when checking PMU fails on virtual environment

PATCH In review Wei Huang 4 participants 6 messages Sep 25, 2014 – Oct 28, 2014

Subsystems (2)
lore
Share & tools
lore

Wei Huang

author
#0 lore raw

PATCH 1/1 perf/x86: Use KERN_INFO when checking PMU fails on virtual environment

PMU checking can fail due to various reasons. On native machine, this is mostly caused by faulty hardware and it is reasonable to use KERN_ERR in reporting. However, when kernel is running on virtualized environment, this checking can fail if virtual PMU is not supported (e.g. KVM on AMD host). It is annoying to see an error message on splash screen, even though we know such failure is benign on virtualized environment.

This patch checks if kernel is running in virtualized environment. If so, it will use KERN_INFO in reporting. This patch was tested successfully on KVM.

---
 arch/x86/kernel/cpu/perf_event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event.c +2 -1
index 918d75f..16c7302 100644
@@ -243,7 +243,8 @@ static bool check_hw_exists(void)
 
 msr_fail:
 	printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n");
-	printk(KERN_ERR "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
+	printk(boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR
+	       "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
 
 	return false;
 }
Signature · 1 line
1.9.3
author
#1 lore raw

Hi Ingo, tglx and hpa,

Any comment on this patch? Thanks.

-Wei

Quoted 32 lines · Wei Huang

PMU checking can fail due to various reasons. On native machine, this is mostly caused by faulty hardware and it is reasonable to use KERN_ERR in reporting. However, when kernel is running on virtualized environment, this checking can fail if virtual PMU is not supported (e.g. KVM on AMD host). It is annoying to see an error message on splash screen, even though we know such failure is benign on virtualized environment.

This patch checks if kernel is running in virtualized environment. If so, it will use KERN_INFO in reporting. This patch was tested successfully on KVM.

---
  arch/x86/kernel/cpu/perf_event.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event.c +2 -1
index 918d75f..16c7302 100644
@@ -243,7 +243,8 @@ static bool check_hw_exists(void)
 
  msr_fail:
  	printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n");
-	printk(KERN_ERR "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
+	printk(boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR
+	       "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
 
  	return false;
  }
#2 lore raw

[tip:perf/core] perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment

In reply to Wei Huang
perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment
Commit-ID:  cc6cd47e7395bc05c5077009808b820633eb3f18
Gitweb:     http://git.kernel.org/tip/cc6cd47e7395bc05c5077009808b820633eb3f18
Author:     Wei Huang <[email protected]>
AuthorDate: Wed, 24 Sep 2014 22:55:14 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Oct 2014 06:04:41 +0200

perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment

PMU checking can fail due to various reasons. On native machine, this is mostly caused by faulty hardware and it is reasonable to use KERN_ERR in reporting. However, when kernel is running on virtualized environment, this checking can fail if virtual PMU is not supported (e.g. KVM on AMD host). It is annoying to see an error message on splash screen, even though we know such failure is benign on virtualized environment.

This patch checks if the kernel is running in a virtualized environment. If so, it will use KERN_INFO in reporting, which reduces the syslog priority of them. This patch was tested successfully on KVM.

---
 arch/x86/kernel/cpu/perf_event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event.c +2 -1
index 918d75f..16c7302 100644
@@ -243,7 +243,8 @@ static bool check_hw_exists(void)
 
 msr_fail:
 	printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n");
-	printk(KERN_ERR "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
+	printk(boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR
+	       "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
 
 	return false;
 }
#3 lore raw

Re: [tip:perf/core] perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment

Quoted 35 lines · tip-bot for Wei Huang
Commit-ID:  cc6cd47e7395bc05c5077009808b820633eb3f18
Gitweb:     http://git.kernel.org/tip/cc6cd47e7395bc05c5077009808b820633eb3f18
Author:     Wei Huang <[email protected]>
AuthorDate: Wed, 24 Sep 2014 22:55:14 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Oct 2014 06:04:41 +0200

perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment

PMU checking can fail due to various reasons. On native machine, this is mostly caused by faulty hardware and it is reasonable to use KERN_ERR in reporting. However, when kernel is running on virtualized environment, this checking can fail if virtual PMU is not supported (e.g. KVM on AMD host). It is annoying to see an error message on splash screen, even though we know such failure is benign on virtualized environment.

This patch checks if the kernel is running in a virtualized environment. If so, it will use KERN_INFO in reporting, which reduces the syslog priority of them. This patch was tested successfully on KVM.

---
 arch/x86/kernel/cpu/perf_event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event.c +0 -0
index 918d75f..16c7302 100644

arch/x86/kernel/cpu/perf_event.c static bool check_hw_exists(void) · line 248

Quoted 7 lines
arch/x86/kernel/cpu/perf_event.c +2 -1
@@ -243,7 +243,8 @@ static bool check_hw_exists(void)
 
 msr_fail:
 	printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n");
-	printk(KERN_ERR "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
+	printk(boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR
+	       "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
 

This is bogus. String concatenation doesn't work like that.

Try "%sFailed...", boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_ERR :
KERN_INFO), etc.

--Andy

maintainer
#4 lore raw

Re: [tip:perf/core] perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment

Quoted 10 lines · Andy Lutomirski

Review

Quoted 6 lines · tip-bot for Wei Huang

msr_fail:

(quoted diff) +2 -1
 	printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n");
-	printk(KERN_ERR "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
+	printk(boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR
+	       "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);

This is bogus. String concatenation doesn't work like that.

Quoted 2 lines

Try "%sFailed...", boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_ERR :
KERN_INFO), etc.

Haha, indeed. The hypervisor message is empty in this case. Wei, test this much? ;-)

---
Subject: perf: Fix bogus kernel printk

Andy spotted the fail in what was intended as a conditional printk level.

Fixes cc6cd47e7395 ("perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment")
---
 arch/x86/kernel/cpu/perf_event.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event.c +3 -2
@@ -243,8 +243,9 @@ static bool check_hw_exists(void)
 
 msr_fail:
 	printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n");
-	printk(boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR
-	       "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
+	printk("%sFailed to access perfctr msr (MSR %x is %Lx)\n",
+		boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR,
+		reg, val_new);
 
 	return false;
 }
#5 lore raw

[tip:perf/urgent] perf: Fix bogus kernel printk

perf: Fix bogus kernel printk
Commit-ID:  65d71fe1375b973083733294795bf2b09d45b3c2
Gitweb:     http://git.kernel.org/tip/65d71fe1375b973083733294795bf2b09d45b3c2
Author:     Peter Zijlstra (Intel) <[email protected]>
AuthorDate: Tue, 7 Oct 2014 19:07:33 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 28 Oct 2014 10:51:01 +0100

perf: Fix bogus kernel printk

Andy spotted the fail in what was intended as a conditional printk level.

Fixes cc6cd47e7395 ("perf/x86: Tone down kernel messages when the PMU check fails in a virtual environment")
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 arch/x86/kernel/cpu/perf_event.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event.c +3 -2
index 1b8299d..66451a6 100644
@@ -243,8 +243,9 @@ static bool check_hw_exists(void)
 
 msr_fail:
 	printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n");
-	printk(boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR
-	       "Failed to access perfctr msr (MSR %x is %Lx)\n", reg, val_new);
+	printk("%sFailed to access perfctr msr (MSR %x is %Lx)\n",
+		boot_cpu_has(X86_FEATURE_HYPERVISOR) ? KERN_INFO : KERN_ERR,
+		reg, val_new);
 
 	return false;
 }