[Libvir] Re: Virtual CPU functions

Philippe Berthault Philippe.Berthault at Bull.net
Tue Aug 1 15:06:59 UTC 2006


I've tried to illustrate an exemple of virDomainGetVcpus API with a 2 
dimensional cpumaps array.
If you are agree with this, I can modify the patch of Michel Ponceau in 
this sense before the end of this week.

I've proposed the virDomainGetCpus API to be in accordance with the 
virDomainPinVcpu which is per vpcu and not per domain as 
virDomainGetVcpus API.
The virDomainPinVcpu API is'nt symmetrical with virDomainGetVcpus and 
must be called N times to perform the CPU mapping of a domain which 
isn't very satisfying.
Another complaint against the virDomainPinVcpu versus virDomainGetVcpus 
API is that the cpumap parameter hasn't the same meaning in these two 
APIs. This point requires to duplicate macro for bit manipulations on 
these maps.

Philippe Berthault
______________________________________________________________________

virConnectPtr pConn;
virDomainPtr pDomain;
virNodeInfo nodeInfo;
virDomainInfo domInfo;
virVcpuInfoPtr pVcpuInfos;
int nbPhysCpus;
unsigned char *cpuMaps[]; /* 1st dimension = per virtual cpu, 2nd 
dimension = per physical cpu */
int oneCpuMapLen;
int vcpu, cpu;

#define CPU_USABLE(maps,vcpu,cpu) (maps[vcpu][((cpu) / 8)] & (1 >> 
((cpu) % 8)))

...
virNodeGetInfo(pConn, &nodeInfo);

nbPhysCpus = nodeInfo.cpus;
/* ? or ? */
nbPhysCpus = nodeInfo.nodes * nodeInfo.sockets * nodeInfo.cores * 
nodeInfo.threads;

virDomainGetInfo(pDomain, &domInfo);
pVcpuInfos = malloc(sizeof(virVcpuInfo)*domInfo.nrVirtCpu);

oneCpuMapLen = (nbPhysCpus + 7) / 8;
cpuMaps = calloc(domInfo.nrVirtCpu, oneCpuMapLen);

virDomainGetVcpus(pDomain, pVcpuInfos, domInfo.nrVirtCpu, cpuMaps, 
oneCpuMapLen);
for (vcpu = 0; vcpu < domInfo.nrVirtCpu; vcpu++) {
    for (cpu = 0; cpu < nbPhysCpus; cpu++) {
        int byteCpu = cpu / 8;
        int bitCpu = cpu % 8;
        int mask = 1 >> bitCpu; /* lowest CPU number is least 
significant bit as M.Ponceau said */
        int cpuUsable = cpuMaps[vcpu][byteCpu] & mask;
        ...
        /* or */
        int cpuUsable = CPU_USABLE(cpuMaps, vcpu, cpu);
        ...
        if (cpuUsable) {
            printf("The physical cpu #%d is usable by virtual cpu #%d of 
domain #%s\n",
                   cpu, vcpu, virDomainGetName(pDomain));
        }
    }
}
______________________________________________________________________




More information about the libvir-list mailing list