From nobody Mon Apr 29 20:25:24 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 163216034447716.152799243640402; Mon, 20 Sep 2021 10:52:24 -0700 (PDT) Received: from localhost ([::1]:51302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSNSp-0005Gj-EC for importer@patchew.org; Mon, 20 Sep 2021 13:52:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSNQZ-0001ii-Nt; Mon, 20 Sep 2021 13:50:05 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:43567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSNQX-0008QJ-5i; Mon, 20 Sep 2021 13:50:03 -0400 Received: by mail-qt1-x82b.google.com with SMTP id a13so2291512qtw.10; Mon, 20 Sep 2021 10:50:00 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id l28sm6073614qkl.127.2021.09.20.10.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:49:59 -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=uCwUlAEuHu9NPWjIuULqWyr2j0RMt56Ie8slVpbbpAE=; b=PQWKIB4S0Zxvt1It95Sesq/Q74CrDLcV81sw18LPMvThIewANb9HxZWpV8ll6E+jIA /b5ruzU9craQVCeRYQuMUa0YFE7FYMxqsum7hYhWp9qj7Vj0zGOpOn9Ed3wFe95lkKjf JKi2CfAcN3hclwQY5VLbyXAULbqN4pYZ9XaLtIqEmQbi/oqwpVengLt64b9a9t6fd+ZX UpHx/n+FHXVadtSNXzNzxLem4YbDk5AWeyF7rpKlZf2xNsRQ/63slSWxqsfGadVIgCky Jkj4oaJN162SJkS6+829415929S0iTa1Gptrz9W52TzcfPWBGXGWG0ClSX0Y/n10Zzri xvbA== 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=uCwUlAEuHu9NPWjIuULqWyr2j0RMt56Ie8slVpbbpAE=; b=HM9JMe9SMxOtGJNGWVU7Rn82R362PRJFLfDOg6FdR6dyedhkvEpnONtHsjhH3sGANf eQx6oe2mFbhxDlE0jlcoQBJ9Kqpwq3qqB/VDzK9RKld56LnuBwesVTUCNL+uqxdAEY3t bqcTG62f85wvyiwkeHovCoVW4gyOOb4eA49zWtsYLtceHhNtq7wY05S1nfUP7ep01S+Z kh5U8yQEGi3HcMvp5OMGFR4yhwG/dbx2tlCO5ESBb4lcyqFDMR5o8GR6iZYwWbUPWCMP HJ48OFHjCItsxhCl7shKxJ/Xu2xM6XYaRBxocwxshr9kvG0DRKER2bfotH2r872KpyGn fZ4w== X-Gm-Message-State: AOAM530AscGQJhMvG/AyLEE366wzW/6kgiqycNMam7KXg/eyUwvh0B8K tnlYHEn6UUsRmFQgyYLlWyhtT1TJgPE= X-Google-Smtp-Source: ABdhPJyfBIBB0Tg991s6zFfIXX/XKeTv50Hg1dYwsADcm3q1CaAMFLbCfMH5UwecSZsmyFREOWWILw== X-Received: by 2002:ac8:5796:: with SMTP id v22mr24013805qta.373.1632160199880; Mon, 20 Sep 2021 10:49:59 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 1/7] spapr_numa.c: split FORM1 code into helpers Date: Mon, 20 Sep 2021 14:49:41 -0300 Message-Id: <20210920174947.556324-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920174947.556324-1-danielhb413@gmail.com> References: <20210920174947.556324-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::82b; envelope-from=danielhb413@gmail.com; helo=mail-qt1-x82b.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: 1632160346529100007 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. Reviewed-by: Greg Kurz Signed-off-by: Daniel Henrique Barboza --- 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 Mon Apr 29 20:25:24 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 1632160334401773.8751791674316; Mon, 20 Sep 2021 10:52:14 -0700 (PDT) Received: from localhost ([::1]:50362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSNSe-0004dy-9b for importer@patchew.org; Mon, 20 Sep 2021 13:52:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSNQb-0001iz-6S; Mon, 20 Sep 2021 13:50:05 -0400 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]:33300) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSNQZ-0008RT-0x; Mon, 20 Sep 2021 13:50:04 -0400 Received: by mail-qk1-x733.google.com with SMTP id d207so20150739qkg.0; Mon, 20 Sep 2021 10:50:02 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id l28sm6073614qkl.127.2021.09.20.10.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:50:01 -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=9snP2SQ90EsaopUkwhiL3G+yqbxkthjiliUkz9xzmQM=; b=WqNDZyw7l5AS1oQW/eSJTLxSDtu/bYsFFKB4TfpmEjXhMCfvt+VJbj3FQdq1XRRfa7 CoXoXQg82erJphWu15EVonXlOjCaEDTWxkVWOlttYqtxwjUQJ5cxaJJk55Jqqdv/s2Hh jMD9lwzD5RCbmgR8GlEnlL4UK6VwRaX5ZPTEL5I2n+Y7INApBa/fCqA/1M/3ULBC4vl8 tZrBRf0SwgbqFYopMTgt7CscW20xmXpwC6U/cMMbfte2Rw/gbhPKkeyfUq8ve9ucRlgg QEKZi0gIDFtImrVQXl1yzQCyS4Vdk5U/T1O6paYu8FJzExrsgt7Fal2457gPk9PqOP60 Yncw== 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=9snP2SQ90EsaopUkwhiL3G+yqbxkthjiliUkz9xzmQM=; b=q9cpZaLhtBx8wA8YhZhwar5JcmEx1CjUeCG2/kin6HIInbpVaQ2Xq3fbJgJTQAIjNa FWiBEMLcXTZ0QdkS+6O9wR5rxbeCTN+i2jyBCTFXaMdh5rX4gDov6YHbwsxNQw0zHF6o o4CbijbioFgV+3j02ZuQOxTBXr+krEddI7iAH4/+3gMOiYLxgFg+2Dj0HX7zwiG+t3El IMI8/FawIbKz6/LcLbVMrhSBf+hofu6jypDL/5zdbaRlNZet07Jpsf5epiL4zAKJrZzc jP++RJOWx3yqGE5ohUXC/L90PVotzIpYJHOheygN8ibE7fO5TKjvWKtPX7M3BVhwpwv/ 4HKQ== X-Gm-Message-State: AOAM532mbJdf2uE17JdeXyDvPQZGSY/Dd49cKbQUYXx5MZhBZzXlLtbo OD9GW1FeN8G9wAqB179u+wq1212Obps= X-Google-Smtp-Source: ABdhPJxuz8D2m6+X2l1Mug6MHgqSeYzheuO3UTUDu8E57cBBd0xQ2wJb3w493m8qnHKanq8wfx/ZWA== X-Received: by 2002:a37:482:: with SMTP id 124mr12118026qke.241.1632160201731; Mon, 20 Sep 2021 10:50:01 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 2/7] spapr_numa.c: scrap 'legacy_numa' concept Date: Mon, 20 Sep 2021 14:49:42 -0300 Message-Id: <20210920174947.556324-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920174947.556324-1-danielhb413@gmail.com> References: <20210920174947.556324-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::733; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x733.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: 1632160337125100001 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. Reviewed-by: Greg Kurz Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_numa.c | 47 +++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 786def7c73..bf520d42b2 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,8 @@ 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 || + ms->numa_state->num_nodes <=3D 1) { uint32_t legacy_refpoints[] =3D { cpu_to_be32(0x4), cpu_to_be32(0x4), --=20 2.31.1 From nobody Mon Apr 29 20:25:24 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 163216034303448.34907112733754; Mon, 20 Sep 2021 10:52:23 -0700 (PDT) Received: from localhost ([::1]:51052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSNSm-00056B-6r for importer@patchew.org; Mon, 20 Sep 2021 13:52:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSNQd-0001rf-NM; Mon, 20 Sep 2021 13:50:07 -0400 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]:39697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSNQb-0008Tj-Hx; Mon, 20 Sep 2021 13:50:07 -0400 Received: by mail-qk1-x731.google.com with SMTP id f130so6106642qke.6; Mon, 20 Sep 2021 10:50:04 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id l28sm6073614qkl.127.2021.09.20.10.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:50:03 -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=yrQu5YA34ScqAepu2aL8vTSPkZWNV/nz4wuSWFBkepg=; b=C4WW48nrkG5MHSQXkUaLcK6yWG1lKtYf6XTuwVT5MAuw4e20j4fsImAvlNi3AY5kw1 pJBCPzFYRoJJRgcsD8kRewm+9S+xZe0pKpVEi0rtYcO1NM/iYPeh2Bv00BZs4CtWJTtU ZiQoj8W6be+snTv3nQ2xEfDJtA6OaxHSvcYMR+deGSJNogmcrrJ2Rn+GKoHPSxXRwCxs u09Q1pFGHCGO5C08Ejp/Y1qkMni6q1o/3TmvcNS2FuARgKEIvtHXYtafFu1vlml8DYxk S3xj1YwEkYm4gDrtNQVwe6rZbORTwSeSXNko5Y1DYOnUx4X/umNH8CLo8mTiARWMgg+D g4bA== 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=yrQu5YA34ScqAepu2aL8vTSPkZWNV/nz4wuSWFBkepg=; b=4/NtLzk2tH6VzzhWRpuaIxThGsmJZYSFxSQFYU1XA4WjSlfwANhXMvB43AZoB/dr+O 31hEt7jQmy9A4rCyX/p/ZI58OQ2srmft2sbm4vQkBECqhFyikdQq4A6zXvODwOc0kdgt Y0vDZ3qBqjJ69sPtoe6+qpiVpMLZcDyzQHzj4BYO/lgzT5hAZKh5xvt39uhaKeF77een gyjXt+YmCOysgbVis/bTq2Y25cfMo0CI9KvD71u6Xpcq0MFaKxtYBFqgGDOfqMdVMYfV J9Odou7uehfRwCuURm6Hvajoelvhq8BZjYRqxY56oWRqLNlyDrDXiPAnhVmuOj9VtUA1 E3sw== X-Gm-Message-State: AOAM530+zvpbdNl+u7fTLlqJIQo5UdqcX1LoARRxgw8AoDM6fLmNDCj1 2fe3O5EleWBRphvPQrlAJOyobR6j9rI= X-Google-Smtp-Source: ABdhPJzPy+vN3UyHGZuI3rX0pC/H8ZfrJmnAzj6SY5V6mIb1qhersk/ud4JYaCY/LDo0cCPoqx0rHw== X-Received: by 2002:a37:f613:: with SMTP id y19mr24995656qkj.524.1632160203687; Mon, 20 Sep 2021 10:50:03 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 3/7] spapr_numa.c: parametrize FORM1 macros Date: Mon, 20 Sep 2021 14:49:43 -0300 Message-Id: <20210920174947.556324-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920174947.556324-1-danielhb413@gmail.com> References: <20210920174947.556324-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::731; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x731.google.com X-Spam_score_int: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.1 / 5.0 requ) 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: 1632160344446100003 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. Reviewed-by: Greg Kurz Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_numa.c | 74 ++++++++++++++++++++++++++++++------------ include/hw/ppc/spapr.h | 28 ++++++++-------- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index bf520d42b2..08e2d6aed8 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -19,6 +19,33 @@ /* Moved from hw/ppc/spapr_pci_nvlink2.c */ #define SPAPR_GPU_NUMA_ID (cpu_to_be32(1)) =20 +/* + * Retrieves max_dist_ref_points of the current NUMA affinity. + */ +static int get_max_dist_ref_points(SpaprMachineState *spapr) +{ + return FORM1_DIST_REF_POINTS; +} + +/* + * Retrieves numa_assoc_size of the current NUMA affinity. + */ +static int get_numa_assoc_size(SpaprMachineState *spapr) +{ + 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 +123,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->numa_assoc_array[i][j] =3D cpu_to_be32(i); } } @@ -134,7 +161,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 @@ -169,7 +196,7 @@ static void spapr_numa_FORM1_affinity_init(SpaprMachine= State *spapr, =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 @@ -177,8 +204,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->numa_assoc_array[i][0] =3D cpu_to_be32(FORM1_DIST_REF_POINT= S); + spapr->numa_assoc_array[i][FORM1_DIST_REF_POINTS] =3D cpu_to_be32(= i); } =20 /* @@ -192,15 +219,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->numa_assoc_array[i][0] =3D cpu_to_be32(FORM1_DIST_REF_POINT= S); =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->numa_assoc_array[i][j] =3D gpu_assoc; } =20 - spapr->numa_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be3= 2(i); + spapr->numa_assoc_array[i][FORM1_DIST_REF_POINTS] =3D cpu_to_be32(= i); } =20 /* @@ -234,13 +261,15 @@ void spapr_numa_write_associativity_dt(SpaprMachineSt= ate *spapr, void *fdt, { _FDT((fdt_setprop(fdt, offset, "ibm,associativity", spapr->numa_assoc_array[nodeid], - sizeof(spapr->numa_assoc_array[nodeid])))); + 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 /* @@ -249,10 +278,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; } @@ -261,12 +290,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 @@ -274,17 +304,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++) { /* @@ -293,8 +324,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)); @@ -383,6 +414,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) { @@ -401,7 +433,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 */ @@ -422,9 +454,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 637652ad16..814e087e98 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -100,23 +100,23 @@ typedef enum { =20 #define FDT_MAX_SIZE 0x200000 =20 +/* Max number of GPUs per system */ +#define NVGPU_MAX_NUM 6 + +/* Max number of NUMA nodes */ +#define NUMA_NODES_MAX_NUM (MAX_NODES + NVGPU_MAX_NUM) + /* - * 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 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. * - * NUMA_ASSOC_SIZE is the base array size of an ibm,associativity + * FORM1_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 these GPUsper a physical box */ -#define NVGPU_MAX_NUM 6 +#define FORM1_DIST_REF_POINTS 4 +#define FORM1_NUMA_ASSOC_SIZE (FORM1_DIST_REF_POINTS + 1) =20 typedef struct SpaprCapabilities SpaprCapabilities; struct SpaprCapabilities { @@ -249,7 +249,7 @@ 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 numa_assoc_array[NUMA_NODES_MAX_NUM][FORM1_NUMA_ASSOC_SIZE]; =20 Error *fwnmi_migration_blocker; }; --=20 2.31.1 From nobody Mon Apr 29 20:25:24 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 1632160477899809.0089425647263; Mon, 20 Sep 2021 10:54:37 -0700 (PDT) Received: from localhost ([::1]:58706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSNUy-0001hI-Uo for importer@patchew.org; Mon, 20 Sep 2021 13:54:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSNQg-0001xK-5N; Mon, 20 Sep 2021 13:50:10 -0400 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]:34440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSNQd-0008V5-17; Mon, 20 Sep 2021 13:50:09 -0400 Received: by mail-qv1-xf31.google.com with SMTP id w8so5633758qvu.1; Mon, 20 Sep 2021 10:50:06 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id l28sm6073614qkl.127.2021.09.20.10.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:50:05 -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=PiDQQT6ZqdXBwxIl3NFs1BC3Ipyj4GbLr8G5EIo4GXQ=; b=UZGa0q+OUeQHeiV0v/TJZUbyjkHPitmQ319L8mb2Iij7NKVEEEGHYtRGFWCNLjyf6T SyPG6BPgNkU2J4SyrUZRz6UELI5PkOygScaE2W/K0EE06Nchzq+Soo+b23CFWOOGT8Y7 3KQW5lKP+cnRbbo5/9OtckxGuLNbOTmMmX48v4WiREpMKNONcj20uJ3LMZsZFHumUezl mvy8XOZWRhsIQRBPrE7oyOOIS50X09NoQ4qCBowiGDwrYdnQV22hxpUHwmM+VJGCS3P1 dNCfQiDYPV9fnlwopHom+Ip06sQ+RQpqmHQp9NDUhkpA423Jj4aJYUGmgtoh5Zz6p5Ya fK4g== 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=PiDQQT6ZqdXBwxIl3NFs1BC3Ipyj4GbLr8G5EIo4GXQ=; b=7urG0a2kG8lBiN34/hlaEVGVFEXgr76znN3hoI2mc19UctcLMUAj0bDNvkfIv4tvJL cmRQXAE1Ga3K4ghu+lWQIe6cvzpnDKx10wo8QOtccLs3Vs1jgSJAbwKZM+2k7JYOZUJh /vtNHeZOlYbsDSBTS4JTbxn/1Tx6oWOowDcHTsjeYBdt0HX678RqTQ8sngk5ukmxkwaF g4U5F4z/v7aQOQzDEmEH5YJLtZATY1JQCSPspeA6BRz+iFVV+qnxqT3owTKgv1hzYBCv rR8mILYV23mddEECKQJGMcpEZq5spSVhRKcx0mHBYNefBctVFrpj+MrQMOi7KpkrcQL1 F90A== X-Gm-Message-State: AOAM532m78ebR6x5oushqeFNgZ5l3wKw56oth1thix+jQHHpd3cC5gAH ZFWt81lPNbDgkkyON5b4nMGnJkqk7cQ= X-Google-Smtp-Source: ABdhPJx1SJ/BpLGlkH1N1kqY3TfhWwunUc0SoM9OCIi3g5tjM2hVQy9Iyk9o2J47xapIr017gQmeeA== X-Received: by 2002:ad4:456e:: with SMTP id o14mr26667590qvu.15.1632160205618; Mon, 20 Sep 2021 10:50:05 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 4/7] spapr_numa.c: rename numa_assoc_array to FORM1_assoc_array Date: Mon, 20 Sep 2021 14:49:44 -0300 Message-Id: <20210920174947.556324-5-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920174947.556324-1-danielhb413@gmail.com> References: <20210920174947.556324-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::f31; envelope-from=danielhb413@gmail.com; helo=mail-qv1-xf31.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: 1632160479478100001 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. The idea of switching values used by the write_dt() functions in spapr_numa.c was already introduced in the previous patch, and the same approach will be used when dealing with the FORM1 and FORM2 arrays. We can accomplish that by that by renaming the existing numa_assoc_array to FORM1_assoc_array, which now is used exclusively to handle FORM1 affinity data. A new helper get_associativity() is then introduced to be used by the write_dt() functions to retrieve the current ibm,associativity array of a given node, after considering affinity selection that might have been done during CAS. All code that was using numa_assoc_array now needs to retrieve the array by calling this function. This will allow for an easier plug of FORM2 data later on. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_hcall.c | 1 + hw/ppc/spapr_numa.c | 38 +++++++++++++++++++++++++------------- include/hw/ppc/spapr.h | 2 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 0e9a5b2e40..9056644890 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 diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 08e2d6aed8..dce9ce987a 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -46,6 +46,15 @@ static int get_vcpu_assoc_size(SpaprMachineState *spapr) return get_numa_assoc_size(spapr) + 1; } =20 +/* + * Retrieves the ibm,associativity array of NUMA node 'node_id' + * for the current NUMA affinity. + */ +static const uint32_t *get_associativity(SpaprMachineState *spapr, int nod= e_id) +{ + return spapr->FORM1_assoc_array[node_id]; +} + static bool spapr_numa_is_symmetrical(MachineState *ms) { int src, dst; @@ -124,7 +133,7 @@ static void spapr_numa_define_FORM1_domains(SpaprMachin= eState *spapr) */ for (i =3D 1; i < nb_numa_nodes; i++) { for (j =3D 1; j < FORM1_DIST_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 @@ -176,8 +185,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; } } } @@ -204,8 +213,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(FORM1_DIST_REF_POINT= S); - spapr->numa_assoc_array[i][FORM1_DIST_REF_POINTS] =3D cpu_to_be32(= 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 /* @@ -219,15 +228,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(FORM1_DIST_REF_POINT= S); + spapr->FORM1_assoc_array[i][0] =3D cpu_to_be32(FORM1_DIST_REF_POIN= TS); =20 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->numa_assoc_array[i][j] =3D gpu_assoc; + spapr->FORM1_assoc_array[i][j] =3D gpu_assoc; } =20 - spapr->numa_assoc_array[i][FORM1_DIST_REF_POINTS] =3D cpu_to_be32(= i); + spapr->FORM1_assoc_array[i][FORM1_DIST_REF_POINTS] =3D cpu_to_be32= (i); } =20 /* @@ -259,14 +268,17 @@ void spapr_numa_associativity_init(SpaprMachineState = *spapr, void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, int offset, int nodeid) { + const uint32_t *associativity =3D get_associativity(spapr, nodeid); + _FDT((fdt_setprop(fdt, offset, "ibm,associativity", - spapr->numa_assoc_array[nodeid], + associativity, get_numa_assoc_size(spapr) * sizeof(uint32_t)))); } =20 static uint32_t *spapr_numa_get_vcpu_assoc(SpaprMachineState *spapr, PowerPCCPU *cpu) { + const uint32_t *associativity =3D get_associativity(spapr, cpu->node_i= d); 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); @@ -280,7 +292,7 @@ static uint32_t *spapr_numa_get_vcpu_assoc(SpaprMachine= State *spapr, */ 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, + memcpy(vcpu_assoc + 1, associativity + 1, (vcpu_assoc_size - 2) * sizeof(uint32_t)); =20 return vcpu_assoc; @@ -319,10 +331,10 @@ int spapr_numa_write_assoc_lookup_arrays(SpaprMachine= State *spapr, void *fdt, cur_index +=3D 2; for (i =3D 0; i < nr_nodes; i++) { /* - * For the lookup-array we use the ibm,associativity array, - * from numa_assoc_array. without the first element (size). + * For the lookup-array we use the ibm,associativity array of the + * current NUMA affinity, without the first element (size). */ - uint32_t *associativity =3D spapr->numa_assoc_array[i]; + const uint32_t *associativity =3D get_associativity(spapr, i); memcpy(cur_index, ++associativity, sizeof(uint32_t) * max_distance_ref_points); cur_index +=3D max_distance_ref_points; diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 814e087e98..6b3dfc5dc2 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -249,7 +249,7 @@ struct SpaprMachineState { unsigned gpu_numa_id; SpaprTpmProxy *tpm_proxy; =20 - uint32_t numa_assoc_array[NUMA_NODES_MAX_NUM][FORM1_NUMA_ASSOC_SIZE]; + uint32_t FORM1_assoc_array[NUMA_NODES_MAX_NUM][FORM1_NUMA_ASSOC_SIZE]; =20 Error *fwnmi_migration_blocker; }; --=20 2.31.1 From nobody Mon Apr 29 20:25:24 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 1632160490317754.0683387659518; Mon, 20 Sep 2021 10:54:50 -0700 (PDT) Received: from localhost ([::1]:59426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSNVB-0002Aw-B6 for importer@patchew.org; Mon, 20 Sep 2021 13:54:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSNQg-0001yy-KR; Mon, 20 Sep 2021 13:50:10 -0400 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]:36624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSNQe-0008WV-RN; Mon, 20 Sep 2021 13:50:10 -0400 Received: by mail-qt1-x82e.google.com with SMTP id d11so16408798qtw.3; Mon, 20 Sep 2021 10:50:08 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id l28sm6073614qkl.127.2021.09.20.10.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:50:07 -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=hVxHdgriD2upNmPHe9n8GeNG82h29/ty3zgSuHIOKGs=; b=eo5Fm7FgtMXUioW79uJx3c50xtvmW3uHRmsZL1NsV/Mwy/VXKLbn4wxWnYRxwyxHwg WmyicRBzOyDSORvrJrCLdLX9Pf2ZDo9mxHOAixgq9ky/Nkyecm1HxRMnNcHUCV2TAxlE 5y9rY1FQ/e8e765ZZzwPSR0G0SIEL6VWRk1BOv8UjdPtaYxLQ4Zs7qybFNjnoimlyeiv q9yEgMUqh1VAjVcJ8JmWsyqBzEX8Nvd5eB35IJKbWmE478vXDFFCu383uZe1bfjcRg3I KsOXRnA1R05lPj1DlCoigNFB/ax7LAJFDICBNZEqLt/at4ioVnt7RTE3cmG6PQ8Jsau4 uibw== 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=hVxHdgriD2upNmPHe9n8GeNG82h29/ty3zgSuHIOKGs=; b=bMxzvObkCGSIuAY6Wkfu7YR85T6LLdKA6kOXWZRDX8t1+Z08yrAQYGg7aIbWsUW5c6 hDTGsku691SRFIjBnmdgPIzCaC5qyCGSclfqte59VP6o/bu63FHCe54ww6G5wbHMFuiM ZYfrqW7sraiGGIpAhQeZP3ql8Zv4nuAYJlYSzN5YDwarNh++yrYCXiq4W5QB+/F/8pW+ MUm4p6It73wr8xBhevo/SsAwUeWmYavFA609mhqPfDyfmjh9fNzsJDpIRIx6KX9+G2z2 sU1oikjpMoMXAcFL5lUsizdm/AVule+hkicyyT1rBOB4a4dy1j8u0yOBUjGvEXiGyvfK oULg== X-Gm-Message-State: AOAM532HpHD19yFq8Vx/AQIZBWTolCI5+ozoDrq0YQL4NS3/OGM7dQCy la05yLhCngAKaMYnv3WwZCAfd9JgPRk= X-Google-Smtp-Source: ABdhPJwxnElOhZUK1xHDRK3/AdpJ1Otw97pGDlXWO2D4FS6NyLqINXgpcFB2SzvSZzI4l3kTd9lGoQ== X-Received: by 2002:ac8:57c7:: with SMTP id w7mr23777654qta.53.1632160207449; Mon, 20 Sep 2021 10:50:07 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 5/7] spapr: move FORM1 verifications to post CAS Date: Mon, 20 Sep 2021 14:49:45 -0300 Message-Id: <20210920174947.556324-6-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920174947.556324-1-danielhb413@gmail.com> References: <20210920174947.556324-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::82e; envelope-from=danielhb413@gmail.com; helo=mail-qt1-x82e.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: 1632160490780100011 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 able 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. Reviewed-by: Greg Kurz Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 33 ----------------------- hw/ppc/spapr_hcall.c | 6 +++++ hw/ppc/spapr_numa.c | 53 ++++++++++++++++++++++++++++++++----- include/hw/ppc/spapr_numa.h | 1 + 4 files changed, 54 insertions(+), 39 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index d39fd4e644..ada85ee083 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2773,39 +2773,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 9056644890..222c1b6bbd 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1198,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 + /* + * Check for NUMA affinity conditions now that we know which NUMA + * affinity the guest will use. + */ + spapr_numa_associativity_check(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 dce9ce987a..6718c0fdd1 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -193,6 +193,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. */ @@ -250,12 +292,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 @@ -265,6 +301,11 @@ void spapr_numa_associativity_init(SpaprMachineState *= spapr, spapr_numa_FORM1_affinity_init(spapr, machine); } =20 +void spapr_numa_associativity_check(SpaprMachineState *spapr) +{ + spapr_numa_FORM1_affinity_check(MACHINE(spapr)); +} + void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, int offset, int nodeid) { diff --git a/include/hw/ppc/spapr_numa.h b/include/hw/ppc/spapr_numa.h index 6f9f02d3de..7cb3367400 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_check(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 Mon Apr 29 20:25:24 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 1632160678456867.8288865477865; Mon, 20 Sep 2021 10:57:58 -0700 (PDT) Received: from localhost ([::1]:36772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSNYC-0005yf-TN for importer@patchew.org; Mon, 20 Sep 2021 13:57:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSNQj-00024E-8t; Mon, 20 Sep 2021 13:50:13 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:46037) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSNQh-000076-4E; Mon, 20 Sep 2021 13:50:13 -0400 Received: by mail-qk1-x729.google.com with SMTP id a10so45519790qka.12; Mon, 20 Sep 2021 10:50:10 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id l28sm6073614qkl.127.2021.09.20.10.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:50:09 -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=eThN0jgy9nSoh8sc0fYP+HjBxuyklHVC2q84/gpb+ls=; b=e4z0xaUf5RKKcxO1RSl1Db5imp1MeDW0FvXnDPUnmGqaflHdVNw+6nF6rDT5QRZHYB XXat0KDChl0tZ1l8NcwbPjF818R4Wn0gZSWmtl4WcsqfpFgcmNjGhdRA0g7Ku5lo6pue VSsUfHn71U6nHLWhDlIAo2ce9fYw/Kgy2l29t6rNZ4kENNIxRka0qACPcTr1UOW9QDvH 4w83DhyUGqqhORsM5n2o3PP+bfHWeWZDOSsoHIAsbQkDv1k3jQQcr0RhJCifga7R47+g 3RXHzHRiY2rmhAuLuQEF5ic+tplZ4JR/jGwjcUTeqkpAZ/k/FLRNZa695wuxnbnIRnHK DVRg== 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=eThN0jgy9nSoh8sc0fYP+HjBxuyklHVC2q84/gpb+ls=; b=ghOoU7gAk1PJvzMqdqsy51QEOuSofKGTwGR3JtpU++LCnQ/EeWbPfhY14y8hOPlY59 AzVnUqwGyBuESL9EsRVDJR/ThfjwDGgbULqET74h79emtlPpDYN+dqKiOLOBz1T61Bq6 /9iFkKm5kilqlXDyHBRpXwJ7FZ4h3R1GPyvebH8RK3ZIQkyrxw6eFFQWcmLbPUFEiRer jg9ghJCqXXMmyt0mXenP+ph8xWcyWBNUYi8E0BPff7JkQzQZPBTzFdl11DzDPNqZHT3X 1GxzOiV6yHVooXrgDdtY9r4Sap7tUyRpujQEneCYBVH1BbRuQ+Ao2vceRktpbJQLnUN5 9vNA== X-Gm-Message-State: AOAM531+6vvN5vwm/ImyCV3DybJzTHLDfMjYfqaQnVeGd/Ym07g/XsZd 0IF8H4ckmDrlQuSjvH5zF6VnQIrc/dU= X-Google-Smtp-Source: ABdhPJwnUDlnTgru6qWBbrk9+z5XSmb0ibUw/kjWtfTYPVI1u3K3W6OmjoQSEygtsfw9i5AfqwH6XA== X-Received: by 2002:a37:746:: with SMTP id 67mr17450539qkh.465.1632160209551; Mon, 20 Sep 2021 10:50:09 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 6/7] spapr_numa.c: FORM2 NUMA affinity support Date: Mon, 20 Sep 2021 14:49:46 -0300 Message-Id: <20210920174947.556324-7-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920174947.556324-1-danielhb413@gmail.com> References: <20210920174947.556324-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::729; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x729.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: 1632160680317100003 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(), get_numa_assoc_size() and get_associativity() now checks for OV5_FORM2_AFFINITY and returns FORM2 values if the guest selected FORM2 affinity during CAS. Reviewed-by: Greg Kurz Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 8 ++ hw/ppc/spapr_numa.c | 146 ++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 9 +++ include/hw/ppc/spapr_ovec.h | 1 + 4 files changed, 164 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ada85ee083..babb662845 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2752,6 +2752,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); @@ -4667,8 +4672,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 6718c0fdd1..13db321997 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -24,6 +24,10 @@ */ static int get_max_dist_ref_points(SpaprMachineState *spapr) { + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + return FORM2_DIST_REF_POINTS; + } + return FORM1_DIST_REF_POINTS; } =20 @@ -32,6 +36,10 @@ static int get_max_dist_ref_points(SpaprMachineState *sp= apr) */ static int get_numa_assoc_size(SpaprMachineState *spapr) { + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + return FORM2_NUMA_ASSOC_SIZE; + } + return FORM1_NUMA_ASSOC_SIZE; } =20 @@ -52,6 +60,9 @@ static int get_vcpu_assoc_size(SpaprMachineState *spapr) */ static const uint32_t *get_associativity(SpaprMachineState *spapr, int nod= e_id) { + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + return spapr->FORM2_assoc_array[node_id]; + } return spapr->FORM1_assoc_array[node_id]; } =20 @@ -295,14 +306,50 @@ 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][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 void spapr_numa_associativity_check(SpaprMachineState *spapr) { + /* + * FORM2 does not have any restrictions we need to handle + * at CAS time, for now. + */ + if (spapr_ovec_test(spapr->ov5_cas, OV5_FORM2_AFFINITY)) { + return; + } + spapr_numa_FORM1_affinity_check(MACHINE(spapr)); } =20 @@ -447,6 +494,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 @@ -454,6 +595,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 6b3dfc5dc2..ee7504b976 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -118,6 +118,13 @@ typedef enum { #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) + typedef struct SpaprCapabilities SpaprCapabilities; struct SpaprCapabilities { uint8_t caps[SPAPR_CAP_NUM]; @@ -145,6 +152,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, @@ -250,6 +258,7 @@ struct SpaprMachineState { SpaprTpmProxy *tpm_proxy; =20 uint32_t FORM1_assoc_array[NUMA_NODES_MAX_NUM][FORM1_NUMA_ASSOC_SIZE]; + uint32_t FORM2_assoc_array[NUMA_NODES_MAX_NUM][FORM2_NUMA_ASSOC_SIZE]; =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 From nobody Mon Apr 29 20:25:24 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 163216047911917.724939120199338; Mon, 20 Sep 2021 10:54:39 -0700 (PDT) Received: from localhost ([::1]:58770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSNV0-0001jh-1x for importer@patchew.org; Mon, 20 Sep 2021 13:54:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSNQl-000278-Uz; Mon, 20 Sep 2021 13:50:16 -0400 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:33557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSNQk-00008i-08; Mon, 20 Sep 2021 13:50:15 -0400 Received: by mail-qt1-x830.google.com with SMTP id x9so3831755qtv.0; Mon, 20 Sep 2021 10:50:12 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id l28sm6073614qkl.127.2021.09.20.10.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 10:50:11 -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=OQCaSIe99OwmQ8bsnK8UlD0RA8Ggd1iynfCZR2kCKy0=; b=YS06vzd/Yn7PzXQU3lkrcwS99dxEURLJPgyTEE8ZC+faZAvJ2Jq+YqbjTvx9gWREA3 O17kr+x620NyGTLy7wQ8C8J8QacikafU55REOoBDhyla6RgzJ7sC9Uipc3uoE4U/nPuk bZKTx3l+vtc2Gj3Ke0E9Pgzc5v2SaYvrE4wcBxIyQ9dr2dbsPtTZw2t4JOOXth6+IdUw kljis6C55SEzoSFEGcdSGhrBbj5ZZGqbH2a1EDKKSjcYCjo2bQr5a/O27mawvH1iR3wG VL5+6Eav11UiBhCM5bGDC5c6qDJyI13B38sfGuL4j5593YwQrN/ylzsoF5tpt2JDUu8d vrGw== 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=OQCaSIe99OwmQ8bsnK8UlD0RA8Ggd1iynfCZR2kCKy0=; b=bHMnhgQxtm5Pd6diaBgInizreTQ7pPsWdqM2A3V7lwPuBHIE3Gw69ZvXKsgs57P8dq WwVUSL51D32Qkbz7zkLsCLbQOAWq9RAJBpzM7RskR1p/KNul5hoQsYvRa3ClHwjz63j3 BwZY70OWfVVUNMy0Z7gAo60kI9gbRckoS4SRWweVMGJw0VVsz718bPZaDSAmbhZVKhSE RqWboYcCmQHSct9iWo7lNti++kll8FwT8EPI0+BlSINOs6YXCP+dJi28SfBesVJFD9NL H3CkTrkw8Jm0rPb+P87R52w4pSPWBAt+HIPaGSn7HX+ri/b9OCV46IGUwpLgQ+5YkNRY njJg== X-Gm-Message-State: AOAM5334VQOD5Cz16/C9BJ2hRA8m0cYNhwwF/+xLb20zBw/D03y0GXR/ l9Z6YuR19pYia7DC/z6N5RNyzBzAt9E= X-Google-Smtp-Source: ABdhPJwm13O8SxpTSi2+kZJ7dcK+6S1xSWF+KUlA3zS1e3goPVFID9F3GWccnmIPzL01mhKFqUhrpQ== X-Received: by 2002:ac8:3d99:: with SMTP id v25mr24446105qtf.396.1632160211752; Mon, 20 Sep 2021 10:50:11 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 7/7] spapr_numa.c: handle auto NUMA node with no distance info Date: Mon, 20 Sep 2021 14:49:47 -0300 Message-Id: <20210920174947.556324-8-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920174947.556324-1-danielhb413@gmail.com> References: <20210920174947.556324-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::830; envelope-from=danielhb413@gmail.com; helo=mail-qt1-x830.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: Igor Mammedov , 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: 1632160479561100003 Content-Type: text/plain; charset="utf-8" numa_complete_configuration() in hw/core/numa.c always adds a NUMA node for the pSeries machine if none was specified, but without node distance information for the single node created. NUMA FORM1 affinity code didn't rely on numa_state information to do its job, but FORM2 does. As is now, this is the result of a pSeries guest with NUMA FORM2 affinity when no NUMA nodes is specified: $ numactl -H available: 1 nodes (0) node 0 cpus: 0 node 0 size: 16222 MB node 0 free: 15681 MB No distance information available. This can be amended in spapr_numa_FORM2_write_rtas_tables(). We're enforcing that the local distance (the distance to the node to itself) is always 10. This allows for the proper creation of the NUMA distance tables, fixing the output of 'numactl -H' in the guest: $ numactl -H available: 1 nodes (0) node 0 cpus: 0 node 0 size: 16222 MB node 0 free: 15685 MB node distances: node 0 0: 10 CC: Igor Mammedov Reviewed-by: Greg Kurz Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_numa.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 13db321997..58d5dc7084 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -539,6 +539,17 @@ static void spapr_numa_FORM2_write_rtas_tables(SpaprMa= chineState *spapr, =20 for (src =3D 0; src < nb_numa_nodes; src++) { for (dst =3D 0; dst < nb_numa_nodes; dst++) { + /* + * We need to be explicit with the local distance + * value to cover the case where the user didn't added any + * NUMA nodes, but QEMU adds the default NUMA node without + * adding the numa_info to retrieve distance info from. + */ + if (src =3D=3D dst) { + node_distances[i++] =3D 10; + continue; + } + node_distances[i++] =3D numa_info[src].distance[dst]; } } --=20 2.31.1