<br><font size=2 face="Arial">For our administration, we need the following actions, while concerned domain is running:</font>
<br><font size=2 face="Arial">1) Change the number of virtual CPUs.</font>
<br><font size=2 face="Arial">2) Change the pinning (affinity) of a virtual CPU on real CPUs.</font>
<br><font size=2 face="Arial">3) Get detailed information for each virtual CPU.</font>
<br><font size=2 face="Arial">Currently there is no Libvirt function provided for that. We suggest to add the following 3 functions (in libvirt.c):</font>
<br><font size=2><tt>/**</tt></font>
<br><font size=2><tt> * virDomainSetVcpus:</tt></font>
<br><font size=2><tt> * @domain: pointer to domain object, or NULL for Domain0</tt></font>
<br><font size=2><tt> * @nvcpus: the new number of virtual CPUs for this domain</tt></font>
<br><font size=2><tt> *</tt></font>
<br><font size=2><tt> * Dynamically change the number of virtual CPUs used by the domain.</tt></font>
<br><font size=2><tt> * Note that this call may fail if the underlying virtualization hypervisor</tt></font>
<br><font size=2><tt> * does not support it or if growing the number is arbitrary limited.</tt></font>
<br><font size=2><tt> * This function requires priviledged access to the hypervisor.</tt></font>
<br><font size=2><tt> *</tt></font>
<br><font size=2><tt> * Returns 0 in case of success, -1 in case of failure.</tt></font>
<br><font size=2><tt> */</tt></font>
<br><font size=2><tt>int virDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)</tt></font>
<br>
<br><font size=2><tt>/**</tt></font>
<br><font size=2><tt> * virDomainPinVcpu:</tt></font>
<br><font size=2><tt> * @domain: pointer to domain object, or NULL for Domain0</tt></font>
<br><font size=2><tt> * @vcpu: virtual CPU number</tt></font>
<br><font size=2><tt> * @cpumap: pointer to a bit map of real CPUs (format in virVcpuInfo)</tt></font>
<br><font size=2><tt> * @maplen: length of cpumap, in 8-bit bytes</tt></font>
<br><font size=2><tt> * </tt></font>
<br><font size=2><tt> * Dynamically change the real CPUs which can be allocated to a virtual CPU.</tt></font>
<br><font size=2><tt> * This function requires priviledged access to the hypervisor.</tt></font>
<br><font size=2><tt> *</tt></font>
<br><font size=2><tt> * Returns 0 in case of success, -1 in case of failure.</tt></font>
<br><font size=2><tt> */</tt></font>
<br><font size=2><tt>int virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,</tt></font>
<br><font size=2><tt>                 unsigned char *cpumap, int maplen)</tt></font>
<br>
<br><font size=2><tt>/**</tt></font>
<br><font size=2><tt> * virDomainGetVcpus:</tt></font>
<br><font size=2><tt> * @domain: pointer to domain object, or NULL for Domain0</tt></font>
<br><font size=2><tt> * @info: pointer to an array of virVcpuInfo structures</tt></font>
<br><font size=2><tt> * @maxinfo: number of structures in info array</tt></font>
<br><font size=2><tt> * </tt></font>
<br><font size=2><tt> * Extract information about virtual CPUs of a domain, store it in info array.</tt></font>
<br><font size=2><tt> *</tt></font>
<br><font size=2><tt> * Returns the number of info filled in case of success, -1 in case of failure.</tt></font>
<br><font size=2><tt> */</tt></font>
<br><font size=2><tt>int virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo)</tt></font>
<br>
<br><font size=2 face="Arial">with the following structure (in libvirt.h):</font>
<br><font size=2><tt>/**</tt></font>
<br><font size=2><tt> * virVcpuInfo: structure for information about a virtual CPU in a domain.</tt></font>
<br><font size=2><tt> */</tt></font>
<br><font size=2><tt>#define VIR_MAX_CPUS                256</tt></font>
<br><font size=2><tt>typedef enum {</tt></font>
<br><font size=2><tt>    VIR_VCPU_OFFLINE        = 0,        /* the virtual CPU is offline */</tt></font>
<br><font size=2><tt>    VIR_VCPU_RUNNING        = 1,        /* the virtual CPU is running */</tt></font>
<br><font size=2><tt>    VIR_VCPU_BLOCKED        = 2,        /* the virtual CPU is blocked on resource */</tt></font>
<br><font size=2><tt>} virVcpuState;</tt></font>
<br>
<br><font size=2><tt>typedef struct _virVcpuInfo virVcpuInfo;</tt></font>
<br><font size=2><tt>struct _virVcpuInfo {</tt></font>
<br><font size=2><tt>    unsigned int number;        /* virtual CPU number */</tt></font>
<br><font size=2><tt>    int state;                        /* value from virVcpuState */</tt></font>
<br><font size=2><tt>    unsigned long long cpuTime; /* CPU time used, in nanoseconds */</tt></font>
<br><font size=2><tt>    int cpu;                        /* real CPU number, or -1 if offline */</tt></font>
<br><font size=2><tt>    unsigned char cpumap[VIR_MAX_CPUS/8]; /* Bit map of usable real CPUs.</tt></font>
<br><font size=2><tt>                Each bit set to 1 means that corresponding CPU is usable.</tt></font>
<br><font size=2><tt>                Bytes are stored in little-endian order: CPU0-7, 8-15...</tt></font>
<br><font size=2><tt>                In each byte, lowest CPU number is least significant bit */</tt></font>
<br><font size=2><tt>};</tt></font>
<br><font size=2><tt>typedef virVcpuInfo *virVcpuInfoPtr;</tt></font>
<br>
<br><font size=2 face="Arial">I have successfully tried those functions via Xen hypervisor, except for the first (SetVcpus) where hypervisor operation DOM0_MAX_VCPUS fails (maybe it is not possible on a running domain ?). That function was successful via Xen daemon.</font>