From nobody Tue May 14 02:23:25 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 ARC-Seal: i=1; a=rsa-sha256; t=1600977236; cv=none; d=zohomail.com; s=zohoarc; b=Z7GzgbEMIDkBkmMsn/4ksDJE93EiujitLLZlBcypRXYcZ04LjlbhE4lsZi1pC5wzVuuHxVP1n9YAvByBkg/EAEAmUO4Fdk/E4LpE1e/R2v3kBWySs70GAKENBvf0yVaS0xlzjBJHpu8ffnWQzfOM8upeWJeEhL6oeL79LpJUNBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600977236; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=neaS6yuMeaOowQGU9uSi8JXfUOeAiUye6JSFdgemN/M=; b=loU0FIQPB/88TNyS20VTJahuN3KY0SSqX2eK8o4vwwGRXftSyNR2gZ5HLef/kk9bdf/SpOpv76tXGFvVdnPRkBzguC7j6seMw11AaGL4B9t2i+uS8F9Ly0/tG+Irs+H6nhRyw9lNlSVzWjDO2xs8UV3KF1bZ/kWKEl5bfwENSdQ= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600977236556639.9403990561038; Thu, 24 Sep 2020 12:53:56 -0700 (PDT) Received: from localhost ([::1]:44030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLXJT-0003Yq-0m for importer@patchew.org; Thu, 24 Sep 2020 15:53:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLXGr-0001m3-6z; Thu, 24 Sep 2020 15:51:13 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:44516) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLXGp-00018P-1X; Thu, 24 Sep 2020 15:51:12 -0400 Received: by mail-qk1-x729.google.com with SMTP id n133so642155qkn.11; Thu, 24 Sep 2020 12:51:10 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:c625:6c0e:4720:8228:5f68]) by smtp.gmail.com with ESMTPSA id f3sm381613qtg.71.2020.09.24.12.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 12:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=neaS6yuMeaOowQGU9uSi8JXfUOeAiUye6JSFdgemN/M=; b=jiA+hdRlmHAhG56t8bq0cPNBlATbNdiOkZUeP0KdzlfPo/6gnax16VIxyRu6QU3VFt 0G7UPzFXmZPgadysSJl++PfH3gVE+eHkXEI5gpgTwpXTBBa16MYlyqOV+TYmIJwjqczP EGR/LJVz22+1C1Rubz7j3n9Awwi073ZHCniPqsgYi42IrZcDId7twebIP459t03TVS8i 7seJpLGnA8Ys6V7AZ6qvBF8p7faqxsLUO2+Vr/c4sSnk9T8hKoMVoY4qpQ9hwllbrn/Y /QD1ZCay/4zhtAenIlaSsK6lEytRDoE1m3UliGMuMyUpz9t6q+LKAWa439fg71kmPtH2 pXmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=neaS6yuMeaOowQGU9uSi8JXfUOeAiUye6JSFdgemN/M=; b=PiFyqqLSX6E28nwSdpCU0b1o6c+ZuQu2d4Ay96dem8uy0wnmahfi4RzUGgCLD6IZn4 Bo/rO2jb2CcxKm3+bTP0zyr3bbE05MD/KyWI5NRJGARTSYRjuIq1HBH/n8GoQDghuVMZ YaNfpA+CGwH+8fsK9ny4zTspehtMZmO/Ha6wjEYFbbRW9Dd4syjR0gJOuDa+Chykwj9z jN8ijQl4Ra10CHBT/WCMW3M0AmphdpIqe3NHvdfTvx3D1b9Tm/siBjtPMNjE5AUmS584 fF8gmxigM6zS2uvCRXBs5C9w1GRYmJBgMexETSKODdwZrx59GyydGNOJdEPgJzo3mkwd FqJQ== X-Gm-Message-State: AOAM532Ttrk8VLoyHPbN4qPf4VrmuTkVGOJ1/TnRZRsnirzGOnejnMMp LUz36Lje6fzJ/B6vatpl8r+Oh7aWYQu03w== X-Google-Smtp-Source: ABdhPJw5ELdcy5TGb+zN6YKjbxYmovHTJQgmwxR2VNHMTVntehVM8u0PVkd6KKFCjXV1R9x+16AsOg== X-Received: by 2002:a05:620a:683:: with SMTP id f3mr744340qkh.491.1600977069487; Thu, 24 Sep 2020 12:51:09 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v2 1/6] spapr: add spapr_machine_using_legacy_numa() helper Date: Thu, 24 Sep 2020 16:50:53 -0300 Message-Id: <20200924195058.362984-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200924195058.362984-1-danielhb413@gmail.com> References: <20200924195058.362984-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-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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) Content-Type: text/plain; charset="utf-8" The changes to come to NUMA support are all guest visible. In theory we could just create a new 5_1 class option flag to avoid the changes to cascade to 5.1 and under. The reality is that these changes are only relevant if the machine has more than one NUMA node. There is no need to change guest behavior that has been around for years needlesly. This new helper will be used by the next patches to determine whether we should retain the (soon to be) legacy NUMA behavior in the pSeries machine. The new behavior will only be exposed if: - machine is pseries-5.2 and newer; - more than one NUMA node is declared in NUMA state. Reviewed-by: Greg Kurz Reviewed-by: David Gibson Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 12 ++++++++++++ include/hw/ppc/spapr.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index e813c7cfb9..c5d8910a74 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -294,6 +294,15 @@ static hwaddr spapr_node0_size(MachineState *machine) return machine->ram_size; } =20 +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 void add_str(GString *s, const gchar *s1) { g_string_append_len(s, s1, strlen(s1) + 1); @@ -4522,8 +4531,11 @@ DEFINE_SPAPR_MACHINE(5_2, "5.2", true); */ static void spapr_machine_5_1_class_options(MachineClass *mc) { + SpaprMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); + spapr_machine_5_2_class_options(mc); compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); + smc->pre_5_2_numa_associativity =3D true; } =20 DEFINE_SPAPR_MACHINE(5_1, "5.1", false); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 114e819969..d1aae03b97 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -143,6 +143,7 @@ struct SpaprMachineClass { bool smp_threads_vsmt; /* set VSMT to smp_threads by default */ hwaddr rma_limit; /* clamp the RMA to this size */ bool pre_5_1_assoc_refpoints; + bool pre_5_2_numa_associativity; =20 void (*phb_placement)(SpaprMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio,=20 @@ -860,6 +861,7 @@ int spapr_max_server_number(SpaprMachineState *spapr); void spapr_store_hpte(PowerPCCPU *cpu, hwaddr ptex, uint64_t pte0, uint64_t pte1); void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered); +bool spapr_machine_using_legacy_numa(SpaprMachineState *spapr); =20 /* DRC callbacks. */ void spapr_core_release(DeviceState *dev); --=20 2.26.2 From nobody Tue May 14 02:23:25 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 ARC-Seal: i=1; a=rsa-sha256; t=1600977540; cv=none; d=zohomail.com; s=zohoarc; b=SvFCKEsfvZRUUym9/Z2pVwDBkw1H3lCdxiq92MRofjWJSMVRPx+tfzXAGWOQay0f4h++c17ds5ANnxlp40rR2jfTEUH0NcxqzF0UNXzjoJkF35oVYNHc5+a3gxbmhkVx/sUJsMlKE+yt+5yzYUYU7Av5UK4pCbQlSyl5egGnKtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600977540; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wshH2JO2gAjBd9CysBLdg4RKPPUJNz/CuF2VnRWsINM=; b=KZlQIrpMGtRLNIo77VGP60y9VzcLAHvhfRhuxmVatuR3Zydo9PrDWQTvycsKIshkRqIwoYvfpLrfKLdPLv9ef06xSnK04870E/mTKPkSpXXv5WGC+XxRRLkGSmZBLlNjbK+WLzkuFlKZJZ10G4wXued87Qz/r1nB07Zo1nMnOu4= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600977540973819.8200296743648; Thu, 24 Sep 2020 12:59:00 -0700 (PDT) Received: from localhost ([::1]:56958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLXON-0000nA-IL for importer@patchew.org; Thu, 24 Sep 2020 15:58:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLXGt-0001nk-Lu; Thu, 24 Sep 2020 15:51:17 -0400 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]:40686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLXGr-00018e-8F; Thu, 24 Sep 2020 15:51:15 -0400 Received: by mail-qk1-x744.google.com with SMTP id w16so672425qkj.7; Thu, 24 Sep 2020 12:51:12 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:c625:6c0e:4720:8228:5f68]) by smtp.gmail.com with ESMTPSA id f3sm381613qtg.71.2020.09.24.12.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 12:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wshH2JO2gAjBd9CysBLdg4RKPPUJNz/CuF2VnRWsINM=; b=CsxrKril2lvKKP9aWIOwvXRoxq3U7+0dYa2zUrapUfH7c6Yo1O60oIvI6RHeaD7EGI cDwuZknCjCyKhfqV11SxAfrOgIvmlc78MW+V86Ko8LAw2ddq90L2X2j3XseIUBKgFYhY +HrWc5e6JHdBPVP4g6vOmU+ZVgRl2xZu6mbP9kLUNvRNKnGGBDtXflcNL+lbcjMfK25f 4Xj2Ny+B0DnaU78DUCw/fxtbxlLwrOggVC4qx8V+wVSl8E/EdnidexYIdFYV7Z1j9sMa +LzfJKqi/ryo5OBWf5IUABYwRp6djwS1Daj5t2FnJEl3LIKFKTN5EB834joIKZ8U7l8d u+tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wshH2JO2gAjBd9CysBLdg4RKPPUJNz/CuF2VnRWsINM=; b=BjtlZhbVuLiJC9FempSp4zemL2BhvZMrSbLrkeg7C58W7bJuRC+i+2x1DkIXZw0pbi usPqd3djX20Guoik89+So/wpIPqDeHx85MF/K4LJzv/fTZD8STRrWArr+PNpcxosg/+7 H9bsje7T91GhQpKaRdlfZqPI93QyKrYvckzypFkmsy+WLmA9CjU+Hae7cXVVpBQxZG9L vYkQeTzaubACBd9RRh2hVqeh03pvI0PlGQiiHDH+DEPNC2vaMwuvPOlpuGkf81x3o6nj OZpZRjotR7QOUKMYdNu2KkJoyzT5zxieDTGM/8Faml00ypZWzteDo7SuLzz2542LcuGV K6Dw== X-Gm-Message-State: AOAM530OXIAWeOHvPOKtyhj+HUpB03pRzFz6W/ho5TIhnIRXkQbQGl0R t5n/wIhAiiw3RieGImA36h5PMge7S7zUug== X-Google-Smtp-Source: ABdhPJx0+4vs6IX9q9IHocIYEErkIW0ylNUOrAfZMqBe2jcCQApyZHM7uyhEisHCSva0I4nZ/zXEBQ== X-Received: by 2002:a05:620a:5b8:: with SMTP id q24mr749494qkq.492.1600977071520; Thu, 24 Sep 2020 12:51:11 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] spapr_numa: forbid asymmetrical NUMA setups Date: Thu, 24 Sep 2020 16:50:54 -0300 Message-Id: <20200924195058.362984-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200924195058.362984-1-danielhb413@gmail.com> References: <20200924195058.362984-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::744; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x744.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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) Content-Type: text/plain; charset="utf-8" The pSeries machine does not support asymmetrical NUMA configurations. This doesn't make much of a different since we're not using user input for pSeries NUMA setup, but this will change in the next patches. To avoid breaking existing setups, gate this change by checking for legacy NUMA support. Reviewed-by: Greg Kurz Signed-off-by: Daniel Henrique Barboza Reviewed-by: David Gibson --- hw/ppc/spapr_numa.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 64fe567f5d..fe395e80a3 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -19,6 +19,24 @@ /* Moved from hw/ppc/spapr_pci_nvlink2.c */ #define SPAPR_GPU_NUMA_ID (cpu_to_be32(1)) =20 +static bool spapr_numa_is_symmetrical(MachineState *ms) +{ + int src, dst; + int nb_numa_nodes =3D ms->numa_state->num_nodes; + NodeInfo *numa_info =3D ms->numa_state->nodes; + + for (src =3D 0; src < nb_numa_nodes; src++) { + for (dst =3D src; dst < nb_numa_nodes; dst++) { + if (numa_info[src].distance[dst] !=3D + numa_info[dst].distance[src]) { + return false; + } + } + } + + return true; +} + void spapr_numa_associativity_init(SpaprMachineState *spapr, MachineState *machine) { @@ -61,6 +79,22 @@ void spapr_numa_associativity_init(SpaprMachineState *sp= apr, =20 spapr->numa_assoc_array[i][MAX_DISTANCE_REF_POINTS] =3D cpu_to_be3= 2(i); } + + /* + * 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. + */ + if (spapr_machine_using_legacy_numa(spapr)) { + return; + } + + if (!spapr_numa_is_symmetrical(machine)) { + error_report("Asymmetrical NUMA topologies aren't supported " + "in the pSeries machine"); + exit(EXIT_FAILURE); + } + } =20 void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, --=20 2.26.2 From nobody Tue May 14 02:23:25 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 ARC-Seal: i=1; a=rsa-sha256; t=1600977438; cv=none; d=zohomail.com; s=zohoarc; b=ErS0Lz0Pk0glT4LltyGcyNckhwxIxJpOI3YPGYP03emDJxUCTlIfViakwjX4FJ+aUA28Lx6TGoLKirfFnnzs8XPW/9icyqj+jktH4Z0OHPfcQJrD5jhn23SAKtsrl45qOHhyw83pUgOJnvZTuNl4hyIWdyuPf6WQy/Evsu50gv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600977438; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=21vV+hmckvLTxsw8vcWpzHxsduGLiKrg1o2Z9DjqQW8=; b=nLDvZ83JwkmMRxs4E7aAaz0nCwqwwlxvczHJmKZia1N+SCOC4ULL1aAYu0ndDQSo3aVA32wGuJ/NN1+Cy590sa5kXK9KEhLpCaRc/rFgYtZ53Pq3aI4hCaSvqi3/DcDhdXyE0EsiHoJJdO1cDhCOif0rAAj/OzhpXGAcSTnd+54= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16009774388631020.4949817804736; Thu, 24 Sep 2020 12:57:18 -0700 (PDT) Received: from localhost ([::1]:51816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLXMj-00072H-Ch for importer@patchew.org; Thu, 24 Sep 2020 15:57:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLXGv-0001o3-P9; Thu, 24 Sep 2020 15:51:19 -0400 Received: from mail-qv1-xf41.google.com ([2607:f8b0:4864:20::f41]:37839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLXGt-00018s-M4; Thu, 24 Sep 2020 15:51:17 -0400 Received: by mail-qv1-xf41.google.com with SMTP id db4so151687qvb.4; Thu, 24 Sep 2020 12:51:14 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:c625:6c0e:4720:8228:5f68]) by smtp.gmail.com with ESMTPSA id f3sm381613qtg.71.2020.09.24.12.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 12:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=21vV+hmckvLTxsw8vcWpzHxsduGLiKrg1o2Z9DjqQW8=; b=DwS3ZqEU/2yqIMBt1ql3BWhUM3Evt5cD2m02BudW5rsWjrAHqw0njW6DwX89lHp9oW Ho5Uw0k2nieFJzzjKVybj2B3siymYOKSV+ojo6FjFCVWR+tBlSlVoMyD8oty1iqUwaQt erYVFdHAescMeUpMFOhCUEfVtfLa3oVJnMm0x565xuYtsFO1zv3higOVTjO1b3LoqpY/ c6DHBNFRimldqEptute0siQZXTA2pbN1reyr9GXu27MfQm/abkYn0DnuKAWkWuTq0E6Q 4U5Lddi5y8y90Zfl4qNkIgDcNLWBBgtsAkzVUZUhmt6PJe11cDaDkr8InqYNgk5K+J0Z UyTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=21vV+hmckvLTxsw8vcWpzHxsduGLiKrg1o2Z9DjqQW8=; b=KURgY+Ym9gyT4oYDlulZym95KSmwh6bt5UwSRmZgeOtAp+eCZEczbBqNCDhtXynhXt CGOcuwPp1LklzxAeO89Ce8z0rOgG9otvNbn14eYOJ+D8M3gQdBcZ9yRZg8yNBUl/CJQR PWXkwt9KOWJ9saNoNCzSYS7u9SJCX/6aqo9n9oeOsrU/v6PA0IE/LsufN0OhPtMYXNn+ nxTGaovZ/k58Rqz1si9+aTt785dUfoW4bdABMkD+LakGBKo8yufHmMu5h+w7DoA9fd+w MJvm/QrzviTOUlDSgxFvFjQzbYGweyyLXiMDFG5uHUA3mclpOjxxG4pYRiKAjQP6kGzI XReg== X-Gm-Message-State: AOAM530QxYzHH/dA7D7xFRgCxCmfG3GxKCdpXS7hfzHn6uAMI6PWHCAl +rgbkCIVnmyDPcmsQvlM+hetQ9IhU7f0vg== X-Google-Smtp-Source: ABdhPJyR5O0Rx1/4+oH/NCOzxv97vhfLBY9HqYBfC8TwSUtCBON/wOQVz7NnutjC47QXsDzCpoUQqQ== X-Received: by 2002:a0c:c543:: with SMTP id y3mr852905qvi.47.1600977073676; Thu, 24 Sep 2020 12:51:13 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] spapr_numa: translate regular NUMA distance to PAPR distance Date: Thu, 24 Sep 2020 16:50:55 -0300 Message-Id: <20200924195058.362984-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200924195058.362984-1-danielhb413@gmail.com> References: <20200924195058.362984-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::f41; envelope-from=danielhb413@gmail.com; helo=mail-qv1-xf41.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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) Content-Type: text/plain; charset="utf-8" QEMU allows the user to set NUMA distances in the command line. For ACPI architectures like x86, this means that user input is used to populate the SLIT table, and the guest perceives the distances as the user chooses to. PPC64 does not work that way. In the PAPR concept of NUMA, associativity relations between the NUMA nodes are provided by the device tree, and the guest kernel is free to calculate the distances as it sees fit. Given how ACPI architectures works, this puts the pSeries machine in a strange spot - users expect to define NUMA distances like in the ACPI case, but QEMU does not have control over it. To give pSeries users a similar experience, we'll need to bring kernel specifics to QEMU to approximate the NUMA distances. The pSeries kernel works with the NUMA distance range 10, 20, 40, 80 and 160. The code starts at 10 (local distance) and searches for a match in the first NUMA level between the resources. If there is no match, the distance is doubled and then it proceeds to try to match in the next NUMA level. Rinse and repeat for MAX_DISTANCE_REF_POINTS levels. This patch introduces a spapr_numa_PAPRify_distances() helper that translates the user distances to kernel distance, which we're going to use to determine the associativity domains for the NUMA nodes. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_numa.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index fe395e80a3..990a5fce08 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -37,6 +37,49 @@ static bool spapr_numa_is_symmetrical(MachineState *ms) return true; } =20 +/* + * This function will translate the user distances into + * what the kernel understand as possible values: 10 + * (local distance), 20, 40, 80 and 160. Current heuristic + * is: + * + * - distances between 11 and 30 inclusive -> rounded to 20 + * - distances between 31 and 60 inclusive -> rounded to 40 + * - distances between 61 and 120 inclusive -> rounded to 80 + * - everything above 120 -> 160 + * + * This step can also be done in the same time as the NUMA + * associativity domains calculation, at the cost of extra + * complexity. We chose to keep it simpler. + * + * Note: this will overwrite the distance values in + * ms->numa_state->nodes. + */ +static void spapr_numa_PAPRify_distances(MachineState *ms) +{ + int src, dst; + int nb_numa_nodes =3D ms->numa_state->num_nodes; + NodeInfo *numa_info =3D ms->numa_state->nodes; + + for (src =3D 0; src < nb_numa_nodes; src++) { + for (dst =3D src; dst < nb_numa_nodes; dst++) { + uint8_t distance =3D numa_info[src].distance[dst]; + uint8_t rounded_distance =3D 160; + + if (distance > 11 && distance <=3D 30) { + rounded_distance =3D 20; + } else if (distance > 31 && distance <=3D 60) { + rounded_distance =3D 40; + } else if (distance > 61 && distance <=3D 120) { + rounded_distance =3D 80; + } + + numa_info[src].distance[dst] =3D rounded_distance; + numa_info[dst].distance[src] =3D rounded_distance; + } + } +} + void spapr_numa_associativity_init(SpaprMachineState *spapr, MachineState *machine) { @@ -95,6 +138,7 @@ void spapr_numa_associativity_init(SpaprMachineState *sp= apr, exit(EXIT_FAILURE); } =20 + spapr_numa_PAPRify_distances(machine); } =20 void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, --=20 2.26.2 From nobody Tue May 14 02:23:25 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 ARC-Seal: i=1; a=rsa-sha256; t=1600977373; cv=none; d=zohomail.com; s=zohoarc; b=eoY+u1OR+4pXmoXzBRmNgj8kDJaD/NXxiBaoJoKMBxnIfQ0mMxnHsp2Dx0dCKM0r5AJKY9LU2T99FjcG4pOYApzoSRFL+vhsoRyWpgn1MfMOG+1Z2E/zfp0iEf/1+9xDJV8xIGaKw+MVexMerM+Q9EalisCSzXtv/+/RRFy5Se8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600977373; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Plnnc/TLWC8T+VLBC0ieE5wAsZmgCaOLQWd67VMkILc=; b=FDri/yrS1HVqvA2Kw040F0O+yUplwDwec3Mq3CZ4pAAIdmUquJtGvk31XGR2LsBO2UdzaLqOfnr5E8uQ9nt7KQRI6ICcTiDb+125USpWrKbnXjW16VrFx4CwOzQdlBSfHebKaX7X67Rd+FAOXxo+kJuCrUaP6gWjhrE5QJlqrsA= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600977373592453.15849302339234; Thu, 24 Sep 2020 12:56:13 -0700 (PDT) Received: from localhost ([::1]:49344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLXLg-0005u8-67 for importer@patchew.org; Thu, 24 Sep 2020 15:56:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLXGx-0001ou-LW; Thu, 24 Sep 2020 15:51:20 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:35795) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLXGv-000192-7R; Thu, 24 Sep 2020 15:51:19 -0400 Received: by mail-qk1-x743.google.com with SMTP id q5so704489qkc.2; Thu, 24 Sep 2020 12:51:16 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:c625:6c0e:4720:8228:5f68]) by smtp.gmail.com with ESMTPSA id f3sm381613qtg.71.2020.09.24.12.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 12:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Plnnc/TLWC8T+VLBC0ieE5wAsZmgCaOLQWd67VMkILc=; b=Pwmf4l/RUBfCAwXWhArAxUGhChP0YYD9JtbUd5Cd+RLHJQi4VXBbal3Z2/5WNiCtBv d+xnx6R2h8bvlAmQwbHQLkoxL6nPJt0gPbYcWNKU1Dwuf45Bzjc4dhZTS3eS4W+j+/G5 2jUTyjjMzPOqsvhJ+vuVQ285MvknAauqa4+kjSpwUENPgKDOPJ0jZL6JFqRnDdcaloXV 5OptgHxWCLfHylrp1AgYzDMasMgyODUR3C3p0iJdcO2yxiSZWq2V1Xdm0A+s7O2Dgwx3 jZLbinRiQu+1/Xll5hMtB++2gHFAxFcW9vH8EBB1apwV5MS8HkEdpLwx+UD0pAfXQo0v XCEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Plnnc/TLWC8T+VLBC0ieE5wAsZmgCaOLQWd67VMkILc=; b=R32gHzmSoXyaRmEhKwIph6a3vq4US60bmh7+6azuPlybD3c73eSqFY3pTvBrD4TO/g /iSD404N1FbuuAfeP/LiwCfb2Dv0bwU7g/KPGBSMgNBJ6g1LjcjN9sHzVvdaYZDQJcYr tYiDhCc6EupK8r7yw0iLjj4BqFgfCSC2okerRAL1KgCJHdm2+uqkDGwq6WdmaUphnLzi 4eyhofqJQQyX6gvA30x2N9FYEQ0GktWXuGv895rSr/oFnq5ezmeC69xn2QdXSGJGUsKs m2O4Va2z35Tl5g5zTuETuyTl1UWa8EYy2P6TewOn0RUsScQHezhwJOKACizaiNIh+vuT EMPw== X-Gm-Message-State: AOAM531EdkRZAyRel2Bp3ongQB61+52c5d7TAr3EeCOuYSRbbr52jbfq HN6JRhfV/IhQ4CqKoKuHAj2AcrLnxov0Ig== X-Google-Smtp-Source: ABdhPJyt2hIQXqMbZKbEepfS6aeTm5FITkrJ6A8C/rX4u+fspQQDfyXlT1lYZSbkH2o1eX9MaQtNjQ== X-Received: by 2002:a05:620a:94e:: with SMTP id w14mr783437qkw.86.1600977075536; Thu, 24 Sep 2020 12:51:15 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v2 4/6] spapr_numa: change reference-points and maxdomain settings Date: Thu, 24 Sep 2020 16:50:56 -0300 Message-Id: <20200924195058.362984-5-danielhb413@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200924195058.362984-1-danielhb413@gmail.com> References: <20200924195058.362984-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::743; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x743.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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) Content-Type: text/plain; charset="utf-8" This is the first guest visible change introduced in spapr_numa.c. The previous settings of both reference-points and maxdomains were too restrictive, but enough for the existing associativity we're setting in the resources. We'll change that in the following patches, populating the associativity arrays based on user input. For those changes to be effective, reference-points and maxdomains must be more flexible. After this patch, we'll have 4 distinct levels of NUMA (0x4, 0x3, 0x2, 0x1) and maxdomains will allow for any type of configuration the user intends to do - under the scope and limitations of PAPR itself, of course. Signed-off-by: Daniel Henrique Barboza Reviewed-by: David Gibson Reviewed-by: Greg Kurz --- hw/ppc/spapr_numa.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index 990a5fce08..ea33439a15 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -222,24 +222,48 @@ int spapr_numa_write_assoc_lookup_arrays(SpaprMachine= State *spapr, void *fdt, */ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rta= s) { + MachineState *ms =3D MACHINE(spapr); SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); uint32_t refpoints[] =3D { cpu_to_be32(0x4), - cpu_to_be32(0x4), + cpu_to_be32(0x3), cpu_to_be32(0x2), + cpu_to_be32(0x1), }; uint32_t nr_refpoints =3D ARRAY_SIZE(refpoints); - uint32_t maxdomain =3D cpu_to_be32(spapr->gpu_numa_id > 1 ? 1 : 0); + uint32_t maxdomain =3D ms->numa_state->num_nodes + spapr->gpu_numa_id; uint32_t maxdomains[] =3D { cpu_to_be32(4), - maxdomain, - maxdomain, - maxdomain, - cpu_to_be32(spapr->gpu_numa_id), + cpu_to_be32(maxdomain), + cpu_to_be32(maxdomain), + cpu_to_be32(maxdomain), + cpu_to_be32(maxdomain) }; =20 - if (smc->pre_5_1_assoc_refpoints) { - nr_refpoints =3D 2; + if (spapr_machine_using_legacy_numa(spapr)) { + uint32_t legacy_refpoints[] =3D { + cpu_to_be32(0x4), + cpu_to_be32(0x4), + cpu_to_be32(0x2), + }; + uint32_t legacy_maxdomain =3D spapr->gpu_numa_id > 1 ? 1 : 0; + uint32_t legacy_maxdomains[] =3D { + cpu_to_be32(4), + cpu_to_be32(legacy_maxdomain), + cpu_to_be32(legacy_maxdomain), + cpu_to_be32(legacy_maxdomain), + cpu_to_be32(spapr->gpu_numa_id), + }; + + nr_refpoints =3D 3; + + memcpy(refpoints, legacy_refpoints, sizeof(legacy_refpoints)); + memcpy(maxdomains, legacy_maxdomains, sizeof(legacy_maxdomains)); + + /* pseries-5.0 and older reference-points array is {0x4, 0x4} */ + if (smc->pre_5_1_assoc_refpoints) { + nr_refpoints =3D 2; + } } =20 _FDT(fdt_setprop(fdt, rtas, "ibm,associativity-reference-points", --=20 2.26.2 From nobody Tue May 14 02:23:25 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 ARC-Seal: i=1; a=rsa-sha256; t=1600977269; cv=none; d=zohomail.com; s=zohoarc; b=abZSZgw/5mvZXZzHqWKkXtxOjJLZeF70xXZnT0xPgZkEas08iTgUUoTdxb7HZVrybPrDZtWO2Wrgo56M5oDBA23UI62oarkFvq8lRuuVuZnAi+kp+hZAO+I7gORaZkFwzbRFfs/o+wEwHbh9AT7RbPRkUBuJvbqURy+okBzvEnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600977269; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wzrMd4eBXeLBiNY+rrKL5I5ntV6Gub53UCMYZ5Jggdc=; b=fvQZYQaiIPez31cEP7h2ChtsfWPCGfW2Xm4PGvIdGI6piFtcm8F5uHkSzOPTWXBvLLBHloOx+vBxrtpEJYLJ2kOQ0fFDdf3qeTxapSs/oFhFnHYEdEXw7a7sS8Br13+2H3V4Ipm2i3F2fk8eouCZkM7hn4awtfU2InVC89nxWcA= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600977269988100.5545791220942; Thu, 24 Sep 2020 12:54:29 -0700 (PDT) Received: from localhost ([::1]:45982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLXK0-0004Ox-JQ for importer@patchew.org; Thu, 24 Sep 2020 15:54:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLXH3-0001ui-H5; Thu, 24 Sep 2020 15:51:27 -0400 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]:37840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLXGx-00019G-Ln; Thu, 24 Sep 2020 15:51:25 -0400 Received: by mail-qv1-xf42.google.com with SMTP id db4so151776qvb.4; Thu, 24 Sep 2020 12:51:18 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:c625:6c0e:4720:8228:5f68]) by smtp.gmail.com with ESMTPSA id f3sm381613qtg.71.2020.09.24.12.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 12:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wzrMd4eBXeLBiNY+rrKL5I5ntV6Gub53UCMYZ5Jggdc=; b=CiNC0aDHBAfDP/YEiV38XII4W1vAc7jr4gneJQydm2I1EMEc9dopJMopyzehNXoWkP g6WSmnWWNVQgWMTKjHdLkpZJbWUVQTmRfbgkhre3yZ1ZuoQLjKQqzrIjvtRjpZOuB8Fw 5urJLZbNLZxVUYq6Qb5hJd6iKhGpYaxoPRkxtBfui6XjOtkOGGE3027Dskx+d7xXIXfa Cis6FJo8Xcv6VTF7X/7lsTymwqizDYuMYNUhltae5Q7AwbpL+c0mxTKgG782eddoZdcX WWk8w8IH9aS2pX7c+BPSlUpW3qD0eR9imX4OqtNf+uN8tZOMWeFRUSkAw7s9BXTCBohv IOPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wzrMd4eBXeLBiNY+rrKL5I5ntV6Gub53UCMYZ5Jggdc=; b=tVIZDEIEmZZu9+I5QKpSMyG8k2fe9AVlgA+zRb8k/h4DZ3RCqj+CWzLxJ4KjVfbMdZ eVCvE5Po50CVt4MYawrlYeo/4ecFe9M48i1toencBSOtOp5AulL1L98PDzW52daMUL6P m8U3aFRqKdqZVipKOfxhkp3S8/ztlM3P+2WdNhD7ot16TKX4RDl/GaZmtFHH+BeZGXpN y55/W+q+OpHh0qlvZdXH9Zpalwst/mSQgnUw3knz0IKJZ33y62CRuaSoL4Z2dHRISGfb zYTYSQ6KEu8yCyV2+qPqOSkRdYOVxjHlmGC0314S2AepXjJwmhY7sGo4r8KywUSXf4Yu QJjw== X-Gm-Message-State: AOAM530dou1VIo6onhnEB7whAGtmyYf7CFQVm2euTOMAbDjAMLIstSo6 8KXS9eK6PoJAqjgzejz2rhFhBZjg9AcRdQ== X-Google-Smtp-Source: ABdhPJwXXMc6DyEtgTTINaU9JgJdnPbTWnXNS4gl5eEwL5y+7hMzM/8z9Q0I7Iey/gsYx8UAtLvTUA== X-Received: by 2002:ad4:47cc:: with SMTP id p12mr879620qvw.26.1600977077662; Thu, 24 Sep 2020 12:51:17 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v2 5/6] spapr_numa: consider user input when defining associativity Date: Thu, 24 Sep 2020 16:50:57 -0300 Message-Id: <20200924195058.362984-6-danielhb413@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200924195058.362984-1-danielhb413@gmail.com> References: <20200924195058.362984-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::f42; envelope-from=danielhb413@gmail.com; helo=mail-qv1-xf42.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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) Content-Type: text/plain; charset="utf-8" This patch puts all the pieces together to finally allow user input when defining the NUMA topology of the spapr guest. We have one more kernel restriction to handle in this patch: the associativity array of node 0 must be filled with zeroes [1]. The strategy below ensures that this will happen. spapr_numa_define_associativity_domains() will read the distance (already PAPRified) between the nodes from numa_state and determine the appropriate NUMA level. The NUMA domains, processed in ascending order, are going to be matched via NUMA levels, and the lowest associativity domain value is assigned to that specific level for both. This will create an heuristic where the associativities of the first nodes have higher priority and are re-used in new matches, instead of overwriting them with a new associativity match. This is necessary because neither QEMU, nor the pSeries kernel, supports multiple associativity domains for each resource, meaning that we have to decide which associativity relation is relevant. Ultimately, all of this results in a best effort approximation for the actual NUMA distances the user input in the command line. Given the nature of how PAPR itself interprets NUMA distances versus the expectations risen by how ACPI SLIT works, there might be better algorithms but, in the end, it'll also result in another way to approximate what the user really wanted. To keep this commit message no longer than it already is, the next patch will update the existing documentation in ppc-spapr-numa.rst with more in depth details and design considerations/drawbacks. [1] https://lore.kernel.org/linuxppc-dev/5e8fbea3-8faf-0951-172a-b41a2138fb= cf@gmail.com/ Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_numa.c | 101 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr_numa.c b/hw/ppc/spapr_numa.c index ea33439a15..21cae3f799 100644 --- a/hw/ppc/spapr_numa.c +++ b/hw/ppc/spapr_numa.c @@ -80,12 +80,99 @@ static void spapr_numa_PAPRify_distances(MachineState *= ms) } } =20 +static uint8_t spapr_numa_get_numa_level(uint8_t distance) +{ + uint8_t numa_level; + + switch (distance) { + case 10: + numa_level =3D 0x4; + break; + case 20: + numa_level =3D 0x3; + break; + case 40: + numa_level =3D 0x2; + break; + case 80: + numa_level =3D 0x1; + break; + default: + numa_level =3D 0; + } + + return numa_level; +} + +static void spapr_numa_define_associativity_domains(SpaprMachineState *spa= pr) +{ + 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; + + for (src =3D 0; src < nb_numa_nodes; src++) { + for (dst =3D src; dst < nb_numa_nodes; dst++) { + /* + * This is how the associativity domain between A and B + * is calculated: + * + * - get the distance between them + * - get the correspondent NUMA level for this distance + * - the arrays were initialized with their own numa_ids, + * and we're calculating the distance in node_id ascending ord= er, + * starting from node 0. This will have a cascade effect in the + * algorithm because the associativity domains that node 0 def= ines + * will be carried over to the other nodes, and node 1 + * associativities will be carried over unless there's already= a + * node 0 associativity assigned, and so on. This happens beca= use + * we'll assign the lowest value of assoc_src and assoc_dst to= be + * the associativity domain of both, for the given NUMA level. + * + * The PPC kernel expects the associativity domains of node 0 = to + * be always 0, and this algorithm will grant that by default. + */ + uint8_t distance =3D numa_info[src].distance[dst]; + uint8_t n_level =3D spapr_numa_get_numa_level(distance); + uint32_t assoc_src, assoc_dst; + + /* + * n_level =3D 0 means that the distance is greater than our l= ast + * rounded value (120). In this case there is no NUMA level ma= tch + * between src and dst and we can skip the remaining of the lo= op. + * + * 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 + * 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 + * v5.9, in arch/powerpc/mm/numa.c, function __node_distance(). + */ + if (n_level =3D=3D 0) { + continue; + } + + assoc_src =3D be32_to_cpu(spapr->numa_assoc_array[src][n_level= ]); + assoc_dst =3D be32_to_cpu(spapr->numa_assoc_array[dst][n_level= ]); + + if (assoc_src < assoc_dst) { + spapr->numa_assoc_array[dst][n_level] =3D cpu_to_be32(asso= c_src); + } else { + spapr->numa_assoc_array[src][n_level] =3D cpu_to_be32(asso= c_dst); + } + } + } + +} + void spapr_numa_associativity_init(SpaprMachineState *spapr, MachineState *machine) { 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, @@ -99,6 +186,17 @@ void spapr_numa_associativity_init(SpaprMachineState *s= papr, 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 /* @@ -128,7 +226,7 @@ void spapr_numa_associativity_init(SpaprMachineState *s= papr, * 1 NUMA node) will not benefit from anything we're going to do * after this point. */ - if (spapr_machine_using_legacy_numa(spapr)) { + if (using_legacy_numa) { return; } =20 @@ -139,6 +237,7 @@ void spapr_numa_associativity_init(SpaprMachineState *s= papr, } =20 spapr_numa_PAPRify_distances(machine); + spapr_numa_define_associativity_domains(spapr); } =20 void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, --=20 2.26.2 From nobody Tue May 14 02:23:25 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 ARC-Seal: i=1; a=rsa-sha256; t=1600977673; cv=none; d=zohomail.com; s=zohoarc; b=f5BfY3MB/yWS2Ay2ZkKqn3UCN2Ry/0491PxaRuLfyBYZhgL6ipOEw1IRiTgiqwqXbdZ4e9Yijyk4X6LGwdgmWSosISC3XRdnePr2AMIr3QtfvFrwQsou9LGywer2g61fa19jVzyWZ/H1/nwbrDYQp23fZNSKZrqmu9bGgq26KGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600977673; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=foegIg+R6xGelzocg1qpmzjKagMlOEuwe5qYOlr3pzs=; b=kaM78U8mLQLs6fFFbJ1L3iPaVjnK2/O6S3fNHbdCGLcNR6aOf9cKwzLsfwitepjemfxW2EKCZ8ctO6TK3B4Si/ZXMRDDFcVjhl5iXXGgcSFloQ4FiyzNU3GiIzy6w7PVM2FcbKgvm7GqlSonLD+F7TBfdi1lQNaf/nghhnyR9d8= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600977673466877.5082494968632; Thu, 24 Sep 2020 13:01:13 -0700 (PDT) Received: from localhost ([::1]:59466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLXQW-0001q2-32 for importer@patchew.org; Thu, 24 Sep 2020 16:01:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLXH5-0001vp-FI; Thu, 24 Sep 2020 15:51:27 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:45493) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLXGz-00019R-JL; Thu, 24 Sep 2020 15:51:27 -0400 Received: by mail-qk1-x72a.google.com with SMTP id o5so637325qke.12; Thu, 24 Sep 2020 12:51:20 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:c625:6c0e:4720:8228:5f68]) by smtp.gmail.com with ESMTPSA id f3sm381613qtg.71.2020.09.24.12.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 12:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=foegIg+R6xGelzocg1qpmzjKagMlOEuwe5qYOlr3pzs=; b=m1EgYW0UMjTFPHBaZXMXeioNJYGgT1lnTtsaPw8GKhljZjg5mgMdOFUq7uf75NLMTG lqIhNTz3neel07A5ljYZpReBYoNrtjGE9EjZd0W94c2wcpPD8GB9J8lAJVypfFTQBBbm E7ncMzAWicOVOTEsuFILpQ2NclI2xtuDdWv2Hk9tJ3kDd7TktLx7+kkojCKyqSCsim5Q qgAw3+LrMFRL+geOlzKauPadJWrP26aagfzV8u8qS4uUo0Fetm2Zi459Ye8pXLmXs1Gd WuAALdIfz3F8vzuutJtKmNhWM0oM9xy8Zvy9edY8n015/zcERj6EF5hlr2HnFqFSnKPj EU/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=foegIg+R6xGelzocg1qpmzjKagMlOEuwe5qYOlr3pzs=; b=QJK0T1SDtKk9bMVvO5XVsodmCHwpAGmZhbqVdFu++U6ruiYdMxRNp/JmeQdcNf9sN0 reRQIVAFPafQj+xerAl0iKRBdq7P+1N43bNkpbNuzWjmlUDxV7R9c0RHgt2XWsnWBVga eo3r6V20+aCrwRixrE+lNzAM/8Gh8vg19fLqBFAaR4pnKQz4c1YlyvN35YJGMvbynu60 l3Ukieoy0nPhopgmqpebgZETW929kk1McqbTSSHpPa5qQZmmfZ7Q2LsvSt6iMZW7nDXB Q9jHV6UUlOdu781E8tBe4HjEMf81nriCAiUCbdijPHd6QwMnn+FYiR1gz+6jCV2P8lhj fLhg== X-Gm-Message-State: AOAM532Nx8rkMwBOKYRklBsbZhmMyp65nnEZLhkSTasV8Nx+WAQJAWWL 3dPpf2snziK40C9k2eCxPiVD7Z6WLA9hpA== X-Google-Smtp-Source: ABdhPJwq5fB/A2adMRjfGCljoriV8GAYYbapbt4V7sChyJ36gsYa/6C34LAXcK/22vKohdks+KXRxQ== X-Received: by 2002:a37:64d4:: with SMTP id y203mr727666qkb.359.1600977079396; Thu, 24 Sep 2020 12:51:19 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v2 6/6] specs/ppc-spapr-numa: update with new NUMA support Date: Thu, 24 Sep 2020 16:50:58 -0300 Message-Id: <20200924195058.362984-7-danielhb413@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200924195058.362984-1-danielhb413@gmail.com> References: <20200924195058.362984-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=danielhb413@gmail.com; helo=mail-qk1-x72a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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) Content-Type: text/plain; charset="utf-8" This update provides more in depth information about the choices and drawbacks of the new NUMA support for the spapr machine. Signed-off-by: Daniel Henrique Barboza --- docs/specs/ppc-spapr-numa.rst | 213 ++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) diff --git a/docs/specs/ppc-spapr-numa.rst b/docs/specs/ppc-spapr-numa.rst index e762038022..994bfb996f 100644 --- a/docs/specs/ppc-spapr-numa.rst +++ b/docs/specs/ppc-spapr-numa.rst @@ -189,3 +189,216 @@ QEMU up to 5.1, as follows: =20 This also means that user input in QEMU command line does not change the NUMA distancing inside the guest for the pseries machine. + +New NUMA mechanics for pseries in QEMU 5.2 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Starting in QEMU 5.2, the pseries machine now considers user input when +setting NUMA topology of the guest. The following changes were made: + +* ibm,associativity-reference-points was changed to {0x4, 0x3, 0x2, 0x1}, = allowing + for 4 distinct NUMA distance values based on the NUMA levels + +* ibm,max-associativity-domains was changed to support multiple associativ= ity + domains in all NUMA levels. This is needed to ensure user flexibility + +* ibm,associativity for all resources now varies with user input + +These changes are only effective for pseries-5.2 and newer machines that a= re +created with more than one NUMA node (disconsidering NUMA nodes created by +the machine itself, e.g. NVLink 2 GPUs). The now legacy support has been +around for such a long time, with users seeing NUMA distances 10 and 40 +(and 80 if using NVLink2 GPUs), and there is no need to disrupt the +existing experience of those guests. + +To bring the user experience x86 users have when tuning up NUMA, we had +to operate under the current pseries Linux kernel logic described in +`How the pseries Linux guest calculates NUMA distances`_. The result +is that we needed to translate NUMA distance user input to pseries +Linux kernel input. + +Translating user distance to kernel distance +-------------------------------------------- + +User input for NUMA distance can vary from 10 to 254. We need to translate +that to the values that the Linux kernel operates on (10, 20, 40, 80, 160). +This is how it is being done: + +* user distance 11 to 30 will be interpreted as 20 +* user distance 31 to 60 will be interpreted as 40 +* user distance 61 to 120 will be interpreted as 80 +* user distance 121 and beyond will be interpreted as 160 +* user distance 10 stays 10 + +The reasoning behind this aproximation is to avoid any round up to the loc= al +distance (10), keeping it exclusive to the 4th NUMA level (which is still +exclusive to the node_id). All other ranges were chosen under the developer +discretion of what would be (somewhat) sensible considering the user input. +Any other strategy can be used here, but in the end the reality is that we= 'll +have to accept that a large array of values will be translated to the same +NUMA topology in the guest, e.g. this user input: + +:: + + 0 1 2 + 0 10 31 120 + 1 31 10 30 + 2 120 30 10 + +And this other user input: + +:: + + 0 1 2 + 0 10 60 61 + 1 60 10 11 + 2 61 11 10 + +Will both be translated to the same values internally: + +:: + + 0 1 2 + 0 10 40 80 + 1 40 10 20 + 2 80 20 10 + +Users are encouraged to use only the kernel values in the NUMA definition = to +avoid being taken by surprise with that the guest is actually seeing in the +topology. There are enough potential surprises that are inherent to the +associativity domain assignment process, discussed below. + + +How associativity domains are assigned +-------------------------------------- + +LOPAPR allows more than one associativity array (or 'string') per allocated +resource. This would be used to represent that the resource has multiple +connections with the board, and then the operational system, when deciding +NUMA distancing, should consider the associativity information that provid= es +the shortest distance. + +The spapr implementation does not support multiple associativity arrays per +resource, neither does the pseries Linux kernel. We'll have to represent t= he +NUMA topology using one associativity per resource, which means that choic= es +and compromises are going to be made. + +Consider the following NUMA topology entered by user input: + +:: + + 0 1 2 3 + 0 10 20 20 40 + 1 20 10 80 40 + 2 20 80 10 20 + 3 40 40 20 10 + +Honoring just the relative distances of node 0 to every other node, one po= ssible +value for all associativity arrays would be: + +* node 0: 0 B A 0 +* node 1: 0 0 A 1 +* node 2: 0 0 A 2 +* node 3: 0 B 0 3 + +With the reference points {0x4, 0x3, 0x2, 0x1}, for node 0: + +* distance from 0 to 1 is 20 (no match at 0x4, will match at 0x3) +* distance from 0 to 2 is 20 (no match at 0x4, will match at 0x3) +* distance from 0 to 3 is 40 (no match at 0x4 and 0x3, will match + at 0x2) + +The distances related to node 0 are well represented. Doing for node 1, an= d keeping +in mind that we don't need to revisit node 0 again, the distance from node= 1 to +2 is 80, matching at 0x4: + +* node 1: C 0 A 1 +* node 2: C 0 A 2 + +Over here we already have the first conflict. Even if we assign a new asso= ciativity +domain at 0x4 for 1 and 2, and we do that in the code, the kernel will def= ine +the distance between 1 and 2 as 20, not 80, because both 1 and 2 have the = "A" +associativity domain from the previous step. If we decide to discard the +associativity with "A" then the node 0 distances are compromised. + +Following up with the distance from 1 to 3 being 40 (a match in 0x2) we ha= ve another +decision to make. These are the current associativity domains of each: + +* node 1: C 0 A 1 +* node 3: 0 B 0 3 + +There is already an associativity domain at 0x2 in node 3, "B", which was = assigned +by the node 0 distances. If we define a new associativity domain at this l= evel +for 1 and 3 we will overwrite the existing associativity between 0 and 3. = What +the code is doing in this case is to assign the existing domain to the +current associativity, in this case, "B" is now assigned to the 0x2 of nod= e 1, +resulting in the following associativity arrays: + +* node 0: 0 B A 0 +* node 1: C 0 A 1 +* node 2: C B A 2 +* node 3: 0 B 0 3 + +In the last step we will analyze just nodes 2 and 3. The desired distance = between +2 and 3 is 20, i.e. a match in 0x3. Node 2 already has a domain assigned i= n 0x3, +A, so we do the same as we did in the previous case and assign it to node 3 +at 0x3. This is the end result for the associativity arrays: + +* node 0: 0 B A 0 +* node 1: C 0 A 1 +* node 2: C B A 2 +* node 3: 0 B A 3 + +The kernel will read these arrays and will calculate the following NUMA to= pology for +the guest: + +:: + + 0 1 2 3 + 0 10 20 20 20 + 1 20 10 20 20 + 2 20 20 10 20 + 3 20 20 20 10 + +Which is not what the user wanted, but it is what the current logic and im= plementation +constraints of the kernel and QEMU will provide inside the LOPAPR specific= ation. + +Changing a single value, specially a low distance value, makes for drastic= changes +in the result. For example, with the same user input from above, but chang= ing the +node distance from 0 to 1 to 40: + +:: + + 0 1 2 3 + 0 10 40 20 40 + 1 40 10 80 40 + 2 20 80 10 20 + 3 40 40 20 10 + +This is the result inside the guest, applying the same heuristics: + +:: + + $ numactl -H + available: 4 nodes (0-3) + (...) + node distances: + node 0 1 2 3 + 0: 10 40 20 20 + 1: 40 10 80 40 + 2: 20 80 10 20 + 3: 20 40 20 10 + +This result is much closer to the user input and only a single distance wa= s changed +from the original. + +The kernel will always match with the shortest associativity domain possib= le, and we're +attempting to retain the previous established relations between the nodes.= This means +that a distance equal to 20 between nodes A and B and the same distance 20= between nodes +A and F will cause the distance between B and F to also be 20. The same wi= ll happen to +other distances, but shorter distances has precedent over it to the distan= ce calculation. + +Users are welcome to use this knowledge and experiment with the input to g= et the +NUMA topology they want, or as closer as they want. The important thing is= to keep +expectations up to par with what we are capable of provide at this moment:= an +approximation. --=20 2.26.2