From nobody Fri May 17 05:54:31 2024 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=1660298705; cv=none; d=zohomail.com; s=zohoarc; b=cf8cHDHSPp4KXFaxvSc3CB7FZPje9vFV0Er7+hVzijhAqnRaPaciJIBT5IxDMONqeOgsdt6EHEbWF0FskX7foJmzG2TyBXywjEjVHhueN0rPTGy4UCn3Vamnp2Pak0F9lK4OT3USHaiCMbyOJz5JLaC2IHWncnDBnMlzJmZ45sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298705; 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=Cl+ZWTLqZhGjV1cgSR8b11jY2+lZT+LoaF+NuMLjGwE=; b=PvAiu3DT8eiw9jEkjnSZS/a1kozfsl+dwPTj9ltp0tHyGkopKfa4DgS7jqq+cpLV3+UmU+P0krPB+cG36ZfRhfepQXijoegtn2yo3F1adalk9aphc9T8HvxHTEv6MSTr2+AKUf0XlMy4rvZ56CGywRu+ihhX8XWjWfxvBZBj5wc= 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 1660298705232612.60988698877; Fri, 12 Aug 2022 03:05:05 -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-2-RGeCUEX1Md2sOkQ771n3PA-1; Fri, 12 Aug 2022 06:04:34 -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 F30128039A1; Fri, 12 Aug 2022 10:04:31 +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 E1FFD112131E; Fri, 12 Aug 2022 10:04:31 +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 96AA71946A5E; Fri, 12 Aug 2022 10:04:30 +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 73C851946A41 for ; Fri, 12 Aug 2022 10:04:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 57ADBC15BA8; Fri, 12 Aug 2022 10:04:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id F15DDC15BA6 for ; Fri, 12 Aug 2022 10:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660298704; 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=Cl+ZWTLqZhGjV1cgSR8b11jY2+lZT+LoaF+NuMLjGwE=; b=LOLt9360stx+63UZoSa/E+PvZjjScuC5Jj6ZSbwYhcX3G7FKXWyzrr0BVHDigU/pXOehgE ixsrh49rLnDbB3+r+md3Jk+mcVbM3AJSmfyvMmTKaidYWsXEtrpHL4mzZKFV+sPk2DzKDD 0Uiza3bycbt72jBVcZd1nRQt485bJZE= X-MC-Unique: RGeCUEX1Md2sOkQ771n3PA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 1/8] virprocess: Core Scheduling support Date: Fri, 12 Aug 2022 12:04:16 +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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1660298706477100001 Since its 5.14 release the Linux kernel allows userspace to define trusted groups of processes/threads that can run on sibling Hyper Threads (HT) at the same time. This is to mitigate side channel attacks like L1TF or MDS. If there are no tasks to fully utilize all HTs, then a HT will idle instead of running a task from another (un-)trusted group. On low level, this is implemented by cookies (effectively an UL value): processes in the same trusted group share the same cookie and cookie is unique to the group. There are four basic operations: 1) PR_SCHED_CORE_GET -- get cookie of given PID, 2) PR_SCHED_CORE_CREATE -- create a new unique cookie for PID, 3) PR_SCHED_CORE_SHARE_TO -- push cookie of the caller onto another PID, 4) PR_SCHED_CORE_SHARE_FROM -- pull cookie of another PID into the caller. Since a system where the code is built can be different to the one where the code is ran let's provide declaration of some values. It's not unusual for distros to ship older linux-headers than the actual kernel. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 4 ++ src/util/virprocess.c | 124 +++++++++++++++++++++++++++++++++++++++ src/util/virprocess.h | 8 +++ 3 files changed, 136 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ac2802095e..23abf663f6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3153,6 +3153,10 @@ virProcessKillPainfullyDelay; virProcessNamespaceAvailable; virProcessRunInFork; virProcessRunInMountNamespace; +virProcessSchedCoreAvailable; +virProcessSchedCoreCreate; +virProcessSchedCoreShareFrom; +virProcessSchedCoreShareTo; virProcessSchedPolicyTypeFromString; virProcessSchedPolicyTypeToString; virProcessSetAffinity; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 013afd91b4..a59e64970d 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -56,6 +56,10 @@ # include #endif =20 +#ifdef __linux__ +# include +#endif + #include "virprocess.h" #include "virerror.h" #include "viralloc.h" @@ -1874,3 +1878,123 @@ virProcessGetSchedInfo(unsigned long long *cpuWait, return 0; } #endif /* __linux__ */ + +#ifdef __linux__ +# ifndef PR_SCHED_CORE +/* Copied from linux/prctl.h */ +# define PR_SCHED_CORE 62 +# define PR_SCHED_CORE_GET 0 +# define PR_SCHED_CORE_CREATE 1 /* create unique core_sched cookie */ +# define PR_SCHED_CORE_SHARE_TO 2 /* push core_sched cookie to pid */ +# define PR_SCHED_CORE_SHARE_FROM 3 /* pull core_sched cookie to pid */ +# endif + +/* Unfortunately, kernel-headers forgot to export these. */ +# ifndef PR_SCHED_CORE_SCOPE_THREAD +# define PR_SCHED_CORE_SCOPE_THREAD 0 +# define PR_SCHED_CORE_SCOPE_THREAD_GROUP 1 +# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP 2 +# endif + +/** + * virProcessSchedCoreAvailable: + * + * Check whether kernel supports Core Scheduling (CONFIG_SCHED_CORE), i.e.= only + * a defined set of PIDs/TIDs can run on sibling Hyper Threads at the same + * time. + * + * Returns: 1 if Core Scheduling is available, + * 0 if Core Scheduling is NOT available, + * -1 otherwise. + */ +int +virProcessSchedCoreAvailable(void) +{ + unsigned long cookie =3D 0; + int rc; + + /* Let's just see if we can get our own sched cookie, and if yes we can + * safely assume CONFIG_SCHED_CORE kernel is available. */ + rc =3D prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, 0, + PR_SCHED_CORE_SCOPE_THREAD, &cookie); + + return rc =3D=3D 0 ? 1 : errno =3D=3D EINVAL ? 0 : -1; +} + +/** + * virProcessSchedCoreCreate: + * + * Creates a new trusted group for the caller process. + * + * Returns: 0 on success, + * -1 otherwise, with errno set. + */ +int +virProcessSchedCoreCreate(void) +{ + /* pid =3D 0 (3rd argument) means the calling process. */ + return prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, + PR_SCHED_CORE_SCOPE_THREAD_GROUP, 0); +} + +/** + * virProcessSchedCoreShareFrom: + * @pid: PID to share group with + * + * Places the current caller process into the trusted group of @pid. + * + * Returns: 0 on success, + * -1 otherwise, with errno set. + */ +int +virProcessSchedCoreShareFrom(pid_t pid) +{ + return prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, pid, + PR_SCHED_CORE_SCOPE_THREAD, 0); +} + +/** + * virProcessSchedCoreShareTo: + * @pid: PID to share group with + * + * Places foreign @pid into the trusted group of the current caller proces= s. + * + * Returns: 0 on success, + * -1 otherwise, with errno set. + */ +int +virProcessSchedCoreShareTo(pid_t pid) +{ + return prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, pid, + PR_SCHED_CORE_SCOPE_THREAD, 0); +} + +#else /* !__linux__ */ + +int +virProcessSchedCoreAvailable(void) +{ + return 0; +} + +int +virProcessSchedCoreCreate(void) +{ + errno =3D ENOSYS; + return -1; +} + +int +virProcessSchedCoreShareFrom(pid_t pid G_GNUC_UNUSED) +{ + errno =3D ENOSYS; + return -1; +} + +int +virProcessSchedCoreShareTo(pid_t pid G_GNUC_UNUSED) +{ + errno =3D ENOSYS; + return -1; +} +#endif /* !__linux__ */ diff --git a/src/util/virprocess.h b/src/util/virprocess.h index 30b6981c73..a3bfd0d911 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -202,3 +202,11 @@ int virProcessGetStatInfo(unsigned long long *cpuTime, int virProcessGetSchedInfo(unsigned long long *cpuWait, pid_t pid, pid_t tid); + +int virProcessSchedCoreAvailable(void); + +int virProcessSchedCoreCreate(void); + +int virProcessSchedCoreShareFrom(pid_t pid); + +int virProcessSchedCoreShareTo(pid_t pid); --=20 2.35.1 From nobody Fri May 17 05:54:31 2024 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=1660298682; cv=none; d=zohomail.com; s=zohoarc; b=ZDt1G13VMZc2V6GZLNINlR1rdOmBeze/JEpScj9oIWivVu3BJV7HL6vWLaBZ4FZxnl7i4GByLHu1qs5C64TVX9ogx1Ntw7r0AFhPfZ7fElR5LX/oT6YxnzyALFtPku0xnE9bXblSHDDwXH4+KNwDnSxPVcAHYKJ+AQDNT1wQLV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298682; 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=lXHWRq5j3YT/m+dV0QzGjflInwV8DX/UdNo9gqd2DfU=; b=Op/7ZeSA2X+Yr1W7hDQbdSewWf0yQJZQQ55B9EQ9drvTYVonYEpkCdbHBT2Y/lYvdx0IGGMSZ3t3vm5oF/q3LxunoOG465njrrIx4i7MqSbW2VcyD9BiSMqaFPJ0BX9qznnOb06x7hjH4gknukbbNjvJd4P5WjhuT0xNzWxx9ts= 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 1660298682334966.1310071587462; Fri, 12 Aug 2022 03:04:42 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-283-8nJWcsfHOkeWZud76IX1Jw-1; Fri, 12 Aug 2022 06:04:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6CA9B3802AC9; Fri, 12 Aug 2022 10:04:33 +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 565262166B26; Fri, 12 Aug 2022 10:04:33 +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 158791946A42; Fri, 12 Aug 2022 10:04:33 +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 3DBC71946A42 for ; Fri, 12 Aug 2022 10:04:32 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1C722C15BA6; Fri, 12 Aug 2022 10:04:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id B63AFC15BB8 for ; Fri, 12 Aug 2022 10:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660298681; 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=lXHWRq5j3YT/m+dV0QzGjflInwV8DX/UdNo9gqd2DfU=; b=MUGuXs3jS0XgPth0Q91wYJuG4jEQIdtGufGl2WEPThy4jHvStSyQj8bHqrya+5JHThkoue CW4nZzc9fBDEo5sjsiTEVPOe2l4ClbvvxJxjV+El/ZkZJwQJtafNthvHrjiZ50NT3Nz5H5 SoxCeisWZyQ3Hm5y1PJXcTScjnvUWXQ= X-MC-Unique: 8nJWcsfHOkeWZud76IX1Jw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 2/8] virCommand: Introduce APIs for core scheduling Date: Fri, 12 Aug 2022 12:04:17 +0200 Message-Id: <95a9a98bb952a766d9e078a7de195cc558fa1544.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.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1660298683496100005 There are two modes of core scheduling that are handy wrt virCommand: 1) create new trusted group when executing a virCommand 2) place freshly executed virCommand into the trusted group of another process. Therefore, implement these two new operations as new APIs: virCommandSetRunAlone() and virCommandSetRunAmong(), respectively. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 2 ++ src/util/vircommand.c | 63 ++++++++++++++++++++++++++++++++++++++++ src/util/vircommand.h | 5 ++++ 3 files changed, 70 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 23abf663f6..02d1c753a4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2103,6 +2103,8 @@ virCommandSetOutputBuffer; virCommandSetOutputFD; virCommandSetPidFile; virCommandSetPreExecHook; +virCommandSetRunAlone; +virCommandSetRunAmong; virCommandSetSELinuxLabel; virCommandSetSendBuffer; virCommandSetUID; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index d78c666f28..745e7c560c 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -148,6 +148,13 @@ struct _virCommand { #endif int mask; =20 + /* schedCore values: + * 0: no core scheduling + * >0: copy scheduling group from PID + * -1: create new scheduling group + */ + pid_t schedCore; + virCommandSendBuffer *sendBuffers; size_t numSendBuffers; }; @@ -434,6 +441,22 @@ virCommandHandshakeChild(virCommand *cmd) static int virExecCommon(virCommand *cmd, gid_t *groups, int ngroups) { + /* Do this before dropping capabilities. */ + if (cmd->schedCore =3D=3D -1 && + virProcessSchedCoreCreate() < 0) { + virReportSystemError(errno, "%s", + _("Unable to set SCHED_CORE")); + return -1; + } + + if (cmd->schedCore > 0 && + virProcessSchedCoreShareFrom(cmd->schedCore) < 0) { + virReportSystemError(errno, + _("Unable to run among %llu"), + (unsigned long long) cmd->schedCore); + return -1; + } + if (cmd->uid !=3D (uid_t)-1 || cmd->gid !=3D (gid_t)-1 || cmd->capabilities || (cmd->flags & VIR_EXEC_CLEAR_CAPS)) { VIR_DEBUG("Setting child uid:gid to %d:%d with caps %llx", @@ -3386,3 +3409,43 @@ virCommandRunNul(virCommand *cmd G_GNUC_UNUSED, return -1; } #endif /* WIN32 */ + +/** + * virCommandSetRunAlone: + * + * Create new trusted group when running the command. In other words, the + * process won't be scheduled to run on a core among with processes from + * another, untrusted group. + */ +void +virCommandSetRunAlone(virCommand *cmd) +{ + if (virCommandHasError(cmd)) + return; + + cmd->schedCore =3D -1; +} + +/** + * virCommandSetRunAmong: + * @pid: pid from a trusted group + * + * When spawning the command place it into the trusted group of @pid so th= at + * these two processes can run on Hyper Threads of a single core at the sa= me + * time. + */ +void +virCommandSetRunAmong(virCommand *cmd, + pid_t pid) +{ + if (virCommandHasError(cmd)) + return; + + if (pid <=3D 0) { + VIR_DEBUG("invalid pid value: %lld", (long long) pid); + cmd->has_error =3D -1; + return; + } + + cmd->schedCore =3D pid; +} diff --git a/src/util/vircommand.h b/src/util/vircommand.h index c7a580e152..98788bcbf7 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -217,4 +217,9 @@ int virCommandRunNul(virCommand *cmd, virCommandRunNulFunc func, void *data); =20 +void virCommandSetRunAlone(virCommand *cmd); + +void virCommandSetRunAmong(virCommand *cmd, + pid_t pid); + G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCommand, virCommandFree); --=20 2.35.1 From nobody Fri May 17 05:54:31 2024 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=1660298680; cv=none; d=zohomail.com; s=zohoarc; b=PrCZPWBW/e9uOukuKERz72JeBadgFRLKf0INlAoH0I7yyS4MC9deTY2SX1jvdZT0FNTqLlp8qu6gnfgUAY+8LkMqN5TTf3s7imc5e8qM/7GQYRAUGN/6Sts5Jn4+svls8hw3Luz9pJHZB0fvOIu7pwkqDSIvfucKBt/Cw/QWZwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298680; 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=3v14BR+AMidqYmxfOSO9K/1k8iw2rONhp4/Uijh+KRE=; b=Pbv8pJmBMQKKzpIhxMLLhC82afJalxWAh8Y6p7aBzoWGZh4XbAf2KMwKX3dIfbiVg0lT1I8RtubZeTVMbjttwoho44QSPi9wO2sytQUl3ENb0YSz/wfTN7PLUlWGgn+UjzFZ1fNnv9jZStWwWdXYf+Ri3wRo/uu4TwJlO2MoVC4= 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 1660298680600303.81004906996816; Fri, 12 Aug 2022 03:04:40 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-300-6O7NPVntNeSKgEpqRNbWVg-1; Fri, 12 Aug 2022 06:04:36 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFEE83C11064; Fri, 12 Aug 2022 10:04:34 +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 AD854492C3B; Fri, 12 Aug 2022 10:04:34 +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 67D921946A42; 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 C972F1946A41 for ; Fri, 12 Aug 2022 10:04:32 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B19C7C15BA8; Fri, 12 Aug 2022 10:04:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5749DC15BA6 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=1660298678; 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=3v14BR+AMidqYmxfOSO9K/1k8iw2rONhp4/Uijh+KRE=; b=UsEai4TGRUNnzL9M4LyPNVw0TpQax7mXkVOwSL4JDYgsgw8pg1uuqjL1I/tlJihFNaPYPO /mddWWRO9jSnqhBpmTlM1Scimcw6lKLR9qrsER6HxjPrj6zBe1gbq1yXG/rvxnBBxFjspG eVUDKeFlW2fXv2XJ21z+SOxZVusI5eQ= X-MC-Unique: 6O7NPVntNeSKgEpqRNbWVg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 3/8] qemu_conf: Introduce a knob to set SCHED_CORE Date: Fri, 12 Aug 2022 12:04:18 +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.85 on 10.11.54.9 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: 1660298681517100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Ideally, we would just pick the best default and users wouldn't have to intervene at all. But in some cases it may be handy to not bother with SCHED_CORE at all or place helper processes into the same group as QEMU. Introduce a knob in qemu.conf to allow users control this behaviour. Signed-off-by: Michal Privoznik --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf.in | 16 +++++++++++++ src/qemu/qemu_conf.c | 38 ++++++++++++++++++++++++++++++ src/qemu/qemu_conf.h | 13 ++++++++++ src/qemu/test_libvirtd_qemu.aug.in | 1 + 5 files changed, 69 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 0f18775121..ed097ea3d9 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -110,6 +110,7 @@ module Libvirtd_qemu =3D | bool_entry "dump_guest_core" | str_entry "stdio_handler" | int_entry "max_threads_per_process" + | str_entry "sched_core" =20 let device_entry =3D bool_entry "mac_filter" | bool_entry "relaxed_acs_check" diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 04b7740136..adcaccfdf1 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -952,3 +952,19 @@ # DO NOT use in production. # #deprecation_behavior =3D "none" + +# If this is set then QEMU and its threads will run in a separate scheduli= ng +# group meaning no other process will share Hyper Threads of a single core= with +# QEMU. Each QEMU has its own group. +# +# Possible options are: +# "none" - (default) nor QEMU nor any of its helper processes are plac= ed into +# separate scheduling group +# "vcpus" - only QEMU vCPU threads are placed into a separate schedulin= g group, +# emulator threads and helper processes remain outside of the= group +# "emulator" - only QEMU and its threads (emulator + vCPUs) are placed into +# separate scheduling group, helper proccesses remain outside= of +# the group +# "full" - both QEMU and its helper processes are placed into separate +# scheduling group +#sched_core =3D "none" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 3b75cdeb95..2634fe737c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -66,6 +66,14 @@ VIR_LOG_INIT("qemu.qemu_conf"); #define QEMU_MIGRATION_PORT_MIN 49152 #define QEMU_MIGRATION_PORT_MAX 49215 =20 +VIR_ENUM_IMPL(virQEMUSchedCore, + QEMU_SCHED_CORE_LAST, + "none", + "vcpus", + "emulator", + "full"); + + static virClass *virQEMUDriverConfigClass; static void virQEMUDriverConfigDispose(void *obj); =20 @@ -629,6 +637,7 @@ virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfig= *cfg, g_auto(GStrv) hugetlbfs =3D NULL; g_autofree char *stdioHandler =3D NULL; g_autofree char *corestr =3D NULL; + g_autofree char *schedCore =3D NULL; size_t i; =20 if (virConfGetValueStringList(conf, "hugetlbfs_mount", true, @@ -706,6 +715,35 @@ virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfi= g *cfg, } } =20 + if (virConfGetValueString(conf, "sched_core", &schedCore) < 0) + return -1; + if (schedCore) { + int val =3D virQEMUSchedCoreTypeFromString(schedCore); + + if (val < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unknown sched_core value %s"), + schedCore); + return -1; + } + + if (val !=3D QEMU_SCHED_CORE_NONE) { + int rv =3D virProcessSchedCoreAvailable(); + + if (rv < 0) { + virReportSystemError(errno, "%s", + _("Unable to detect SCHED_CORE")); + return -1; + } else if (rv =3D=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("SCHED_CORE not supported by kernel")); + return -1; + } + } + + cfg->schedCore =3D val; + } + return 0; } =20 diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index c40c452f58..0dd7c55db3 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -44,6 +44,17 @@ =20 #define QEMU_DRIVER_NAME "QEMU" =20 +typedef enum { + QEMU_SCHED_CORE_NONE =3D 0, + QEMU_SCHED_CORE_VCPUS, + QEMU_SCHED_CORE_EMULATOR, + QEMU_SCHED_CORE_FULL, + + QEMU_SCHED_CORE_LAST +} virQEMUSchedCore; + +VIR_ENUM_DECL(virQEMUSchedCore); + typedef struct _virQEMUDriver virQEMUDriver; =20 typedef struct _virQEMUDriverConfig virQEMUDriverConfig; @@ -216,6 +227,8 @@ struct _virQEMUDriverConfig { char **capabilityfilters; =20 char *deprecationBehavior; + + virQEMUSchedCore schedCore; }; =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref); diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index 757d21c33f..1dbd692921 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -116,3 +116,4 @@ module Test_libvirtd_qemu =3D { "1" =3D "capname" } } { "deprecation_behavior" =3D "none" } +{ "sched_core" =3D "none" } --=20 2.35.1 From nobody Fri May 17 05:54:31 2024 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 From nobody Fri May 17 05:54:31 2024 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=1660298712; cv=none; d=zohomail.com; s=zohoarc; b=anaT/fp4RKAEAc8BNjNRrkDy9T3XM5dVoDzRqVerIzhtRIUjQIsHjYU86KC9YYO56DnM+TDorZ1p+sbYqGS5tIAgFV4MrKx9r3K0NgkvnYsLLZSrrQio0qHcR4f9n5RS+xr7QBi4RyHTxU9hGq5dNmQDmB/Vg3Nj4lErPJX4nE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298712; 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=B4bgzKhZcEtkvj4aWPIEP860yH65lcrTXe+SVxo+T88=; b=n6ubnYuZtFTFMPTdCKeUA4YIB4CDhzLDbko2XN6is48nglx5+3ik8yiy0shHgQqkxEzT1vnrBSkTczQlhVyZ6a/CcNQjVPAVkeuGBUAGTyslZcuV8lz69dmpdYaJBk6kSgLcAu/XtwGJr41d6M72b89sAzPLPep8DNBUbl2zuDY= 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 1660298712358272.61143536985446; Fri, 12 Aug 2022 03:05:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-yzXxSAYAOzmLnqIOG0kVcg-1; Fri, 12 Aug 2022 06:04:39 -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 2F5033801175; Fri, 12 Aug 2022 10:04:36 +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 1C8BC112131B; Fri, 12 Aug 2022 10:04:36 +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 CE7A61946A42; Fri, 12 Aug 2022 10:04:35 +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 0C39B1946A41 for ; Fri, 12 Aug 2022 10:04:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E85E1C15BA8; 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 8E423C15BA6 for ; Fri, 12 Aug 2022 10:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660298711; 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=B4bgzKhZcEtkvj4aWPIEP860yH65lcrTXe+SVxo+T88=; b=IRHe1fSb3LUvokoEaBMZU0rk1VL4NTBg2uFiZ/x4LTT3dC0S8BDj/rDcZg+SP9NVFIY9uo 28vOmkeryTZ/eLw4uPH/gznnLCOXz6dKDmiK03+qnJqXcnth0HdMix3fBks5vPWdvUdAfo oem7PubfLQYkHmiFv6+Ldl+FIpW5PeI= X-MC-Unique: yzXxSAYAOzmLnqIOG0kVcg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 5/8] qemu_process: Enable SCHED_CORE for QEMU process Date: Fri, 12 Aug 2022 12:04:20 +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: 1660298714363100001 Content-Type: text/plain; charset="utf-8"; x-default="true" For QEMU_SCHED_CORE_EMULATOR or QEMU_SCHED_CORE_FULL the QEMU process (and its vCPU threads) should be placed into its own scheduling group. Since we have the dummy process running for exactly this purpose use its PID as an argument to virCommandSetRunAmong(). Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8b027f2d39..f112209ae6 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7556,6 +7556,9 @@ qemuProcessLaunch(virConnectPtr conn, virCommandSetMaxProcesses(cmd, cfg->maxProcesses); if (cfg->maxFiles > 0) virCommandSetMaxFiles(cmd, cfg->maxFiles); + if (cfg->schedCore =3D=3D QEMU_SCHED_CORE_EMULATOR || + cfg->schedCore =3D=3D QEMU_SCHED_CORE_FULL) + virCommandSetRunAmong(cmd, priv->schedCoreChildPID); =20 /* In this case, however, zero means that core dumps should be * disabled, and so we always need to set the limit explicitly */ --=20 2.35.1 From nobody Fri May 17 05:54:31 2024 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=1660298709; cv=none; d=zohomail.com; s=zohoarc; b=X6vUhh9PvpvIktT7U+pNiFNRac9Em1rthVET07+phc+2Yyw2qnCVjxqQ0oq1ZFdHDXM6OyL49kf3uCNrnO1UFbicSOFcysdjW9u7347KL42JuF7hLFDo0yUvYxsHcKsAnCTNSfBiEXkJeOOl2IlENwsLzXsdJNECKTNV7G750zk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298709; 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=ZGtRJhVoBXWMjpWjZls3FZe3ABtYj5FC9iqxXrjwEf0=; b=XTwyNlDbFHGWfGNWRLRvrwdzzK+cepw4edUkrbIRcL8HqZpERAzmkKh4a7kSDzYjhLGHGsEl8j7gKN6TTBSx0F2zTKdWVCmPmOPcksPfXq3AlEDUY1Zqr5o10HyIUrE/7wg3dkgUNPgkRadkfF8KOivWw0aBQRiNeGmH8UmQgSc= 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 1660298709401601.5188242212887; Fri, 12 Aug 2022 03:05:09 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205-tGEvY3S6MISMR_Yotruqzw-1; Fri, 12 Aug 2022 06:04:39 -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 AE1AC3800C4C; Fri, 12 Aug 2022 10:04:36 +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 994351121325; Fri, 12 Aug 2022 10:04:36 +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 2AFE51946A64; Fri, 12 Aug 2022 10:04:36 +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 9B4941946A5E for ; Fri, 12 Aug 2022 10:04:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8923FC15BA8; Fri, 12 Aug 2022 10:04:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2ECDDC15BA6 for ; Fri, 12 Aug 2022 10:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660298708; 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=ZGtRJhVoBXWMjpWjZls3FZe3ABtYj5FC9iqxXrjwEf0=; b=MrtbY46crUjWpA4ruxTLL14NjsHv6/A5BRo32mVENkHHWHYCbFJIB2VVXSnokAfrJFShzj PWsRnIVEUTslZXzfPGzoDR+zowpEbb7xTkF/9WL/9sSaTR183kA6fiipM7QokXxwsxO3zs X70bVeOIPA9lNabSd6H/w/cgHwDccu8= X-MC-Unique: tGEvY3S6MISMR_Yotruqzw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 6/8] qemu: Enable SCHED_CORE for helper processes Date: Fri, 12 Aug 2022 12:04:21 +0200 Message-Id: <454092f564e4657c38b9c9b91bcc0fa9bec57c1c.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.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: 1660298710413100001 Content-Type: text/plain; charset="utf-8"; x-default="true" For QEMU_SCHED_CORE_FULL case, all helper processes should be placed into the same scheduling group as the QEMU process they serve. It may happen though, that a helper process is started before QEMU (cold start of a domain). But we have the dummy process running from which the QEMU process will inherit the scheduling group, so we can use the dummy process PID as an argument to virCommandSetRunAmong(). Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 9 +++++++++ src/qemu/qemu_security.c | 11 +++++++++++ src/qemu/qemu_virtiofs.c | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f112209ae6..a8f8a7cb47 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2852,6 +2852,15 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm) * qemu (so that it shares the same view of the system). */ virCommandSetPreExecHook(cmd, qemuProcessStartPRDaemonHook, vm); =20 + if (cfg->schedCore =3D=3D QEMU_SCHED_CORE_FULL) { + pid_t cookie_pid =3D vm->pid; + + if (cookie_pid <=3D 0) + cookie_pid =3D priv->schedCoreChildPID; + + virCommandSetRunAmong(cmd, cookie_pid); + } + if (virCommandRun(cmd, NULL) < 0) goto cleanup; =20 diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index 3be1766764..5b7d5f30c2 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -683,6 +683,9 @@ qemuSecurityCommandRun(virQEMUDriver *driver, int *exitstatus, int *cmdret) { + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + qemuDomainObjPrivate *priv =3D vm->privateData; + if (virSecurityManagerSetChildProcessLabel(driver->securityManager, vm->def, cmd) < 0) return -1; @@ -691,6 +694,14 @@ qemuSecurityCommandRun(virQEMUDriver *driver, virCommandSetUID(cmd, uid); if (gid !=3D (gid_t) -1) virCommandSetGID(cmd, gid); + if (cfg->schedCore =3D=3D QEMU_SCHED_CORE_FULL) { + pid_t pid =3D vm->pid; + + if (pid <=3D 0) + pid =3D priv->schedCoreChildPID; + + virCommandSetRunAmong(cmd, pid); + } =20 if (virSecurityManagerPreFork(driver->securityManager) < 0) return -1; diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c index ce55286ab5..348908eb43 100644 --- a/src/qemu/qemu_virtiofs.c +++ b/src/qemu/qemu_virtiofs.c @@ -179,6 +179,7 @@ qemuVirtioFSStart(virQEMUDriver *driver, virDomainFSDef *fs) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virCommand) cmd =3D NULL; g_autofree char *socket_path =3D NULL; g_autofree char *pidfile =3D NULL; @@ -252,6 +253,16 @@ qemuVirtioFSStart(virQEMUDriver *driver, virCommandNonblockingFDs(cmd); virCommandDaemonize(cmd); =20 + if (cfg->schedCore =3D=3D QEMU_SCHED_CORE_FULL) { + pid_t cookie_pid =3D vm->pid; + + if (cookie_pid <=3D 0) + cookie_pid =3D priv->schedCoreChildPID; + + virCommandSetRunAmong(cmd, cookie_pid); + } + + if (qemuExtDeviceLogCommand(driver, vm, cmd, "virtiofsd") < 0) goto error; =20 --=20 2.35.1 From nobody Fri May 17 05:54:31 2024 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=1660298684; cv=none; d=zohomail.com; s=zohoarc; b=X16WTxRdTpwpOwZWxH6aChAOJHaFraGq7gJBHehOjbqwiTH1lMO96zZ9WgkFtLfGJM6Uur2iClKAkU8Yo7oLb7tWi/zAXPUA52ngRfXsuWLkPzsuDow/2TsQBNXNnGIcc+GnRRLG0ST8eSXTYq4CIsWB+L4m56w4bCu3wu+Mmn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660298684; 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=LxJ9F/RkVvnrCzId8wBCRi2MZIK5StOPN5N39LKVHb8=; b=YindfAj/AO3qwhvS7DT9gigkhXJx2APJ/zqj3lASVMusYm1ZjviM5QiGMaplx9KsH+JWuDw/Yp04z9IJ3FoQ5+Q/WqXoG5lI3jMsHZ3R+nSdUhmCSMaAXxOTz+JipUi4ZJbWpblN1f6mRxlYY1Sa6WfP4+io4+rnFSAaZQ2pzL0= 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 16602986849550.4587655298763593; Fri, 12 Aug 2022 03:04:44 -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-612-ZJ94WFA7OIGMJCcmF6cDIA-1; Fri, 12 Aug 2022 06:04:39 -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 5F5C38039A2; 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 4E7DB492C3B; 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 1991E1946A42; 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 4E02A1946A41 for ; Fri, 12 Aug 2022 10:04:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2ABFDC15BA8; 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 C4237C15BA6 for ; Fri, 12 Aug 2022 10:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660298683; 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=LxJ9F/RkVvnrCzId8wBCRi2MZIK5StOPN5N39LKVHb8=; b=UAHLJzbNItgjfrO84b9xYjXiQUTmyuLhvFRNcYae8UGnivhwzyMsLGLWxz2Z5sO6b+l9NA n4ORBTSDiWzFrsB5pO1Wsg8Hu4Xeaef3GLf7S6VdkKXdPWeeNJWelgZkZELPq9mwZYYwHH ehJmaZnlHPae25r/i5Spv5CDllJ3ayA= X-MC-Unique: ZJ94WFA7OIGMJCcmF6cDIA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 7/8] qemu: Enable SCHED_CORE for vCPUs Date: Fri, 12 Aug 2022 12:04:22 +0200 Message-Id: <4955f274c0d26aa41791585c1a8271b96d962674.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: 1660298685521100009 Content-Type: text/plain; charset="utf-8"; x-default="true" For QEMU_SCHED_CORE_VCPUS case, the vCPU threads should be placed all into one scheduling group, but not the emulator or any of its threads. Therefore, as soon as vCPU TIDs are detected, fork off a child which then creates a separate scheduling group and adds all vCPU threads into it. Please note, this commit only handles the cold boot case. Hotplug is going to be implemented in the next commit. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a8f8a7cb47..f9c4f72496 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5874,9 +5874,44 @@ qemuProcessSetupVcpu(virDomainObj *vm, } =20 =20 +static int +qemuProcessSetupAllVcpusSchedCoreHelper(pid_t ppid G_GNUC_UNUSED, + void *opaque) +{ + virDomainObj *vm =3D opaque; + size_t i; + + /* Since we are setting all vCPU threads at once and from a forked off + * child, we don't need the dummy schedCoreChildPID and can create one= on + * our own. */ + if (virProcessSchedCoreCreate() < 0) { + virReportSystemError(errno, "%s", + _("Unable to set SCHED_CORE")); + + return -1; + } + + for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { + pid_t vcpupid =3D qemuDomainGetVcpuPid(vm, i); + + if (vcpupid > 0 && + virProcessSchedCoreShareTo(vcpupid) < 0) { + virReportSystemError(errno, + _("unable to share scheduling cookie to %= lld"), + (long long) vcpupid); + return -1; + } + } + + return 0; +} + + static int qemuProcessSetupVcpus(virDomainObj *vm) { + qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); virDomainVcpuDef *vcpu; unsigned int maxvcpus =3D virDomainDefGetVcpusMax(vm->def); size_t i; @@ -5919,6 +5954,10 @@ qemuProcessSetupVcpus(virDomainObj *vm) return -1; } =20 + if (cfg->schedCore =3D=3D QEMU_SCHED_CORE_VCPUS && + virProcessRunInFork(qemuProcessSetupAllVcpusSchedCoreHelper, vm) <= 0) + return -1; + return 0; } =20 --=20 2.35.1 From nobody Fri May 17 05:54:31 2024 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