From nobody Mon Feb 9 07:43:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1660298715; cv=none; d=zohomail.com; s=zohoarc; b=cM+Cp2ptg/gnG0WWCVTmhOxrvpgM6bIjKuT4AXZZaNN0QPmmEUOZB1sKn7/54t2/puFDsNUvAFyD/6H6Z2xqxi7amBpGKrX6om8H9AlpGnYVLkiIrUee0PVk+At8L/YTihmYwRD/yVOCEddFTNKJM2JZAp7lYcE+Zp7HENMMqZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298715; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sPku26GIVDFC2Em7hAIYeZdBoMTEx4YdSTzsnxKDZzE=; b=YfYvq1y10+kw1qhChHdHNe9VkLGDcURDo8DlkUshVP6t3JCe/4yTL5gGEqX4Kua9Egq8NLRLCuy6BIO/4UZuhC2XemN57am0lAgq5EYpSdk1lJYwhfcsXU3TGlpskkeG4WJ5KvkJEQI1FfoBtvm578hVNy6JTJEffZald/GvGE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1660298715183258.5599423752052; Fri, 12 Aug 2022 03:05:15 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-vsxr0nq5N9a-daDbNXPDCw-1; Fri, 12 Aug 2022 06:04:41 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D89C28039B5; Fri, 12 Aug 2022 10:04:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5A3D40334B; Fri, 12 Aug 2022 10:04:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7D59C1946A5F; Fri, 12 Aug 2022 10:04:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DA4A31946A5C for ; Fri, 12 Aug 2022 10:04:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BFA4FC15BA8; Fri, 12 Aug 2022 10:04:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 651E8C15BA6 for ; Fri, 12 Aug 2022 10:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660298714; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=sPku26GIVDFC2Em7hAIYeZdBoMTEx4YdSTzsnxKDZzE=; b=esrIfCbcbnfzCbhUW3pDreDQfGGGddDF0z+uPNivkQdCtzC1v5QwGRqAqE+LbPEP1PVAD1 wbASd8ap1ilqe+5EcmO25Xv8rslA1vmEWo6ZLGeFGDzaPdJsriqjaW6SwzC3T+jifz1lxB FZsbyhYX7mOM5uEotkLGQuHE/XVcXYQ= X-MC-Unique: vsxr0nq5N9a-daDbNXPDCw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 8/8] qemu: Enable for vCPUs on hotplug Date: Fri, 12 Aug 2022 12:04:23 +0200 Message-Id: <9a2171d3d13655ab7a6c5bce793e741464aafd80.1660298204.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1660298716420100003 Content-Type: text/plain; charset="utf-8"; x-default="true" As advertised in the previous commit, QEMU_SCHED_CORE_VCPUS case is implemented for hotplug case. The implementation is very similar to the cold boot case, except here we fork off for every vCPU (because the implementation is done in qemuProcessSetupVcpu() which is also the function that's called from hotplug code). But that's okay because our hotplug APIs allow hotplugging one device at the time. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2074559 Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 63 +++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_process.h | 3 +- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 30f146f2f4..ff7f87f362 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6240,7 +6240,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriver *driver, vcpuinfo->online =3D true; =20 if (vcpupriv->tid > 0 && - qemuProcessSetupVcpu(vm, i) < 0) + qemuProcessSetupVcpu(vm, i, true) < 0) return -1; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f9c4f72496..8892bf40e4 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5817,10 +5817,48 @@ qemuProcessNetworkPrepareDevices(virQEMUDriver *dri= ver, } =20 =20 +struct qemuProcessSetupVcpuSchedCoreHelperData { + pid_t vcpupid; + pid_t dummypid; +}; + +static int +qemuProcessSetupVcpuSchedCoreHelper(pid_t ppid G_GNUC_UNUSED, + void *opaque) +{ + struct qemuProcessSetupVcpuSchedCoreHelperData *data =3D opaque; + + if (data->dummypid !=3D -1) { + if (virProcessSchedCoreShareFrom(data->dummypid) < 0) { + virReportSystemError(errno, + _("unable to share scheduling cookie from= %lld"), + (long long) data->dummypid); + return -1; + } + } else { + if (virProcessSchedCoreCreate() < 0) { + virReportSystemError(errno, "%s", + _("unable to create new scheduling group"= )); + return -1; + } + } + + if (virProcessSchedCoreShareTo(data->vcpupid) < 0) { + virReportSystemError(errno, + _("unable to share scheduling cookie to %lld"= ), + (long long) data->vcpupid); + return -1; + } + + return 0; +} + + /** * qemuProcessSetupVcpu: * @vm: domain object * @vcpuid: id of VCPU to set defaults + * @schedCore: whether to set scheduling group * * This function sets resource properties (cgroups, affinity, scheduler) f= or a * vCPU. This function expects that the vCPU is online and the vCPU pids w= ere @@ -5830,8 +5868,11 @@ qemuProcessNetworkPrepareDevices(virQEMUDriver *driv= er, */ int qemuProcessSetupVcpu(virDomainObj *vm, - unsigned int vcpuid) + unsigned int vcpuid, + bool schedCore) { + qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); pid_t vcpupid =3D qemuDomainGetVcpuPid(vm, vcpuid); virDomainVcpuDef *vcpu =3D virDomainDefGetVcpu(vm->def, vcpuid); virDomainResctrlMonDef *mon =3D NULL; @@ -5844,6 +5885,24 @@ qemuProcessSetupVcpu(virDomainObj *vm, &vcpu->sched) < 0) return -1; =20 + if (schedCore && + cfg->schedCore =3D=3D QEMU_SCHED_CORE_VCPUS) { + struct qemuProcessSetupVcpuSchedCoreHelperData data =3D { .vcpupid= =3D vcpupid, + .dummypid =3D -1 }; + + for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { + pid_t temptid =3D qemuDomainGetVcpuPid(vm, i); + + if (temptid > 0) { + data.dummypid =3D temptid; + break; + } + } + + if (virProcessRunInFork(qemuProcessSetupVcpuSchedCoreHelper, &data= ) < 0) + return -1; + } + for (i =3D 0; i < vm->def->nresctrls; i++) { size_t j =3D 0; virDomainResctrlDef *ct =3D vm->def->resctrls[i]; @@ -5950,7 +6009,7 @@ qemuProcessSetupVcpus(virDomainObj *vm) if (!vcpu->online) continue; =20 - if (qemuProcessSetupVcpu(vm, i) < 0) + if (qemuProcessSetupVcpu(vm, i, false) < 0) return -1; } =20 diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 421efc6016..4dfb2485c0 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -187,7 +187,8 @@ int qemuConnectAgent(virQEMUDriver *driver, virDomainOb= j *vm); =20 =20 int qemuProcessSetupVcpu(virDomainObj *vm, - unsigned int vcpuid); + unsigned int vcpuid, + bool schedCore); int qemuProcessSetupIOThread(virDomainObj *vm, virDomainIOThreadIDDef *iothread); =20 --=20 2.35.1