From nobody Sat Feb 7 09:30:12 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=1660298681; cv=none; d=zohomail.com; s=zohoarc; b=Dhm3VDQwmRgLxVFUrYGOagFz0SjHFxen95f2B1LWounJ77eCkk8A+P8FMcuDHf5LWjzZLicaIHGuBT/RduRuLwh3Qz9cTmXm58rHlZPsOrLCq6e5QaOplQLsVpM5ScYosjaBfIS04uEOT/9jMz1sA86ljFjxUJKryU7Cc+gCJag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298681; 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=Mp3ZuS+cF8dIyicVWHvsiVUx/q0Kh60pG9VkyljKAbc=; b=cWfmrUPXWY4t3oEbxLGLiGoHzmJCWwixBF8A7BVXAFu86f8L070XUlU7XYzKbXXY/lxuFnS+5cQMX6IcmMVHV5413LchQiaYNaGWPk8JFJ3RH7C9eAPfunnHniA9GDI/7LdZohD0Z5QUU3u/OOGVErzhzNuaCwERWLrZc1TsZJI= 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 1660298681412896.7093560306697; Fri, 12 Aug 2022 03:04:41 -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-278-YYFTkjJFPyGOgZ-wdgXRZQ-1; Fri, 12 Aug 2022 06:04:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30D371019CA3; Fri, 12 Aug 2022 10:04:35 +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 1B79C1121320; Fri, 12 Aug 2022 10:04:35 +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 AD3541946A67; Fri, 12 Aug 2022 10:04:34 +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 631421946A41 for ; Fri, 12 Aug 2022 10:04:33 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 52E41C15BA8; Fri, 12 Aug 2022 10:04:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC546C15BA6 for ; Fri, 12 Aug 2022 10:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660298680; 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=Mp3ZuS+cF8dIyicVWHvsiVUx/q0Kh60pG9VkyljKAbc=; b=KYZaXVRvW3s4Jz61NhvyYxmeRn+zXVsc55FSiSJtGkGlQBGQkdOnsKvCSGPR+vMrKv8gYQ kU5o8dYO6jGbD8E2ZkZTsoRpIUxzh5mo+6v36+AUbc4yCN/eLZdw4/5X8tfPp9Yn7ojO0W ekTQoO0V8Xwd7pfakoj/UZDsUKcDX0Y= X-MC-Unique: YYFTkjJFPyGOgZ-wdgXRZQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 4/8] qemu_domain: Introduce qemuDomainSchedCoreStart() Date: Fri, 12 Aug 2022 12:04:19 +0200 Message-Id: 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.78 on 10.11.54.3 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: 1660298683497100006 Content-Type: text/plain; charset="utf-8"; x-default="true" The aim of this helper function is to spawn a child process in which new scheduling group is created. This dummy process will then used to distribute scheduling group from (e.g. when starting helper processes or QEMU itself). The process is not needed for QEMU_SCHED_CORE_NONE case (obviously) nor for QEMU_SCHED_CORE_VCPUS case (because in that case a slightly different child will be forked off). Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 105 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 12 +++++ src/qemu/qemu_process.c | 4 ++ 3 files changed, 121 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9d5dd07958..6b30aec67d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1747,6 +1747,8 @@ qemuDomainObjPrivateFree(void *data) g_object_unref(priv->eventThread); } =20 + qemuDomainSchedCoreStop(priv); + g_free(priv); } =20 @@ -1778,6 +1780,9 @@ qemuDomainObjPrivateAlloc(void *opaque) priv->migMaxBandwidth =3D QEMU_DOMAIN_MIG_BANDWIDTH_MAX; priv->driver =3D opaque; =20 + priv->schedCoreChildPID =3D -1; + priv->schedCoreChildFD =3D -1; + return g_steal_pointer(&priv); } =20 @@ -11691,3 +11696,103 @@ qemuDomainObjWait(virDomainObj *vm) =20 return 0; } + + +int +qemuDomainSchedCoreStart(virQEMUDriverConfig *cfg, + virDomainObj *vm) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + int waitfd[2] =3D { -1, -1 }; + int syncfd[2] =3D { -1, -1 }; + pid_t child =3D -1; + + if (cfg->schedCore =3D=3D QEMU_SCHED_CORE_NONE || + cfg->schedCore =3D=3D QEMU_SCHED_CORE_VCPUS) { + /* We don't need any dummy process for any of these two variants. = */ + return 0; + } + + if (virPipe(waitfd) < 0 || + virPipe(syncfd) < 0) + return -1; + + if ((child =3D virFork()) < 0) + goto error; + + if (child =3D=3D 0) { + /* child */ + int rc; + char c; + + VIR_FORCE_CLOSE(waitfd[1]); + VIR_FORCE_CLOSE(syncfd[0]); + + errno =3D 0; + rc =3D virProcessSchedCoreCreate(); + c =3D errno; + ignore_value(safewrite(syncfd[1], &c, 1)); + VIR_FORCE_CLOSE(syncfd[1]); + + if (rc < 0) { + virReportSystemError(errno, "%s", + _("Unable to set SCHED_CORE")); + goto error; + } + + ignore_value(saferead(waitfd[0], &c, 1)); + + VIR_FORCE_CLOSE(waitfd[0]); + } else { + /* parent */ + char c =3D '\0'; + VIR_FORCE_CLOSE(waitfd[0]); + VIR_FORCE_CLOSE(syncfd[1]); + + if (saferead(syncfd[0], &c, 1) < 0) { + virReportSystemError(errno, "%s", + _("unable to read from pipe")); + goto error; + } + VIR_FORCE_CLOSE(syncfd[0]); + + if (c !=3D 0) { + virReportSystemError(c, "%s", + _("Unable to set SCHED_CORE")); + goto error; + } + + VIR_DEBUG("Spawned dummy process for schedCore (%s) pid=3D%lld fd= =3D%d", + virQEMUSchedCoreTypeToString(cfg->schedCore), + (long long) child, waitfd[1]); + + priv->schedCoreChildPID =3D child; + priv->schedCoreChildFD =3D waitfd[1]; + } + + return 0; + + error: + VIR_FORCE_CLOSE(waitfd[0]); + VIR_FORCE_CLOSE(waitfd[1]); + VIR_FORCE_CLOSE(syncfd[0]); + VIR_FORCE_CLOSE(syncfd[1]); + return -1; +} + + +void +qemuDomainSchedCoreStop(qemuDomainObjPrivate *priv) +{ + if (priv->schedCoreChildFD !=3D -1) { + ignore_value(safewrite(priv->schedCoreChildFD, "q", 1)); + VIR_FORCE_CLOSE(priv->schedCoreChildFD); + } + + if (priv->schedCoreChildPID !=3D -1) { + VIR_DEBUG("Killing dummy procces for schedCore pid=3D%lld", + (long long) priv->schedCoreChildPID); + virProcessAbort(priv->schedCoreChildPID); + priv->schedCoreChildPID =3D -1; + } +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 592ee9805b..620830ccf5 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -244,6 +244,11 @@ struct _qemuDomainObjPrivate { =20 unsigned long long originalMemlock; /* Original RLIMIT_MEMLOCK, zero i= f no * restore will be required later = */ + + /* Info on dummy process for schedCore. A short lived process used only + * briefly when starting a guest. Don't save/parse into XML. */ + pid_t schedCoreChildPID; + pid_t schedCoreChildFD; }; =20 #define QEMU_DOMAIN_PRIVATE(vm) \ @@ -1098,3 +1103,10 @@ qemuDomainRemoveLogs(virQEMUDriver *driver, =20 int qemuDomainObjWait(virDomainObj *vm); + +int +qemuDomainSchedCoreStart(virQEMUDriverConfig *cfg, + virDomainObj *vm); + +void +qemuDomainSchedCoreStop(qemuDomainObjPrivate *priv); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index cfcf879f59..8b027f2d39 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7502,6 +7502,9 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuProcessGenID(vm, flags) < 0) goto cleanup; =20 + if (qemuDomainSchedCoreStart(cfg, vm) < 0) + goto cleanup; + if (qemuExtDevicesStart(driver, vm, incoming !=3D NULL) < 0) goto cleanup; =20 @@ -7774,6 +7777,7 @@ qemuProcessLaunch(virConnectPtr conn, ret =3D 0; =20 cleanup: + qemuDomainSchedCoreStop(priv); qemuDomainSecretDestroy(vm); return ret; } --=20 2.35.1