[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/30] target-i386: kvm: cache KVM_GET_SUPPORTED_CPUI
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 12/30] target-i386: kvm: cache KVM_GET_SUPPORTED_CPUID data |
Date: |
Thu, 16 Jun 2016 16:16:07 +0200 |
From: Chao Peng <address@hidden>
KVM_GET_SUPPORTED_CPUID ioctl is called frequently when initializing
CPU. Depends on CPU features and CPU count, the number of calls can be
extremely high which slows down QEMU booting significantly. In our
testing, we saw 5922 calls with switches:
-cpu SandyBridge -smp 6,sockets=6,cores=1,threads=1
This ioctl takes more than 100ms, which is almost half of the total
QEMU startup time.
While for most cases the data returned from two different invocations
are not changed, that means, we can cache the data to avoid trapping
into kernel for the second time. To make sure the cache safe one
assumption is desirable: the ioctl is stateless. This is not true for
CPUID leaves in general (such as CPUID leaf 0xD, whose value depends
on guest XCR0 and IA32_XSS) but it is true of KVM_GET_SUPPORTED_CPUID,
which runs before there is a value for XCR0 and IA32_XSS.
Signed-off-by: Chao Peng <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
target-i386/kvm.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 7b092ee..ff92b1d 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -106,6 +106,8 @@ static int has_xsave;
static int has_xcrs;
static int has_pit_state2;
+static struct kvm_cpuid2 *cpuid_cache;
+
int kvm_has_pit_state2(void)
{
return has_pit_state2;
@@ -199,9 +201,14 @@ static struct kvm_cpuid2 *get_supported_cpuid(KVMState *s)
{
struct kvm_cpuid2 *cpuid;
int max = 1;
+
+ if (cpuid_cache != NULL) {
+ return cpuid_cache;
+ }
while ((cpuid = try_get_cpuid(s, max)) == NULL) {
max *= 2;
}
+ cpuid_cache = cpuid;
return cpuid;
}
@@ -319,8 +326,6 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t
function,
ret |= cpuid_1_edx & CPUID_EXT2_AMD_ALIASES;
}
- g_free(cpuid);
-
/* fallback for older kernels */
if ((function == KVM_CPUID_FEATURES) && !found) {
ret = get_para_features(s);
--
2.5.5
- [Qemu-devel] [PULL 01/30] configure: Remove unused CONFIG_ZERO_MALLOC setting, (continued)
- [Qemu-devel] [PULL 01/30] configure: Remove unused CONFIG_ZERO_MALLOC setting, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 04/30] configure: Enable -Werror for MinGW builds, too, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 07/30] avx2 configure: Use primitives in test, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 02/30] os-posix: include sys/mman.h, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 05/30] Makefile: Fix tag file generation targets, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 08/30] configure: Remove unused CONFIG_SIGEV_THREAD_ID switch, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 09/30] nbd: Don't use *_to_cpup() functions, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 03/30] clean-includes: run it once more, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 10/30] nbd: Don't use cpu_to_*w() functions, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 06/30] Make avx2 configure test work with -O2, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 12/30] target-i386: kvm: cache KVM_GET_SUPPORTED_CPUID data,
Paolo Bonzini <=
- [Qemu-devel] [PULL 14/30] linux-headers: update to Linux 4.6, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 13/30] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 11/30] nbd: simplify the nbd_request and nbd_reply structs, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 16/30] vl.c: Add '-L help' which lists data dirs., Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 15/30] KVM: use KVM_CAP_MAX_VCPU_ID, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 17/30] nbd: Use BDRV_REQ_FUA for better FUA where supported, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 21/30] nbd: Reject unknown request flags, Paolo Bonzini, 2016/06/16
- [Qemu-devel] [PULL 20/30] nbd: Improve server handling of bogus commands, Paolo Bonzini, 2016/06/16