[Libvir] New (last ?) virtual cpu functions proposal

Here the new virtual cpu functions proposal. What do you think about it ? /** * *virVcpuInfo*: structure for information about a virtual CPU in a domain. */ typedef enum { VIR_VCPU_OFFLINE = 0, /* the virtual CPU is offline */ VIR_VCPU_RUNNING = 1, /* the virtual CPU is running */ VIR_VCPU_BLOCKED = 2, /* the virtual CPU is blocked on resource */ *} virVcpuState*; typedef struct _virVcpuInfo virVcpuInfo; struct _virVcpuInfo { unsigned int number; /* virtual CPU number */ int state; /* value from virVcpuState */ unsigned long long cpuTime; /* CPU time used, in nanoseconds */ int cpu; /* real CPU number, or -1 if offline */ }; typedef virVcpuInfo **virVcpuInfoPtr*; /** * *virDomainSetVcpus*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*nvcpus*: the new number of virtual CPUs for this domain * * Dynamically change the number of virtual CPUs used by the domain. * Note that this call may fail if the underlying virtualization hypervisor * does not support it or if growing the number is arbitrary limited. * This function requires priviledged access to the hypervisor. * * Returns 0 in case of success, -1 in case of failure. */ int *virDomainSetVcpus* (virDomainPtr domain, unsigned int nvcpus); /** * *virDomainPinVcpu*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*vcpu*: virtual CPU number * @*cpumap*: pointer to a bit map of real CPUs (in 8-bit bytes). * Each bit set to 1 means that corresponding CPU is usable. * Bytes are stored in little-endian order: CPU0-7, 8-15... * In each byte, lowest CPU number is least significant bit. * @*maplen*: number of bytes in cpumap, from 1 up to size of CPU map in * underlying virtualization system (Xen...). * If maplen < size, missing bytes are set to zero. * If maplen > size, failure code is returned. * * Dynamically change the real CPUs which can be allocated to a virtual CPU. * This function requires priviledged access to the hypervisor. * * Returns 0 in case of success, -1 in case of failure. */ int *virDomainPinVcpu* (virDomainPtr domain, unsigned int vcpu, unsigned char *cpumap, int maplen); /* Macros for bit manipulation in cpumap */ #define *USE_CPU*(cpumap,cpu) (cpumap[(cpu)/8] |= (1<<((cpu)%8))) #define *UNUSE_CPU*(cpumap,cpu) (cpumap[(cpu)/8] &= ~(1<<((cpu)%8))) /** * *virDomainGetVcpus*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*info*: pointer to an array of virVcpuInfo structures * @*maxinfo*: number of structures in info array * @*cpumaps*: pointer to a bit map of real CPUs for all vcpus of this domain. * If cpumaps is NULL, then no cpumap information is returned by the API. * It's assumed there is <maxinfo> cpumap in cpumaps. * The memory allocated to cpumaps must be (maxinfo * maplen) bytes. * One cpumap inside cupmaps have the format described in virDomainPinVcpu API. * @*maplen*: number of bytes in one cpumap, from 1 up to size of CPU map in * underlying virtualization system (Xen...). * * Extract information about virtual CPUs of domain, store it in info array. * * Returns the number of info filled in case of success, -1 in case of failure. */ int *virDomainGetVcpus* (virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, unsigned char *cpumaps, /* may be NULL */ int maplen); /* Macros for bit testing in cpumaps */ #define *CPU_USABLE*(cpumaps,maplen,vcpu,cpu) \ (cpumaps[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8))) /* * Macro for copying the cpumap of a vcpu from cupmaps inside a standalone cpumap. * This macro is useful in case of using virDomainPinVcpu() after virDomainGetVcpus(). * cpumap must be previously allocated. */ #define *COPY_CPUMAP*(cpumaps,maplen,vcpu,cpumap) \ memcpy(cpumap, &(cpumaps[(vcpu)*(maplen)]), (maplen))

