[libvirt] [PATCH] kvm: maxVCPU runtime detection

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

 



Hi,
with recent linux kernels we can detect the maximum number of virtual
cpus at runtime via an ioctl. Possible patch attached. It does this on
every call to qemudGetMaxVCPUs. Would you prefer something that does
this only once in qemudStartup()?
Cheers,
 -- Guido
>From 2e7d875ce080360035b43b2f2125b23073f8dcc0 Mon Sep 17 00:00:00 2001
From: Guido Guenther <agx@xxxxxxxxxxx>
Date: Fri, 22 Aug 2008 14:47:49 +0200
Subject: [PATCH] for kvm determine maxVCPUs at runtime

needs linux > 2.6.26
---
 configure.in      |    5 +++++
 src/qemu_driver.c |   33 ++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/configure.in b/configure.in
index 14dd776..f88e00b 100644
--- a/configure.in
+++ b/configure.in
@@ -303,6 +303,11 @@ if test "$with_qemu" = "yes" ; then
                    AC_MSG_ERROR([You must install kernel-headers in order to compile libvirt]))
 fi
 
+dnl
+dnl check for kvm headers
+dnl
+AC_CHECK_HEADERS([linux/kvm.h])
+
 dnl Need to test if pkg-config exists
 PKG_PROG_PKG_CONFIG
 
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 5b8e6a6..511749b 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -44,6 +44,7 @@
 #include <pwd.h>
 #include <stdio.h>
 #include <sys/wait.h>
+#include <sys/ioctl.h>
 
 #if HAVE_NUMACTL
 #include <numa.h>
@@ -53,6 +54,10 @@
 #include <sched.h>
 #endif
 
+#if HAVE_LINUX_KVM_H
+#include <linux/kvm.h>
+#endif
+
 #include "qemu_driver.h"
 #include "qemu_conf.h"
 #include "c-ctype.h"
@@ -72,6 +77,9 @@
 static int qemudShutdown(void);
 #endif
 
+/* device for kvm ioctls */
+#define KVM_DEVICE "/dev/kvm"
+
 /* qemudDebug statements should be changed to use this macro instead. */
 #define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
 #define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
@@ -1768,6 +1776,29 @@ static const char *qemudGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
     return "QEMU";
 }
 
+
+static int kvmGetMaxVCPUs(void) {
+    int maxvcpus = 1;
+
+#if defined(KVM_CAP_NR_VCPUS)
+    int r, fd;
+
+    fd = open(KVM_DEVICE, O_RDONLY);
+    if (fd < 0) {
+        qemudLog(QEMUD_WARN, _("Unable to open " KVM_DEVICE ": %s\n"), strerror(errno));
+        return maxvcpus;
+    }
+
+    r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
+    if (r > 0)
+        maxvcpus = r;
+
+    close(fd);
+#endif
+    return maxvcpus;
+}
+
+
 static int qemudGetMaxVCPUs(virConnectPtr conn, const char *type) {
     if (!type)
         return 16;
@@ -1778,7 +1809,7 @@ static int qemudGetMaxVCPUs(virConnectPtr conn, const char *type) {
     /* XXX future KVM will support SMP. Need to probe
        kernel to figure out KVM module version i guess */
     if (STRCASEEQ(type, "kvm"))
-        return 1;
+        return kvmGetMaxVCPUs();
 
     if (STRCASEEQ(type, "kqemu"))
         return 1;
-- 
1.5.6.3

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]