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

Re: [libvirt] [PATCH] kvm: maxVCPU runtime detection



On Fri, Aug 22, 2008 at 03:16:42PM +0200, Guido G?nther wrote:
> 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

>  
> +dnl
> +dnl check for kvm headers
> +dnl
> +AC_CHECK_HEADERS([linux/kvm.h])

Hmm, I wonder if that's commonly installed by Fedora/Debian RPMs
for KVM....

It might be neccessary to just #define the IOCTL constant in
our own header files if its not available.

> @@ -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;
> +}

This is all very cool. IIRC Cole has some code which could guess
a reasonable maxvcpus from KVM version number which we could
potentially fallback to

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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