On Wed, Aug 02, 2006 at 11:47:14AM +0200, Philippe Berthault wrote:
Here the new virtual cpu functions proposal. What do you think about it ?
looks fine to me, except for some extra '*' showing up around identifiers :-) I would just add documentations for the parameters of the macros in the final version but it's a detail. thanks ! Daniel
/** * *virVcpuInfo*: structure for information about a virtual CPU in a domain. */ typedef enum { VIR_VCPU_OFFLINE = 0, /* the virtual CPU is offline */ VIR_VCPU_RUNNING = 1, /* the virtual CPU is running */ VIR_VCPU_BLOCKED = 2, /* the virtual CPU is blocked on resource */ *} virVcpuState*;
typedef struct _virVcpuInfo virVcpuInfo; struct _virVcpuInfo { unsigned int number; /* virtual CPU number */ int state; /* value from virVcpuState */ unsigned long long cpuTime; /* CPU time used, in nanoseconds */ int cpu; /* real CPU number, or -1 if offline */ }; typedef virVcpuInfo **virVcpuInfoPtr*;
/** * *virDomainSetVcpus*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*nvcpus*: the new number of virtual CPUs for this domain * * Dynamically change the number of virtual CPUs used by the domain. * Note that this call may fail if the underlying virtualization hypervisor * does not support it or if growing the number is arbitrary limited. * This function requires priviledged access to the hypervisor. * * Returns 0 in case of success, -1 in case of failure. */ int *virDomainSetVcpus* (virDomainPtr domain, unsigned int nvcpus);
/** * *virDomainPinVcpu*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*vcpu*: virtual CPU number * @*cpumap*: pointer to a bit map of real CPUs (in 8-bit bytes). * Each bit set to 1 means that corresponding CPU is usable. * Bytes are stored in little-endian order: CPU0-7, 8-15... * In each byte, lowest CPU number is least significant bit. * @*maplen*: number of bytes in cpumap, from 1 up to size of CPU map in * underlying virtualization system (Xen...). * If maplen < size, missing bytes are set to zero. * If maplen > size, failure code is returned. * * Dynamically change the real CPUs which can be allocated to a virtual CPU. * This function requires priviledged access to the hypervisor. * * Returns 0 in case of success, -1 in case of failure. */ int *virDomainPinVcpu* (virDomainPtr domain, unsigned int vcpu, unsigned char *cpumap, int maplen);
/* Macros for bit manipulation in cpumap */ #define *USE_CPU*(cpumap,cpu) (cpumap[(cpu)/8] |= (1<<((cpu)%8))) #define *UNUSE_CPU*(cpumap,cpu) (cpumap[(cpu)/8] &= ~(1<<((cpu)%8)))
/** * *virDomainGetVcpus*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*info*: pointer to an array of virVcpuInfo structures * @*maxinfo*: number of structures in info array * @*cpumaps*: pointer to a bit map of real CPUs for all vcpus of this domain. * If cpumaps is NULL, then no cpumap information is returned by the API. * It's assumed there is <maxinfo> cpumap in cpumaps. * The memory allocated to cpumaps must be (maxinfo * maplen) bytes. * One cpumap inside cupmaps have the format described in virDomainPinVcpu API. * @*maplen*: number of bytes in one cpumap, from 1 up to size of CPU map in * underlying virtualization system (Xen...). * * Extract information about virtual CPUs of domain, store it in info array. * * Returns the number of info filled in case of success, -1 in case of failure. */ int *virDomainGetVcpus* (virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, unsigned char *cpumaps, /* may be NULL */ int maplen);
/* Macros for bit testing in cpumaps */ #define *CPU_USABLE*(cpumaps,maplen,vcpu,cpu) \ (cpumaps[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8)))
/* * Macro for copying the cpumap of a vcpu from cupmaps inside a standalone cpumap. * This macro is useful in case of using virDomainPinVcpu() after virDomainGetVcpus(). * cpumap must be previously allocated. */ #define *COPY_CPUMAP*(cpumaps,maplen,vcpu,cpumap) \ memcpy(cpumap, &(cpumaps[(vcpu)*(maplen)]), (maplen))
-- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Daniel Veillard | Red Hat http://redhat.com/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

In the mail I've sent (in HTML format), there was no extra '*' around identifiers. It's seems that your mail server doesn't accept HTML and I suspect it has replaced all HTML tags by these '*'. Philippe Berthault.

On Wed, Aug 02, 2006 at 01:26:19PM +0200, Philippe Berthault wrote:
In the mail I've sent (in HTML format), there was no extra '*' around identifiers.
It's seems that your mail server doesn't accept HTML and I suspect it has replaced all HTML tags by these '*'.
This has nothing to do with mail server but with the MUA and the user. I read only the text part of mime-multipart in mails (mutt in a text login to a remote computer), in general don't expect me to read an HTML attachement ever (also mean I never read HTML only mails :-) Daniel -- Daniel Veillard | Red Hat http://redhat.com/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

