From nobody Sun Feb 8 18:32:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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=1665064210; cv=none; d=zohomail.com; s=zohoarc; b=iA6Bd/cLxQ5JL6MjUGmE+7SDYUMKkzhzR9wX70mJD72MHqa9RLYPbYXj9d/1SRLqybR1uKWvSLQfHiFF03/MVNh+5XW55rgZQoKqbzwNb54lJrHxcwwcTv9LwK4cdyWcohkzrNJ+uilm60RjUcvvqxnbcvnCGr70xf4YTfEZ+Q4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665064210; 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=ebX22NkYWbc+1AFWFhMpsDX5bf/2dk78xysRQHKEhRM=; b=a7x8Ygc6PwVoY/fmzV7KMMJ6zDny7Aw1otbP64QR9Tq7Ii3xAyAZbulWjG9VB3XLFYjhbkSNNs6pQc0Hx3UqIZ7v/QTd9g0lU1jBzWAmP2c3pHbVgQkenDu8puTgF8ey/A/7DbyvOO7f9UTdmQOK2QRay1QSq2lSiVY3gs7lARU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 16650642103601001.8094154778997; Thu, 6 Oct 2022 06:50:10 -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-413-cAfqiSj1MuOPS-I2tfJXcw-1; Thu, 06 Oct 2022 09:50:05 -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 2DDE882DFCD; Thu, 6 Oct 2022 13:49:58 +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 18B0B40315F; Thu, 6 Oct 2022 13:49:58 +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 08D8E1946589; Thu, 6 Oct 2022 13:49:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5CD321946589 for ; Thu, 6 Oct 2022 13:49:56 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4F29C14583FC; Thu, 6 Oct 2022 13:49:56 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id E865514583FA for ; Thu, 6 Oct 2022 13:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665064207; 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=ebX22NkYWbc+1AFWFhMpsDX5bf/2dk78xysRQHKEhRM=; b=VgmG7yw3Sh7UrSkmbVnf5OOomYJSQD83/hdzSYiwEgrYp4RxA/SDiDZM9EFNFpzpzD6LUU XecQFKHhFJiTRPkjiq4j7rz0gJPEh8PrPeIgzlVnSX6F4o1SvTttPU3AleSBIqpfCcFRyk Ew3+/jRhAJhpRgDa2MOg2kn6fwVpgMg= X-MC-Unique: cAfqiSj1MuOPS-I2tfJXcw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v4 4/8] qemu_domain: Introduce qemuDomainSchedCoreStart() Date: Thu, 6 Oct 2022 15:49:46 +0200 Message-Id: <73bb5bbe6759d13f2c0238e315b46961db4b39aa.1665064015.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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 3.1 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: 1665064210967100002 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 858d14af6a..326ffdd335 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1778,6 +1778,8 @@ qemuDomainObjPrivateFree(void *data) g_object_unref(priv->eventThread); } =20 + qemuDomainSchedCoreStop(priv); + g_free(priv); } =20 @@ -1799,6 +1801,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 @@ -11771,3 +11776,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")); + _exit(EXIT_FAILURE); + } + + ignore_value(saferead(waitfd[0], &c, 1)); + VIR_FORCE_CLOSE(waitfd[0]); + _exit(EXIT_SUCCESS); + } 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 a22deaf113..d86ef5f3d6 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -242,6 +242,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 97336e2622..7385f9fb28 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7485,6 +7485,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 @@ -7757,6 +7760,7 @@ qemuProcessLaunch(virConnectPtr conn, ret =3D 0; =20 cleanup: + qemuDomainSchedCoreStop(priv); qemuDomainSecretDestroy(vm); return ret; } --=20 2.35.1