From nobody Mon Feb 9 11:29:34 2026 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529965844941417.3187803629793; Mon, 25 Jun 2018 15:30:44 -0700 (PDT) Received: from localhost ([::1]:49526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXa0S-0005Qv-5Q for importer@patchew.org; Mon, 25 Jun 2018 18:30:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXZvh-0001u8-SQ for qemu-devel@nongnu.org; Mon, 25 Jun 2018 18:25:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXZvf-0003IM-Om for qemu-devel@nongnu.org; Mon, 25 Jun 2018 18:25:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXZvf-0003Hi-Fp for qemu-devel@nongnu.org; Mon, 25 Jun 2018 18:25:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1352344515; Mon, 25 Jun 2018 22:25:46 +0000 (UTC) Received: from localhost (ovpn-116-16.gru2.redhat.com [10.97.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EB677FD57; Mon, 25 Jun 2018 22:25:46 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org Date: Mon, 25 Jun 2018 19:25:22 -0300 Message-Id: <20180625222524.382-11-ehabkost@redhat.com> In-Reply-To: <20180625222524.382-1-ehabkost@redhat.com> References: <20180625222524.382-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 25 Jun 2018 22:25:46 +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] [PULL 10/12] i386: Fix up the Node id for CPUID_8000_001E 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: Paolo Bonzini , Babu Moger , Richard Henderson 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" From: Babu Moger This is part of topoext support. To keep the compatibility, it is better we support all the combination of nr_cores and nr_threads currently supported. By allowing more nr_cores and nr_threads, we might end up with more nodes than we can actually support with the real hardware. We need to fix up the node id to make this work. We can achieve this by shifting the socket_id bits left to address more nodes. Signed-off-by: Babu Moger Message-Id: <1529443919-67509-2-git-send-email-babu.moger@amd.com> Reviewed-by: Eduardo Habkost Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7a4484bb06..130391c840 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -19,6 +19,7 @@ =20 #include "qemu/osdep.h" #include "qemu/cutils.h" +#include "qemu/bitops.h" =20 #include "cpu.h" #include "exec/exec-all.h" @@ -472,6 +473,8 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86= CPU *cpu, uint32_t *ecx, uint32_t *edx) { struct core_topology topo =3D {0}; + unsigned long nodes; + int shift; =20 build_core_topology(cs->nr_cores, cpu->core_id, &topo); *eax =3D cpu->apic_id; @@ -504,7 +507,28 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X8= 6CPU *cpu, * 2 Socket id * 1:0 Node id */ - *ecx =3D ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | topo.no= de_id; + if (topo.num_nodes <=3D 4) { + *ecx =3D ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | + topo.node_id; + } else { + /* + * Node id fix up. Actual hardware supports up to 4 nodes. But with + * more than 32 cores, we may end up with more than 4 nodes. + * Node id is a combination of socket id and node id. Only require= ment + * here is that this number should be unique accross the system. + * Shift the socket id to accommodate more nodes. We dont expect b= oth + * socket id and node id to be big number at the same time. This i= s not + * an ideal config but we need to to support it. Max nodes we can = have + * is 32 (255/8) with 8 cores per node and 255 max cores. We only = need + * 5 bits for nodes. Find the left most set bit to represent the t= otal + * number of nodes. find_last_bit returns last set bit(0 based). L= eft + * shift(+1) the socket id to represent all the nodes. + */ + nodes =3D topo.num_nodes - 1; + shift =3D find_last_bit(&nodes, 8); + *ecx =3D ((topo.num_nodes - 1) << 8) | (cpu->socket_id << (shift += 1)) | + topo.node_id; + } *edx =3D 0; } =20 --=20 2.18.0.rc1.1.g3f1ff2140