[libvirt] [PATCH v2 14/15] test: Refactor vcpu pinning and vcpu info retrieval

John Ferlan jferlan at redhat.com
Wed Jun 24 20:23:27 UTC 2015



On 06/24/2015 10:11 AM, Peter Krempa wrote:
> Drop internal data structures and use the proper fields in virDomainDef.
> 
> This allows to greatly simplify the code and allows to remove the
> private data structure that was holding just redundant data.
> 
> This patch also fixes the bogous output where we'd report that a fresh

Another bogus typo

> VM without vCPU pinning would not run on all vcpus.
> ---
>  src/test/test_driver.c | 224 +++++++++++--------------------------------------
>  1 file changed, 49 insertions(+), 175 deletions(-)
> 
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index ae332ef..ed67dca 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c

...

> @@ -2541,45 +2416,47 @@ static int testDomainGetVcpus(virDomainPtr domain,
> 
>      statbase = (tv.tv_sec * 1000UL * 1000UL) + tv.tv_usec;
> 
> -
>      hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo);
>      maxcpu = maplen * 8;
>      if (maxcpu > hostcpus)
>          maxcpu = hostcpus;
> 
> +    if (!(allcpumap = virBitmapNew(hostcpus)))
> +        goto cleanup;
> +
> +    virBitmapSetAll(allcpumap);
> +
>      /* Clamp to actual number of vcpus */
>      if (maxinfo > privdom->def->vcpus)
>          maxinfo = privdom->def->vcpus;
> 
> -    /* Populate virVcpuInfo structures */
> -    if (info != NULL) {
> -        memset(info, 0, sizeof(*info) * maxinfo);
> +    memset(info, 0, sizeof(*info) * maxinfo);
> +    memset(cpumaps, 0, maxinfo * maplen);
> 
> -        for (i = 0; i < maxinfo; i++) {
> -            virVcpuInfo privinfo = privdomdata->vcpu_infos[i];
> +    for (i = 0; i < maxinfo; i++) {
> +        virDomainPinDefPtr pininfo;
> +        virBitmapPtr bitmap = NULL;
> 
> -            info[i].number = privinfo.number;
> -            info[i].state = privinfo.state;
> -            info[i].cpu = privinfo.cpu;
> +        pininfo = virDomainPinFind(def->cputune.vcpupin,
> +                                   def->cputune.nvcpupin,
> +                                   i);
> 
> -            /* Fake an increasing cpu time value */
> -            info[i].cpuTime = statbase / 10;
> -        }
> -    }
> +        if (pininfo && pininfo->cpumask)
> +            bitmap = pininfo->cpumask;
> +        else if (def->cpumask)
> +            bitmap = def->cpumask;
> +        else
> +            bitmap = allcpumap;
> 
> -    /* Populate cpumaps */
> -    if (cpumaps != NULL) {
> -        int privmaplen = VIR_CPU_MAPLEN(hostcpus);
> -        memset(cpumaps, 0, maplen * maxinfo);
> +        if (cpumaps)
> +            virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
> 
> -        for (v = 0; v < maxinfo; v++) {
> -            unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
> +        info[i].number = i;
> +        info[i].state = VIR_VCPU_RUNNING;
> +        info[i].cpu = virBitmapLastSetBit(bitmap);
> 
> -            for (i = 0; i < maxcpu; i++) {
> -                if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i))
> -                    VIR_USE_CPU(cpumap, i);
> -            }
> -        }
> +        /* Fake an increasing cpu time value */
> +        info[i].cpuTime = statbase / 10;
>      }
> 
>      ret = maxinfo;

...

Coverity determines that there's a need for virBitmapFree(allcpumap);


John




More information about the libvir-list mailing list