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

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



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


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