[tip:tools/kvm] kvm tools: Don' t disable PerfMon if host does not support it

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  8c2537c9826eac50311c57077b90961caa99d454
Gitweb:     http://git.kernel.org/tip/8c2537c9826eac50311c57077b90961caa99d454
Author:     Cyrill Gorcunov <gorcunov@xxxxxxxxx>
AuthorDate: Tue, 1 Oct 2013 20:07:02 +0400
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Fri, 1 Nov 2013 10:52:54 +0200

kvm tools: Don't disable PerfMon if host does not support it

KVM provides of PMU with architectural events, so don't disable
the NMI drivent based performance events when they are available
on the host.

Signed-off-by: Cyrill Gorcunov <gorcunov@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Pekka Enberg <penberg@xxxxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Sasha Levin <sasha.levin@xxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxxxxx>
Cc: Asias He <asias.hejun@xxxxxxxxx>
---
 tools/kvm/x86/cpuid.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/tools/kvm/x86/cpuid.c b/tools/kvm/x86/cpuid.c
index 72ab983..c3b67d9 100644
--- a/tools/kvm/x86/cpuid.c
+++ b/tools/kvm/x86/cpuid.c
@@ -6,8 +6,6 @@
 #include <sys/ioctl.h>
 #include <stdlib.h>
 
-#define CPUID_FUNC_PERFMON		0x0A
-
 #define	MAX_KVM_CPUID_ENTRIES		100
 
 static void filter_cpuid(struct kvm_cpuid2 *kvm_cpuid)
@@ -38,9 +36,32 @@ static void filter_cpuid(struct kvm_cpuid2 *kvm_cpuid)
 			/* Clear X86_FEATURE_EPB */
 			entry->ecx = entry->ecx & ~(1 << 3);
 			break;
-		case CPUID_FUNC_PERFMON:
-			entry->eax = 0x00; /* disable it */
+		case 10: { /* Architectural Performance Monitoring */
+			union cpuid10_eax {
+				struct {
+					unsigned int version_id		:8;
+					unsigned int num_counters	:8;
+					unsigned int bit_width		:8;
+					unsigned int mask_length	:8;
+				} split;
+				unsigned int full;
+			} eax;
+
+			/*
+			 * If the host has perf system running,
+			 * but no architectural events available
+			 * through kvm pmu -- disable perf support,
+			 * thus guest won't even try to access msr
+			 * registers.
+			 */
+			if (entry->eax) {
+				eax.full = entry->eax;
+				if (eax.split.version_id != 2 ||
+				    !eax.split.num_counters)
+					entry->eax = 0;
+			}
 			break;
+		}
 		default:
 			/* Keep the CPUID function as -is */
 			break;
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux