From nobody Wed Oct 23 00:28:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1726725413; cv=none; d=zohomail.com; s=zohoarc; b=fEINvNIw8y4QIWPc22O3wwElbiyVlH4loBlw2YA09/ioQ4ESLEPlWF4jZEvp/RjQ4a//QFnd1BaXT23L8prx0tThcg8ZKUfHmsoorBJBAwWW3hSyOp1W/9AN0jRmIHY7lulK4sgqAKkaK5nDeXlMMvSP0HcQxZaZzyrgcYzdDTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726725413; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+LWrLtjR+PxUgTxvAPD8gfuwSJ1qwj4rPrv/G+NV0mw=; b=fSh3N+nj6xkwM17HoICyx9araX2upeMFbF3DDLQR1+uRcgvURn5eNPT9eQ00tHlVVyS+2eRHGs0iksRGhx5xLFcDLeoPSytuvqk7J+5uGoAKgReVvqA2He1OY3czTt8vIkJP5ETVoTK+j3jsBVP6Esz9ziJMGTux+syxhn9/MzE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726725413383512.5795336407288; Wed, 18 Sep 2024 22:56:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srA9n-0002Fx-1E; Thu, 19 Sep 2024 01:56:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srA9Q-0007dY-1N; Thu, 19 Sep 2024 01:56:27 -0400 Received: from mgamail.intel.com ([192.198.163.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srA9N-0007Oq-V7; Thu, 19 Sep 2024 01:56:23 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2024 22:56:20 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa006.fm.intel.com with ESMTP; 18 Sep 2024 22:56:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726725382; x=1758261382; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=swUKe7Dk5Q6yJ5VJiLcmgO4PNjWAtrL0i/B6l+A1Xbk=; b=PCTomY9s02qTh2irRjUlZtOAs0KmV94xFPUJZmAQwjbtxHYziWOXmkr+ XsGU32kuV4piwtik0NW0U45joOaklIRSdtdTHtq/E7sjRdcxtExuan1N6 dDbOJShM9uyNfPLkhjNw38xrJCMaumtQZxDS6/S3mBANFxYNMsFL7MfTx swmgEmIHuUZGSiwZ5/Cj8VdcI9Rp6yPUVYuu73GJBcvGxcZFN2ByB6bu3 61mmwNnc15T06wC7WtSMaFClnCmfb9pMTyyYUHzWEdlwhCIHjlJOWd4Hr UeWCuKCKA7vwIi4pPqmWs9Kn1ICE8j78lLxy0MveV5lv0Du7YfAmOwvgB w==; X-CSE-ConnectionGUID: yQTJvgCVTyumXg8iz06Biw== X-CSE-MsgGUID: vXVJ8n8KRg6JHpnYBs4KFQ== X-IronPort-AV: E=McAfee;i="6700,10204,11199"; a="25813668" X-IronPort-AV: E=Sophos;i="6.10,240,1719903600"; d="scan'208";a="25813668" X-CSE-ConnectionGUID: 0tIfENWWT32Xu6SDNpEnXA== X-CSE-MsgGUID: OO4hh/zZRMaI4/Pt2zCRAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,240,1719903600"; d="scan'208";a="69418778" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Sergio Lopez , Jason Wang , Stefano Stabellini , Anthony PERARD , Paul Durrant , "Edgar E . Iglesias" , Eric Blake , Markus Armbruster , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC v2 08/12] hw/i386: Use get_max_topo_by_level() to get topology information Date: Thu, 19 Sep 2024 14:11:24 +0800 Message-Id: <20240919061128.769139-9-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919061128.769139-1-zhao1.liu@intel.com> References: <20240919061128.769139-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.15; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1726725414121116600 Content-Type: text/plain; charset="utf-8" To honor the custom topology case and generate correct APIC ID for hybrid CPU topology, Use get_max_topo_by_level() to get topology information instead of accessing MachineState.smp directly. Signed-off-by: Zhao Liu --- hw/i386/x86-common.c | 19 +++++++++++++------ hw/i386/x86.c | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c index 75d4b2f3d43a..58591e015569 100644 --- a/hw/i386/x86-common.c +++ b/hw/i386/x86-common.c @@ -202,11 +202,15 @@ void x86_cpus_init(X86MachineState *x86ms, int defaul= t_cpu_version) =20 static void x86_fixup_topo_ids(MachineState *ms, X86CPU *cpu) { + int max_modules, max_dies; + + max_modules =3D get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE); + max_dies =3D get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE); /* * die-id was optional in QEMU 4.0 and older, so keep it optional * if there's only one die per socket. */ - if (cpu->module_id < 0 && ms->smp.modules =3D=3D 1) { + if (cpu->module_id < 0 && max_modules =3D=3D 1) { cpu->module_id =3D 0; } =20 @@ -214,7 +218,7 @@ static void x86_fixup_topo_ids(MachineState *ms, X86CPU= *cpu) * module-id was optional in QEMU 9.0 and older, so keep it optional * if there's only one module per die. */ - if (cpu->die_id < 0 && ms->smp.dies =3D=3D 1) { + if (cpu->die_id < 0 && max_dies =3D=3D 1) { cpu->die_id =3D 0; } } @@ -393,6 +397,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, MachineState *ms =3D MACHINE(hotplug_dev); X86MachineState *x86ms =3D X86_MACHINE(hotplug_dev); X86CPUTopoInfo topo_info; + int max_modules, max_dies; =20 if (!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) { error_setg(errp, "Invalid CPU type, expected cpu type: '%s'", @@ -413,13 +418,15 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, =20 init_topo_info(&topo_info, x86ms); =20 - if (ms->smp.modules > 1) { - env->nr_modules =3D ms->smp.modules; + max_modules =3D get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE); + if (max_modules > 1) { + env->nr_modules =3D max_modules; set_bit(CPU_TOPOLOGY_LEVEL_MODULE, env->avail_cpu_topo); } =20 - if (ms->smp.dies > 1) { - env->nr_dies =3D ms->smp.dies; + max_dies =3D get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE); + if (max_dies > 1) { + env->nr_dies =3D max_dies; set_bit(CPU_TOPOLOGY_LEVEL_DIE, env->avail_cpu_topo); } =20 diff --git a/hw/i386/x86.c b/hw/i386/x86.c index cdf7b81ad0e3..55904b545d84 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -44,16 +44,20 @@ void init_topo_info(X86CPUTopoInfo *topo_info, { MachineState *ms =3D MACHINE(x86ms); =20 - topo_info->dies_per_pkg =3D ms->smp.dies; + topo_info->dies_per_pkg =3D + get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE); /* * Though smp.modules means the number of modules in one cluster, * i386 doesn't support cluster level so that the smp.clusters * always defaults to 1, therefore using smp.modules directly is * fine here. */ - topo_info->modules_per_die =3D ms->smp.modules; - topo_info->cores_per_module =3D ms->smp.cores; - topo_info->threads_per_core =3D ms->smp.threads; + topo_info->modules_per_die =3D + get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE); + topo_info->cores_per_module =3D + get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_CORE); + topo_info->threads_per_core =3D + get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_THREAD); } =20 /* @@ -103,7 +107,7 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids(M= achineState *ms) X86MachineState *x86ms =3D X86_MACHINE(ms); unsigned int max_cpus =3D ms->smp.max_cpus; X86CPUTopoInfo topo_info; - int i; + int i, max_dies, max_modules; =20 if (ms->possible_cpus) { /* @@ -120,6 +124,8 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids(M= achineState *ms) =20 init_topo_info(&topo_info, x86ms); =20 + max_dies =3D get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE); + max_modules =3D get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE); for (i =3D 0; i < ms->possible_cpus->len; i++) { X86CPUTopoIDs topo_ids; =20 @@ -131,11 +137,11 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids= (MachineState *ms) &topo_info, &topo_ids); ms->possible_cpus->cpus[i].props.has_socket_id =3D true; ms->possible_cpus->cpus[i].props.socket_id =3D topo_ids.pkg_id; - if (ms->smp.dies > 1) { + if (max_dies > 1) { ms->possible_cpus->cpus[i].props.has_die_id =3D true; ms->possible_cpus->cpus[i].props.die_id =3D topo_ids.die_id; } - if (ms->smp.modules > 1) { + if (max_modules > 1) { ms->possible_cpus->cpus[i].props.has_module_id =3D true; ms->possible_cpus->cpus[i].props.module_id =3D topo_ids.module= _id; } --=20 2.34.1