Re: [PATCH 08/12] Introduce virDomainHypervisorPinAdd and virDomainHypervisorPinDel functions

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

 



On Wed, Jul 25, 2012 at 01:25:52PM +0800, tangchen wrote:
> From: Tang Chen <tangchen@xxxxxxxxxxxxxx>
> 
> Introduce 2 APIs to support hypervisor threads pin.
>     1) virDomainHypervisorPinAdd: setup hypervisor threads pin with a given cpumap string.
>     2) virDomainHypervisorPinDel: remove all hypervisor threads pin.
> 
> Signed-off-by: Tang Chen <tangchen@xxxxxxxxxxxxxx>
> Signed-off-by: Hu Tao <hutao@xxxxxxxxxxxxxx>
> ---
>  src/conf/domain_conf.c   |   72 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/conf/domain_conf.h   |    6 ++++
>  src/libvirt_private.syms |    2 ++
>  3 files changed, 80 insertions(+)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index bedbf79..cec158d 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -10957,6 +10957,78 @@ virDomainVcpuPinDel(virDomainDefPtr def, int vcpu)
>      return 0;
>  }
>  
> +int
> +virDomainHypervisorPinAdd(virDomainDefPtr def,
> +                          unsigned char *cpumap,
> +                          int maplen)
> +{
> +    virDomainVcpuPinDefPtr hypervisorpin = NULL;
> +    char *cpumask = NULL;
> +    int i;
> +
> +    if (VIR_ALLOC_N(cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) {
> +        virReportOOMError();
> +        goto cleanup;
> +    }
> +

We have to check maplen here to avoid accessing beyond cpumask.

> +    /* Convert bitmap (cpumap) to cpumask, which is byte map. */
> +    for (i = 0; i < maplen; i++) {
> +        int cur;
> +
> +        for (cur = 0; cur < 8; cur++) {
> +            if (cpumap[i] & (1 << cur))
> +                cpumask[i * 8 + cur] = 1;
> +        }
> +    }
> +
> +    if (!def->cputune.hypervisorpin) {
> +        /* No hypervisorpin exists yet. */
> +        if (VIR_ALLOC(hypervisorpin) < 0) {
> +            virReportOOMError();
> +            goto cleanup;
> +        }
> +
> +        hypervisorpin->vcpuid = -1;
> +        hypervisorpin->cpumask = cpumask;
> +        def->cputune.hypervisorpin = hypervisorpin;
> +    } else {
> +        /* Since there is only 1 hypervisorpin for each vm,
> +         * juest replace the old one.
> +         */
> +        VIR_FREE(def->cputune.hypervisorpin->cpumask);
> +        def->cputune.hypervisorpin->cpumask = cpumask;
> +    }
> +
> +    return 0;
> +
> +cleanup:
> +    if (cpumask)
> +        VIR_FREE(cpumask);
> +    return -1;
> +}
> +
> +int
> +virDomainHypervisorPinDel(virDomainDefPtr def)
> +{
> +    virDomainVcpuPinDefPtr hypervisorpin = NULL;
> +
> +    /* No hypervisorpin exists yet */
> +    if (!def->cputune.hypervisorpin) {
> +        return 0;
> +    }
> +
> +    hypervisorpin = def->cputune.hypervisorpin;
> +
> +    VIR_FREE(hypervisorpin->cpumask);
> +    VIR_FREE(hypervisorpin);
> +    def->cputune.hypervisorpin = NULL;
> +
> +    if (def->cputune.hypervisorpin)
> +        return -1;
> +
> +    return 0;
> +}
> +
>  static int
>  virDomainLifecycleDefFormat(virBufferPtr buf,
>                              int type,
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index 11f0eb0..64096d5 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -1985,6 +1985,12 @@ int virDomainVcpuPinAdd(virDomainDefPtr def,
>  
>  int virDomainVcpuPinDel(virDomainDefPtr def, int vcpu);
>  
> +int virDomainHypervisorPinAdd(virDomainDefPtr def,
> +                              unsigned char *cpumap,
> +                              int maplen);
> +
> +int virDomainHypervisorPinDel(virDomainDefPtr def);
> +
>  int virDomainDiskIndexByName(virDomainDefPtr def, const char *name,
>                               bool allow_ambiguous);
>  const char *virDomainDiskPathByName(virDomainDefPtr, const char *name);
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 867c2e7..a57486a 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -491,6 +491,8 @@ virDomainTimerTrackTypeFromString;
>  virDomainTimerTrackTypeToString;
>  virDomainVcpuPinAdd;
>  virDomainVcpuPinDel;
> +virDomainHypervisorPinAdd;
> +virDomainHypervisorPinDel;
>  virDomainVcpuPinFindByVcpu;
>  virDomainVcpuPinIsDuplicate;
>  virDomainVideoDefFree;
> -- 
> 1.7.10.2
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

-- 
Thanks,
Hu Tao

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]