From nobody Sat Apr 27 11:43:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631303887807122.71548228707502; Fri, 10 Sep 2021 12:58:07 -0700 (PDT) Received: from localhost ([::1]:41634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOmf0-00084m-Oi for importer@patchew.org; Fri, 10 Sep 2021 15:58:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOmcz-0005KY-Ij; Fri, 10 Sep 2021 15:56:01 -0400 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]:44922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOmcy-00068N-1n; Fri, 10 Sep 2021 15:56:01 -0400 Received: by mail-qk1-x732.google.com with SMTP id c10so3299566qko.11; Fri, 10 Sep 2021 12:55:59 -0700 (PDT) Received: from rekt.COMFAST ([191.193.98.206]) by smtp.gmail.com with ESMTPSA id k10sm3873356qth.44.2021.09.10.12.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 12:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dxtZtWDgZA6YJSxyyw3iHUi2LBO3kQ0MAQByjWcSlJI=; b=Fakp+l4wBbe3WQ8JxYsv9XRhbm0NEeswrGwSP6RxeE8whJBC8kCgmqUpAujGbc1x9r 0MQDZ6ScaGbxD7HYIhqUwS1dVsmrfYNXH53pLwTRHCsdAYPLhqRHdwHWZ6go6Z986T3g euZnrvJSVw9rmyPtMD+9jmI+RVTKtw3raVo2aDo1fftNnGWG17rzrG1xWLyK9/bAKs66 Yaa5lQj6siGYAftX1n9fwZSLvVGqiAvSQjnU5SOV9beMIEW9eySQhjZQ2RWz3/ptS+Uz H7fPHlLGpxd801Ge7P6YpniAbD8qsk2ZxpOd+X5fxxMLQ1Wqu/YG7GXq8UCEPnC7fE4P Fo9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dxtZtWDgZA6YJSxyyw3iHUi2LBO3kQ0MAQByjWcSlJI=; b=qZokLgs7eATHb4WiLVhq9nw3gY3zYDW4onr993QXq6dV+fqh5sGDrle9scuk2z0CnC rHK9KKXUBYHRBTxqeTnaO77xxsE+8MRuPbY/08a1XEkdTMbnTg3549pWZGUXCsyeGr3A OgnWxVmKVaonbx/QA3g8MnNhSU0F2R/uWl/dbRZAwPXR44SM9rzLCDjUkaI10gDK8O6+ Kh3hdmTd1QEsfBOMnf3L/236MqHImrArGpnAu6vYIYKOWCegvYetRTA7n/HUcg2Hx1G/ m8odm65XFUvN+TTkaaZY0yv3ilZ2CsfD1Ixv2pJkzYpXbZOtcc+CrJuz8PXyohhjpapj V1sg== X-Gm-Message-State: AOAM531oeXIYo/XwjoCX2Enx1kd7KaM4SRA/gLndGLRq7E+0YD5vLSoA k1RFxnU59GEehx4AMqZ2fD40GLGdFyE= X-Google-Smtp-Source: ABdhPJzNps809OPP3/klZuqq5FCc3izjBWqIdNeEgTIUy+eHUR1+Vw6ECsIJRTPDpO3vKInJqKhUXQ== X-Received: by 2002:a37:f613:: with SMTP id y19mr9262483qkj.524.1631303758764; Fri, 10 Sep 2021 12:55:58 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v6 1/6] spapr_numa.c: split FORM1 code into helpers Date: Fri, 10 Sep 2021 16:55:34 -0300 Message-Id: <20210910195539.797170-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910195539.797170-1-danielhb413@gmail.com> References: <20210910195539.797170-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::732; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x732.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631303889659100003 Content-Type: text/plain; charset="utf-8" The upcoming FORM2 NUMA affinity will support asymmetric NUMA topologies and doesn't need be concerned with all the legacy support for older pseries FORM1 guests. We're also not going to calculate associativity domains based on numa distance (via spapr_numa_define_associativity_domains) since the distances will be written directly into new DT properties. Let's split FORM1 code into its own functions to allow for easier insertion of FORM2 logic later on. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Greg Kurz --- hw/ppc/spapr_numa.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 779f18b994..786def7c73 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -92,7 +92,7 @@ static uint8_t spapr_numa_get_numa_level(uint8_t distance) return 0; } =20 -static void spapr_numa_define_associativity_domains(SpaprMachineState *spa= pr) +static void spapr_numa_define_FORM1_domains(SpaprMachineState *spapr) { MachineState *ms =3D MACHINE(spapr); NodeInfo *numa_info =3D ms->numa_state->nodes; @@ -155,8 +155,11 @@ static void spapr_numa_define_associativity_domains(Sp= aprMachineState *spapr) =20 } =20 -void spapr_numa_associativity_init(SpaprMachineState *spapr, - MachineState *machine) +/* + * Set NUMA machine state data based on FORM1 affinity semantics. + */ +static void spapr_numa_FORM1_affinity_init(SpaprMachineState *spapr, + MachineState *machine) { SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); int nb_numa_nodes =3D machine->numa_state->num_nodes; @@ -225,7 +228,13 @@ void spapr_numa_associativity_init(SpaprMachineState *= spapr, exit(EXIT_FAILURE); } =20 - spapr_numa_define_associativity_domains(spapr); + spapr_numa_define_FORM1_domains(spapr); +} + +void spapr_numa_associativity_init(SpaprMachineState *spapr, + MachineState *machine) +{ + spapr_numa_FORM1_affinity_init(spapr, machine); } =20 void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, @@ -302,12 +311,8 @@ int spapr_numa_write_assoc_lookup_arrays(SpaprMachineS= tate *spapr, void *fdt, return ret; } =20 -/* - * Helper that writes ibm,associativity-reference-points and - * max-associativity-domains in the RTAS pointed by @rtas - * in the DT @fdt. - */ -void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rta= s) +static void spapr_numa_FORM1_write_rtas_dt(SpaprMachineState *spapr, + void *fdt, int rtas) { MachineState *ms =3D MACHINE(spapr); SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); @@ -365,6 +370,16 @@ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr= , void *fdt, int rtas) maxdomains, sizeof(maxdomains))); } =20 +/* + * Helper that writes ibm,associativity-reference-points and + * max-associativity-domains in the RTAS pointed by @rtas + * in the DT @fdt. + */ +void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rta= s) +{ + spapr_numa_FORM1_write_rtas_dt(spapr, fdt, rtas); +} + static target_ulong h_home_node_associativity(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, --=20 2.31.1 From nobody Sat Apr 27 11:43:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631303892019381.6179599198522; Fri, 10 Sep 2021 12:58:12 -0700 (PDT) Received: from localhost ([::1]:41914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOmf4-0008GB-VG for importer@patchew.org; Fri, 10 Sep 2021 15:58:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOmd1-0005QW-W1; Fri, 10 Sep 2021 15:56:04 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:43991) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOmd0-0006A2-Az; Fri, 10 Sep 2021 15:56:03 -0400 Received: by mail-qk1-x72e.google.com with SMTP id ay33so3297525qkb.10; Fri, 10 Sep 2021 12:56:01 -0700 (PDT) Received: from rekt.COMFAST ([191.193.98.206]) by smtp.gmail.com with ESMTPSA id k10sm3873356qth.44.2021.09.10.12.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 12:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gyeZlgxoWzHHnT8aODnPJyPHP+W7+r4WPQYccpg78CY=; b=pUjakHkw/S2MNzID7lwbtBgWCpGROfoXQlGEXtt+lOLAEC1IDHw69343lX35+hnSRu WVVgyszLeno3Y65kI/2u8lWmHF11I3hclSEupbgz5qjsvefZuFcTJgZSWBF/49YlPxax V2m2LOD7woPMBMKVPgzsI9YLRAXize3cN/i7T31rj94gyZC7DSCR++WQsV2Y4MLG5VPT 8WWKt6H8EY5buYOQRWwqhqevZIFljnNKx9W2gWOcu1tGWV4mU5vTNxCnvH6H8KkXA76E 7vYKbuNUSAQFYeHH0MTEC0pl8g/IyVGppsgYOUTzhEkUGuEL2RK0z8SvIMgmVN5+wF0o /Ffw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gyeZlgxoWzHHnT8aODnPJyPHP+W7+r4WPQYccpg78CY=; b=N4cYM25LFqdDK2PbV40HKRBmVQoJMAg3lBEEJ30yp+q1N/o9X1XsCg/5k/uFmk1T9Z l4I+q3J5q8uVMCms8+pTR5wP/ukJMVDM+7arp3SHI+aApw0IFr0mSWdT5uar6zaNrhHu 5GPvrzRatOocXq9KAJBK8+WyIwYECyItd4LhWpOiYvN41hPUO76IVSG8nTdi1LMMI8/9 nA8dOO3ELY7ptv3fRccPRuuMMtWmTI9KAs2PheMhOuQb/Xe2FLfoylmyu2T0VXfiHuTF SDS5VJU1JT+TevkCODKdyIx0JB4RealBGL85UGfDULXlpBfMf3MQ84irW/th0w2ldLF8 jNXg== X-Gm-Message-State: AOAM533eMTCFoKHrjMqOTEx0b8FsOVoY2ji2j8+ZGPEwfVz8UcyTBKwB GQdy3w/Oo674QOqNIgsUOAgXSb8Wfms= X-Google-Smtp-Source: ABdhPJx5I3BpNxI9HxVXsFz1lWg4IETvqd1UcqmFcCM0tYSAyLyszowYWRrnv3z3Yu4Ap6OovK1MvA== X-Received: by 2002:a37:a104:: with SMTP id k4mr9255645qke.382.1631303761042; Fri, 10 Sep 2021 12:56:01 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v6 2/6] spapr_numa.c: scrap 'legacy_numa' concept Date: Fri, 10 Sep 2021 16:55:35 -0300 Message-Id: <20210910195539.797170-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910195539.797170-1-danielhb413@gmail.com> References: <20210910195539.797170-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x72e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631303894074100001 Content-Type: text/plain; charset="utf-8" When first introduced, 'legacy_numa' was a way to refer to guests that either wouldn't be affected by associativity domain calculations, namely the ones with only 1 NUMA node, and pre 5.2 guests that shouldn't be affected by it because it would be an userspace change. Calling these cases 'legacy_numa' was a convenient way to label these cases. We're about to introduce a new NUMA affinity, FORM2, and this concept of 'legacy_numa' is now a bit misleading because, although it is called 'legacy' it is in fact a FORM1 exclusive contraint. This patch removes spapr_machine_using_legacy_numa() and open code the conditions in each caller. While we're at it, move the chunk inside spapr_numa_FORM1_affinity_init() that sets all numa_assoc_array domains with 'node_id' to spapr_numa_define_FORM1_domains(). This chunk was being executed if !pre_5_2_numa_associativity and num_nodes =3D> 1, the same conditions in which spapr_numa_define_FORM1_domains() is called shortly after. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Greg Kurz --- hw/ppc/spapr_numa.c | 46 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 786def7c73..fb6059550f 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -19,15 +19,6 @@ /* Moved from hw/ppc/spapr_pci_nvlink2.c */ #define SPAPR_GPU_NUMA_ID (cpu_to_be32(1)) =20 -static bool spapr_machine_using_legacy_numa(SpaprMachineState *spapr) -{ - MachineState *machine =3D MACHINE(spapr); - SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(machine); - - return smc->pre_5_2_numa_associativity || - machine->numa_state->num_nodes <=3D 1; -} - static bool spapr_numa_is_symmetrical(MachineState *ms) { int src, dst; @@ -97,7 +88,18 @@ static void spapr_numa_define_FORM1_domains(SpaprMachine= State *spapr) MachineState *ms =3D MACHINE(spapr); NodeInfo *numa_info =3D ms->numa_state->nodes; int nb_numa_nodes =3D ms->numa_state->num_nodes; - int src, dst, i; + int src, dst, i, j; + + /* + * Fill all associativity domains of non-zero NUMA nodes with + * node_id. This is required because the default value (0) is + * considered a match with associativity domains of node 0. + */ + for (i =3D 1; i < nb_numa_nodes; i++) { + for (j =3D 1; j < MAX_DISTANCE_REF_POINTS; j++) { + spapr->numa_assoc_array[i][j] =3D cpu_to_be32(i); + } + } =20 for (src =3D 0; src < nb_numa_nodes; src++) { for (dst =3D src; dst < nb_numa_nodes; dst++) { @@ -164,7 +166,6 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachine= State *spapr, SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); int nb_numa_nodes =3D machine->numa_state->num_nodes; int i, j, max_nodes_with_gpus; - bool using_legacy_numa =3D spapr_machine_using_legacy_numa(spapr); =20 /* * For all associativity arrays: first position is the size, @@ -178,17 +179,6 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachin= eState *spapr, for (i =3D 0; i < nb_numa_nodes; i++) { spapr->numa_assoc_array[i][0] =3D cpu_to_be32(MAX_DISTANCE_REF_POI= NTS); spapr->numa_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be3= 2(i); - - /* - * Fill all associativity domains of non-zero NUMA nodes with - * node_id. This is required because the default value (0) is - * considered a match with associativity domains of node 0. - */ - if (!using_legacy_numa && i !=3D 0) { - for (j =3D 1; j < MAX_DISTANCE_REF_POINTS; j++) { - spapr->numa_assoc_array[i][j] =3D cpu_to_be32(i); - } - } } =20 /* @@ -214,11 +204,13 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachi= neState *spapr, } =20 /* - * Legacy NUMA guests (pseries-5.1 and older, or guests with only - * 1 NUMA node) will not benefit from anything we're going to do - * after this point. + * Guests pseries-5.1 and older uses zeroed associativity domains, + * i.e. no domain definition based on NUMA distance input. + * + * Same thing with guests that have only one NUMA node. */ - if (using_legacy_numa) { + if (smc->pre_5_2_numa_associativity || + machine->numa_state->num_nodes <=3D 1) { return; } =20 @@ -334,7 +326,7 @@ static void spapr_numa_FORM1_write_rtas_dt(SpaprMachine= State *spapr, cpu_to_be32(maxdomain) }; =20 - if (spapr_machine_using_legacy_numa(spapr)) { + if (smc->pre_5_2_numa_associativity) { uint32_t legacy_refpoints[] =3D { cpu_to_be32(0x4), cpu_to_be32(0x4), --=20 2.31.1 From nobody Sat Apr 27 11:43:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631304107267894.3546869229683; Fri, 10 Sep 2021 13:01:47 -0700 (PDT) Received: from localhost ([::1]:50930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOmiY-0005q2-2m for importer@patchew.org; Fri, 10 Sep 2021 16:01:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOmd4-0005Vh-Bg; Fri, 10 Sep 2021 15:56:08 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:41595) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOmd2-0006DB-CG; Fri, 10 Sep 2021 15:56:06 -0400 Received: by mail-qk1-x72a.google.com with SMTP id bk29so3312035qkb.8; Fri, 10 Sep 2021 12:56:03 -0700 (PDT) Received: from rekt.COMFAST ([191.193.98.206]) by smtp.gmail.com with ESMTPSA id k10sm3873356qth.44.2021.09.10.12.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 12:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yblo498m6P+waxUTZyt/YLrTpH6VQgxXC7Mf/1PG7x8=; b=NWQDIFVdYfAhfjMMDIc6UAv6t7949AlFfpVqMlTFy6L5/4H0nGMQ0r8qmzbhfQR/Mx F5gbPjyzo830uH+6dkRrRN5TaZdOJBsfvAnNw0OhP9wCaYaV/xnNfFwdi6u0nfIFzLuG J/2ntDW/zQjZ6igQ6h6HIKzBU/AiQ99jVLd7m3j6TgnhrZBOw7LTsWxDUFhMAMdszPTo nFT05OW9b7M49eWRbH3njv4tcXUue1jnOdRo9vGZzEu0jjlCwfopuAgQN57GEmegFdqy SJwBTlCJphHLPU6eRuWK4vYgBolhSbQSqtKWdhEZ3cndXRd3ENe/1Dg0C1caJNRXWTj/ +UPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yblo498m6P+waxUTZyt/YLrTpH6VQgxXC7Mf/1PG7x8=; b=2rjGvypWX0EJQ0tS0Boz4MPBPyZPoi+WbRtiqo8wohhO9TlPP1xSAS2tfJ/BE+4SXG kqQlDNX9IWNxeI0JaHcfnQz4NEYDYBY3tq0jibtQ3cPX3jbGyCpIkOQ1mYozVG4mPJSe DTwNost+KrGtsTsINlMhX93xfhlo4E0kSK1mCWvH7+PlczRlpK1YukkKz6tNmCdvevUH /piheLLeCWntSr6NEKG1PKANQ/39CGSyvKv8V5xFIgZjAjDQKgUz6/xOdnW5GyLGP+9T WIh+knfDYGz5xZFiFAiWdCwCgGKA4f3bK3Lw30JFTmWCNgAOZ0uD5rNK+bObbeT0Yzy1 Mp9A== X-Gm-Message-State: AOAM530yAUQFELqo9jrCAGl5pC/SdKPTCHAdIhWNIoWv3kDBS0S8EgLa MdTUnib6hGqvfbGN4CMtDOK8WIcclKw= X-Google-Smtp-Source: ABdhPJzRJeAuQTwyoxgJPVcgwjf+IpPl+nL0xgGz2m9em2PKZkTIi0G2cRJyPwqOqc1oDXWrN50P4A== X-Received: by 2002:a05:620a:1397:: with SMTP id k23mr9210949qki.380.1631303762915; Fri, 10 Sep 2021 12:56:02 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v6 3/6] spapr: introduce spapr_numa_associativity_reset() Date: Fri, 10 Sep 2021 16:55:36 -0300 Message-Id: <20210910195539.797170-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910195539.797170-1-danielhb413@gmail.com> References: <20210910195539.797170-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x72a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631304108966100001 Content-Type: text/plain; charset="utf-8" Introducing a new NUMA affinity, FORM2, requires a new mechanism to switch between affinity modes after CAS. Also, we want FORM2 data structures and functions to be completely separated from the existing FORM1 code, allowing us to avoid adding new code that inherits the existing complexity of FORM1. At the same time, it's also desirable to minimize the amount of changes made in write_dt() functions that are used to write ibm,associativity of the resources, RTAS artifacts and h_home_node_associativity. These functions can work in the same way in both NUMA affinity modes, as long as we use a similar data structure and parametrize it properly depending on the affinity mode selected. This patch introduces spapr_numa_associativity_reset() to start this process. This function will be used to switch to the chosen NUMA affinity after CAS and after migrating the guest. To do that, the existing 'numa_assoc_array' is renamed to 'FORM1_assoc_array' and will hold FORM1 data that is populated at associativity_init(). 'numa_assoc_array' is now a pointer that can be switched between the existing affinity arrays. We don't have FORM2 data structures yet, so 'numa_assoc_array' will always point to 'FORM1_assoc_array'. We also take the precaution of pointing 'numa_assoc_array' to 'FORM1_assoc_array' in associativity_init() time, before CAS, to not change FORM1 availability for existing guests. A small change in spapr_numa_write_associativity_dt() is made to reflect the fact that 'numa_assoc_array' is now a pointer and we must be explicit with the size being written in the DT. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 14 +++++++++++++ hw/ppc/spapr_hcall.c | 7 +++++++ hw/ppc/spapr_numa.c | 42 +++++++++++++++++++++++++++++-------- include/hw/ppc/spapr.h | 3 ++- include/hw/ppc/spapr_numa.h | 1 + 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index d39fd4e644..5afbb76cab 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1786,6 +1786,20 @@ static int spapr_post_load(void *opaque, int version= _id) return err; } =20 + /* + * NUMA affinity selection is made in CAS time. There is no reliable + * way of telling whether the guest already went through CAS before + * migration due to how spapr_ov5_cas_needed works: a FORM1 guest can + * be migrated with ov5_cas empty regardless of going through CAS + * first. + * + * One solution is to call numa_associativity_reset(). The downside + * is that a guest migrated before CAS will reset it again when going + * through it, but since it's a lightweight operation it's worth being + * a little redundant to be safe. + */ + spapr_numa_associativity_reset(spapr); + return err; } =20 diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 0e9a5b2e40..82ab92ddba 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -17,6 +17,7 @@ #include "kvm_ppc.h" #include "hw/ppc/fdt.h" #include "hw/ppc/spapr_ovec.h" +#include "hw/ppc/spapr_numa.h" #include "mmu-book3s-v3.h" #include "hw/mem/memory-device.h" =20 @@ -1197,6 +1198,12 @@ target_ulong do_client_architecture_support(PowerPCC= PU *cpu, spapr->cas_pre_isa3_guest =3D !spapr_ovec_test(ov1_guest, OV1_PPC_3_00= ); spapr_ovec_cleanup(ov1_guest); =20 + /* + * Reset numa_assoc_array now that we know which NUMA affinity + * the guest will use. + */ + spapr_numa_associativity_reset(spapr); + /* * Ensure the guest asks for an interrupt mode we support; * otherwise terminate the boot. diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index fb6059550f..327952ba9e 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -97,7 +97,7 @@ static void spapr_numa_define_FORM1_domains(SpaprMachineS= tate *spapr) */ for (i =3D 1; i < nb_numa_nodes; i++) { for (j =3D 1; j < MAX_DISTANCE_REF_POINTS; j++) { - spapr->numa_assoc_array[i][j] =3D cpu_to_be32(i); + spapr->FORM1_assoc_array[i][j] =3D cpu_to_be32(i); } } =20 @@ -149,8 +149,8 @@ static void spapr_numa_define_FORM1_domains(SpaprMachin= eState *spapr) * and going up to 0x1. */ for (i =3D n_level; i > 0; i--) { - assoc_src =3D spapr->numa_assoc_array[src][i]; - spapr->numa_assoc_array[dst][i] =3D assoc_src; + assoc_src =3D spapr->FORM1_assoc_array[src][i]; + spapr->FORM1_assoc_array[dst][i] =3D assoc_src; } } } @@ -167,6 +167,11 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachin= eState *spapr, int nb_numa_nodes =3D machine->numa_state->num_nodes; int i, j, max_nodes_with_gpus; =20 + /* init FORM1_assoc_array */ + for (i =3D 0; i < MAX_NODES + NVGPU_MAX_NUM; i++) { + spapr->FORM1_assoc_array[i] =3D g_new0(uint32_t, NUMA_ASSOC_SIZE); + } + /* * For all associativity arrays: first position is the size, * position MAX_DISTANCE_REF_POINTS is always the numa_id, @@ -177,8 +182,8 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachine= State *spapr, * 'i' will be a valid node_id set by the user. */ for (i =3D 0; i < nb_numa_nodes; i++) { - spapr->numa_assoc_array[i][0] =3D cpu_to_be32(MAX_DISTANCE_REF_POI= NTS); - spapr->numa_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be3= 2(i); + spapr->FORM1_assoc_array[i][0] =3D cpu_to_be32(MAX_DISTANCE_REF_PO= INTS); + spapr->FORM1_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be= 32(i); } =20 /* @@ -192,15 +197,15 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachi= neState *spapr, max_nodes_with_gpus =3D nb_numa_nodes + NVGPU_MAX_NUM; =20 for (i =3D nb_numa_nodes; i < max_nodes_with_gpus; i++) { - spapr->numa_assoc_array[i][0] =3D cpu_to_be32(MAX_DISTANCE_REF_POI= NTS); + spapr->FORM1_assoc_array[i][0] =3D cpu_to_be32(MAX_DISTANCE_REF_PO= INTS); =20 for (j =3D 1; j < MAX_DISTANCE_REF_POINTS; j++) { uint32_t gpu_assoc =3D smc->pre_5_1_assoc_refpoints ? SPAPR_GPU_NUMA_ID : cpu_to_be32(i); - spapr->numa_assoc_array[i][j] =3D gpu_assoc; + spapr->FORM1_assoc_array[i][j] =3D gpu_assoc; } =20 - spapr->numa_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be3= 2(i); + spapr->FORM1_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be= 32(i); } =20 /* @@ -227,14 +232,33 @@ void spapr_numa_associativity_init(SpaprMachineState = *spapr, MachineState *machine) { spapr_numa_FORM1_affinity_init(spapr, machine); + + /* + * Default to FORM1 affinity until CAS. We'll call affinity_reset() + * during CAS when we're sure about which NUMA affinity the guest + * is going to use. + * + * This step is a failsafe - guests in the wild were able to read + * FORM1 affinity info before CAS for a long time. Since affinity_rese= t() + * is just a pointer switch between data that was already populated + * here, this is an acceptable overhead to be on the safer side. + */ + spapr->numa_assoc_array =3D spapr->FORM1_assoc_array; +} + +void spapr_numa_associativity_reset(SpaprMachineState *spapr) +{ + /* No FORM2 affinity implemented yet */ + spapr->numa_assoc_array =3D spapr->FORM1_assoc_array; } =20 void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, int offset, int nodeid) { + /* Hardcode the size of FORM1 associativity array for now */ _FDT((fdt_setprop(fdt, offset, "ibm,associativity", spapr->numa_assoc_array[nodeid], - sizeof(spapr->numa_assoc_array[nodeid])))); + NUMA_ASSOC_SIZE * sizeof(uint32_t)))); } =20 static uint32_t *spapr_numa_get_vcpu_assoc(SpaprMachineState *spapr, diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 637652ad16..8a9490f0bf 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -249,7 +249,8 @@ struct SpaprMachineState { unsigned gpu_numa_id; SpaprTpmProxy *tpm_proxy; =20 - uint32_t numa_assoc_array[MAX_NODES + NVGPU_MAX_NUM][NUMA_ASSOC_SIZE]; + uint32_t *FORM1_assoc_array[MAX_NODES + NVGPU_MAX_NUM]; + uint32_t **numa_assoc_array; =20 Error *fwnmi_migration_blocker; }; diff --git a/include/hw/ppc/spapr_numa.h b/include/hw/ppc/spapr_numa.h index 6f9f02d3de..ccf3e4eae8 100644 --- a/include/hw/ppc/spapr_numa.h +++ b/include/hw/ppc/spapr_numa.h @@ -24,6 +24,7 @@ */ void spapr_numa_associativity_init(SpaprMachineState *spapr, MachineState *machine); +void spapr_numa_associativity_reset(SpaprMachineState *spapr); void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rta= s); void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, int offset, int nodeid); --=20 2.31.1 From nobody Sat Apr 27 11:43:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631303896099765.2976362168706; Fri, 10 Sep 2021 12:58:16 -0700 (PDT) Received: from localhost ([::1]:42290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOmf9-0008VQ-1Q for importer@patchew.org; Fri, 10 Sep 2021 15:58:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOmdA-0005gR-2T; Fri, 10 Sep 2021 15:56:13 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:40898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOmd4-0006FP-D8; Fri, 10 Sep 2021 15:56:10 -0400 Received: by mail-qk1-x72b.google.com with SMTP id t190so3314940qke.7; Fri, 10 Sep 2021 12:56:05 -0700 (PDT) Received: from rekt.COMFAST ([191.193.98.206]) by smtp.gmail.com with ESMTPSA id k10sm3873356qth.44.2021.09.10.12.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 12:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WLWelTPzb0nMh38ylqvBqaWt3HlyKPgglsqoi/GpX5A=; b=WB+vrbspqDKivMfqkshkmuUdqGmJ5MSgyoXb2vVkb1dhP6436x4rqs7zz/1QKioagB dQ2lJkpYiMy7UUZUjvFVKfv/mzS9Mw0xUoBrS5U3MQzFKtweEHimC3zaZi3yJt4AwvEe HqMvrpxm3NAcaxLA716QepbT3KyK0FXWlujY7J9j2xypM+OlLJQDyg+SH8/T7AhDcxUQ dAYkKhSPVi13VSkg8YJ8Y5d4B/ep3kCAzbxEpRCyMw4bGsbQNMhsCL2yieEG5FTq13yd AddqrbRg3oOtV2XGhclWxX9+oJCvqb/QZEEJIV/1dzJZuR3pT2S0NIfe1loJV2Dwi2Y9 6o3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WLWelTPzb0nMh38ylqvBqaWt3HlyKPgglsqoi/GpX5A=; b=u2lGQK8ozSM6lsLGhjy9tnpr7ui3ulWn7xVv0doWsVBonIwfXGy0RH4Bl7Igv1iQ0U DTc5O0tXjNJZBR1S+sjIKz0cEIRThNWD155MPwz33RZXfJ3CJWYY5elN/EesgKkVDsAT 3MqB5CnFna193MS2Sqe3K37RKpNVjNGqLncoodRwsSKgaOfAIxl5VQA850t1P9HnRCGV gQHG/YOoC8dJls5Pb38H0ajWKN65SQaIKPlLgtgTA0IDfzjE5O1MOyndfss+Bo6we5ke azaN5pBtHecNxeUQC/Og0MciI7o3AXkcpM94UQAo+Fi5+080tuF9TWyFmAYidJcA/Q7f UWDA== X-Gm-Message-State: AOAM533waHsxwVOHmFlOnpoZhb6PWdOELlzNDVgGPxMljY1gt31Tpi/6 7u8lxcO0UAju9+QviJkTYZL/B/vW/jg= X-Google-Smtp-Source: ABdhPJwLw4JXDsJ9mCtjMiy/c/qQdZHxiHfvIOGnaEc6Ub7iRlo6JnSxtrbD8DBvGapBZDrrZZGD+w== X-Received: by 2002:a05:620a:1035:: with SMTP id a21mr9319645qkk.422.1631303764865; Fri, 10 Sep 2021 12:56:04 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v6 4/6] spapr_numa.c: parametrize FORM1 macros Date: Fri, 10 Sep 2021 16:55:37 -0300 Message-Id: <20210910195539.797170-5-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910195539.797170-1-danielhb413@gmail.com> References: <20210910195539.797170-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x72b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631303898209100003 Content-Type: text/plain; charset="utf-8" The next preliminary step to introduce NUMA FORM2 affinity is to make the existing code independent of FORM1 macros and values, i.e. MAX_DISTANCE_REF_POINTS, NUMA_ASSOC_SIZE and VCPU_ASSOC_SIZE. This patch accomplishes that by doing the following: - move the NUMA related macros from spapr.h to spapr_numa.c where they are used. spapr.h gets instead a 'NUMA_NODES_MAX_NUM' macro that is used to refer to the maximum number of NUMA nodes, including GPU nodes, that the machine can support; - MAX_DISTANCE_REF_POINTS and NUMA_ASSOC_SIZE are renamed to FORM1_DIST_REF_POINTS and FORM1_NUMA_ASSOC_SIZE. These FORM1 specific macros are used in FORM1 init functions; - code that uses MAX_DISTANCE_REF_POINTS now retrieves the max_dist_ref_points value using get_max_dist_ref_points(). NUMA_ASSOC_SIZE is replaced by get_numa_assoc_size() and VCPU_ASSOC_SIZE is replaced by get_vcpu_assoc_size(). These functions are used by the generic device tree functions and h_home_node_associativity() and will allow them to switch between FORM1 and FORM2 without changing their core logic. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_numa.c | 93 +++++++++++++++++++++++++++++++----------- include/hw/ppc/spapr.h | 22 +++------- 2 files changed, 74 insertions(+), 41 deletions(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 327952ba9e..7ad4b6582b 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -19,6 +19,47 @@ /* Moved from hw/ppc/spapr_pci_nvlink2.c */ #define SPAPR_GPU_NUMA_ID (cpu_to_be32(1)) =20 +/* + * NUMA FORM1 macros. FORM1_DIST_REF_POINTS was taken from + * MAX_DISTANCE_REF_POINTS in arch/powerpc/mm/numa.h from Linux + * kernel source. It represents the amount of associativity domains + * for non-CPU resources. + * + * FORM1_NUMA_ASSOC_SIZE is the base array size of an ibm,associativity + * array for any non-CPU resource. + */ +#define FORM1_DIST_REF_POINTS 4 +#define FORM1_NUMA_ASSOC_SIZE (FORM1_DIST_REF_POINTS + 1) + +/* + * Retrieves max_dist_ref_points of the current NUMA affinity. + */ +static int get_max_dist_ref_points(SpaprMachineState *spapr) +{ + /* No FORM2 affinity implemented yet */ + return FORM1_DIST_REF_POINTS; +} + +/* + * Retrieves numa_assoc_size of the current NUMA affinity. + */ +static int get_numa_assoc_size(SpaprMachineState *spapr) +{ + /* No FORM2 affinity implemented yet */ + return FORM1_NUMA_ASSOC_SIZE; +} + +/* + * Retrieves vcpu_assoc_size of the current NUMA affinity. + * + * vcpu_assoc_size is the size of ibm,associativity array + * for CPUs, which has an extra element (vcpu_id) in the end. + */ +static int get_vcpu_assoc_size(SpaprMachineState *spapr) +{ + return get_numa_assoc_size(spapr) + 1; +} + static bool spapr_numa_is_symmetrical(MachineState *ms) { int src, dst; @@ -96,7 +137,7 @@ static void spapr_numa_define_FORM1_domains(SpaprMachine= State *spapr) * considered a match with associativity domains of node 0. */ for (i =3D 1; i < nb_numa_nodes; i++) { - for (j =3D 1; j < MAX_DISTANCE_REF_POINTS; j++) { + for (j =3D 1; j < FORM1_DIST_REF_POINTS; j++) { spapr->FORM1_assoc_array[i][j] =3D cpu_to_be32(i); } } @@ -134,7 +175,7 @@ static void spapr_numa_define_FORM1_domains(SpaprMachin= eState *spapr) * * The Linux kernel will assume that the distance between src = and * dst, in this case of no match, is 10 (local distance) doubl= ed - * for each NUMA it didn't match. We have MAX_DISTANCE_REF_POI= NTS + * for each NUMA it didn't match. We have FORM1_DIST_REF_POINTS * levels (4), so this gives us 10*2*2*2*2 =3D 160. * * This logic can be seen in the Linux kernel source code, as = of @@ -168,13 +209,13 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachi= neState *spapr, int i, j, max_nodes_with_gpus; =20 /* init FORM1_assoc_array */ - for (i =3D 0; i < MAX_NODES + NVGPU_MAX_NUM; i++) { - spapr->FORM1_assoc_array[i] =3D g_new0(uint32_t, NUMA_ASSOC_SIZE); + for (i =3D 0; i < NUMA_NODES_MAX_NUM; i++) { + spapr->FORM1_assoc_array[i] =3D g_new0(uint32_t, FORM1_NUMA_ASSOC_= SIZE); } =20 /* * For all associativity arrays: first position is the size, - * position MAX_DISTANCE_REF_POINTS is always the numa_id, + * position FORM1_DIST_REF_POINTS is always the numa_id, * represented by the index 'i'. * * This will break on sparse NUMA setups, when/if QEMU starts @@ -182,8 +223,8 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachine= State *spapr, * 'i' will be a valid node_id set by the user. */ for (i =3D 0; i < nb_numa_nodes; i++) { - spapr->FORM1_assoc_array[i][0] =3D cpu_to_be32(MAX_DISTANCE_REF_PO= INTS); - spapr->FORM1_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be= 32(i); + spapr->FORM1_assoc_array[i][0] =3D cpu_to_be32(FORM1_DIST_REF_POIN= TS); + spapr->FORM1_assoc_array[i][FORM1_DIST_REF_POINTS] =3D cpu_to_be32= (i); } =20 /* @@ -197,15 +238,15 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachi= neState *spapr, max_nodes_with_gpus =3D nb_numa_nodes + NVGPU_MAX_NUM; =20 for (i =3D nb_numa_nodes; i < max_nodes_with_gpus; i++) { - spapr->FORM1_assoc_array[i][0] =3D cpu_to_be32(MAX_DISTANCE_REF_PO= INTS); + spapr->FORM1_assoc_array[i][0] =3D cpu_to_be32(FORM1_DIST_REF_POIN= TS); =20 - for (j =3D 1; j < MAX_DISTANCE_REF_POINTS; j++) { + for (j =3D 1; j < FORM1_DIST_REF_POINTS; j++) { uint32_t gpu_assoc =3D smc->pre_5_1_assoc_refpoints ? SPAPR_GPU_NUMA_ID : cpu_to_be32(i); spapr->FORM1_assoc_array[i][j] =3D gpu_assoc; } =20 - spapr->FORM1_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be= 32(i); + spapr->FORM1_assoc_array[i][FORM1_DIST_REF_POINTS] =3D cpu_to_be32= (i); } =20 /* @@ -255,16 +296,17 @@ void spapr_numa_associativity_reset(SpaprMachineState= *spapr) void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, int offset, int nodeid) { - /* Hardcode the size of FORM1 associativity array for now */ _FDT((fdt_setprop(fdt, offset, "ibm,associativity", spapr->numa_assoc_array[nodeid], - NUMA_ASSOC_SIZE * sizeof(uint32_t)))); + get_numa_assoc_size(spapr) * sizeof(uint32_t)))); } =20 static uint32_t *spapr_numa_get_vcpu_assoc(SpaprMachineState *spapr, PowerPCCPU *cpu) { - uint32_t *vcpu_assoc =3D g_new(uint32_t, VCPU_ASSOC_SIZE); + int max_distance_ref_points =3D get_max_dist_ref_points(spapr); + int vcpu_assoc_size =3D get_vcpu_assoc_size(spapr); + uint32_t *vcpu_assoc =3D g_new(uint32_t, vcpu_assoc_size); int index =3D spapr_get_vcpu_id(cpu); =20 /* @@ -273,10 +315,10 @@ static uint32_t *spapr_numa_get_vcpu_assoc(SpaprMachi= neState *spapr, * 0, put cpu_id last, then copy the remaining associativity * domains. */ - vcpu_assoc[0] =3D cpu_to_be32(MAX_DISTANCE_REF_POINTS + 1); - vcpu_assoc[VCPU_ASSOC_SIZE - 1] =3D cpu_to_be32(index); + vcpu_assoc[0] =3D cpu_to_be32(max_distance_ref_points + 1); + vcpu_assoc[vcpu_assoc_size - 1] =3D cpu_to_be32(index); memcpy(vcpu_assoc + 1, spapr->numa_assoc_array[cpu->node_id] + 1, - (VCPU_ASSOC_SIZE - 2) * sizeof(uint32_t)); + (vcpu_assoc_size - 2) * sizeof(uint32_t)); =20 return vcpu_assoc; } @@ -285,12 +327,13 @@ int spapr_numa_fixup_cpu_dt(SpaprMachineState *spapr,= void *fdt, int offset, PowerPCCPU *cpu) { g_autofree uint32_t *vcpu_assoc =3D NULL; + int vcpu_assoc_size =3D get_vcpu_assoc_size(spapr); =20 vcpu_assoc =3D spapr_numa_get_vcpu_assoc(spapr, cpu); =20 /* Advertise NUMA via ibm,associativity */ return fdt_setprop(fdt, offset, "ibm,associativity", vcpu_assoc, - VCPU_ASSOC_SIZE * sizeof(uint32_t)); + vcpu_assoc_size * sizeof(uint32_t)); } =20 =20 @@ -298,17 +341,18 @@ int spapr_numa_write_assoc_lookup_arrays(SpaprMachine= State *spapr, void *fdt, int offset) { MachineState *machine =3D MACHINE(spapr); + int max_distance_ref_points =3D get_max_dist_ref_points(spapr); int nb_numa_nodes =3D machine->numa_state->num_nodes; int nr_nodes =3D nb_numa_nodes ? nb_numa_nodes : 1; uint32_t *int_buf, *cur_index, buf_len; int ret, i; =20 /* ibm,associativity-lookup-arrays */ - buf_len =3D (nr_nodes * MAX_DISTANCE_REF_POINTS + 2) * sizeof(uint32_t= ); + buf_len =3D (nr_nodes * max_distance_ref_points + 2) * sizeof(uint32_t= ); cur_index =3D int_buf =3D g_malloc0(buf_len); int_buf[0] =3D cpu_to_be32(nr_nodes); /* Number of entries per associativity list */ - int_buf[1] =3D cpu_to_be32(MAX_DISTANCE_REF_POINTS); + int_buf[1] =3D cpu_to_be32(max_distance_ref_points); cur_index +=3D 2; for (i =3D 0; i < nr_nodes; i++) { /* @@ -317,8 +361,8 @@ int spapr_numa_write_assoc_lookup_arrays(SpaprMachineSt= ate *spapr, void *fdt, */ uint32_t *associativity =3D spapr->numa_assoc_array[i]; memcpy(cur_index, ++associativity, - sizeof(uint32_t) * MAX_DISTANCE_REF_POINTS); - cur_index +=3D MAX_DISTANCE_REF_POINTS; + sizeof(uint32_t) * max_distance_ref_points); + cur_index +=3D max_distance_ref_points; } ret =3D fdt_setprop(fdt, offset, "ibm,associativity-lookup-arrays", in= t_buf, (cur_index - int_buf) * sizeof(uint32_t)); @@ -406,6 +450,7 @@ static target_ulong h_home_node_associativity(PowerPCCP= U *cpu, target_ulong procno =3D args[1]; PowerPCCPU *tcpu; int idx, assoc_idx; + int vcpu_assoc_size =3D get_vcpu_assoc_size(spapr); =20 /* only support procno from H_REGISTER_VPA */ if (flags !=3D 0x1) { @@ -424,7 +469,7 @@ static target_ulong h_home_node_associativity(PowerPCCP= U *cpu, * 12 associativity domains for vcpus. Assert and bail if that's * not the case. */ - G_STATIC_ASSERT((VCPU_ASSOC_SIZE - 1) <=3D 12); + g_assert((vcpu_assoc_size - 1) <=3D 12); =20 vcpu_assoc =3D spapr_numa_get_vcpu_assoc(spapr, tcpu); /* assoc_idx starts at 1 to skip associativity size */ @@ -445,9 +490,9 @@ static target_ulong h_home_node_associativity(PowerPCCP= U *cpu, * macro. The ternary will fill the remaining registers with -1 * after we went through vcpu_assoc[]. */ - a =3D assoc_idx < VCPU_ASSOC_SIZE ? + a =3D assoc_idx < vcpu_assoc_size ? be32_to_cpu(vcpu_assoc[assoc_idx++]) : -1; - b =3D assoc_idx < VCPU_ASSOC_SIZE ? + b =3D assoc_idx < vcpu_assoc_size ? be32_to_cpu(vcpu_assoc[assoc_idx++]) : -1; =20 args[idx] =3D ASSOCIATIVITY(a, b); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 8a9490f0bf..2554928250 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -100,23 +100,11 @@ typedef enum { =20 #define FDT_MAX_SIZE 0x200000 =20 -/* - * NUMA related macros. MAX_DISTANCE_REF_POINTS was taken - * from Linux kernel arch/powerpc/mm/numa.h. It represents the - * amount of associativity domains for non-CPU resources. - * - * NUMA_ASSOC_SIZE is the base array size of an ibm,associativity - * array for any non-CPU resource. - * - * VCPU_ASSOC_SIZE represents the size of ibm,associativity array - * for CPUs, which has an extra element (vcpu_id) in the end. - */ -#define MAX_DISTANCE_REF_POINTS 4 -#define NUMA_ASSOC_SIZE (MAX_DISTANCE_REF_POINTS + 1) -#define VCPU_ASSOC_SIZE (NUMA_ASSOC_SIZE + 1) +/* Max number of GPUs per system */ +#define NVGPU_MAX_NUM 6 =20 -/* Max number of these GPUsper a physical box */ -#define NVGPU_MAX_NUM 6 +/* Max number of NUMA nodes */ +#define NUMA_NODES_MAX_NUM (MAX_NODES + NVGPU_MAX_NUM) =20 typedef struct SpaprCapabilities SpaprCapabilities; struct SpaprCapabilities { @@ -249,7 +237,7 @@ struct SpaprMachineState { unsigned gpu_numa_id; SpaprTpmProxy *tpm_proxy; =20 - uint32_t *FORM1_assoc_array[MAX_NODES + NVGPU_MAX_NUM]; + uint32_t *FORM1_assoc_array[NUMA_NODES_MAX_NUM]; uint32_t **numa_assoc_array; =20 Error *fwnmi_migration_blocker; --=20 2.31.1 From nobody Sat Apr 27 11:43:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631304089875709.4980305790567; Fri, 10 Sep 2021 13:01:29 -0700 (PDT) Received: from localhost ([::1]:50608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOmiF-0005d5-Cc for importer@patchew.org; Fri, 10 Sep 2021 16:01:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOmdF-0005lJ-Jb; Fri, 10 Sep 2021 15:56:18 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:38799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOmd6-0006Gy-Lb; Fri, 10 Sep 2021 15:56:11 -0400 Received: by mail-qt1-x82f.google.com with SMTP id g11so2560769qtk.5; Fri, 10 Sep 2021 12:56:07 -0700 (PDT) Received: from rekt.COMFAST ([191.193.98.206]) by smtp.gmail.com with ESMTPSA id k10sm3873356qth.44.2021.09.10.12.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 12:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lnj82D7Iqit6aGU3+jjvOh1+PKs9zxH1Qv/gZJ0LXIs=; b=RcuEzGvx9ioQr5gT4GNPEEF9lKxAUrAinbPCWJLgvMDHMRNNXlucW39MYfO2IRvDaw zIjMheCxzaotu3Nb8xMMXs+i4w11Ps4dp1q6Kno3gc8uCTRzHmuYSyqvKJ9WOmoKiPbH R3nq0+mhjTMMI2gghaBPfJnPxoGUweBTWX4I/EUbe8L2xP4s5Ds/YIcI3igDkGfRxQVB HJsUobzdfhDg4DBWPwoWtIxSXPaHvwf7qUOzRRJCnFB/noQhKxNRg5yYyh0pc687gL3L wb4q0a9QCjBbUCcZlO/YvZvnW3qvfulaqO1nwkEYg+11Dym20rGo3XpjCO0LXlTOV3RT o0Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lnj82D7Iqit6aGU3+jjvOh1+PKs9zxH1Qv/gZJ0LXIs=; b=NiZvqI79SERjJSUppvR+KwsGm1NH/zuMzsGIidfTy0TO2huL/RRl4m7/SK3b5fzkgD xaXzHYE2+fFZGtRnIttw1DUUCUzXE1z8EeGvxilbHrUnHinQrI4+ki154JfS0oei3lJn 4pTFOYWC0Sv/1fZ+p2dtAzQSbQyQEnHi+m3gFwijdijEndryaumMoXJGGLTjE85b7ogF 7Tt6yeyBgQUo7TAYMGnj1mHW3yckp4b7o4TaxZ5MtM2dG8NWuPN8JKQobTFxvsCSdYSw nNmSdgt+350wh+C/I+NzDKCSZ6uan1d+oZkQJ7kN6aJl7JwwjG1oH+528uVazjkUoGCY Npyw== X-Gm-Message-State: AOAM532GZuuwcv9RRKJFVvL6R7PLas+VGth0G+pz8ZahpzBdvSi19bH3 aB6Y4qe4EfmGXhvjdAX7+zwlIvMXrcs= X-Google-Smtp-Source: ABdhPJzOQ7kXBV+hagb09VTMjFFiW+JMbQlAZH3N32w0arcBX1x/XlCiu5hK7/6mDsxWiIJpWcygmQ== X-Received: by 2002:a05:622a:3d4:: with SMTP id k20mr9649369qtx.353.1631303766850; Fri, 10 Sep 2021 12:56:06 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v6 5/6] spapr: move FORM1 verifications to post CAS Date: Fri, 10 Sep 2021 16:55:38 -0300 Message-Id: <20210910195539.797170-6-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910195539.797170-1-danielhb413@gmail.com> References: <20210910195539.797170-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::82f; envelope-from=danielhb413@gmail.com; helo=mail-qt1-x82f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631304091757100001 Content-Type: text/plain; charset="utf-8" FORM2 NUMA affinity is prepared to deal with empty (memory/cpu less) NUMA nodes. This is used by the DAX KMEM driver to locate a PAPR SCM device that has a different latency than the original NUMA node from the regular memory. FORM2 is also enable to deal with asymmetric NUMA distances gracefully, something that our FORM1 implementation doesn't do. Move these FORM1 verifications to a new function and wait until after CAS, when we're sure that we're sticking with FORM1, to enforce them. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 35 +---------------------- hw/ppc/spapr_hcall.c | 2 +- hw/ppc/spapr_numa.c | 55 ++++++++++++++++++++++++++++++++----- include/hw/ppc/spapr_numa.h | 3 +- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 5afbb76cab..0703a26093 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1798,7 +1798,7 @@ static int spapr_post_load(void *opaque, int version_= id) * through it, but since it's a lightweight operation it's worth being * a little redundant to be safe. */ - spapr_numa_associativity_reset(spapr); + spapr_numa_associativity_reset(spapr, false); =20 return err; } @@ -2787,39 +2787,6 @@ static void spapr_machine_init(MachineState *machine) /* init CPUs */ spapr_init_cpus(spapr); =20 - /* - * check we don't have a memory-less/cpu-less NUMA node - * Firmware relies on the existing memory/cpu topology to provide the - * NUMA topology to the kernel. - * And the linux kernel needs to know the NUMA topology at start - * to be able to hotplug CPUs later. - */ - if (machine->numa_state->num_nodes) { - for (i =3D 0; i < machine->numa_state->num_nodes; ++i) { - /* check for memory-less node */ - if (machine->numa_state->nodes[i].node_mem =3D=3D 0) { - CPUState *cs; - int found =3D 0; - /* check for cpu-less node */ - CPU_FOREACH(cs) { - PowerPCCPU *cpu =3D POWERPC_CPU(cs); - if (cpu->node_id =3D=3D i) { - found =3D 1; - break; - } - } - /* memory-less and cpu-less node */ - if (!found) { - error_report( - "Memory-less/cpu-less nodes are not supported (node= %d)", - i); - exit(1); - } - } - } - - } - spapr->gpu_numa_id =3D spapr_numa_initial_nvgpu_numa_id(machine); =20 /* Init numa_assoc_array */ diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 82ab92ddba..2dc22e2dc7 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1202,7 +1202,7 @@ target_ulong do_client_architecture_support(PowerPCCP= U *cpu, * Reset numa_assoc_array now that we know which NUMA affinity * the guest will use. */ - spapr_numa_associativity_reset(spapr); + spapr_numa_associativity_reset(spapr, true); =20 /* * Ensure the guest asks for an interrupt mode we support; diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 7ad4b6582b..0ade63c2d3 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -198,6 +198,48 @@ static void spapr_numa_define_FORM1_domains(SpaprMachi= neState *spapr) =20 } =20 +static void spapr_numa_FORM1_affinity_check(MachineState *machine) +{ + int i; + + /* + * Check we don't have a memory-less/cpu-less NUMA node + * Firmware relies on the existing memory/cpu topology to provide the + * NUMA topology to the kernel. + * And the linux kernel needs to know the NUMA topology at start + * to be able to hotplug CPUs later. + */ + if (machine->numa_state->num_nodes) { + for (i =3D 0; i < machine->numa_state->num_nodes; ++i) { + /* check for memory-less node */ + if (machine->numa_state->nodes[i].node_mem =3D=3D 0) { + CPUState *cs; + int found =3D 0; + /* check for cpu-less node */ + CPU_FOREACH(cs) { + PowerPCCPU *cpu =3D POWERPC_CPU(cs); + if (cpu->node_id =3D=3D i) { + found =3D 1; + break; + } + } + /* memory-less and cpu-less node */ + if (!found) { + error_report( +"Memory-less/cpu-less nodes are not supported with FORM1 NUMA (node %d)", = i); + exit(EXIT_FAILURE); + } + } + } + } + + if (!spapr_numa_is_symmetrical(machine)) { + error_report( +"Asymmetrical NUMA topologies aren't supported in the pSeries machine usin= g FORM1 NUMA"); + exit(EXIT_FAILURE); + } +} + /* * Set NUMA machine state data based on FORM1 affinity semantics. */ @@ -260,12 +302,6 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachin= eState *spapr, return; } =20 - if (!spapr_numa_is_symmetrical(machine)) { - error_report("Asymmetrical NUMA topologies aren't supported " - "in the pSeries machine"); - exit(EXIT_FAILURE); - } - spapr_numa_define_FORM1_domains(spapr); } =20 @@ -287,10 +323,15 @@ void spapr_numa_associativity_init(SpaprMachineState = *spapr, spapr->numa_assoc_array =3D spapr->FORM1_assoc_array; } =20 -void spapr_numa_associativity_reset(SpaprMachineState *spapr) +void spapr_numa_associativity_reset(SpaprMachineState *spapr, + bool post_CAS_check) { /* No FORM2 affinity implemented yet */ spapr->numa_assoc_array =3D spapr->FORM1_assoc_array; + + if (post_CAS_check) { + spapr_numa_FORM1_affinity_check(MACHINE(spapr)); + } } =20 void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, diff --git a/include/hw/ppc/spapr_numa.h b/include/hw/ppc/spapr_numa.h index ccf3e4eae8..246767d0a8 100644 --- a/include/hw/ppc/spapr_numa.h +++ b/include/hw/ppc/spapr_numa.h @@ -24,7 +24,8 @@ */ void spapr_numa_associativity_init(SpaprMachineState *spapr, MachineState *machine); -void spapr_numa_associativity_reset(SpaprMachineState *spapr); +void spapr_numa_associativity_reset(SpaprMachineState *spapr, + bool post_CAS_check); void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rta= s); void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, int offset, int nodeid); --=20 2.31.1 From nobody Sat Apr 27 11:43:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631304123323935.9390116531744; Fri, 10 Sep 2021 13:02:03 -0700 (PDT) Received: from localhost ([::1]:51784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOmin-0006RC-T9 for importer@patchew.org; Fri, 10 Sep 2021 16:02:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOmdH-0005mb-FN; Fri, 10 Sep 2021 15:56:20 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:42945) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOmd8-0006IW-CR; Fri, 10 Sep 2021 15:56:15 -0400 Received: by mail-qk1-x72e.google.com with SMTP id t4so3298449qkb.9; Fri, 10 Sep 2021 12:56:09 -0700 (PDT) Received: from rekt.COMFAST ([191.193.98.206]) by smtp.gmail.com with ESMTPSA id k10sm3873356qth.44.2021.09.10.12.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 12:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ONO1XN79/I80lTzqXELVruANGjMyyEb07J0RTZJ2s7Q=; b=THnuIYK0chth0UQLDvanB53EJ+geMFFjdoZUX1VHcTJkW87YZkCmVRSKCynJR+N5pl yh1Wlk9+TUxarlgNZpP6+cuoEHMslmn6xJU1z9VvRKCyVjVJy/IRwlrKAvxaMeU1NjM3 xnJaQWytpCEHz7OyC7Z95zSQJkGb/oyYQgvW5W0EZDaUwUy2UXQSySMm24knwKLf2yNY xL65Rm9ikEeyCcC6278nyOYd4L4b60EECxTUuG/J6zVfpJGbnzKoz/5ckfPEuT4ks62b 5F5UvwZNIoKN3gGvvUAmx6KaDUHXP2d9IcEn8oyKnUhQosdkPq7jIYdsqmeOrKcg2mZt HMEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ONO1XN79/I80lTzqXELVruANGjMyyEb07J0RTZJ2s7Q=; b=ToUHykZp3QmtRKYSLNPPy6smVPMpzrRCnoe9In4/nA6tbQPaziojF1+04KvqXRLW1e RMTxIEBRAZGs96WW/qK3K/2NvAE6o5o7e+rJwnGZsOYLrapM5V3//5NryXpl3rXHnka1 iB45BGm/Vv/2tvRYYVg/9aLMeyTkBbwCHltzHpVc/nMghWq/dukMfxT9sANIpvswuNhQ CsU7UNE4fSv0Cd7lCNACyV4XOYmwu7kklC3mTn1XYRIc58bUFVY1dbIqgkj8tBVg9aIf WH63/xSlaGKaHJ5yUkIqX2kOmhWv6BZKumaxaCduBZP6DrjVV22XQTh4BL/nrWhNUw6a wi9w== X-Gm-Message-State: AOAM530HCiylRQ7CCps1To4YQbPfC5IO6GnOiPLX2dgCUr1zC7P0roqA 3WwSlL72CIHkB56O++8bmWiUAS5rzLM= X-Google-Smtp-Source: ABdhPJxCr1gDgca96NX3Zx1vjS6r9FuazG5RNYVZsXjhIQZ9R5gsBpiFkP9/Cub9i/Ueb8uv7qWkrA== X-Received: by 2002:a05:620a:a85:: with SMTP id v5mr9290794qkg.261.1631303768676; Fri, 10 Sep 2021 12:56:08 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v6 6/6] spapr_numa.c: FORM2 NUMA affinity support Date: Fri, 10 Sep 2021 16:55:39 -0300 Message-Id: <20210910195539.797170-7-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910195539.797170-1-danielhb413@gmail.com> References: <20210910195539.797170-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x72e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , qemu-ppc@nongnu.org, groug@kaod.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631304123704100003 Content-Type: text/plain; charset="utf-8" The main feature of FORM2 affinity support is the separation of NUMA distances from ibm,associativity information. This allows for a more flexible and straightforward NUMA distance assignment without relying on complex associations between several levels of NUMA via ibm,associativity matches. Another feature is its extensibility. This base support contains the facilities for NUMA distance assignment, but in the future more facilities will be added for latency, performance, bandwidth and so on. This patch implements the base FORM2 affinity support as follows: - the use of FORM2 associativity is indicated by using bit 2 of byte 5 of ibm,architecture-vec-5. A FORM2 aware guest can choose to use FORM1 or FORM2 affinity. Setting both forms will default to FORM2. We're not advertising FORM2 for pseries-6.1 and older machine versions to prevent guest visible changes in those; - ibm,associativity-reference-points has a new semantic. Instead of being used to calculate distances via NUMA levels, it's now used to indicate the primary domain index in the ibm,associativity domain of each resource. In our case it's set to {0x4}, matching the position where we already place logical_domain_id; - two new RTAS DT artifacts are introduced: ibm,numa-lookup-index-table and ibm,numa-distance-table. The index table is used to list all the NUMA logical domains of the platform, in ascending order, and allows for spartial NUMA configurations (although QEMU ATM doesn't support that). ibm,numa-distance-table is an array that contains all the distances from the first NUMA node to all other nodes, then the second NUMA node distances to all other nodes and so on; - get_max_dist_ref_points() and get_numa_assoc_size() now checks for OV5_FORM2_AFFINITY and returns FORM2 values if the guest selected FORM2 affinity during CAS. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 8 ++ hw/ppc/spapr_numa.c | 151 +++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 2 + include/hw/ppc/spapr_ovec.h | 1 + 4 files changed, 159 insertions(+), 3 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0703a26093..23aba5ae2d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2766,6 +2766,11 @@ static void spapr_machine_init(MachineState *machine) =20 spapr_ovec_set(spapr->ov5, OV5_FORM1_AFFINITY); =20 + /* Do not advertise FORM2 NUMA support for pseries-6.1 and older */ + if (!smc->pre_6_2_numa_affinity) { + spapr_ovec_set(spapr->ov5, OV5_FORM2_AFFINITY); + } + /* advertise support for dedicated HP event source to guests */ if (spapr->use_hotplug_event_source) { spapr_ovec_set(spapr->ov5, OV5_HP_EVT); @@ -4681,8 +4686,11 @@ DEFINE_SPAPR_MACHINE(6_2, "6.2", true); */ static void spapr_machine_6_1_class_options(MachineClass *mc) { + SpaprMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); + spapr_machine_6_2_class_options(mc); compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); + smc->pre_6_2_numa_affinity =3D true; } =20 DEFINE_SPAPR_MACHINE(6_1, "6.1", false); diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 0ade63c2d3..dd52b8921c 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -31,12 +31,22 @@ #define FORM1_DIST_REF_POINTS 4 #define FORM1_NUMA_ASSOC_SIZE (FORM1_DIST_REF_POINTS + 1) =20 +/* + * FORM2 NUMA affinity has a single associativity domain, giving + * us a assoc size of 2. + */ +#define FORM2_DIST_REF_POINTS 1 +#define FORM2_NUMA_ASSOC_SIZE (FORM2_DIST_REF_POINTS + 1) + /* * Retrieves max_dist_ref_points of the current NUMA affinity. */ static int get_max_dist_ref_points(SpaprMachineState *spapr) { - /* No FORM2 affinity implemented yet */ + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + return FORM2_DIST_REF_POINTS; + } + return FORM1_DIST_REF_POINTS; } =20 @@ -45,7 +55,10 @@ static int get_max_dist_ref_points(SpaprMachineState *sp= apr) */ static int get_numa_assoc_size(SpaprMachineState *spapr) { - /* No FORM2 affinity implemented yet */ + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + return FORM2_NUMA_ASSOC_SIZE; + } + return FORM1_NUMA_ASSOC_SIZE; } =20 @@ -305,10 +318,39 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachi= neState *spapr, spapr_numa_define_FORM1_domains(spapr); } =20 +/* + * Init NUMA FORM2 machine state data + */ +static void spapr_numa_FORM2_affinity_init(SpaprMachineState *spapr) +{ + int i; + + /* + * For all resources but CPUs, FORM2 associativity arrays will + * be a size 2 array with the following format: + * + * ibm,associativity =3D {1, numa_id} + * + * CPUs will write an additional 'vcpu_id' on top of the arrays + * being initialized here. 'numa_id' is represented by the + * index 'i' of the loop. + * + * Given that this initialization is also valid for GPU associativity + * arrays, handle everything in one single step by populating the + * arrays up to NUMA_NODES_MAX_NUM. + */ + for (i =3D 0; i < NUMA_NODES_MAX_NUM; i++) { + spapr->FORM2_assoc_array[i] =3D g_new0(uint32_t, 2); + spapr->FORM2_assoc_array[i][0] =3D cpu_to_be32(1); + spapr->FORM2_assoc_array[i][1] =3D cpu_to_be32(i); + } +} + void spapr_numa_associativity_init(SpaprMachineState *spapr, MachineState *machine) { spapr_numa_FORM1_affinity_init(spapr, machine); + spapr_numa_FORM2_affinity_init(spapr); =20 /* * Default to FORM1 affinity until CAS. We'll call affinity_reset() @@ -326,7 +368,11 @@ void spapr_numa_associativity_init(SpaprMachineState *= spapr, void spapr_numa_associativity_reset(SpaprMachineState *spapr, bool post_CAS_check) { - /* No FORM2 affinity implemented yet */ + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + spapr->numa_assoc_array =3D spapr->FORM2_assoc_array; + return; + } + spapr->numa_assoc_array =3D spapr->FORM1_assoc_array; =20 if (post_CAS_check) { @@ -471,6 +517,100 @@ static void spapr_numa_FORM1_write_rtas_dt(SpaprMachi= neState *spapr, maxdomains, sizeof(maxdomains))); } =20 +static void spapr_numa_FORM2_write_rtas_tables(SpaprMachineState *spapr, + void *fdt, int rtas) +{ + MachineState *ms =3D MACHINE(spapr); + NodeInfo *numa_info =3D ms->numa_state->nodes; + int nb_numa_nodes =3D ms->numa_state->num_nodes; + int distance_table_entries =3D nb_numa_nodes * nb_numa_nodes; + g_autofree uint32_t *lookup_index_table =3D NULL; + g_autofree uint32_t *distance_table =3D NULL; + int src, dst, i, distance_table_size; + uint8_t *node_distances; + + /* + * ibm,numa-lookup-index-table: array with length and a + * list of NUMA ids present in the guest. + */ + lookup_index_table =3D g_new0(uint32_t, nb_numa_nodes + 1); + lookup_index_table[0] =3D cpu_to_be32(nb_numa_nodes); + + for (i =3D 0; i < nb_numa_nodes; i++) { + lookup_index_table[i + 1] =3D cpu_to_be32(i); + } + + _FDT(fdt_setprop(fdt, rtas, "ibm,numa-lookup-index-table", + lookup_index_table, + (nb_numa_nodes + 1) * sizeof(uint32_t))); + + /* + * ibm,numa-distance-table: contains all node distances. First + * element is the size of the table as uint32, followed up + * by all the uint8 distances from the first NUMA node, then all + * distances from the second NUMA node and so on. + * + * ibm,numa-lookup-index-table is used by guest to navigate this + * array because NUMA ids can be sparse (node 0 is the first, + * node 8 is the second ...). + */ + distance_table =3D g_new0(uint32_t, distance_table_entries + 1); + distance_table[0] =3D cpu_to_be32(distance_table_entries); + + node_distances =3D (uint8_t *)&distance_table[1]; + i =3D 0; + + for (src =3D 0; src < nb_numa_nodes; src++) { + for (dst =3D 0; dst < nb_numa_nodes; dst++) { + node_distances[i++] =3D numa_info[src].distance[dst]; + } + } + + distance_table_size =3D distance_table_entries * sizeof(uint8_t) + + sizeof(uint32_t); + _FDT(fdt_setprop(fdt, rtas, "ibm,numa-distance-table", + distance_table, distance_table_size)); +} + +/* + * This helper could be compressed in a single function with + * FORM1 logic since we're setting the same DT values, with the + * difference being a call to spapr_numa_FORM2_write_rtas_tables() + * in the end. The separation was made to avoid clogging FORM1 code + * which already has to deal with compat modes from previous + * QEMU machine types. + */ +static void spapr_numa_FORM2_write_rtas_dt(SpaprMachineState *spapr, + void *fdt, int rtas) +{ + MachineState *ms =3D MACHINE(spapr); + uint32_t number_nvgpus_nodes =3D spapr->gpu_numa_id - + spapr_numa_initial_nvgpu_numa_id(ms); + + /* + * In FORM2, ibm,associativity-reference-points will point to + * the element in the ibm,associativity array that contains the + * primary domain index (for FORM2, the first element). + * + * This value (in our case, the numa-id) is then used as an index + * to retrieve all other attributes of the node (distance, + * bandwidth, latency) via ibm,numa-lookup-index-table and other + * ibm,numa-*-table properties. + */ + uint32_t refpoints[] =3D { cpu_to_be32(1) }; + + uint32_t maxdomain =3D ms->numa_state->num_nodes + number_nvgpus_nodes; + uint32_t maxdomains[] =3D { cpu_to_be32(1), cpu_to_be32(maxdomain) }; + + _FDT(fdt_setprop(fdt, rtas, "ibm,associativity-reference-points", + refpoints, sizeof(refpoints))); + + _FDT(fdt_setprop(fdt, rtas, "ibm,max-associativity-domains", + maxdomains, sizeof(maxdomains))); + + spapr_numa_FORM2_write_rtas_tables(spapr, fdt, rtas); +} + /* * Helper that writes ibm,associativity-reference-points and * max-associativity-domains in the RTAS pointed by @rtas @@ -478,6 +618,11 @@ static void spapr_numa_FORM1_write_rtas_dt(SpaprMachin= eState *spapr, */ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rta= s) { + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + spapr_numa_FORM2_write_rtas_dt(spapr, fdt, rtas); + return; + } + spapr_numa_FORM1_write_rtas_dt(spapr, fdt, rtas); } =20 diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 2554928250..2a4502b65d 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -133,6 +133,7 @@ struct SpaprMachineClass { hwaddr rma_limit; /* clamp the RMA to this size */ bool pre_5_1_assoc_refpoints; bool pre_5_2_numa_associativity; + bool pre_6_2_numa_affinity; =20 bool (*phb_placement)(SpaprMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio, @@ -238,6 +239,7 @@ struct SpaprMachineState { SpaprTpmProxy *tpm_proxy; =20 uint32_t *FORM1_assoc_array[NUMA_NODES_MAX_NUM]; + uint32_t *FORM2_assoc_array[NUMA_NODES_MAX_NUM]; uint32_t **numa_assoc_array; =20 Error *fwnmi_migration_blocker; diff --git a/include/hw/ppc/spapr_ovec.h b/include/hw/ppc/spapr_ovec.h index 48b716a060..c3e8b98e7e 100644 --- a/include/hw/ppc/spapr_ovec.h +++ b/include/hw/ppc/spapr_ovec.h @@ -49,6 +49,7 @@ typedef struct SpaprOptionVector SpaprOptionVector; /* option vector 5 */ #define OV5_DRCONF_MEMORY OV_BIT(2, 2) #define OV5_FORM1_AFFINITY OV_BIT(5, 0) +#define OV5_FORM2_AFFINITY OV_BIT(5, 2) #define OV5_HP_EVT OV_BIT(6, 5) #define OV5_HPT_RESIZE OV_BIT(6, 7) #define OV5_DRMEM_V2 OV_BIT(22, 0) --=20 2.31.1