[libvirt] [PATCH 1/2] cpuset: Add cpuset cgroup support.

Daniel P. Berrange berrange at redhat.com
Thu Jun 30 09:34:38 UTC 2011


On Thu, Jun 30, 2011 at 11:08:32AM +0800, Gui Jianfeng wrote:
> Currently, libvirt makes use of sched_setaffinity() to set Guest processes's
> cpu affinity. But, sometimes, for instance, when QEmu uses vhost-net, the
> kernel part of vhost will create a kernel thread for some purpose. In this
> case, such kernel thread won't inherit QEmu's cpu affinity.
> 
> This patch enables cpuset cgroup in libvirt and setting cpu affinity by 
> configuring cpuset cgroup.
> 
> Signed-off-by: Gui Jianfeng <guijianfeng at cn.fujitsu.com>
> ---
>  src/libvirt_private.syms |    1 +
>  src/qemu/qemu_cgroup.c   |   22 ++++++++++++++++++++++
>  src/qemu/qemu_conf.c     |    3 ++-
>  src/util/cgroup.c        |   18 ++++++++++++++++++
>  src/util/cgroup.h        |    2 ++
>  5 files changed, 45 insertions(+), 1 deletions(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 626ac6c..e7aebc7 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -83,6 +83,7 @@ virCgroupMounted;
>  virCgroupPathOfController;
>  virCgroupRemove;
>  virCgroupSetBlkioWeight;
> +virCgroupCpusetSetcpus;
>  virCgroupSetCpuShares;
>  virCgroupSetFreezerState;
>  virCgroupSetMemory;
> diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
> index 1298924..eb92409 100644
> --- a/src/qemu/qemu_cgroup.c
> +++ b/src/qemu/qemu_cgroup.c
> @@ -296,6 +296,28 @@ int qemuSetupCgroup(struct qemud_driver *driver,
>          }
>      }
>  
> +    if (vm->def->cpumask != NULL) {
> +        if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPUSET)) {
> +            char *cpumask = NULL;
> +            if ((cpumask =
> +                 virDomainCpuSetFormat(vm->def->cpumask, vm->def->cpumasklen)) == NULL)
> +                goto cleanup;
> +
> +            rc = virCgroupCpusetSetcpus(cgroup, cpumask);
> +            if(rc != 0) {
> +                virReportSystemError(-rc,
> +                                     _("Unable to set cpus for domain %s"),
> +                                     vm->def->name);
> +                VIR_FREE(cpumask);
> +                goto cleanup;
> +            }
> +            VIR_FREE(cpumask);
> +        } else {
> +            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                            _("Cpuset is not available on this host"));

This is an effective regression for any existing deployments which
are not using cgroups, or do not have the cpuset controller mounted.

IMHO, this 'else' clause should just be removed, to allow the existing
cpu affinity code to run normally.


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list