[Libvir] Re: Virtual CPU functions

Daniel Veillard veillard at redhat.com
Tue Aug 1 15:44:28 UTC 2006


On Tue, Aug 01, 2006 at 05:06:59PM +0200, Philippe Berthault wrote:
> I've tried to illustrate an exemple of virDomainGetVcpus API with a 2 
> dimensional cpumaps array.

  Hum, right, the best is probably to go down to some examples at this
point.

> If you are agree with this, I can modify the patch of Michel Ponceau in 
> this sense before the end of this week.

  That would be good, even though I can't garantee the proposed API won't
change, that would allow more people to work on the code.

> I've proposed the virDomainGetCpus API to be in accordance with the 
> virDomainPinVcpu which is per vpcu and not per domain as 
> virDomainGetVcpus API.

  I wonder how people are most likely to use those APIs. Building scenarios
like:
    - physical CPU is to be locked to serve only VCPU N in domain D
    - domain A and domain B should be served by disjoint physical CPUs sets
    - monitoring 
 are the most common uses I would guess but I may be wrong.
First would require:
    - virDomainPinVcpu I guess
Second would require:
    - virDomainGetCpus and a number of calls to limit to sets :-\
The last one is likely to require getting full maps, and since it is likely 
to be called frequently the cheapest the better

  If people who expressed interest on the list about VCPU function could
express their principal use case it may help getting the APIs right.

> 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.

  Yes those are good points. There is an orthogonality decision on the
API, access could be done by VCPU or by CPU, if you provide one at a time
kind of accesses and of the wrong kind you may hit API problems really fast.

> 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)))

  Hum, I don't think the array code is right here, it is basically a one
dimention array, so maps[][] won't do what you expect.

> ...
> 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);
>        ...

    both are wrong IMHO :-)
one need to compute the index based on domInfo.nrVirtCpu

>        if (cpuUsable) {
>            printf("The physical cpu #%d is usable by virtual cpu #%d of 
> domain #%s\n",
>                   cpu, vcpu, virDomainGetName(pDomain));
>        }
>    }
> }

  I'm tempted to say:
    - let's collect use case
    - post the code you have
    - distinguish the problem of getting low level access in the library right
      and getting the API right those are separate

 thanks,

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard at redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/




More information about the libvir-list mailing list