From nobody Fri May 3 15:00:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493288216148296.4690819717871; Thu, 27 Apr 2017 03:16:56 -0700 (PDT) Received: from localhost ([::1]:59784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3gTm-0008OP-MH for importer@patchew.org; Thu, 27 Apr 2017 06:16:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3gQ8-0005Zr-14 for qemu-devel@nongnu.org; Thu, 27 Apr 2017 06:13:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3gQ5-0008Qw-0Z for qemu-devel@nongnu.org; Thu, 27 Apr 2017 06:13:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3gQ4-0008QD-Na for qemu-devel@nongnu.org; Thu, 27 Apr 2017 06:13:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE474C04BD24; Thu, 27 Apr 2017 10:13:03 +0000 (UTC) Received: from thinkpad.redhat.com (unknown [10.36.118.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46F7789320; Thu, 27 Apr 2017 10:13:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BE474C04BD24 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lvivier@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BE474C04BD24 From: Laurent Vivier To: Eduardo Habkost Date: Thu, 27 Apr 2017 12:12:58 +0200 Message-Id: <20170427101259.13798-2-lvivier@redhat.com> In-Reply-To: <20170427101259.13798-1-lvivier@redhat.com> References: <20170427101259.13798-1-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 27 Apr 2017 10:13:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/2] numa: introduce numa_auto_assign_ram() function in MachineClass X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We need to change the way we distribute the memory across the nodes. To keep compatibility between machine type version introduce a machine type dependent function. Signed-off-by: Laurent Vivier --- include/hw/boards.h | 2 ++ numa.c | 44 +++++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 31d9c72..e571b22 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -136,6 +136,8 @@ struct MachineClass { int minimum_page_bits; bool has_hotpluggable_cpus; int numa_mem_align_shift; + void (*numa_auto_assign_ram)(uint64_t *nodes, + int nb_nodes, ram_addr_t size); =20 HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); diff --git a/numa.c b/numa.c index 6fc2393..2770c18 100644 --- a/numa.c +++ b/numa.c @@ -294,6 +294,38 @@ static void validate_numa_cpus(void) g_free(seen_cpus); } =20 +static void numa_auto_assign_ram(MachineClass *mc, NodeInfo *nodes, + int nb_nodes, ram_addr_t size) +{ + int i; + uint64_t usedmem =3D 0; + + if (mc->numa_auto_assign_ram) { + uint64_t *mem =3D g_new(uint64_t, nb_nodes); + + mc->numa_auto_assign_ram(mem, nb_nodes, size); + + for (i =3D 0; i < nb_nodes; i++) { + nodes[i].node_mem =3D mem[i]; + } + + g_free(mem); + + return; + } + + /* Align each node according to the alignment + * requirements of the machine class + */ + + for (i =3D 0; i < nb_nodes - 1; i++) { + nodes[i].node_mem =3D (size / nb_nodes) & + ~((1 << mc->numa_mem_align_shift) - 1); + usedmem +=3D nodes[i].node_mem; + } + nodes[i].node_mem =3D size - usedmem; +} + void parse_numa_opts(MachineClass *mc) { int i; @@ -336,17 +368,7 @@ void parse_numa_opts(MachineClass *mc) } } if (i =3D=3D nb_numa_nodes) { - uint64_t usedmem =3D 0; - - /* Align each node according to the alignment - * requirements of the machine class - */ - for (i =3D 0; i < nb_numa_nodes - 1; i++) { - numa_info[i].node_mem =3D (ram_size / nb_numa_nodes) & - ~((1 << mc->numa_mem_align_shift) = - 1); - usedmem +=3D numa_info[i].node_mem; - } - numa_info[i].node_mem =3D ram_size - usedmem; + numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size); } =20 numa_total =3D 0; --=20 2.9.3 From nobody Fri May 3 15:00:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1493288082579304.97890526844776; Thu, 27 Apr 2017 03:14:42 -0700 (PDT) Received: from localhost ([::1]:59767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3gRd-0006TS-84 for importer@patchew.org; Thu, 27 Apr 2017 06:14:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3gQ8-0005Zq-0X for qemu-devel@nongnu.org; Thu, 27 Apr 2017 06:13:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3gQ6-0008Rv-Ls for qemu-devel@nongnu.org; Thu, 27 Apr 2017 06:13:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59744) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3gQ6-0008R9-D1 for qemu-devel@nongnu.org; Thu, 27 Apr 2017 06:13:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C7B861D15; Thu, 27 Apr 2017 10:13:05 +0000 (UTC) Received: from thinkpad.redhat.com (unknown [10.36.118.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C7B689320; Thu, 27 Apr 2017 10:13:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6C7B861D15 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lvivier@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6C7B861D15 From: Laurent Vivier To: Eduardo Habkost Date: Thu, 27 Apr 2017 12:12:59 +0200 Message-Id: <20170427101259.13798-3-lvivier@redhat.com> In-Reply-To: <20170427101259.13798-1-lvivier@redhat.com> References: <20170427101259.13798-1-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 27 Apr 2017 10:13:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/2] numa, spapr: equally distribute memory on nodes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When there are more nodes than memory available to put the minimum allowed memory by node, all the memory is put on the last node. This is because we put (ram_size / nb_numa_nodes) & ~((1 << mc->numa_mem_align_shift) - 1); on each node, and in this case the value is 0. This is particularly true with pseries, as the memory must be aligned to 256MB. To avoid this problem, this patch uses an error diffusion algorithm [1] to distribute equally the memory on nodes. Example: qemu-system-ppc64 -S -nographic -nodefaults -monitor stdio -m 1G -smp 8 \ -numa node -numa node -numa node \ -numa node -numa node -numa node Before: (qemu) info numa 6 nodes node 0 cpus: 0 6 node 0 size: 0 MB node 1 cpus: 1 7 node 1 size: 0 MB node 2 cpus: 2 node 2 size: 0 MB node 3 cpus: 3 node 3 size: 0 MB node 4 cpus: 4 node 4 size: 0 MB node 5 cpus: 5 node 5 size: 1024 MB After: (qemu) info numa 6 nodes node 0 cpus: 0 6 node 0 size: 0 MB node 1 cpus: 1 7 node 1 size: 256 MB node 2 cpus: 2 node 2 size: 0 MB node 3 cpus: 3 node 3 size: 256 MB node 4 cpus: 4 node 4 size: 256 MB node 5 cpus: 5 node 5 size: 256 MB [1] https://en.wikipedia.org/wiki/Error_diffusion Signed-off-by: Laurent Vivier --- hw/ppc/spapr.c | 21 ++++++++++++++++++++- include/hw/ppc/spapr.h | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 80d12d0..be498e2 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3106,6 +3106,23 @@ static void spapr_pic_print_info(InterruptStatsProvi= der *obj, ics_pic_print_info(spapr->ics, mon); } =20 +static void spapr_numa_auto_assign_ram(uint64_t *nodes, int nb_nodes, + ram_addr_t size) +{ + int i; + uint64_t usedmem =3D 0, node_mem; + uint64_t granularity =3D size / nb_nodes; + uint64_t propagate =3D 0; + + for (i =3D 0; i < nb_nodes - 1; i++) { + node_mem =3D (granularity + propagate) & ~(SPAPR_MEMORY_BLOCK_SIZE= - 1); + propagate =3D granularity + propagate - node_mem; + nodes[i] =3D node_mem; + usedmem +=3D node_mem; + } + nodes[i] =3D ram_size - usedmem; +} + static void spapr_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -3162,7 +3179,8 @@ static void spapr_machine_class_init(ObjectClass *oc,= void *data) * SPAPR_MEMORY_BLOCK_SIZE (256M) since that's the granularity * in which LMBs are represented and hot-added */ - mc->numa_mem_align_shift =3D 28; + mc->numa_mem_align_shift =3D SPAPR_MEMORY_BLOCK_SIZE_SHIFT; + mc->numa_auto_assign_ram =3D spapr_numa_auto_assign_ram; } =20 static const TypeInfo spapr_machine_info =3D { @@ -3242,6 +3260,7 @@ static void spapr_machine_2_9_class_options(MachineCl= ass *mc) { spapr_machine_2_10_class_options(mc); SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_9); + mc->numa_auto_assign_ram =3D NULL; } =20 DEFINE_SPAPR_MACHINE(2_9, "2.9", false); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 5802f88..8f4a588 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -653,7 +653,8 @@ int spapr_rtc_import_offset(sPAPRRTCState *rtc, int64_t= legacy_offset); =20 int spapr_rng_populate_dt(void *fdt); =20 -#define SPAPR_MEMORY_BLOCK_SIZE (1 << 28) /* 256MB */ +#define SPAPR_MEMORY_BLOCK_SIZE_SHIFT 28 /* 256MB */ +#define SPAPR_MEMORY_BLOCK_SIZE (1 << SPAPR_MEMORY_BLOCK_SIZE_SHIFT) =20 /* * This defines the maximum number of DIMM slots we can have for sPAPR --=20 2.9.3