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

Re: [libvirt] [PATCH 07/12] Add qemuProcessSetHypervisorAffinites and set hypervisor threads affinities



On Wed, Jul 25, 2012 at 01:25:16PM +0800, tangchen wrote:
> From: Tang Chen <tangchen cn fujitsu com>
> 
> Hypervisor threads should also be pinned by sched_setaffinity(), just
> the same as vcpu threads.
> 
> Signed-off-by: Tang Chen <tangchen cn fujitsu com>
> Signed-off-by: Hu Tao <hutao cn fujitsu com>
> ---
>  src/qemu/qemu_process.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
> 
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index d89b4d5..bb1640a 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -2005,6 +2005,56 @@ cleanup:
>      return ret;
>  }
>  
> +/* Set CPU affinities for hypervisor threads if hypervisorpin xml provided. */
> +static int
> +qemuProcessSetHypervisorAffinites(virConnectPtr conn,
> +                                  virDomainObjPtr vm)
> +{
> +    virDomainDefPtr def = vm->def;
> +    pid_t pid = vm->pid;
> +    unsigned char *cpumask = NULL;
> +    unsigned char *cpumap = NULL;
> +    virNodeInfo nodeinfo;
> +    int cpumaplen, hostcpus, maxcpu, i;
> +    int ret = -1;
> +
> +    if (virNodeGetInfo(conn, &nodeinfo) != 0)
> +        return -1;
> +
> +    if (!def->cputune.hypervisorpin)
> +        return 0;

Reorder into:

    if (!def->cputune.hypervisorpin)
        return 0;

    if (virNodeGetInfo(conn, &nodeinfo) != 0)
        return -1;


> +
> +    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
> +    cpumaplen = VIR_CPU_MAPLEN(hostcpus);
> +    maxcpu = cpumaplen * 8;
> +
> +    if (maxcpu > hostcpus)
> +        maxcpu = hostcpus;
> +
> +    if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) {
> +        virReportOOMError();
> +        return -1;
> +    }
> +
> +    cpumask = (unsigned char *)def->cputune.hypervisorpin->cpumask;
> +    for(i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
> +        if (cpumask[i])
> +            VIR_USE_CPU(cpumap, i);
> +    }
> +
> +    if (virProcessInfoSetAffinity(pid,
> +                                  cpumap,
> +                                  cpumaplen,
> +                                  maxcpu) < 0) {
> +        goto cleanup;
> +    }
> +
> +    ret = 0;
> +cleanup:
> +    VIR_FREE(cpumap);
> +    return ret;
> +}
> +
>  static int
>  qemuProcessInitPasswords(virConnectPtr conn,
>                           struct qemud_driver *driver,
> @@ -3765,6 +3815,10 @@ int qemuProcessStart(virConnectPtr conn,
>      if (qemuProcessSetVcpuAffinites(conn, vm) < 0)
>          goto cleanup;
>  
> +    VIR_DEBUG("Setting hypervisor threads affinities");
> +    if (qemuProcessSetHypervisorAffinites(conn, vm) < 0)
> +        goto cleanup;
> +
>      VIR_DEBUG("Setting any required VM passwords");
>      if (qemuProcessInitPasswords(conn, driver, vm) < 0)
>          goto cleanup;
> -- 
> 1.7.10.2
> 
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list

-- 
Thanks,
Hu Tao


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