PMU tests
cover PMU tests
Following is a simple unit test for the PMU emulation.
Avi Kivity (4):
Build tests with optimization enabled
startup: prepare CPU for floating point operation Add rdpmc instruction accessor
Add PMU test
Makefile | 2 +- config-x86-common.mak | 4 ++- lib/x86/processor.h | 8 ++++++ lib/x86/smp.c | 9 +++++++ x86/cstart.S | 2 + x86/cstart64.S | 2 + x86/pmu.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 x86/pmu.c
Signature · 1 line
1.7.5.3
PATCH 1/4 Build tests with optimization enabled
Signed-off-by Avi Kivity <[email protected]>
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -6,7 +6,7 @@ DESTDIR := $(PREFIX)/share/qemu/tests .PHONY: arch_clean clean #make sure env CFLAGS variable is not used -CFLAGS = -g +CFLAGS = -g -O2 libgcc := $(shell $(CC) --print-libgcc-file-name)
Signature · 1 line
1.7.5.3
PATCH 2/4 startup: prepare CPU for floating point operation
In reply to Avi Kivity- Clear cr0.ts
- Enable cr4.osxsave and cr4.osxmmexcpt (for sse)
Signed-off-by Avi Kivity <[email protected]>
--- lib/x86/smp.c | 9 +++++++++ x86/cstart.S | 2 ++ x86/cstart64.S | 2 ++ 3 files changed, 13 insertions(+), 0 deletions(-)
lib/x86/smp.c +9 -0
@@ -3,6 +3,7 @@#include "smp.h" #include "apic.h" #include "fwcfg.h" +#include "processor.h" #define IPI_VECTOR 0x20
@@ -124,6 +125,14 @@ void on_cpu_async(int cpu, void (*function)(void *data), void *data)__on_cpu (cpu, function, data,0 ); } +void __setup_cpu (void *data) +{ +write_cr4 (read_cr4 () + |0x200 /* OSFXSR; for SSE */ + |0x400 /* OSXMMEXCPT, ditto */ + ); + asmvolatile ("clts" ); +}void smp_init (void ) {
x86/cstart.S +2 -0
@@ -121,6 +121,7 @@ ap_start32: sti nop lock incw cpu_online_count + call __setup_cpu 1: hlt jmp 1b
@@ -172,6 +173,7 @@ smp_init: 1: pause cmpw %ax, cpu_online_count jne 1b + call __setup_cpu smp_init_done: ret
x86/cstart64.S +2 -0
@@ -170,6 +170,7 @@ ap_start64: call load_tss call enable_apic call enable_x2apic + call __setup_cpu sti nop lock incw cpu_online_count
@@ -234,6 +235,7 @@ smp_init: 1: pause cmpw %ax, cpu_online_count jne 1b + call __setup_cpu smp_init_done: ret
Signature · 1 line
1.7.5.3
PATCH 3/4 Add rdpmc instruction accessor
In reply to Avi KivitySigned-off-by Avi Kivity <[email protected]>
--- lib/x86/processor.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
lib/x86/processor.h +8 -0
@@ -2,6 +2,7 @@#define LIBCFLAT_PROCESSOR_H #include "libcflat.h" +#include <stdint.h> struct descriptor_table_ptr {u16 limit;
@@ -99,6 +100,13 @@ static inline void wrmsr(u32 index, u64 val) asmvolatile ("wrmsr" : :"a" (a),"d" (d),"c" (index) :"memory" ); } +static inline uint64_t rdpmc (uint32_t index) +{ +uint32_t a, d; + asmvolatile ("rdpmc" :"=a" (a),"=d" (d) :"c" (index)); +return a | ((uint64_t )d <<32 ); +} +static inline void write_cr0 (ulong val) { asmvolatile ("mov %0, %%cr0" : :"r" (val) :"memory" );
Signature · 1 line
1.7.5.3
PATCH 4/4 Add PMU test
In reply to Avi KivitySigned-off-by Avi Kivity <[email protected]>
--- config-x86-common.mak | 4 ++- x86/pmu.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletions(-) create mode 100644 x86/pmu.c
config-x86-common.mak +3 -1
@@ -34,7 +34,7 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \ $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \ $(TEST_DIR)/kvmclock_test.flat $(TEST_DIR)/eventinj.flat \ - $(TEST_DIR)/s3.flat + $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat tests-common += api/api-sample tests-common += api/dirty-log
@@ -85,6 +85,8 @@ $(TEST_DIR)/eventinj.elf: $(cstart.o) $(TEST_DIR)/eventinj.o $(TEST_DIR)/s3.elf: $(cstart.o) $(TEST_DIR)/s3.o +$(TEST_DIR)/pmu.elf: $(cstart.o) $(TEST_DIR)/pmu.o + arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
x86/pmu.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.5.3