OpenCloudOS-Kernel/arch/x86/kvm/svm
Like Xu ea5cbc9ff8 KVM: x86/svm/pmu: Rewrite get_gp_pmc_amd() for more counters scalability
If the number of AMD gp counters continues to grow, the code will
be very clumsy and the switch-case design of inline get_gp_pmc_amd()
will also bloat the kernel text size.

The target code is taught to manage two groups of MSRs, each
representing a different version of the AMD PMU counter MSRs.
The MSR addresses of each group are contiguous, with no holes,
and there is no intersection between two sets of addresses,
but they are discrete in functionality by design like this:

[Group A : All counter MSRs are tightly bound to all event select MSRs ]

  MSR_K7_EVNTSEL0			0xc0010000
  MSR_K7_EVNTSELi			0xc0010000 + i
  ...
  MSR_K7_EVNTSEL3			0xc0010003
  MSR_K7_PERFCTR0			0xc0010004
  MSR_K7_PERFCTRi			0xc0010004 + i
  ...
  MSR_K7_PERFCTR3			0xc0010007

[Group B : The counter MSRs are interleaved with the event select MSRs ]

  MSR_F15H_PERF_CTL0		0xc0010200
  MSR_F15H_PERF_CTR0		(0xc0010200 + 1)
  ...
  MSR_F15H_PERF_CTLi		(0xc0010200 + 2 * i)
  MSR_F15H_PERF_CTRi		(0xc0010200 + 2 * i + 1)
  ...
  MSR_F15H_PERF_CTL5		(0xc0010200 + 2 * 5)
  MSR_F15H_PERF_CTR5		(0xc0010200 + 2 * 5 + 1)

Rewrite get_gp_pmc_amd() in this way: first determine which group of
registers is accessed, then determine if it matches its requested type,
applying different scaling ratios respectively, and finally get pmc_idx
to pass into amd_pmc_idx_to_pmc().

Signed-off-by: Like Xu <likexu@tencent.com>
Link: https://lore.kernel.org/r/20220831085328.45489-8-likexu@tencent.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
2022-09-28 12:47:23 -07:00
..
avic.c KVM: x86: nSVM: optimize svm_set_x2apic_msr_interception 2022-06-24 12:52:59 -04:00
hyperv.h KVM: nSVM: Split off common definitions for Hyper-V on KVM and KVM on Hyper-V 2022-02-10 13:50:45 -05:00
nested.c KVM: x86: Rename inject_pending_events() to kvm_check_and_inject_events() 2022-09-26 12:03:11 -04:00
pmu.c KVM: x86/svm/pmu: Rewrite get_gp_pmc_amd() for more counters scalability 2022-09-28 12:47:23 -07:00
sev.c KVM: SVM: Disable SEV-ES support if MMIO caching is disable 2022-08-10 15:08:25 -04:00
svm.c KVM: SVM: Make an event request if INIT or SIPI is pending when GIF is set 2022-09-26 12:37:19 -04:00
svm.h Merge remote-tracking branch 'kvm/next' into kvm-next-5.20 2022-08-01 03:21:00 -04:00
svm_onhyperv.c KVM: SVM: Fix kvm_cache_regs.h inclusions for is_guest_mode() 2022-04-02 05:34:40 -04:00
svm_onhyperv.h KVM: nSVM: Split off common definitions for Hyper-V on KVM and KVM on Hyper-V 2022-02-10 13:50:45 -05:00
svm_ops.h x86/kvm: Always inline vmload() / vmsave() 2021-09-15 15:51:45 +02:00
vmenter.S x86: Add magic AMD return-thunk 2022-06-27 10:33:59 +02:00