From: Yue Wenyuan <yuewenyuan(a)huawei.com>
This patch implements libvirt_lxc process pin with emulatorpin
specified in xml.
Signed-off-by: Wang Rui <moon.wangrui(a)huawei.com>
Signed-off-by: Yue Wenyuan <yuewenyuan(a)huawei.com>
---
src/lxc/lxc_cgroup.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
src/lxc/lxc_cgroup.h | 4 +++
src/lxc/lxc_controller.c | 4 +++
3 files changed, 76 insertions(+)
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index f9af31c..f696bf8 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -530,3 +530,71 @@ int virLXCCgroupSetup(virDomainDefPtr def,
cleanup:
return ret;
}
+
+static int virLXCCgroupSetupCpusetTuneForEmulator(virDomainDefPtr def,
+ virCgroupPtr cgroup,
+ virBitmapPtr nodemask)
+{
+ int ret = -1;
+ char *mask = NULL;
+
+ if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
+ if (def->cputune.emulatorpin) {
+ if (!(mask = virBitmapFormat(def->cputune.emulatorpin->cpumask)))
+ return ret;
+ } else if (def->cpumask) {
+ if (!(mask = virBitmapFormat(def->cpumask)))
+ return ret;
+ }
+ if (virCgroupSetCpusetCpus(cgroup, mask) < 0)
+ goto cleanup;
+ }
+
+ if (virDomainNumatuneMaybeFormatNodeset(def->numatune, nodemask,
+ &mask, -1) < 0)
+ goto cleanup;
+
+ if (mask && virCgroupSetCpusetMems(cgroup, mask) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(mask);
+ return ret;
+}
+
+int virLXCCgroupSetupForEmulator(virDomainDefPtr def,
+ virCgroupPtr cgroup,
+ virBitmapPtr nodemask)
+{
+ virCgroupPtr cgroup_emulator = NULL;
+
+ if (!virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_CPUSET))
+ return 0;
+
+ if (cgroup == NULL)
+ return 0; /* Not supported, so claim success */
+
+ if (virCgroupNewEmulator(cgroup, true, &cgroup_emulator) < 0)
+ goto error;
+
+ if (virCgroupMoveTask(cgroup, cgroup_emulator) < 0)
+ goto error;
+
+ if (virCgroupHasController(cgroup_emulator, VIR_CGROUP_CONTROLLER_CPUSET) &&
+ virLXCCgroupSetupCpusetTuneForEmulator(def, cgroup_emulator, nodemask) < 0)
+ goto error;
+
+ virCgroupFree(&cgroup_emulator);
+ return 0;
+
+ error:
+
+ if (cgroup_emulator) {
+ virCgroupRemove(cgroup_emulator);
+ virCgroupFree(&cgroup_emulator);
+ }
+
+ return -1;
+}
diff --git a/src/lxc/lxc_cgroup.h b/src/lxc/lxc_cgroup.h
index 0e78126..32086c5 100644
--- a/src/lxc/lxc_cgroup.h
+++ b/src/lxc/lxc_cgroup.h
@@ -33,6 +33,10 @@ int virLXCCgroupSetup(virDomainDefPtr def,
virCgroupPtr cgroup,
virBitmapPtr nodemask);
+int virLXCCgroupSetupForEmulator(virDomainDefPtr def,
+ virCgroupPtr cgroup,
+ virBitmapPtr nodemask);
+
int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo);
int
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 1861dd6..1a62e20 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -698,6 +698,10 @@ static int virLXCControllerSetupResourceLimits(virLXCControllerPtr
ctrl)
if (virLXCCgroupSetup(ctrl->def, ctrl->cgroup, nodemask) < 0)
goto cleanup;
+ VIR_DEBUG("Setting cgroup for lxc emulator");
+ if (virLXCCgroupSetupForEmulator(ctrl->def, ctrl->cgroup, nodemask) < 0)
+ goto cleanup;
+
ret = 0;
cleanup:
virBitmapFree(nodemask);
--
1.7.12.4