[libvirt] [PATCH v2.1 11/21] Add qemuProcessSetEmulatorAffinites and set emulator threads affinities

Daniel Veillard veillard at redhat.com
Wed Aug 22 08:20:01 UTC 2012


On Tue, Aug 21, 2012 at 05:18:34PM +0800, Hu Tao wrote:
> From: Tang Chen <tangchen at cn.fujitsu.com>
> 
> Emulator threads should also be pinned by sched_setaffinity(), just
> the same as vcpu threads.
> 
> Signed-off-by: Tang Chen <tangchen at cn.fujitsu.com>
> Signed-off-by: Hu Tao <hutao at 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 762f298..90d44c4 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -2002,6 +2002,56 @@ cleanup:
>      return ret;
>  }
>  
> +/* Set CPU affinities for emulator threads if emulatorpin xml provided. */
> +static int
> +qemuProcessSetEmulatorAffinites(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.emulatorpin)
> +        return 0;
> +
> +    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
> +    cpumaplen = VIR_CPU_MAPLEN(hostcpus);
> +    maxcpu = cpumaplen * CHAR_BIT;
> +
> +    if (maxcpu > hostcpus)
> +        maxcpu = hostcpus;
> +
> +    if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) {
> +        virReportOOMError();
> +        return -1;
> +    }
> +
> +    cpumask = (unsigned char *)def->cputune.emulatorpin->cpumask;
> +    for(i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {

   missing space between for and (

> +        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,
> @@ -3764,6 +3814,10 @@ int qemuProcessStart(virConnectPtr conn,
>      if (qemuProcessSetVcpuAffinites(conn, vm) < 0)
>          goto cleanup;
>  
> +    VIR_DEBUG("Setting affinity of emulator threads");
> +    if (qemuProcessSetEmulatorAffinites(conn, vm) < 0)
> +        goto cleanup;
> +
>      VIR_DEBUG("Setting any required VM passwords");
>      if (qemuProcessInitPasswords(conn, driver, vm) < 0)
>          goto cleanup;

  Looks okay, ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list