Re: [libvirt PATCH 13/13] ch_driver: emulator threadinfo & pinning callbacks

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

 





On 10/21/21 16:31, Vineeth Pillai wrote:
From: Praveen K Paladugu <prapal@xxxxxxxxxxxxxxxxxxx>

Signed-off-by: Vineeth Pillai <viremana@xxxxxxxxxxxxxxxxxxx>
---
  src/ch/ch_driver.c | 154 +++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 154 insertions(+)

diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
index 97dfda85e1..786e2292a5 100644
--- a/src/ch/ch_driver.c
+++ b/src/ch/ch_driver.c
@@ -1321,6 +1321,158 @@ chDomainPinVcpu(virDomainPtr dom,
                                    VIR_DOMAIN_AFFECT_LIVE);
  }
+
+
+static int
+chDomainGetEmulatorPinInfo(virDomainPtr dom,
+                             unsigned char *cpumaps,
+                             int maplen,
+                             unsigned int flags)
+{
+    virDomainObj *vm = NULL;
+    virDomainDef *def;
+    virCHDomainObjPrivate *priv;
+    bool live;
+    int ret = -1;
+    virBitmap *cpumask = NULL;
+    g_autoptr(virBitmap) bitmap = NULL;
+    virBitmap *autoCpuset = NULL;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!(vm = chDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainGetEmulatorPinInfoEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (!(def = virDomainObjGetOneDefState(vm, flags, &live)))
+        goto cleanup;
+
+    if (live) {
+        priv = vm->privateData;
+        autoCpuset = priv->autoCpuset;
+    }
+    if (def->cputune.emulatorpin) {
+        cpumask = def->cputune.emulatorpin;
+    } else if (def->cpumask) {
+        cpumask = def->cpumask;
+    } else if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO &&
+               autoCpuset) {
+        cpumask = autoCpuset;
+    } else {
+        if (!(bitmap = virHostCPUGetAvailableCPUsBitmap()))
+            goto cleanup;
+        cpumask = bitmap;
+    }
+
+    virBitmapToDataBuf(cpumask, cpumaps, maplen);
+
+    ret = 1;
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+static int
+chDomainPinEmulator(virDomainPtr dom,
+                      unsigned char *cpumap,
+                      int maplen,
+                      unsigned int flags)
+{
+    virCHDriver *driver = dom->conn->privateData;
+    virDomainObj *vm;
+    virCgroup *cgroup_emulator = NULL;
+    virDomainDef *def;
+    virDomainDef *persistentDef;
+    int ret = -1;
+    virCHDomainObjPrivate *priv;
+    virBitmap *pcpumap = NULL;
+    g_autoptr(virCHDriverConfig) cfg = NULL;
+    g_autofree char *str = NULL;
+    virTypedParameterPtr eventParams = NULL;
+    int eventNparams = 0;
+    int eventMaxparams = 0;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    cfg = virCHDriverGetConfig(driver);
+
+    if (!(vm = chDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainPinEmulatorEnsureACL(dom->conn, vm->def, flags) < 0)
+        goto cleanup;
+
+    if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0)
+        goto cleanup;
+
+    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
+        goto endjob;
+
+    priv = vm->privateData;
+
+    if (!(pcpumap = virBitmapNewData(cpumap, maplen)))
+        goto endjob;
+
+    if (virBitmapIsAllClear(pcpumap)) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("Empty cpu list for pinning"));
+        goto endjob;
+    }
+
+    if (def) {
+        if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
+            if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR,
+                                   0, false, &cgroup_emulator) < 0)
+                goto endjob;
+
+            if (chSetupCgroupCpusetCpus(cgroup_emulator, pcpumap) < 0) {
+                virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                               _("failed to set cpuset.cpus in cgroup"
+                                 " for emulator threads"));
+                goto endjob;
+            }
+        }
+
+        if (virProcessSetAffinity(vm->pid, pcpumap, false) < 0)
+            goto endjob;
+
+        virBitmapFree(def->cputune.emulatorpin);
+        def->cputune.emulatorpin = NULL;
+
+        if (!(def->cputune.emulatorpin = virBitmapNewCopy(pcpumap)))
+            goto endjob;
+
+        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
+            goto endjob;
+
+        str = virBitmapFormat(pcpumap);
+        if (virTypedParamsAddString(&eventParams, &eventNparams,
+                                    &eventMaxparams,
+                                    VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN,
+                                    str) < 0)
+            goto endjob;
+
+    }
+
+
+    ret = 0;
+
+    endjob:

Wrong label indentation.

+        virCHDomainObjEndJob(vm);
+
+    cleanup:

Same here.


Thanks,


Daniel

+        if (cgroup_emulator)
+            virCgroupFree(cgroup_emulator);
+        virBitmapFree(pcpumap);
+        virDomainObjEndAPI(&vm);
+        return ret;
+}
+
  #define CH_NB_NUMA_PARAM 2
static int
@@ -1639,6 +1791,8 @@ static virHypervisorDriver chHypervisorDriver = {
      .domainGetVcpuPinInfo = chDomainGetVcpuPinInfo,         /* 7.9.0 */
      .domainPinVcpu = chDomainPinVcpu,                       /* 7.9.0 */
      .domainPinVcpuFlags = chDomainPinVcpuFlags,             /* 7.9.0 */
+    .domainPinEmulator = chDomainPinEmulator,               /* 7.9.0 */
+    .domainGetEmulatorPinInfo = chDomainGetEmulatorPinInfo, /* 7.9.0 */
      .nodeGetCPUMap = chNodeGetCPUMap,                       /* 7.9.0 */
      .domainSetNumaParameters = chDomainSetNumaParameters,   /* 7.9.0 */
      .domainGetNumaParameters = chDomainGetNumaParameters,   /* 7.9.0 */





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

  Powered by Linux