Re: Re: Virtual CPU functions

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

 



On Tue, Aug 01, 2006 at 07:05:49PM +0200, Philippe Berthault wrote:
>>unsigned char *cpuMaps[]; /* 1st dimension = per virtual cpu, 2nd
>>dimension = per physical cpu */
...
> >>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
> >
> >  
> I don't understand why you think both are wrong. The first 'for' loop 
> index is based on domInfo.nrVirtCpu.

  Just a C implem nitpick, but that can lead to interesting debugging
sessions (I think I got beaten by that a couple of time).
  Nowhere the compiler can guess that you're accessing a 2 dimentional array
with a row of length domInfo.nrVirtCpu, it's a one dimension array so I
think cpuMaps[vcpu][byteCpu] is equivalent to cpuMaps[vcpu + byteCpu] there
and unless I misunderstood both case that won't work as expected. This is
also why I suggested a macro this can of code is easy to get wrong.

Daniel

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]