]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch_process: Setup emulator and iothread settings
authorPraveen K Paladugu <prapal@linux.microsoft.com>
Tue, 25 Jan 2022 16:19:58 +0000 (16:19 +0000)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 28 Jan 2022 16:04:50 +0000 (17:04 +0100)
using virCHProcessSetupPid

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/ch/ch_monitor.c
src/ch/ch_monitor.h
src/ch/ch_process.c

index fcf71f472db2cf61aa41e7618a7c0103128c86e6..4d5d2c69b8a013b54a1d8359f4b92042722e8232 100644 (file)
@@ -928,3 +928,64 @@ virCHMonitorGetInfo(virCHMonitor *mon, virJSONValue **info)
 {
     return virCHMonitorGet(mon, URL_VM_INFO, info);
 }
+
+/**
+ * virCHMonitorGetIOThreads:
+ * @mon: Pointer to the monitor
+ * @iothreads: Location to return array of IOThreadInfo data
+ *
+ * Retrieve the list of iothreads defined/running for the machine
+ *
+ * Returns count of IOThreadInfo structures on success
+ *        -1 on error.
+ */
+int
+virCHMonitorGetIOThreads(virCHMonitor *mon,
+                         virDomainIOThreadInfo ***iothreads)
+{
+    size_t nthreads = 0;
+    size_t niothreads = 0;
+    int thd_index;
+    virDomainIOThreadInfo **iothreadinfolist = NULL;
+    virDomainIOThreadInfo *iothreadinfo = NULL;
+
+    *iothreads = NULL;
+    nthreads = virCHMonitorRefreshThreadInfo(mon);
+
+    iothreadinfolist = g_new0(virDomainIOThreadInfo*, nthreads + 1);
+
+    for (thd_index = 0; thd_index < nthreads; thd_index++) {
+        g_autoptr(virBitmap) map = NULL;
+
+        if (mon->threads[thd_index].type == virCHThreadTypeIO) {
+            iothreadinfo = g_new0(virDomainIOThreadInfo, 1);
+
+            iothreadinfo->iothread_id = mon->threads[thd_index].ioInfo.tid;
+
+            if (!(map = virProcessGetAffinity(iothreadinfo->iothread_id)))
+                goto error;
+
+            if (virBitmapToData(map, &(iothreadinfo->cpumap),
+                                &(iothreadinfo->cpumaplen)) < 0) {
+                goto error;
+            }
+
+            /* Append to iothreadinfolist */
+            iothreadinfolist[niothreads] = g_steal_pointer(&iothreadinfo);
+            niothreads++;
+        }
+    }
+
+    VIR_DEBUG("niothreads = %ld", niothreads);
+    *iothreads = g_steal_pointer(iothreadinfolist);
+    return niothreads;
+
+ error:
+    if (iothreadinfolist) {
+        for (thd_index = 0; thd_index < niothreads; thd_index++)
+            virDomainIOThreadInfoFree(iothreadinfolist[thd_index]);
+        VIR_FREE(iothreadinfolist);
+    }
+    virDomainIOThreadInfoFree(iothreadinfo);
+    return -1;
+}
index 6646316454cf1015c16af01d83cd035fc7073bbf..ffc80e8910821cbd7bdcb99e6fe7cf0d62d0c6c8 100644 (file)
@@ -119,3 +119,5 @@ int virCHMonitorGetCPUInfo(virCHMonitor *mon,
                            size_t maxvcpus);
 size_t virCHMonitorGetThreadInfo(virCHMonitor *mon, bool refresh,
                                  virCHMonitorThreadInfo **threads);
+int virCHMonitorGetIOThreads(virCHMonitor *mon,
+                             virDomainIOThreadInfo ***iothreads);
index 8ab6dc9d63f4310f8aecd74c2d2b3b1103de3bd9..414e203154e8321ccd92994aeaf36d722ec27cac 100644 (file)
@@ -41,7 +41,6 @@ VIR_LOG_INIT("ch.ch_process");
 #define START_VM_POSTFIX ": starting up vm\n"
 
 
