From patchwork Thu Jul 7 15:17:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Krempa X-Patchwork-Id: 9219119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DABF460574 for ; Thu, 7 Jul 2016 15:18:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAD1527F86 for ; Thu, 7 Jul 2016 15:18:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF9EB27F8C; Thu, 7 Jul 2016 15:18:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 65FA227F86 for ; Thu, 7 Jul 2016 15:18:00 +0000 (UTC) Received: from localhost ([::1]:40553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLB3v-0006x8-Kb for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Jul 2016 11:17:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLB3B-0006ja-8B for qemu-devel@nongnu.org; Thu, 07 Jul 2016 11:17:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bLB37-0005T3-3k for qemu-devel@nongnu.org; Thu, 07 Jul 2016 11:17:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34455) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLB36-0005Sw-SH for qemu-devel@nongnu.org; Thu, 07 Jul 2016 11:17:09 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8746A80085 for ; Thu, 7 Jul 2016 15:17:08 +0000 (UTC) Received: from angien.brq.redhat.com (dhcp129-133.brq.redhat.com [10.34.129.133]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u67FH4ZF002169; Thu, 7 Jul 2016 11:17:07 -0400 From: Peter Krempa To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2016 17:17:14 +0200 Message-Id: <417b83d0e074e2004aa35bef337d32ac2c89f559.1467904342.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 07 Jul 2016 15:17:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 2/2] numa: Add node_id data in query-hotpluggable-cpus 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: dgibson@redhat.com, Peter Krempa , imammedo@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a helper that looks up the NUMA node for a given CPU and use it to fill the node_id in the PPC and X86 impls of query-hotpluggable-cpus. Signed-off-by: Peter Krempa --- hw/i386/pc.c | 7 +++++++ hw/ppc/spapr.c | 8 ++++++-- include/sysemu/numa.h | 1 + numa.c | 13 +++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4ba02c4..a0b9507 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2115,6 +2115,7 @@ static HotpluggableCPUList *pc_query_hotpluggable_cpus(MachineState *machine) HotpluggableCPUList *head = NULL; PCMachineState *pcms = PC_MACHINE(machine); const char *cpu_type; + int node_id; cpu = pcms->possible_cpus->cpus[0].cpu; assert(cpu); /* BSP is always present */ @@ -2138,6 +2139,12 @@ static HotpluggableCPUList *pc_query_hotpluggable_cpus(MachineState *machine) cpu_props->core_id = topo.core_id; cpu_props->has_thread_id = true; cpu_props->thread_id = topo.smt_id; + + if ((node_id = numa_node_get_by_cpu_index(i)) >= 0) { + cpu_props->has_node_id = true; + cpu_props->node_id = node_id; + } + cpu_item->props = cpu_props; cpu = pcms->possible_cpus->cpus[i].cpu; diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index d1f5195..06ba7fc 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2370,6 +2370,7 @@ static HotpluggableCPUList *spapr_query_hotpluggable_cpus(MachineState *machine) sPAPRMachineState *spapr = SPAPR_MACHINE(machine); int spapr_max_cores = max_cpus / smp_threads; int smt = kvmppc_smt_threads(); + int node_id; for (i = 0; i < spapr_max_cores; i++) { HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1); @@ -2381,8 +2382,11 @@ static HotpluggableCPUList *spapr_query_hotpluggable_cpus(MachineState *machine) cpu_item->vcpu_id = i; cpu_props->has_core_id = true; cpu_props->core_id = i * smt; - /* TODO: add 'has_node/node' here to describe - to which node core belongs */ + + if ((node_id = numa_node_get_by_cpu_index(i)) >= 0) { + cpu_props->has_node_id = true; + cpu_props->node_id = node_id; + } cpu_item->props = cpu_props; if (spapr->cores[i]) { diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h index bb184c9..04d7097 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -31,5 +31,6 @@ extern QemuOptsList qemu_numa_opts; void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node); void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node); uint32_t numa_get_node(ram_addr_t addr, Error **errp); +int numa_node_get_by_cpu_index(int cpu_index); #endif diff --git a/numa.c b/numa.c index cbae430..365738a 100644 --- a/numa.c +++ b/numa.c @@ -506,6 +506,19 @@ void query_numa_node_mem(uint64_t node_mem[]) } } +int numa_node_get_by_cpu_index(int cpu_index) +{ + int i; + + for (i = 0; i < nb_numa_nodes; i++) { + if (test_bit(cpu_index, numa_info[i].node_cpu)) { + return i; + } + } + + return -1; +} + static int query_memdev(Object *obj, void *opaque) { MemdevList **list = opaque;