From patchwork Thu Apr 27 10:12:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 755945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wDCWy686Cz9sNJ for ; Thu, 27 Apr 2017 20:15:58 +1000 (AEST) Received: from localhost ([::1]:59777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3gSp-0007Ju-9O for incoming@patchwork.ozlabs.org; Thu, 27 Apr 2017 06:15:55 -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) 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 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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); 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); } +static void numa_auto_assign_ram(MachineClass *mc, NodeInfo *nodes, + int nb_nodes, ram_addr_t size) +{ + int i; + uint64_t usedmem = 0; + + if (mc->numa_auto_assign_ram) { + uint64_t *mem = g_new(uint64_t, nb_nodes); + + mc->numa_auto_assign_ram(mem, nb_nodes, size); + + for (i = 0; i < nb_nodes; i++) { + nodes[i].node_mem = mem[i]; + } + + g_free(mem); + + return; + } + + /* Align each node according to the alignment + * requirements of the machine class + */ + + for (i = 0; i < nb_nodes - 1; i++) { + nodes[i].node_mem = (size / nb_nodes) & + ~((1 << mc->numa_mem_align_shift) - 1); + usedmem += nodes[i].node_mem; + } + nodes[i].node_mem = size - usedmem; +} + void parse_numa_opts(MachineClass *mc) { int i; @@ -336,17 +368,7 @@ void parse_numa_opts(MachineClass *mc) } } if (i == nb_numa_nodes) { - uint64_t usedmem = 0; - - /* Align each node according to the alignment - * requirements of the machine class - */ - for (i = 0; i < nb_numa_nodes - 1; i++) { - numa_info[i].node_mem = (ram_size / nb_numa_nodes) & - ~((1 << mc->numa_mem_align_shift) - 1); - usedmem += numa_info[i].node_mem; - } - numa_info[i].node_mem = ram_size - usedmem; + numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size); } numa_total = 0;