<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Here the new virtual cpu functions proposal.<br>
What do you think about it ?<br>
<br>
<br>
<br>
<tt><font color="#009900">/**<br>
 * <b>virVcpuInfo</b>: structure for information about a virtual CPU
in a domain.<br>
 */</font><br>
typedef enum {<br>
    VIR_VCPU_OFFLINE    = 0,    <font color="#009900">/* the virtual
CPU is offline */</font><br>
    VIR_VCPU_RUNNING    = 1,    <font color="#009900">/* the virtual
CPU is running */</font><br>
    VIR_VCPU_BLOCKED    = 2,    <font color="#009900">/* the virtual
CPU is blocked on resource */</font><br>
<b>} virVcpuState</b>;<br>
<br>
typedef struct _virVcpuInfo virVcpuInfo;<br>
struct _virVcpuInfo {<br>
    unsigned int number;        <font color="#009900">/* virtual CPU
number */</font><br>
    int state;                  <font color="#009900">/* value from
virVcpuState */</font><br>
    unsigned long long cpuTime; <font color="#009900">/* CPU time
used, in nanoseconds */</font><br>
    int cpu;                    <font color="#009900">/* real CPU
number, or -1 if offline */</font><br>
};<br>
typedef virVcpuInfo *<b>virVcpuInfoPtr</b>;<br>
<br>
<br>
<font color="#009900">/**<br>
 * <b>virDomainSetVcpus</b>:<br>
 * @<b>domain</b>: pointer to domain object, or NULL for Domain0<br>
 * @<b>nvcpus</b>: 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>
 */</font><br>
int <b>virDomainSetVcpus</b>   (virDomainPtr <font color="#3333ff">domain</font>,<br>
                         unsigned int <font color="#3333ff">nvcpus</font>);<br>
<br>
<br>
<font color="#009900">/**<br>
 * <b>virDomainPinVcpu</b>:<br>
 * @<b>domain</b>: pointer to domain object, or NULL for Domain0<br>
 * @<b>vcpu</b>: virtual CPU number<br>
 * @<b>cpumap</b>: 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>
 * @<b>maplen</b>: 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>
 */</font><br>
int <b>virDomainPinVcpu</b>    (virDomainPtr <font color="#3333ff">domain</font>,<br>
                         unsigned int <font color="#3333ff">vcpu</font>,<br>
                         unsigned char *<font color="#3333ff">cpumap</font>,<br>
                         int <font color="#3333ff">maplen</font>);<br>
<br>
<font color="#009900">/* Macros for bit manipulation in cpumap */</font><br>
#define <b>USE_CPU</b>(<font color="#3333ff">cpumap</font>,<font
 color="#3333ff">cpu</font>)     (cpumap[(cpu)/8] |= 
(1<<((cpu)%8)))<br>
#define <b>UNUSE_CPU</b>(<font color="#3333ff">cpumap</font>,<font
 color="#3333ff">cpu</font>)   (cpumap[(cpu)/8] &=
~(1<<((cpu)%8)))<br>
<br>
<br>
<font color="#009900">/**<br>
 * <b>virDomainGetVcpus</b>:<br>
 * @<b>domain</b>: pointer to domain object, or NULL for Domain0<br>
 * @<b>info</b>: pointer to an array of virVcpuInfo structures<br>
 * @<b>maxinfo</b>: number of structures in info array<br>
 * @<b>cpumaps</b>: 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>
 * @<b>maplen</b>: 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>
 */</font><br>
int <b>virDomainGetVcpus</b>   (virDomainPtr <font color="#3333ff">domain</font>,<br>
                         virVcpuInfoPtr <font color="#3333ff">info</font>,<br>
                         int <font color="#3333ff">maxinfo</font>,<br>
                         unsigned char *<font color="#3333ff">cpumaps</font>,
<font color="#009900">/* may be NULL */</font><br>
                         int <font color="#3333ff">maplen</font>);<br>
<br>
<font color="#009900">/* Macros for bit testing in cpumaps */</font><br>
#define <b>CPU_USABLE</b>(<font color="#3333ff">cpumaps</font>,<font
 color="#3333ff">maplen</font>,<font color="#3333ff">vcpu</font>,<font
 color="#3333ff">cpu</font>) \<br>
    (cpumaps[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8)))<br>
<font color="#009900"><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>
 */</font><br>
#define <b>COPY_CPUMAP</b>(<font color="#3333ff">cpumaps</font>,<font
 color="#3333ff">maplen</font>,<font color="#3333ff">vcpu</font>,<font
 color="#3333ff">cpumap</font>) \<br>
    memcpy(cpumap, &(cpumaps[(vcpu)*(maplen)]), (maplen))<br>
<br>
</tt>
</body>
</html>