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