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

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

 



"Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
> 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....

I've just checked up to date rawhide and debian unstable systems.
Both had this:

    $ grep KVM_CHECK_EXTENSION /usr/include/linux/kvm.h
    #define KVM_CHECK_EXTENSION       _IO(KVMIO,   0x03)

But rawhide lacks KVM_CAP_NR_VCPUS, while Debian has it.

    $ grep -r KVM_CAP_NR_VCPUS /usr/include/linux/kvm.h
    #define KVM_CAP_NR_VCPUS 9       /* returns max vcpus per vm */

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

Good point.
Otherwise, this patch looks fine.

>> @@ -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

--
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]