All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Chao Peng <chao.p.peng@linux.intel.com>
Subject: [Qemu-devel] [PULL 12/30] target-i386: kvm: cache KVM_GET_SUPPORTED_CPUID data
Date: Thu, 16 Jun 2016 16:16:07 +0200	[thread overview]
Message-ID: <1466086585-16526-13-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1466086585-16526-1-git-send-email-pbonzini@redhat.com>

From: Chao Peng <chao.p.peng@linux.intel.com>

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 <chao.p.peng@linux.intel.com>
Message-Id: <1465784487-23482-1-git-send-email-chao.p.peng@linux.intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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

  parent reply	other threads:[~2016-06-16 14:16 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-16 14:15 [Qemu-devel] [PULL 00/30] KVM, build, NBD, SCSI patches for 2016-06-16 Paolo Bonzini
2016-06-16 14:15 ` [Qemu-devel] [PULL 01/30] configure: Remove unused CONFIG_ZERO_MALLOC setting Paolo Bonzini
2016-06-16 14:15 ` [Qemu-devel] [PULL 02/30] os-posix: include sys/mman.h Paolo Bonzini
2016-06-16 14:15 ` [Qemu-devel] [PULL 03/30] clean-includes: run it once more Paolo Bonzini
2016-06-16 14:15 ` [Qemu-devel] [PULL 04/30] configure: Enable -Werror for MinGW builds, too Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 05/30] Makefile: Fix tag file generation targets Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 06/30] Make avx2 configure test work with -O2 Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 07/30] avx2 configure: Use primitives in test Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 08/30] configure: Remove unused CONFIG_SIGEV_THREAD_ID switch Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 09/30] nbd: Don't use *_to_cpup() functions Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 10/30] nbd: Don't use cpu_to_*w() functions Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 11/30] nbd: simplify the nbd_request and nbd_reply structs Paolo Bonzini
2016-06-16 14:16 ` Paolo Bonzini [this message]
2016-06-16 14:16 ` [Qemu-devel] [PULL 13/30] scsi-disk: Use (unsigned long) typecasts when using "%lu" format string Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 14/30] linux-headers: update to Linux 4.6 Paolo Bonzini
2016-06-16 16:09   ` Christian Borntraeger
2016-06-16 16:31     ` Greg Kurz
2016-06-16 14:16 ` [Qemu-devel] [PULL 15/30] KVM: use KVM_CAP_MAX_VCPU_ID Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 16/30] vl.c: Add '-L help' which lists data dirs Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 17/30] nbd: Use BDRV_REQ_FUA for better FUA where supported Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 18/30] nbd: More debug typo fixes, use correct formats Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 19/30] nbd: Quit server after any write error Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 20/30] nbd: Improve server handling of bogus commands Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 21/30] nbd: Reject unknown request flags Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 22/30] nbd: Group all Linux-specific ioctl code in one place Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 23/30] nbd: Clean up ioctl handling of qemu-nbd -c Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 24/30] nbd: Detect servers that send unexpected error values Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 25/30] nbd: Avoid magic number for NBD max name size Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 26/30] scsi: esp: check buffer length before reading scsi command Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 27/30] scsi: esp: respect FIFO invariant after message phase Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 28/30] scsi: esp: clean up handle_ti/esp_do_dma if s->do_cmd Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 29/30] scsi: esp: make cmdbuf big enough for maximum CDB size Paolo Bonzini
2016-06-16 14:16 ` [Qemu-devel] [PULL 30/30] vl: smp_parse: cleanups Paolo Bonzini
2016-06-21 15:40   ` Igor Mammedov
2016-06-21 16:22     ` Andrew Jones
2016-06-16 16:02 ` [Qemu-devel] [PULL 00/30] KVM, build, NBD, SCSI patches for 2016-06-16 Peter Maydell
2016-06-16 16:29   ` Paolo Bonzini
2016-06-16 16:55     ` Peter Maydell
2016-06-16 17:01       ` Paolo Bonzini
2016-06-16 17:08         ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466086585-16526-13-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.