From patchwork Tue Feb 12 21:48:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1040881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43zc5W3pPGz9sCh for ; Wed, 13 Feb 2019 08:59:59 +1100 (AEDT) Received: from localhost ([127.0.0.1]:46741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtg5t-0003Tn-GI for incoming@patchwork.ozlabs.org; Tue, 12 Feb 2019 16:59:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43573) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtg40-0002OC-EY for qemu-devel@nongnu.org; Tue, 12 Feb 2019 16:58:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtg3y-0007KN-S9 for qemu-devel@nongnu.org; Tue, 12 Feb 2019 16:58:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53684) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtg3y-00074i-Jq for qemu-devel@nongnu.org; Tue, 12 Feb 2019 16:57:58 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4E6DC0BEAA6; Tue, 12 Feb 2019 21:48:44 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-204-62.brq.redhat.com [10.40.204.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCE5410018F9; Tue, 12 Feb 2019 21:48:40 +0000 (UTC) From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 12 Feb 2019 22:48:27 +0100 Message-Id: <20190212214827.30543-5-lvivier@redhat.com> In-Reply-To: <20190212214827.30543-1-lvivier@redhat.com> References: <20190212214827.30543-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 12 Feb 2019 21:48:45 +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 4/4] numa: check threads of the same core are on the same node 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 , Eduardo Habkost , qemu-ppc@nongnu.org, Igor Mammedov , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" A core cannot be split between two nodes. To check if a thread of the same core has already been assigned to a node, this patch reverses the numa topology checking order and exits if the topology is not valid. Update test/numa-test accordingly. Fixes: 722387e78daf ("spapr: get numa node mapping from possible_cpus instead of numa_get_node_for_cpu()") Cc: imammedo@redhat.com Signed-off-by: Laurent Vivier --- hw/core/machine.c | 27 ++++++++++++++++++++++++--- tests/numa-test.c | 4 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index a2c29692b55e..c0a556b0dce7 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -602,6 +602,7 @@ void machine_set_cpu_numa_node(MachineState *machine, MachineClass *mc = MACHINE_GET_CLASS(machine); bool match = false; int i; + const CpuInstanceProperties *previous_props = NULL; if (!mc->possible_cpu_arch_ids) { error_setg(errp, "mapping of CPUs to NUMA node is not supported"); @@ -634,18 +635,38 @@ void machine_set_cpu_numa_node(MachineState *machine, } /* skip slots with explicit mismatch */ - if (props->has_thread_id && props->thread_id != slot->props.thread_id) { + if (props->has_socket_id && props->socket_id != slot->props.socket_id) { continue; } - if (props->has_core_id && props->core_id != slot->props.core_id) { + if (props->has_core_id) { + if (props->core_id != slot->props.core_id) { continue; + } + if (slot->props.has_node_id) { + /* we have a node where our core is already assigned */ + previous_props = &slot->props; + } } - if (props->has_socket_id && props->socket_id != slot->props.socket_id) { + if (props->has_thread_id && props->thread_id != slot->props.thread_id) { continue; } + /* check current thread matches node of the thread of the same core */ + if (previous_props && previous_props->has_node_id && + previous_props->node_id != props->node_id) { + char *cpu_str = cpu_props_to_string(props); + char *node_str = cpu_props_to_string(previous_props); + error_setg(errp, "Invalid node-id=%"PRIu64" of [%s]: core-id " + "[%s] is already assigned to node-id %"PRIu64, + props->node_id, cpu_str, + node_str, previous_props->node_id); + g_free(cpu_str); + g_free(node_str); + return; + } + /* reject assignment if slot is already assigned, for compatibility * of legacy cpu_index mapping with SPAPR core based mapping do not * error out if cpu thread and matched core have the same node-id */ diff --git a/tests/numa-test.c b/tests/numa-test.c index 5280573fc992..a7c3c5b4dee8 100644 --- a/tests/numa-test.c +++ b/tests/numa-test.c @@ -112,7 +112,7 @@ static void pc_numa_cpu(const void *data) "-numa cpu,node-id=1,socket-id=0 " "-numa cpu,node-id=0,socket-id=1,core-id=0 " "-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=0 " - "-numa cpu,node-id=1,socket-id=1,core-id=1,thread-id=1"); + "-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=1"); qtest_start(cli); cpus = get_cpus(&resp); g_assert(cpus); @@ -141,7 +141,7 @@ static void pc_numa_cpu(const void *data) } else if (socket == 1 && core == 1 && thread == 0) { g_assert_cmpint(node, ==, 0); } else if (socket == 1 && core == 1 && thread == 1) { - g_assert_cmpint(node, ==, 1); + g_assert_cmpint(node, ==, 0); } else { g_assert(false); }