From nobody Mon Feb 9 06:07:20 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=1668440146; cv=none; d=zohomail.com; s=zohoarc; b=hrFTX4TFO4732w1yFpBDGlKNX1+dvrEplyU2Wcet7hTdogMfjyHx8I3sEIY1wI52TTetTqR8/6YBAzAXutm2JnFVkWkP/s5D6SBIEhvhVkE6MwoGRFZExtP4llz9TDdG/CkbH0o8ZQcYM8Ihhj/tNxheBh1zVLGgKG2tzLdLfLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668440146; 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=x+dg6oUggChKViknOG1stlSweJk28Pzg9ZKgZRbjo5k=; b=h+5+89sKyxr33BQs0MkTiqJAk1kRKRtoq9bk0rCKx/CGOj9s69t9xl+BQ5tOdcYjuuT/N8Cr0y3+2mG89fal1rEuplKAweY+MAWe+SMuvwfKO2a5l5YMRTL3I5C2iMwE7RzAVLsizyjWrZpIRM/LrdKxoxaPYGihRUKeKIjnkXk= 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 1668440146969322.14375510153525; Mon, 14 Nov 2022 07:35:46 -0800 (PST) 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-201-KuWDXCKnMAy76qdWDknCGg-1; Mon, 14 Nov 2022 10:35:44 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2ECFA38012CE; Mon, 14 Nov 2022 15:35:40 +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 1B05DC15BB3; Mon, 14 Nov 2022 15:35:40 +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 0F158194658C; Mon, 14 Nov 2022 15:35:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 39BDE1946589 for ; Mon, 14 Nov 2022 15:35:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0E50147505E; Mon, 14 Nov 2022 15:35:38 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7D83475062 for ; Mon, 14 Nov 2022 15:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668440146; 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=x+dg6oUggChKViknOG1stlSweJk28Pzg9ZKgZRbjo5k=; b=XrTzX3VgClW4y5TyEn3l9dFT0AGw05V0f9643qNEeftX4iygI3/RQNzZf1X3N8oRzLrSZj 3698cvetfUNEEKYJuZj9dPgWA5u4PYGcu6bVIMDtP8v9DI4VnaBgglCyCFcO92aS17bK3u DM6zY84PKPD88Ck2eYGfYm8fejytsjM= X-MC-Unique: KuWDXCKnMAy76qdWDknCGg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/7] qemu_command: Introduce qemuBuildThreadContextProps() Date: Mon, 14 Nov 2022 16:35:30 +0100 Message-Id: <5738e30b8a08a769fbd9b95498c1620130be6eaf.1668439393.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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.8 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: 1668440148594100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The aim of thread-context object is to set affinity on threads that allocate memory for a memory-backend-* object. For instance: -object '{"qom-type":"thread-context","id":"tc-ram-node0","node-affinity":[= 3]}' \ -object '{"qom-type":"memory-backend-memfd","id":"ram-node0","hugetlb":true= ,\ "hugetlbsize":2097152,"share":true,"prealloc":true,"prealloc-thre= ads":8,\ "size":15032385536,"host-nodes":[3],"policy":"preferred",\ "prealloc-context":"tc-ram-node0"}' \ allocates 14GiB worth of memory, backed by 2MiB hugepages from host NUMA node 3, using 8 threads. If it weren't for thread-context these threads wouldn't have any affinity and thus theoretically could be scheduled to run on CPUs of different NUMA node (which is what I saw occasionally). Therefore, whenever we are pinning memory (IOW setting host-nodes attribute), we can generate thread-context object with the same affinity. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/qemu/qemu_command.c | 48 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_command.h | 5 +++++ 2 files changed, 53 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 41b9f7cb52..392b248628 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3603,6 +3603,54 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg, } =20 =20 +int +qemuBuildThreadContextProps(virJSONValue **tcProps, + virJSONValue **memProps, + qemuDomainObjPrivate *priv) +{ + g_autoptr(virJSONValue) props =3D NULL; + virJSONValue *nodemask =3D NULL; + g_autoptr(virJSONValue) nodemaskCopy =3D NULL; + g_autofree char *tcAlias =3D NULL; + const char *memalias =3D NULL; + + if (tcProps) + *tcProps =3D NULL; + + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_THREAD_CONTEXT)) + return 0; + + nodemask =3D virJSONValueObjectGetArray(*memProps, "host-nodes"); + if (!nodemask) + return 0; + + memalias =3D virJSONValueObjectGetString(*memProps, "id"); + if (!memalias) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("memory device alias is not assigned")); + return -1; + } + + tcAlias =3D g_strdup_printf("tc-%s", memalias); + nodemaskCopy =3D virJSONValueCopy(nodemask); + + if (virJSONValueObjectAdd(&props, + "s:qom-type", "thread-context", + "s:id", tcAlias, + "a:node-affinity", &nodemaskCopy, + NULL) < 0) + return -1; + + if (virJSONValueObjectAdd(memProps, + "s:prealloc-context", tcAlias, + NULL) < 0) + return -1; + + *tcProps =3D g_steal_pointer(&props); + return 0; +} + + static char * qemuBuildLegacyNicStr(virDomainNetDef *net) { diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 2578367df9..761cc5d865 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -147,6 +147,11 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg, const virDomainDef *def, const virDomainMemoryDef *mem); =20 +int +qemuBuildThreadContextProps(virJSONValue **tcProps, + virJSONValue **memProps, + qemuDomainObjPrivate *priv); + /* Current, best practice */ virJSONValue * qemuBuildPCIHostdevDevProps(const virDomainDef *def, --=20 2.37.4