From nobody Wed May 8 13:32:52 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 1631914390932832.1632215170021; Fri, 17 Sep 2021 14:33:10 -0700 (PDT) Received: from localhost ([::1]:38220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRLTp-0002Jr-Lw for importer@patchew.org; Fri, 17 Sep 2021 17:33:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRLP7-00039T-TF; Fri, 17 Sep 2021 17:28:17 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]:44851) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRLP6-0007lg-BT; Fri, 17 Sep 2021 17:28:17 -0400 Received: by mail-oi1-x22c.google.com with SMTP id o66so13145205oib.11; Fri, 17 Sep 2021 14:28:15 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id s16sm710560otq.78.2021.09.17.14.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 14:28:13 -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=BqlgjChOOOscwUgTTA3JbZL2PZA8OtiRrwUtdKA1iKJAWzL7/EDNe4KmlG2M0MQo9b sAT3wP+QHmje9/9kFLA41bBpN/JtR39bsq57BynB1LU510kP6r8SqDk1K7gd7h2BP0P8 x/h6ZrtnVMONznGxfydr8FYKOpDZAs69TB9UbIb1MV6PPRkjkY5hEkeQEdT41gIy7Ti2 RD5rAN7PKCd2i0NCx6EKrom5PBGlnNJK+OqZ9rCIHr8DWSWhkP9bsBI7hJpSlOsD2OCS Du3WohD0IVJJ1PtJqo2GhNSOuSfzPd8hDHkRIB7dO6EwzzM9thB/DCGapX3dsOC9eebi +ryw== 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=6SU78E3VpL/gwvqTrKBs8pPr9d8/gSbelucK1+rKO9EEBfYALURzDYh2j300f8J1HU hqi5IPlclF5H3D9TmxOs5x2pMsN+d3nrHsm7qZ2JKqfH+V7cxOxr9mN8uPG473J5LrGf 54j0Wje43q1H3xlB4Fcg1PrZVhUwC8dPv7Hrg64I/OdrGmwKq5fg6ucy5R94igEDF2Qy fprO3ssl47f0TBI1kFDdj/oMomZ7j6VzGHI4P7Y3phXt3Vg6OvFUoVEYng16zPj1ky/b oErQ7ELGpmbM9MeyfXgkcGSRYDQx9AQa/Yxc8O0biIQPvF7JxNVBAsh+ZfpAsr7sNIrX BMcQ== X-Gm-Message-State: AOAM531eEONiyOZGj8I6dblkFqJHUK+70SukKvwNaToq0c7JBgUQksJh R8jmsF66ntETv6acsnRf27V/MG26iA0= X-Google-Smtp-Source: ABdhPJyEf1P79Dr8JfytOHZG9lCn3XPKaHln8Oxrf867oP/LGs9y3G+lzWN9EzYN4+cJoyeXMfT6hQ== X-Received: by 2002:aca:f108:: with SMTP id p8mr5575216oih.63.1631914093348; Fri, 17 Sep 2021 14:28:13 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v8 1/7] spapr_numa.c: split FORM1 code into helpers Date: Fri, 17 Sep 2021 18:27:56 -0300 Message-Id: <20210917212802.424481-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917212802.424481-1-danielhb413@gmail.com> References: <20210917212802.424481-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::22c; envelope-from=danielhb413@gmail.com; helo=mail-oi1-x22c.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: 1631914392139100001 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 Wed May 8 13:32:52 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 1631914191224257.5231525076405; Fri, 17 Sep 2021 14:29:51 -0700 (PDT) Received: from localhost ([::1]:60114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRLQc-0006N3-53 for importer@patchew.org; Fri, 17 Sep 2021 17:29:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRLP8-0003AP-K6; Fri, 17 Sep 2021 17:28:18 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]:41671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRLP6-0007mM-V4; Fri, 17 Sep 2021 17:28:18 -0400 Received: by mail-oi1-x236.google.com with SMTP id 6so15812498oiy.8; Fri, 17 Sep 2021 14:28:16 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id s16sm710560otq.78.2021.09.17.14.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 14:28:15 -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=SM2iIW4WBVyOaAQCb87sHdal3zSVLe4nYiudSdMeUd93urvOV8DsN0kM4ta7O8stL/ pIyQA4LPgFOvwJnpRxhKdKTeRLj0wX4zHvLeLGEPBfv3NyrOZmgHy8YXd2am/xi5mJIC MXuuKjiN8fPF2/qMMyaG1cfd58/zAf4/BC41eEYZlzBBmoXNlBBIC/wW8gRpscgArwlV wHT4iNqZYzxNu74t3/59MMbkqXYzAoqe/ADQszuNYLtYD0D74v+Fn3ZF1j36ygrBp3PA Rn0h/2ya86TjwouZhtEHl1e4sU4/OWA6t8yBjy+Pn993zfvjmkwgrSqRk6cTr0kZcKcO mC5w== 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=Yi0tc8TO1+PqU3AYMej4JcVqc1uwsLQ3uoxiYST8U6Y3IaRdOrHAX2kClVg6mOz883 KJjWLMdc3xK2EY6LD3j0b8mypkp/TGM60vG6ZIWR2GeTz7vx5OpV2lmbVycbgi6tggq/ 5/ZOvK6hIuFSnU183hdb0RCYKBFw1503WcJ986LR+cORY0XGO76mOTozKnkm/h6Th87x nLkcixW2dauhkgSr/snvS5oQPA3xH+tGirJYciiKuPUTzhIiov1ZfGXPLLf9NfvIO/8v jA7I9SNNBTP/eSH34oAN8OqCAMN5uOqhLpRDJQvD9Nuaa0fYFYGRa9boyCA+yG820ZCI yQ+A== X-Gm-Message-State: AOAM5327alsN0Pn6oxfZVVKfORBlkqN6p+KMANaWdiMOqRFJsUfoqcYH c/n1pjc1LjwQJuk6WOsLlVYePUcSLbk= X-Google-Smtp-Source: ABdhPJxiD/eZYWiyGUPgNMS72mWd3sovgpxByU8EVaNzkC8+gfM1hrqCU3x53wGnRk/B5bPOoLnsNg== X-Received: by 2002:aca:2206:: with SMTP id b6mr14177869oic.88.1631914095360; Fri, 17 Sep 2021 14:28:15 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v8 2/7] spapr_numa.c: scrap 'legacy_numa' concept Date: Fri, 17 Sep 2021 18:27:57 -0300 Message-Id: <20210917212802.424481-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917212802.424481-1-danielhb413@gmail.com> References: <20210917212802.424481-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::236; envelope-from=danielhb413@gmail.com; helo=mail-oi1-x236.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: 1631914192673100001 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 Wed May 8 13:32:52 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 1631914489079600.0999572593585; Fri, 17 Sep 2021 14:34:49 -0700 (PDT) Received: from localhost ([::1]:41678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRLVQ-0004fd-0s for importer@patchew.org; Fri, 17 Sep 2021 17:34:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRLPC-0003E7-LU; Fri, 17 Sep 2021 17:28:22 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]:42835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRLP9-0007o9-2k; Fri, 17 Sep 2021 17:28:22 -0400 Received: by mail-oi1-x22e.google.com with SMTP id bi4so15782437oib.9; Fri, 17 Sep 2021 14:28:18 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id s16sm710560otq.78.2021.09.17.14.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 14:28:17 -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=9JOzN3rWm3FFciYenzpwBRvfCXEizyti9Aet1FQRIX8=; b=bSD7qQQXJC5soRImEx+LDOCN3oElI+OIMKLV+8UzqtBSPLxeFxaCjH1g4lLdp7Q4F9 MI7juuCQHtXfM2x7V6zr8zo3ni/uvIH0OxYlKj27Dk18BbG03VMTqi70eN+EHzeH1kEm qgM+btqUh1R3VW5LRC2ddvfeh63GgVCocXsKMSa6M1dXoqdLBIZGnZqgpNJsAkvuXvsu kSxQKBmjjLYmlC4d1bLg8FEKz0b+AyVgz16YBo8htJhKjYDDrmi5Yn24e37seuCPzfTc zGJi+MsLzsDBS+E9F5a7MgMtasGOLFBdAXUJLq4YERxsgqiUsCGVGd86v71JVVrHsmuS IuIA== 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=9JOzN3rWm3FFciYenzpwBRvfCXEizyti9Aet1FQRIX8=; b=E8bOSkgN7XsNqCRLpqO0jAfCmW3J8FduzkgASlvOqbKxFcl4PRr07VJPZp9k97X6TU pIHCcV27Fh/y3ni39R7kC4M/b//XcEeGVqXettj9yaAIpOQOXPmAQOT/5H97O1MK4cyv Wy5jVM5/5KJ2hfc1lDuvh7YTTgDYBOye9/FMuVizCAOR80JoCcIb1niWrLxIp+sC85WQ MdGUIwd/bD3CeZ2I4qRbbMBLBQNdyMiVAKi9ha6P1+22pk8ENZBbvTPzN05z9F5OY6K6 dXJhov7kV8CKUh6fsbEWi814NEJU5uSkL8tyYGBojDXbwUmvaTwpwGycGyKskDwoCyDk p9Xg== X-Gm-Message-State: AOAM531NeItiXp8p1S8ceq1EwdYV5oX7vBd4fMT3TXqC+/R6uDIKwuq/ DMqnp1quAgkfHKlpqPiImxaxbR+XeNA= X-Google-Smtp-Source: ABdhPJzs0mVItUnmbu1pHYS3yLptObKev+rR2wbTTXGkpX0EsJ/6L1kqoHbDXxuvCc9Bb2f1cN5Ozg== X-Received: by 2002:a54:410d:: with SMTP id l13mr5769460oic.112.1631914097492; Fri, 17 Sep 2021 14:28:17 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v8 3/7] spapr_numa.c: parametrize FORM1 macros Date: Fri, 17 Sep 2021 18:27:58 -0300 Message-Id: <20210917212802.424481-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917212802.424481-1-danielhb413@gmail.com> References: <20210917212802.424481-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::22e; envelope-from=danielhb413@gmail.com; helo=mail-oi1-x22e.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: 1631914490473100001 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 Reviewed-by: Greg Kurz --- 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 Wed May 8 13:32:52 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 1631914188146670.921095856019; Fri, 17 Sep 2021 14:29:48 -0700 (PDT) Received: from localhost ([::1]:59668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRLQY-00064n-TY for importer@patchew.org; Fri, 17 Sep 2021 17:29:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRLPF-0003KL-BV; Fri, 17 Sep 2021 17:28:25 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]:38523) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRLPB-0007pn-1K; Fri, 17 Sep 2021 17:28:25 -0400 Received: by mail-oi1-x22a.google.com with SMTP id u22so7573350oie.5; Fri, 17 Sep 2021 14:28:20 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id s16sm710560otq.78.2021.09.17.14.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 14:28:19 -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=mbxlMn3tkA7P9Qq/1zYw3dV6E8rUfG0Y1psduhrKyuI=; b=kOJ9YpuTYyLFhuZiCJt12Hf3RrvDXUTPytaWxdCvi7SXTqI+QQ7TfPpHb2G1aYdcZi CYtl+145KdCgk6EAAnnv4QnshX40XC8H8XMDl8dSnE5P/6EuUKbg+NmTQgaDzGI+4cVG JlMTnMSd0Rc7XBUuLE0zsezOYx1W/XKjOfkakLQtGlzAuvQsavHXKoQvzulCKj/rBnEK AwY3SBp0PVc50oYfh6O6Xudq5qUnFSN6PFkub1QKDFcOJykA+2T8dKNw9iJj90s8KuCR MiXikexe9WJebJ1BAnTQg01mj5IL0vPQCve6XK4TBohRyqJLpMWxjrEzjsrhnjUL7Fl3 NIxQ== 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=mbxlMn3tkA7P9Qq/1zYw3dV6E8rUfG0Y1psduhrKyuI=; b=n2rlp/bSJOZRHiQjnowhRrsCAp22VrOGZ7+wUD9DgguebWBl2dNEilLlUPBwHVq8yY DmbR65vNUTPMGO4y1xL2nrpWAH0tfA77w7SAxz/lQRm7YA6uQOxOcz9aeM1zI+ug4QE2 CU2G3+as9PxmPwyiG9zGKktrb09ozaNGB2AsBbEFFXcOaxRIaTggsHqFpb9J3UP6/NiD gWvY0n43L946lnGyYlt7g8plSWt30noX86tToPkSexGUCtrF+jfyWNghDe93Vroj5nI3 iBrDIjUY4SPjW7aW2UdUyZfkgjn031FDV0PsFmv9DsPatGgKDiaosgX/hye9+Oa/qFMi hKHA== X-Gm-Message-State: AOAM531K3Y4SjDr5n6d8hQRUCKy8IcuQ3aGfYowOme6dHJBOcoiHCyxY xdxhCXhM/02/I16A0mYjBwQ+R/+MvtA= X-Google-Smtp-Source: ABdhPJyX7juJMLaJvzAT+luNzWB2WvK1rF0xNHCUqgVHswMC36R0SApCttcHo+m9MtM1fqCHEdHE7Q== X-Received: by 2002:a05:6808:913:: with SMTP id w19mr15061225oih.97.1631914099515; Fri, 17 Sep 2021 14:28:19 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v8 4/7] spapr_numa.c: rename numa_assoc_array to FORM1_assoc_array Date: Fri, 17 Sep 2021 18:27:59 -0300 Message-Id: <20210917212802.424481-5-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917212802.424481-1-danielhb413@gmail.com> References: <20210917212802.424481-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::22a; envelope-from=danielhb413@gmail.com; helo=mail-oi1-x22a.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: 1631914190473100001 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..7339d00d20 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 uint32_t *get_associativity(SpaprMachineState *spapr, int node_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,8 +268,10 @@ void spapr_numa_associativity_init(SpaprMachineState *= spapr, void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, int offset, int nodeid) { + 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 @@ -270,6 +281,7 @@ static uint32_t *spapr_numa_get_vcpu_assoc(SpaprMachine= State *spapr, 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); + uint32_t *associativity =3D get_associativity(spapr, cpu->node_id); int index =3D spapr_get_vcpu_id(cpu); =20 /* @@ -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]; + 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 Wed May 8 13:32:52 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 1631914678464785.9513159035348; Fri, 17 Sep 2021 14:37:58 -0700 (PDT) Received: from localhost ([::1]:46302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRLYT-0007z1-FG for importer@patchew.org; Fri, 17 Sep 2021 17:37:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRLPS-0003zG-Cq; Fri, 17 Sep 2021 17:28:38 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]:45764) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRLPC-0007rp-TO; Fri, 17 Sep 2021 17:28:38 -0400 Received: by mail-oi1-x233.google.com with SMTP id j66so15766873oih.12; Fri, 17 Sep 2021 14:28:22 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id s16sm710560otq.78.2021.09.17.14.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 14:28:21 -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=kiPKorNNMNDIXpxCvfCCNF20vmLrRMKgVM6q76yHe7c=; b=pIrloHgCAKKe591RcZvOLo06QIGyJzxbXWr0u+GAm65e0cNUowgIrA/a4UnQU+XpcK aefCsUyTRKMbZUcomPSlvkvA1j3UI5ZRMS2wj2gyY0S93+LkgqAdTam064OBMMDxBpbi vVADJ6kHE71w3gz2D7sFaj5+Wrm3AoBxrTP4v13UB2HtgHhcFVOcqFVuHAMTyp+zs44p MSlWY7vfMZZHznhpAb0kBPyFnrNi7xwL0l3RwG1uRSBlY7VMspP6g3HCe4bXHBdzm1rw 4kDVcfVb8RdlavwYipdTmAmN2pv+o+/FpMzQgg6Vavqxku4rND6cbjE4wyiP4FFS/upp 8yvA== 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=kiPKorNNMNDIXpxCvfCCNF20vmLrRMKgVM6q76yHe7c=; b=sVk/fSDvVt/EAEX6rwurlWKjazkiPIV2OL3o7BIW0eejaG80fARBxsZ+JA0rGF99nX FSA6yMCUEVD8/aGrasRAocbGm5tOv11oQIm8NRKESIsJTMUEem5MtDyitbMPesvRcU+e UBK0zPEvMvslyyfXZAvw7WYZhYC+oaVVaYO22oueEsBIGzDdzWvGMytf74xh75OZcD8O dbYpNcStiBvPMTZrMed8NVzMdFeeOOUujJDMcUBmFHDWWIl7qGTq8TeaUEgnu5xsRo3x E8Q9onvwwxa3tVI0SJW72BVpWV/iz5Pg3KTIcwaQnnKypp8Vr/glRNMggWLMJHm+oNQZ LKSA== X-Gm-Message-State: AOAM5338tPttkLuXyXZqkxJ/yArhUwQ/tnvYywpVkNfLflnF8XTmTK/X iG2csYbzkeY3otbnFFW9RLUogC+HfdI= X-Google-Smtp-Source: ABdhPJyKV1RMYbw6KpCYhRtqkPCmtWfz6lWEv8DFfZal8RF98wnPD2L7+McsdhCBg08wmCr8N4ogFg== X-Received: by 2002:a05:6808:169f:: with SMTP id bb31mr5768846oib.18.1631914101397; Fri, 17 Sep 2021 14:28:21 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v8 5/7] spapr: move FORM1 verifications to post CAS Date: Fri, 17 Sep 2021 18:28:00 -0300 Message-Id: <20210917212802.424481-6-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917212802.424481-1-danielhb413@gmail.com> References: <20210917212802.424481-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::233; envelope-from=danielhb413@gmail.com; helo=mail-oi1-x233.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, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: 1631914679183100001 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. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Greg Kurz --- 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 7339d00d20..dfe4fada01 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 Wed May 8 13:32:52 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 1631914396014391.1464703510719; Fri, 17 Sep 2021 14:33:16 -0700 (PDT) Received: from localhost ([::1]:38592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRLTu-0002YD-R0 for importer@patchew.org; Fri, 17 Sep 2021 17:33:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRLPI-0003TC-9c; Fri, 17 Sep 2021 17:28:28 -0400 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]:34697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRLPF-0007u9-Q5; Fri, 17 Sep 2021 17:28:28 -0400 Received: by mail-oo1-xc32.google.com with SMTP id g4-20020a4ab044000000b002900bf3b03fso3654242oon.1; Fri, 17 Sep 2021 14:28:24 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id s16sm710560otq.78.2021.09.17.14.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 14:28:23 -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=mzFhOyctRijVDKSHK8Zrbxl1rpitiRZreC6L+HMEcBQ=; b=CwK9zOBkrEgE8HhPss8WmvNOtSfAJt3Qndxwhodb3m9bzLpHtvnzFjCupmm/nR1YwL DRuBHglTQYx0IKkdLHPoXNk+zVMBqWxsdVs2ln21A/+RGzowkOPFF2j/GJnXaFnrPV07 LDM+E2AtLVWO9aba51YduWyjHthELW63v6tapQ3Klj/MphLVXqvxK0iQzXsnNlKqTonS u9W/hw/wc1P2v3Wqgmah2IQ25TDlgyW/pgT4KiWSnW5t0j0Gsy6dOXS6jCQTf6BgdYPr cyZ5vFzyXgmUMiRxnFvgfYvE4SCy/8O4sVmz2f6eD2Lor/3zZ4Skpbw8z2MP2UgWYU/0 ZH8A== 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=mzFhOyctRijVDKSHK8Zrbxl1rpitiRZreC6L+HMEcBQ=; b=IYcW+a1UJ8jQsD2Mvp3OYqtU1p4Gf4kVrfhxxTC+FcG1xItPuRkWa7Mztxvvs7y2nz 599SrrBkqiXmspUYTbj8NsefqAmYRhXbouWKSTiA2F4PL7OyLHkCD5K86GibQVw6VG0R QfS3UK1QhECwqcszyofHd1b0uTVl6zdyBOTWJ+B9ASTcMF/mXKW6iNDLVD+G+VWUmVIs ZoEjAxDdxoWsCmU0DRj6wyAt9VbRwh5P7sLMooup0xpJGNb5sIxOMrIAfg0/8zsc9ivo 8bdQdgEWC4LqK5vn9WBnB9tmo7X1LOzvX20YpqRY7I9XlvQefuywnJqM1YE/hnVPnl8g tarQ== X-Gm-Message-State: AOAM530g4LD98alhMLHlEkJ6D9HzdVrp07ufCoVrEcANfgJTBYogxH+3 EGxByYtfISW/lN5oWTqxQyh/7dWh14s= X-Google-Smtp-Source: ABdhPJwuGv175uzQ1o6e4GG9kBVVycea4K7TP+suRHytb8cV7BkyExN9sMdZf+i/cAXGBzJkle8JZA== X-Received: by 2002:a4a:dc51:: with SMTP id q17mr10564397oov.10.1631914103811; Fri, 17 Sep 2021 14:28:23 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v8 6/7] spapr_numa.c: FORM2 NUMA affinity support Date: Fri, 17 Sep 2021 18:28:01 -0300 Message-Id: <20210917212802.424481-7-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917212802.424481-1-danielhb413@gmail.com> References: <20210917212802.424481-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::c32; envelope-from=danielhb413@gmail.com; helo=mail-oo1-xc32.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: 1631914396635100001 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. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Greg Kurz --- 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 dfe4fada01..659513b405 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 uint32_t *get_associativity(SpaprMachineState *spapr, int node_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 Wed May 8 13:32:52 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 1631914607176597.6284135416292; Fri, 17 Sep 2021 14:36:47 -0700 (PDT) Received: from localhost ([::1]:44096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRLXK-0006U1-2n for importer@patchew.org; Fri, 17 Sep 2021 17:36:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRLPK-0003aM-Af; Fri, 17 Sep 2021 17:28:30 -0400 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]:46760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRLPI-0007w9-1Z; Fri, 17 Sep 2021 17:28:30 -0400 Received: by mail-oo1-xc2d.google.com with SMTP id q26-20020a4adc5a000000b002918a69c8eeso3631204oov.13; Fri, 17 Sep 2021 14:28:27 -0700 (PDT) Received: from rekt.COMFAST ([177.189.43.50]) by smtp.gmail.com with ESMTPSA id s16sm710560otq.78.2021.09.17.14.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 14:28:26 -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=xXwiVuzQxbFRMa8BHWzYHEIQoCujnnuryEaFVH2T7Ak=; b=owYkajHNIfE3gvFkhx+ZYfP4UBgR9Qu23bRChAljxPno817GhTkPr8FlhzI8sLLwWf xLrTIkBHYyvxNu1+0Wq39RpdCIzey2tt+oSaTGq6hKQDVOyegdSTmrNIiurdagRU0T5p 2+n+DZC4wUi4wJqrZoRHqVkaZSGTPoE+87tu01ULUj34eB5wOBWovqUchh/1BxZjkB/r KXVXr+SUnm7PKE9AhKhPylqYqlVqtm0KrC10vcY5CiZFVEk+HsPvMbY6zBMi8qvEMxJB B8rkENoWbyaW9BtEZzc9HMhfY+iWnYnlUZFBcnkVFCD+AuDhqPu2SwIqjacI0qK3QWVP Y8DA== 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=xXwiVuzQxbFRMa8BHWzYHEIQoCujnnuryEaFVH2T7Ak=; b=GG8s5znrZbIbWkqYHsWXo0C18/yTcgIN9+4v0ouHKjmxWS30ZKPIjnThPNk7EHElig 3iHd5zz+I+MzSTIIa10MsdzjJZo3/G2EkzpCP/ZMbF2u04Nt8ldrUw7x3A/BArZJbz9n iN47QBzjHvCP7A6rPIH8PnXWyyasBrewWJ3YFTMOeQZaQzEIUihPkoUh0Llw0FHCE8Oo CGZ/wJo8EgQhWfKENdWNGClLVJaqVASFWXec3MuH9itZeeQje/sDXnmcvcIxak1Pclfn 99AVv0aRL2wd1yFrN5aJG2LzNK9V6k7nBSjC75GT11jjr/1oxvowCb0cyqIPhQUIWvPr rCxg== X-Gm-Message-State: AOAM5317cwdeuJI0k+djynmZpbKkyEAcJaKjkwkvkpZh1KmAhKvwlJEQ g4QNZKNZCmFuKF8NnnOH3XyGlrIqMfc= X-Google-Smtp-Source: ABdhPJzhxwGHxt1ihe3vWUD5XzoV5bUEFFXiW28jfcmVjHfZq930+Airoftudj4nUuWD4bWsQhuaew== X-Received: by 2002:a4a:ba0f:: with SMTP id b15mr10555514oop.31.1631914106415; Fri, 17 Sep 2021 14:28:26 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v8 7/7] spapr_numa.c: handle auto NUMA node with no distance info Date: Fri, 17 Sep 2021 18:28:02 -0300 Message-Id: <20210917212802.424481-8-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917212802.424481-1-danielhb413@gmail.com> References: <20210917212802.424481-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::c2d; envelope-from=danielhb413@gmail.com; helo=mail-oo1-xc2d.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: 1631914608896100001 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 Signed-off-by: Daniel Henrique Barboza Acked-by: Igor Mammedov Reviewed-by: Greg Kurz --- 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 659513b405..0cead2e7f5 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