Re: [kvm-unit-tests PATCH v4 14/24] x86/pmu: Read cpuid(10) in the pmu_init() to reduce VM-Exit

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

 



On Mon, Oct 24, 2022, Like Xu wrote:
> From: Like Xu <likexu@xxxxxxxxxxx>
> 
> The type of CPUID accessors can also go in the common pmu. Re-reading
> cpuid(10) each time when needed, adding the overhead of eimulating
> CPUID isn't meaningless in the grand scheme of the test.
> 
> A common "PMU init" routine would allow the library to provide helpers
> access to more PMU common information.
> 
> Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Signed-off-by: Like Xu <likexu@xxxxxxxxxxx>
> ---
>  lib/x86/pmu.c |  7 +++++++
>  lib/x86/pmu.h | 26 +++++++++++++-------------
>  lib/x86/smp.c |  2 ++
>  3 files changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/lib/x86/pmu.c b/lib/x86/pmu.c
> index 9d048ab..e8b9ae9 100644
> --- a/lib/x86/pmu.c
> +++ b/lib/x86/pmu.c
> @@ -1 +1,8 @@
>  #include "pmu.h"
> +
> +struct cpuid cpuid_10;
> +
> +void pmu_init(void)
> +{
> +    cpuid_10 = cpuid(10);

Tabs, not spaces.

> +}
> \ No newline at end of file
> diff --git a/lib/x86/pmu.h b/lib/x86/pmu.h
> index 078a974..7f4e797 100644
> --- a/lib/x86/pmu.h
> +++ b/lib/x86/pmu.h
> @@ -33,9 +33,13 @@
>  #define EVNTSEL_INT	(1 << EVNTSEL_INT_SHIFT)
>  #define EVNTSEL_INV	(1 << EVNTSEL_INV_SHIF)
>  
> +extern struct cpuid cpuid_10;

Instead of taking a raw snapshot of CPUID.0xA, process the CPUID info during
pmu_init() and fill "struct pmu_cap pmu" directly.

> diff --git a/lib/x86/smp.c b/lib/x86/smp.c
> index b9b91c7..29197fc 100644
> --- a/lib/x86/smp.c
> +++ b/lib/x86/smp.c
> @@ -4,6 +4,7 @@
>  #include <asm/barrier.h>
>  
>  #include "processor.h"
> +#include "pmu.h"
>  #include "atomic.h"
>  #include "smp.h"
>  #include "apic.h"
> @@ -155,6 +156,7 @@ void smp_init(void)
>  		on_cpu(i, setup_smp_id, 0);
>  
>  	atomic_inc(&active_cpus);
> +	pmu_init();

Initializing the PMU has nothing to do with SMP initialization.  There's also an
opportunity for more cleanup: all paths call bringup_aps() => enable_x2apic() =>
smp_init(), providing a kitchen sink helper can consolidate that code and provide
a convenient location for PMU initialization.

void bsp_rest_init(void)
{
	bringup_aps();
	enable_x2apic();
	smp_init();
	pmu_init();
}



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux