From nobody Wed Oct 23 00:25:22 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=1726725472; cv=none; d=zohomail.com; s=zohoarc; b=Qpy/5bauGP5O4Ue6ZhREHGVovQPKAyCZS7G0XuvzxnYFNyiiH6TbTWCVYWoNhcJQKt32sczHxi8/hlkyQxA7v2B0lPecjhSxz+rt/z2cPf75iZp07pk4z+975AeMf3YoYyFwR4gsZ/EdGvU1j4WnUhQBgvX/E5H6+Zynbmc4wSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726725472; 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=CC4mPbdPv35OyEY+fYAEHmj6/eb5tP0mYjktEkFnOyw=; b=Cp27J9cWLi4CkPcGhMUfE6QMnNt7Z0EmubHf5tzQsMm3QogqeL/eSRST8+SIf7InQyg6KYft0rcSdaJX4zkr76KHO5i6htv63NZfPA7+lxZ/PuP9pXc5tTrl6ygZfSrYxVGAXqyyXaKIlAz1ofnvBPMqnfdW4rFqja9euOX5o5Q= 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 1726725472348167.6315300837491; Wed, 18 Sep 2024 22:57:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srA9k-0001de-0r; Thu, 19 Sep 2024 01:56:44 -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 1srA9L-0007Hq-TN; Thu, 19 Sep 2024 01:56:21 -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 1srA9I-0007Oq-Kw; Thu, 19 Sep 2024 01:56:18 -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:14 -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:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726725377; x=1758261377; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NEuBE48juMTcQ/dJZHqJkRWuT1BVDd+3siUk37y9rsM=; b=DRNRvqMQTNE3O3IwDeJJcblYC/f99+LaLlNpNqinxDNAMmheAyC6r/bs +qXs68DSsp2Czvr3V/LSb/w+RQlpbWN6ukQeBJ7kw0kw1TqisIEmqfpxb 6NF3aI43zgopRTvhd41DsNelAgAmZbqHbEYTB6s9zldXJl75qFybdpQh+ K8XrckbiLemy83IRzZ4lrPGw7xiRfBy5tMI7G/ilcP2SYKP8H2B0ELam/ aIetsNFFeN5uCNrh3DZgJFQ7ZmmvIB5YIzKLq7yjacGAdMj9vMuDOL8S6 cTR7r108qzOCcjot0sQPU+enxWBDFHSrR1ySgnwgHgTZ/NvouWWpvwiTT A==; X-CSE-ConnectionGUID: LzdMyRNRQiC9btrEmAi6eg== X-CSE-MsgGUID: NjSE/fQUSrqTZJfpMm4/qg== X-IronPort-AV: E=McAfee;i="6700,10204,11199"; a="25813638" X-IronPort-AV: E=Sophos;i="6.10,240,1719903600"; d="scan'208";a="25813638" X-CSE-ConnectionGUID: uRrDVkRIRWuVWkVS9YAxng== X-CSE-MsgGUID: NLGU4weHTJKIgFAW97vQLw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,240,1719903600"; d="scan'208";a="69418749" 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 07/12] hw/core: Re-implement topology helpers to honor max limitations Date: Thu, 19 Sep 2024 14:11:23 +0800 Message-Id: <20240919061128.769139-8-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: 1726725474451116600 Content-Type: text/plain; charset="utf-8" For custom topology case, the valid and reliable topology information be obtained from topology max limitations. Therefore, re-implement machine_topo_get_cores_per_socket() and machine_topo_get_threads_per_socket() to consider the custom topology case. And further, use the wrapped helper to set CPUState.nr_threads/ nr_cores, avoiding topology mismatches in custom topology scenarios. Additionally, since test-smp-parse needs more stubs to compile with cpu-slot.c, keep the old helpers for test-smp-parse' use for now. The legacy old helpers will be cleaned up when full compilation support is added later on. Signed-off-by: Zhao Liu --- hw/core/machine-smp.c | 8 +++++--- hw/cpu/cpu-slot.c | 18 ++++++++++++++++++ include/hw/boards.h | 9 +++++++-- include/hw/cpu/cpu-slot.h | 2 ++ system/cpus.c | 2 +- tests/unit/test-smp-parse.c | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index d3be4352267d..2965b042fd92 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -376,14 +376,16 @@ bool machine_parse_smp_cache(MachineState *ms, return true; } =20 -unsigned int machine_topo_get_cores_per_socket(const MachineState *ms) +unsigned int machine_topo_get_cores_per_socket_old(const MachineState *ms) { + assert(!ms->topo); return ms->smp.cores * ms->smp.modules * ms->smp.clusters * ms->smp.di= es; } =20 -unsigned int machine_topo_get_threads_per_socket(const MachineState *ms) +unsigned int machine_topo_get_threads_per_socket_old(const MachineState *m= s) { - return ms->smp.threads * machine_topo_get_cores_per_socket(ms); + assert(!ms->topo); + return ms->smp.threads * machine_topo_get_cores_per_socket_old(ms); } =20 CpuTopologyLevel machine_get_cache_topo_level(const MachineState *ms, diff --git a/hw/cpu/cpu-slot.c b/hw/cpu/cpu-slot.c index f2b9c412926f..8c0d55e835e2 100644 --- a/hw/cpu/cpu-slot.c +++ b/hw/cpu/cpu-slot.c @@ -204,6 +204,8 @@ static int get_smp_info_by_level(const CpuTopology *smp= _info, return smp_info->cores; case CPU_TOPOLOGY_LEVEL_MODULE: return smp_info->modules; + case CPU_TOPOLOGY_LEVEL_CLUSTER: + return smp_info->clusters; case CPU_TOPOLOGY_LEVEL_DIE: return smp_info->dies; case CPU_TOPOLOGY_LEVEL_SOCKET: @@ -356,6 +358,22 @@ int get_max_topo_by_level(const MachineState *ms, CpuT= opologyLevel level) return ms->topo->stat.entries[level].max_limit; } =20 +unsigned int machine_topo_get_cores_per_socket(const MachineState *ms) +{ + int cores =3D 1, i; + + for (i =3D CPU_TOPOLOGY_LEVEL_CORE; i < CPU_TOPOLOGY_LEVEL_SOCKET; i++= ) { + cores *=3D get_max_topo_by_level(ms, i); + } + return cores; +} + +unsigned int machine_topo_get_threads_per_socket(const MachineState *ms) +{ + return get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_THREAD) * + machine_topo_get_cores_per_socket(ms); +} + bool machine_parse_custom_topo_config(MachineState *ms, const SMPConfiguration *config, Error **errp) diff --git a/include/hw/boards.h b/include/hw/boards.h index 6ef4ea322590..faf7859debdd 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -48,8 +48,13 @@ void machine_parse_smp_config(MachineState *ms, bool machine_parse_smp_cache(MachineState *ms, const SmpCachePropertiesList *caches, Error **errp); -unsigned int machine_topo_get_cores_per_socket(const MachineState *ms); -unsigned int machine_topo_get_threads_per_socket(const MachineState *ms); +/* + * TODO: Drop these old helpers when cpu-slot.c could be compiled for + * test-smp-parse. Pls use machine_topo_get_cores_per_socket() and + * machine_topo_get_threads_per_socket() instead. + */ +unsigned int machine_topo_get_cores_per_socket_old(const MachineState *ms); +unsigned int machine_topo_get_threads_per_socket_old(const MachineState *m= s); CpuTopologyLevel machine_get_cache_topo_level(const MachineState *ms, CacheLevelAndType cache); void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t s= ize); diff --git a/include/hw/cpu/cpu-slot.h b/include/hw/cpu/cpu-slot.h index f56a0b08dca4..230309b67fe1 100644 --- a/include/hw/cpu/cpu-slot.h +++ b/include/hw/cpu/cpu-slot.h @@ -81,6 +81,8 @@ struct CPUSlot { void machine_plug_cpu_slot(MachineState *ms); bool machine_create_topo_tree(MachineState *ms, Error **errp); int get_max_topo_by_level(const MachineState *ms, CpuTopologyLevel level); +unsigned int machine_topo_get_cores_per_socket(const MachineState *ms); +unsigned int machine_topo_get_threads_per_socket(const MachineState *ms); bool machine_parse_custom_topo_config(MachineState *ms, const SMPConfiguration *config, Error **errp); diff --git a/system/cpus.c b/system/cpus.c index 1c818ff6828c..53e7cfb8a55f 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -667,7 +667,7 @@ void qemu_init_vcpu(CPUState *cpu) MachineState *ms =3D MACHINE(qdev_get_machine()); =20 cpu->nr_cores =3D machine_topo_get_cores_per_socket(ms); - cpu->nr_threads =3D ms->smp.threads; + cpu->nr_threads =3D get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_THREA= D); cpu->stopped =3D true; cpu->random_seed =3D qemu_guest_random_seed_thread_part1(); =20 diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c index f9bccb56abc7..44d2213a7163 100644 --- a/tests/unit/test-smp-parse.c +++ b/tests/unit/test-smp-parse.c @@ -801,8 +801,8 @@ static void check_parse(MachineState *ms, const SMPConf= iguration *config, /* call the generic parser */ machine_parse_smp_config(ms, config, &err); =20 - ms_threads_per_socket =3D machine_topo_get_threads_per_socket(ms); - ms_cores_per_socket =3D machine_topo_get_cores_per_socket(ms); + ms_threads_per_socket =3D machine_topo_get_threads_per_socket_old(ms); + ms_cores_per_socket =3D machine_topo_get_cores_per_socket_old(ms); output_topo_str =3D cpu_topology_to_string(&ms->smp, ms_threads_per_socket, ms_cores_per_socket, --=20 2.34.1