From nobody Sat Feb 7 07:24:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1635149589842830.9315422069307; Mon, 25 Oct 2021 01:13:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-522-rEKZlIQXMzWUHcS9ZIKtNg-1; Mon, 25 Oct 2021 04:12:32 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 724191018729; Mon, 25 Oct 2021 08:12:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 567AF1980E; Mon, 25 Oct 2021 08:12:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 238401832DF5; Mon, 25 Oct 2021 08:12:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19LHjDTp014523 for ; Thu, 21 Oct 2021 13:45:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id A87C6C77E0; Thu, 21 Oct 2021 17:45:13 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A2D2ABDC4C for ; Thu, 21 Oct 2021 17:45:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49D3F808784 for ; Thu, 21 Oct 2021 17:45:08 +0000 (UTC) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by relay.mimecast.com with ESMTP id us-mta-481-FOnYfTTdPyGdJoM_16AJvw-1; Thu, 21 Oct 2021 13:45:06 -0400 Received: from prapal-ch2.oiwy50ateaxezb1sqsoezlib2f.xx.internal.cloudapp.net (unknown [20.80.162.67]) by linux.microsoft.com (Postfix) with ESMTPSA id C38E820B6C60; Thu, 21 Oct 2021 10:38:22 -0700 (PDT) X-MC-Unique: rEKZlIQXMzWUHcS9ZIKtNg-1 X-MC-Unique: FOnYfTTdPyGdJoM_16AJvw-1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C38E820B6C60 From: Vineeth Pillai To: libvir-list@redhat.com Subject: [libvirt PATCH 13/13] ch_driver: emulator threadinfo & pinning callbacks Date: Thu, 21 Oct 2021 17:38:05 +0000 Message-Id: <20211021173805.3118611-14-viremana@linux.microsoft.com> In-Reply-To: <20211021173805.3118611-1-viremana@linux.microsoft.com> References: <20211021173805.3118611-1-viremana@linux.microsoft.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 19LHjDTp014523 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 25 Oct 2021 04:11:53 -0400 Cc: william.douglas@intel.com, viremana@linux.microsoft.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1635149590784100001 Content-Type: text/plain; charset="utf-8" From: Praveen K Paladugu Signed-off-by: Vineeth Pillai --- 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); } =20 + + +static int +chDomainGetEmulatorPinInfo(virDomainPtr dom, + unsigned char *cpumaps, + int maplen, + unsigned int flags) +{ + virDomainObj *vm =3D NULL; + virDomainDef *def; + virCHDomainObjPrivate *priv; + bool live; + int ret =3D -1; + virBitmap *cpumask =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; + virBitmap *autoCpuset =3D NULL; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (!(vm =3D chDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainGetEmulatorPinInfoEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (!(def =3D virDomainObjGetOneDefState(vm, flags, &live))) + goto cleanup; + + if (live) { + priv =3D vm->privateData; + autoCpuset =3D priv->autoCpuset; + } + if (def->cputune.emulatorpin) { + cpumask =3D def->cputune.emulatorpin; + } else if (def->cpumask) { + cpumask =3D def->cpumask; + } else if (vm->def->placement_mode =3D=3D VIR_DOMAIN_CPU_PLACEMENT_MOD= E_AUTO && + autoCpuset) { + cpumask =3D autoCpuset; + } else { + if (!(bitmap =3D virHostCPUGetAvailableCPUsBitmap())) + goto cleanup; + cpumask =3D bitmap; + } + + virBitmapToDataBuf(cpumask, cpumaps, maplen); + + ret =3D 1; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int +chDomainPinEmulator(virDomainPtr dom, + unsigned char *cpumap, + int maplen, + unsigned int flags) +{ + virCHDriver *driver =3D dom->conn->privateData; + virDomainObj *vm; + virCgroup *cgroup_emulator =3D NULL; + virDomainDef *def; + virDomainDef *persistentDef; + int ret =3D -1; + virCHDomainObjPrivate *priv; + virBitmap *pcpumap =3D NULL; + g_autoptr(virCHDriverConfig) cfg =3D NULL; + g_autofree char *str =3D NULL; + virTypedParameterPtr eventParams =3D NULL; + int eventNparams =3D 0; + int eventMaxparams =3D 0; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + cfg =3D virCHDriverGetConfig(driver); + + if (!(vm =3D 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 =3D vm->privateData; + + if (!(pcpumap =3D 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_CPU= SET)) { + if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATO= R, + 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 =3D NULL; + + if (!(def->cputune.emulatorpin =3D virBitmapNewCopy(pcpumap))) + goto endjob; + + if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) + goto endjob; + + str =3D virBitmapFormat(pcpumap); + if (virTypedParamsAddString(&eventParams, &eventNparams, + &eventMaxparams, + VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN, + str) < 0) + goto endjob; + + } + + + ret =3D 0; + + endjob: + virCHDomainObjEndJob(vm); + + cleanup: + if (cgroup_emulator) + virCgroupFree(cgroup_emulator); + virBitmapFree(pcpumap); + virDomainObjEndAPI(&vm); + return ret; +} + #define CH_NB_NUMA_PARAM 2 =20 static int @@ -1639,6 +1791,8 @@ static virHypervisorDriver chHypervisorDriver =3D { .domainGetVcpuPinInfo =3D chDomainGetVcpuPinInfo, /* 7.9.0 */ .domainPinVcpu =3D chDomainPinVcpu, /* 7.9.0 */ .domainPinVcpuFlags =3D chDomainPinVcpuFlags, /* 7.9.0 */ + .domainPinEmulator =3D chDomainPinEmulator, /* 7.9.0 */ + .domainGetEmulatorPinInfo =3D chDomainGetEmulatorPinInfo, /* 7.9.0 */ .nodeGetCPUMap =3D chNodeGetCPUMap, /* 7.9.0 */ .domainSetNumaParameters =3D chDomainSetNumaParameters, /* 7.9.0 */ .domainGetNumaParameters =3D chDomainGetNumaParameters, /* 7.9.0 */ --=20 2.27.0