-
 static virCHMonitor *
 virCHProcessConnectMonitor(virCHDriver *driver,
                            virDomainObj *vm)
@@ -306,6 +305,76 @@ virCHProcessSetupPid(virDomainObj *vm,
     return ret;
 }
 
+static int
+virCHProcessSetupIOThread(virDomainObj *vm,
+                          virDomainIOThreadInfo *iothread)
+{
+    virCHDomainObjPrivate *priv = vm->privateData;
+
+    return virCHProcessSetupPid(vm, iothread->iothread_id,
+                                VIR_CGROUP_THREAD_IOTHREAD,
+                                iothread->iothread_id,
+                                priv->autoCpuset, /* This should be updated when CLH supports accepting
+                                                     iothread settings from input domain definition */
+                                vm->def->cputune.iothread_period,
+                                vm->def->cputune.iothread_quota,
+                                NULL); /* CLH doesn't allow choosing a scheduler for iothreads.*/
+}
+
+static int
+virCHProcessSetupIOThreads(virDomainObj *vm)
+{
+    virCHDomainObjPrivate *priv = vm->privateData;
+    virDomainIOThreadInfo **iothreads = NULL;
+    size_t i;
+    size_t  niothreads;
+
+    niothreads = virCHMonitorGetIOThreads(priv->monitor, &iothreads);
+    for (i = 0; i < niothreads; i++) {
+        VIR_DEBUG("IOThread index = %ld , tid = %d", i, iothreads[i]->iothread_id);
+        if (virCHProcessSetupIOThread(vm, iothreads[i]) < 0)
+            return -1;
+    }
+    return 0;
+}
+
+static int
+virCHProcessSetupEmulatorThread(virDomainObj *vm,
+                         virCHMonitorEmuThreadInfo emuthread)
+{
+    return virCHProcessSetupPid(vm, emuthread.tid,
+                               VIR_CGROUP_THREAD_EMULATOR, 0,
+                               vm->def->cputune.emulatorpin,
+                               vm->def->cputune.emulator_period,
+                               vm->def->cputune.emulator_quota,
+                               vm->def->cputune.emulatorsched);
+}
+
+static int
+virCHProcessSetupEmulatorThreads(virDomainObj *vm)
+{
+    int thd_index = 0;
+    virCHDomainObjPrivate *priv = vm->privateData;
+
+    /* Cloud-hypervisor start 4 Emulator threads by default:
+     * vmm
+     * cloud-hypervisor
+     * http-server
+     * signal_handler */
+    for (thd_index = 0; thd_index < priv->monitor->nthreads; thd_index++) {
+        if (priv->monitor->threads[thd_index].type == virCHThreadTypeEmulator) {
+            VIR_DEBUG("Setup tid = %d (%s) Emulator thread",
+                      priv->monitor->threads[thd_index].emuInfo.tid,
+                      priv->monitor->threads[thd_index].emuInfo.thrName);
+
+            if (virCHProcessSetupEmulatorThread(vm,
+                                                priv->monitor->threads[thd_index].emuInfo) < 0)
+                return -1;
+        }
+    }
+    return 0;
+}
+
 /**
  * virCHProcessSetupVcpu:
  * @vm: domain object
@@ -439,6 +508,14 @@ virCHProcessStart(virCHDriver *driver,
 
     virCHDomainRefreshThreadInfo(vm);
 
+    VIR_DEBUG("Setting emulator tuning/settings");
+    if (virCHProcessSetupEmulatorThreads(vm) < 0)
+        goto cleanup;
+
+    VIR_DEBUG("Setting iothread tuning/settings");
+    if (virCHProcessSetupIOThreads(vm) < 0)
+        goto cleanup;
+
     VIR_DEBUG("Setting global CPU cgroup (if required)");
     if (virDomainCgroupSetupGlobalCpuCgroup(vm,
                                             priv->cgroup,