Thanks for the proposal! Just a few questions inline, otherwise looks good for my use cases. Philippe Berthault wrote:
Here the new virtual cpu functions proposal. What do you think about it ?
/** * *virVcpuInfo*: structure for information about a virtual CPU in a domain. */ typedef enum { VIR_VCPU_OFFLINE = 0, /* the virtual CPU is offline */ VIR_VCPU_RUNNING = 1, /* the virtual CPU is running */ VIR_VCPU_BLOCKED = 2, /* the virtual CPU is blocked on resource */ *} virVcpuState*;
typedef struct _virVcpuInfo virVcpuInfo; struct _virVcpuInfo { unsigned int number; /* virtual CPU number */ int state; /* value from virVcpuState */ unsigned long long cpuTime; /* CPU time used, in nanoseconds */ int cpu; /* real CPU number, or -1 if offline */ }; typedef virVcpuInfo **virVcpuInfoPtr*;
/** * *virDomainSetVcpus*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*nvcpus*: the new number of virtual CPUs for this domain * * Dynamically change the number of virtual CPUs used by the domain. * Note that this call may fail if the underlying virtualization hypervisor * does not support it or if growing the number is arbitrary limited. * This function requires priviledged access to the hypervisor. * * Returns 0 in case of success, -1 in case of failure. */ int *virDomainSetVcpus* (virDomainPtr domain, unsigned int nvcpus);
/** * *virDomainPinVcpu*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*vcpu*: virtual CPU number * @*cpumap*: pointer to a bit map of real CPUs (in 8-bit bytes). * Each bit set to 1 means that corresponding CPU is usable. * Bytes are stored in little-endian order: CPU0-7, 8-15... * In each byte, lowest CPU number is least significant bit. * @*maplen*: number of bytes in cpumap, from 1 up to size of CPU map in * underlying virtualization system (Xen...). * If maplen < size, missing bytes are set to zero. * If maplen > size, failure code is returned. * * Dynamically change the real CPUs which can be allocated to a virtual CPU. * This function requires priviledged access to the hypervisor. * * Returns 0 in case of success, -1 in case of failure. */ int *virDomainPinVcpu* (virDomainPtr domain, unsigned int vcpu, unsigned char *cpumap, int maplen);
How do I get the "size of CPU map in underlying virtualization system" described in maplen comments?
/* Macros for bit manipulation in cpumap */ #define *USE_CPU*(cpumap,cpu) (cpumap[(cpu)/8] |= (1<<((cpu)%8))) #define *UNUSE_CPU*(cpumap,cpu) (cpumap[(cpu)/8] &= ~(1<<((cpu)%8)))
/** * *virDomainGetVcpus*: * @*domain*: pointer to domain object, or NULL for Domain0 * @*info*: pointer to an array of virVcpuInfo structures * @*maxinfo*: number of structures in info array * @*cpumaps*: pointer to a bit map of real CPUs for all vcpus of this domain. * If cpumaps is NULL, then no cpumap information is returned by the API. * It's assumed there is <maxinfo> cpumap in cpumaps. * The memory allocated to cpumaps must be (maxinfo * maplen) bytes. * One cpumap inside cupmaps have the format described in virDomainPinVcpu API. * @*maplen*: number of bytes in one cpumap, from 1 up to size of CPU map in * underlying virtualization system (Xen...). * * Extract information about virtual CPUs of domain, store it in info array. * * Returns the number of info filled in case of success, -1 in case of failure. */ int *virDomainGetVcpus* (virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, unsigned char *cpumaps, /* may be NULL */ int maplen);
If there is no physical cpu affinity (e.g. the default - vcpus can float among any pcpu), does each cpumap in cpumaps have all bits set? Do we indicate no affinity by having all possible pcpus marked as bound?
/* Macros for bit testing in cpumaps */ #define *CPU_USABLE*(cpumaps,maplen,vcpu,cpu) \ (cpumaps[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8)))
/* * Macro for copying the cpumap of a vcpu from cupmaps inside a standalone cpumap. * This macro is useful in case of using virDomainPinVcpu() after virDomainGetVcpus(). * cpumap must be previously allocated. */ #define *COPY_CPUMAP*(cpumaps,maplen,vcpu,cpumap) \ memcpy(cpumap, &(cpumaps[(vcpu)*(maplen)]), (maplen))
------------------------------------------------------------------------
-- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

How do I get the "size of CPU map in underlying virtualization system" described in maplen comments? The maplen must be computed from the number of physical CPU of the
Hello, platform. This information can be get from the virNodeGetInfo() libvirt API. In example: virNodeInfo nodeInfo; virConnectPtr pLibvirt; int mapLen; pLibvirt = virConnectOpen(NULL); virNodeGetInfo(pLibvirt, &nodeInfo); mapLen = (nodeInfo.cpus + 7) / 8;
If there is no physical cpu affinity (e.g. the default - vcpus can float among any pcpu), does each cpumap in cpumaps have all bits set? Do we indicate no affinity by having all possible pcpus marked as bound? If the affinity is 'any', each bit of the related CPU in the cpumap is set. In example, if your platform has 4 processors, then the cpumap value will be 0x0F which means: pcpu #0, pcpu #1, pcpu #2 and pcpu #3. The non existent processors have their related bits set to 0 in cpumap.
To indicate the 'any' affinity, all bits in cpumap must be set before calling the virDomainPinVcpu API. Regards, Philippe Berthault.
participants (3)
-
Daniel Veillard
-
Jim Fehlig
-
Philippe Berthault