aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNadav Amit <namit@cs.technion.ac.il>2014-08-20 06:25:52 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2014-08-20 07:01:25 -0400
commitd27aa7f15c3b1105c8cd8c2d190ab354f877cac5 (patch)
tree8dc7288ebafc088d36fa192950893ce8126d18b6
parenta32e84594ddf018cc618a8781298804c3e6131ce (diff)
KVM: x86: Clarify PMU related features bit manipulation
kvm_pmu_cpuid_update makes a lot of bit manuiplation operations, when in fact there are already unions that can be used instead. Changing the bit manipulation to the union for clarity. This patch does not change the functionality. Signed-off-by: Nadav Amit <namit@cs.technion.ac.il> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/pmu.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 3dd6accb64ec..8e6b7d869d2f 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -15,6 +15,7 @@
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/kvm_host.h> 16#include <linux/kvm_host.h>
17#include <linux/perf_event.h> 17#include <linux/perf_event.h>
18#include <asm/perf_event.h>
18#include "x86.h" 19#include "x86.h"
19#include "cpuid.h" 20#include "cpuid.h"
20#include "lapic.h" 21#include "lapic.h"
@@ -463,7 +464,8 @@ void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu)
463{ 464{
464 struct kvm_pmu *pmu = &vcpu->arch.pmu; 465 struct kvm_pmu *pmu = &vcpu->arch.pmu;
465 struct kvm_cpuid_entry2 *entry; 466 struct kvm_cpuid_entry2 *entry;
466 unsigned bitmap_len; 467 union cpuid10_eax eax;
468 union cpuid10_edx edx;
467 469
468 pmu->nr_arch_gp_counters = 0; 470 pmu->nr_arch_gp_counters = 0;
469 pmu->nr_arch_fixed_counters = 0; 471 pmu->nr_arch_fixed_counters = 0;
@@ -475,25 +477,27 @@ void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu)
475 entry = kvm_find_cpuid_entry(vcpu, 0xa, 0); 477 entry = kvm_find_cpuid_entry(vcpu, 0xa, 0);
476 if (!entry) 478 if (!entry)
477 return; 479 return;
480 eax.full = entry->eax;
481 edx.full = entry->edx;
478 482
479 pmu->version = entry->eax & 0xff; 483 pmu->version = eax.split.version_id;
480 if (!pmu->version) 484 if (!pmu->version)
481 return; 485 return;
482 486
483 pmu->nr_arch_gp_counters = min((int)(entry->eax >> 8) & 0xff, 487 pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters,
484 INTEL_PMC_MAX_GENERIC); 488 INTEL_PMC_MAX_GENERIC);
485 pmu->counter_bitmask[KVM_PMC_GP] = 489 pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1;
486 ((u64)1 << ((entry->eax >> 16) & 0xff)) - 1; 490 pmu->available_event_types = ~entry->ebx &
487 bitmap_len = (entry->eax >> 24) & 0xff; 491 ((1ull << eax.split.mask_length) - 1);
488 pmu->available_event_types = ~entry->ebx & ((1ull << bitmap_len) - 1);
489 492
490 if (pmu->version == 1) { 493 if (pmu->version == 1) {
491 pmu->nr_arch_fixed_counters = 0; 494 pmu->nr_arch_fixed_counters = 0;
492 } else { 495 } else {
493 pmu->nr_arch_fixed_counters = min((int)(entry->edx & 0x1f), 496 pmu->nr_arch_fixed_counters =
497 min_t(int, edx.split.num_counters_fixed,
494 INTEL_PMC_MAX_FIXED); 498 INTEL_PMC_MAX_FIXED);
495 pmu->counter_bitmask[KVM_PMC_FIXED] = 499 pmu->counter_bitmask[KVM_PMC_FIXED] =
496 ((u64)1 << ((entry->edx >> 5) & 0xff)) - 1; 500 ((u64)1 << edx.split.bit_width_fixed) - 1;
497 } 501 }
498 502
499 pmu->global_ctrl = ((1 << pmu->nr_arch_gp_counters) - 1) | 503 pmu->global_ctrl = ((1 << pmu->nr_arch_gp_counters) - 1) |