From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420365; cv=none; d=zohomail.com; s=zohoarc; b=bFzMxQ09HJpEw2ZZaS/Q8Pjp815HcNElPQTCHFSvzqpAPE+/4dAnul1E+XlqHpuaKWjfGmptZzfyYkv3FxRmUYP3p0rPp+s1Usw+WjX5S/jcfzfwPkZDpGuGja9gzV3DyXuYgVQeNt1frCfaAZYoZMRFZ1vQgCHVDwQ1MLpAW9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420365; 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=fX/ovjyGqpZ77jDPMaGP9R2s47Hh/ie90qAXMY/eHKU=; b=ZC12I0kI4usSZknfat2qCdItglO7NtdJZr8se+GWIwbjavEIpu0If9VSqPe0RPbuYopSrs5wmCVd5SNx5DatTv2Jt0TiysaGka0qZeCfrRqvn2c+Z7zYRzPSiqAG1GMvHvrKbB7iRb1fGzOUMZZ76gSod9RG7zVrrD+3FNfTGlI= 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 1708420365763348.2326662096659; Tue, 20 Feb 2024 01:12:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMAP-0000gQ-2O; Tue, 20 Feb 2024 04:11:57 -0500 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 1rcMAM-0000ex-HF; Tue, 20 Feb 2024 04:11:54 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAK-0003Km-NL; Tue, 20 Feb 2024 04:11:54 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:11:50 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:11:45 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420313; x=1739956313; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f72SFWwq+PohiF2H5sIw0CnPQG3e0SkCa+ntNndt4BU=; b=CYFkUtdvqtkF2iTN5WRcDRgTEmqz7XZYy/SWLfZRQjqA8ppNbSJlWd1v Dj2tkOopIy92IftTwS1XW4crgriEmS2ZGancmZHFiE42GFLB5mAXHCSUU kVip0229cjiCAdv0bSz87roOz4NgOK0oG8DC4NtJ33C+H3UJXYNcFm61Y 0WmIVxuh2wgeJg/Us2hzP9405z1CmAyJG/+XlAUs3s1Ac8B4voBDIH8Nn o4la0iWk+xcbSLZwyDWQA5sh6xTkOarv9ravPiLQ2wAc6BJ1a0D5MC0Fp L7oZmQXOESMiOSEez08dksSt/SExsbPi1d6JjF4W2yraF0hiu/wU2rWHE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2374958" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2374958" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5012851" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 1/8] hw/core: Rename CpuTopology to CPUTopology Date: Tue, 20 Feb 2024 17:24:57 +0800 Message-Id: <20240220092504.726064-2-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420367710100011 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Use CPUTopology to honor the generic style of CPU capitalization abbreviations. Signed-off-by: Zhao Liu --- hw/s390x/cpu-topology.c | 6 +++--- include/hw/boards.h | 8 ++++---- include/hw/s390x/cpu-topology.h | 6 +++--- tests/unit/test-smp-parse.c | 14 +++++++------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/hw/s390x/cpu-topology.c b/hw/s390x/cpu-topology.c index f16bdf65faa0..016f6c1c15ac 100644 --- a/hw/s390x/cpu-topology.c +++ b/hw/s390x/cpu-topology.c @@ -86,7 +86,7 @@ bool s390_has_topology(void) */ static void s390_topology_init(MachineState *ms) { - CpuTopology *smp =3D &ms->smp; + CPUTopology *smp =3D &ms->smp; =20 s390_topology.cores_per_socket =3D g_new0(uint8_t, smp->sockets * smp->books * smp->drawers); @@ -181,7 +181,7 @@ void s390_topology_reset(void) */ static bool s390_topology_cpu_default(S390CPU *cpu, Error **errp) { - CpuTopology *smp =3D ¤t_machine->smp; + CPUTopology *smp =3D ¤t_machine->smp; CPUS390XState *env =3D &cpu->env; =20 /* All geometry topology attributes must be set or all unset */ @@ -234,7 +234,7 @@ static bool s390_topology_check(uint16_t socket_id, uin= t16_t book_id, uint16_t drawer_id, uint16_t entitlement, bool dedicated, Error **errp) { - CpuTopology *smp =3D ¤t_machine->smp; + CPUTopology *smp =3D ¤t_machine->smp; =20 if (socket_id >=3D smp->sockets) { error_setg(errp, "Unavailable socket: %d", socket_id); diff --git a/include/hw/boards.h b/include/hw/boards.h index 78dea50054a1..e63dec919da2 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -333,7 +333,7 @@ typedef struct DeviceMemoryState { } DeviceMemoryState; =20 /** - * CpuTopology: + * CPUTopology: * @cpus: the number of present logical processors on the machine * @drawers: the number of drawers on the machine * @books: the number of books in one drawer @@ -345,7 +345,7 @@ typedef struct DeviceMemoryState { * @threads: the number of threads in one core * @max_cpus: the maximum number of logical processors on the machine */ -typedef struct CpuTopology { +typedef struct CPUTopology { unsigned int cpus; unsigned int drawers; unsigned int books; @@ -356,7 +356,7 @@ typedef struct CpuTopology { unsigned int cores; unsigned int threads; unsigned int max_cpus; -} CpuTopology; +} CPUTopology; =20 /** * MachineState: @@ -407,7 +407,7 @@ struct MachineState { const char *cpu_type; AccelState *accelerator; CPUArchIdList *possible_cpus; - CpuTopology smp; + CPUTopology smp; struct NVDIMMState *nvdimms_state; struct NumaState *numa_state; }; diff --git a/include/hw/s390x/cpu-topology.h b/include/hw/s390x/cpu-topolog= y.h index c064f427e948..ff09c57a4428 100644 --- a/include/hw/s390x/cpu-topology.h +++ b/include/hw/s390x/cpu-topology.h @@ -63,17 +63,17 @@ static inline void s390_topology_reset(void) =20 extern S390Topology s390_topology; =20 -static inline int s390_std_socket(int n, CpuTopology *smp) +static inline int s390_std_socket(int n, CPUTopology *smp) { return (n / smp->cores) % smp->sockets; } =20 -static inline int s390_std_book(int n, CpuTopology *smp) +static inline int s390_std_book(int n, CPUTopology *smp) { return (n / (smp->cores * smp->sockets)) % smp->books; } =20 -static inline int s390_std_drawer(int n, CpuTopology *smp) +static inline int s390_std_drawer(int n, CPUTopology *smp) { return (n / (smp->cores * smp->sockets * smp->books)) % smp->drawers; } diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c index 24972666a74d..f660d6b0df45 100644 --- a/tests/unit/test-smp-parse.c +++ b/tests/unit/test-smp-parse.c @@ -86,8 +86,8 @@ */ typedef struct SMPTestData { SMPConfiguration config; - CpuTopology expect_prefer_sockets; - CpuTopology expect_prefer_cores; + CPUTopology expect_prefer_sockets; + CPUTopology expect_prefer_cores; const char *expect_error; } SMPTestData; =20 @@ -395,7 +395,7 @@ static char *smp_config_to_string(const SMPConfiguratio= n *config) } =20 /* Use the different calculation than machine_topo_get_threads_per_socket(= ). */ -static unsigned int cpu_topology_get_threads_per_socket(const CpuTopology = *topo) +static unsigned int cpu_topology_get_threads_per_socket(const CPUTopology = *topo) { /* Check the divisor to avoid invalid topology examples causing SIGFPE= . */ if (!topo->sockets) { @@ -406,7 +406,7 @@ static unsigned int cpu_topology_get_threads_per_socket= (const CpuTopology *topo) } =20 /* Use the different calculation than machine_topo_get_cores_per_socket().= */ -static unsigned int cpu_topology_get_cores_per_socket(const CpuTopology *t= opo) +static unsigned int cpu_topology_get_cores_per_socket(const CPUTopology *t= opo) { /* Check the divisor to avoid invalid topology examples causing SIGFPE= . */ if (!topo->threads) { @@ -416,12 +416,12 @@ static unsigned int cpu_topology_get_cores_per_socket= (const CpuTopology *topo) } } =20 -static char *cpu_topology_to_string(const CpuTopology *topo, +static char *cpu_topology_to_string(const CPUTopology *topo, unsigned int threads_per_socket, unsigned int cores_per_socket) { return g_strdup_printf( - "(CpuTopology) {\n" + "(CPUTopology) {\n" " .cpus =3D %u,\n" " .sockets =3D %u,\n" " .dies =3D %u,\n" @@ -438,7 +438,7 @@ static char *cpu_topology_to_string(const CpuTopology *= topo, } =20 static void check_parse(MachineState *ms, const SMPConfiguration *config, - const CpuTopology *expect_topo, const char *expect= _err, + const CPUTopology *expect_topo, const char *expect= _err, bool is_valid) { g_autofree char *config_str =3D smp_config_to_string(config); --=20 2.34.1 From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420365; cv=none; d=zohomail.com; s=zohoarc; b=PEw4ajyxB1nxeCblc8x3RglkEJyiBo2ESHfFMJVZXYg7sAUCfvwJAFWoo2saVftfQj8rC81RuRFO5qHXt75l5Baa9rU7DX0p6zfRmwwZxmVyceM0N7E5MLWyClNAkl/lnkOQHKiA9DXV/YhZuG16/M7hYSwazRmckTDEwH5EvO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420365; 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=WSt6T7hdGb+vs2/uFmhOqnan/Wf0a6Qem8gqm0VZDGo=; b=jPe203dw4o0wl/miD2QfWBVzVOXKYeNoX1DFljrtGeHvMzCKQejVGbtDGHY394zje2CIsUjxwEGMjJJfmXr+fZ1Gaa+4HyE70jmLFtuZqEq1vRHB7QVWr/RxyAFSFbI+EY/MpRvtBkC+Iu55MpXCmE8eZwdAjzPh16BJgUBTGlY= 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 1708420365675744.5245240148236; Tue, 20 Feb 2024 01:12:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMAV-0000ha-0Z; Tue, 20 Feb 2024 04:12:03 -0500 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 1rcMAT-0000gy-7r; Tue, 20 Feb 2024 04:12:01 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAQ-0003Nd-S5; Tue, 20 Feb 2024 04:12:00 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:11:56 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:11:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420319; x=1739956319; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nXvdPraIKnI4AFbDZfobt0iujTMEBz7nDxXX+7ZH9uk=; b=UJ/7NA1KfbmAjgOheCdA/GdD08YsSQuzZanI8XZ7wt5wPG3BjBod6S9Y 66M8ix0wJ8jk3eXAWuaWCiHsIgmfPwm7J96dIN9zjXZa2hPGFuCl8UEeD izE4bHiJRSEROx44iNCF/ZshlyXIVfcPNIQ3Gj/dEu5tUJBpAPOucPVYy hggEXffiaPUy7d5fdhME8bB1CCOk8r2R2eaUxx6yJKKOvY2MmJYLWfwct m6T7fr8W9aHczHFhk0v2T8/t5P3QXapjYEouXSQHJfxkITiJ8GrKXwZhh aKgLZtpYFr7cpxcnI4Rb7/SyrlAipTrEIfcSAeyI01CLeugUAnoco52Xs g==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2374972" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2374972" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5012880" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 2/8] hw/core: Move CPU topology enumeration into arch-agnostic file Date: Tue, 20 Feb 2024 17:24:58 +0800 Message-Id: <20240220092504.726064-3-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420367748100016 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Cache topology needs to be defined based on CPU topology levels. Thus, move CPU topology enumeration into a common header. To match the general topology naming style, rename CPU_TOPO_LEVEL_SMT and CPU_TOPO_LEVEL_PACKAGE to CPU_TOPO_LEVEL_THREAD and CPU_TOPO_LEVEL_SOCKET. Also, enumerate additional topology levels for non-i386 arches, and add helpers for topology enumeration and string conversion. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 ++ hw/core/cpu-topology.c | 56 ++++++++++++++++++++++++++++++++++ hw/core/meson.build | 1 + include/hw/core/cpu-topology.h | 40 ++++++++++++++++++++++++ include/hw/i386/topology.h | 18 +---------- target/i386/cpu.c | 24 +++++++-------- target/i386/cpu.h | 2 +- tests/unit/meson.build | 3 +- 8 files changed, 115 insertions(+), 31 deletions(-) create mode 100644 hw/core/cpu-topology.c create mode 100644 include/hw/core/cpu-topology.h diff --git a/MAINTAINERS b/MAINTAINERS index 7d61fb93194b..4b1cce938915 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1871,6 +1871,7 @@ R: Yanan Wang S: Supported F: hw/core/cpu-common.c F: hw/core/cpu-sysemu.c +F: hw/core/cpu-topology.c F: hw/core/machine-qmp-cmds.c F: hw/core/machine.c F: hw/core/machine-smp.c @@ -1882,6 +1883,7 @@ F: qapi/machine-common.json F: qapi/machine-target.json F: include/hw/boards.h F: include/hw/core/cpu.h +F: include/hw/core/cpu-topology.h F: include/hw/cpu/cluster.h F: include/sysemu/numa.h F: tests/unit/test-smp-parse.c diff --git a/hw/core/cpu-topology.c b/hw/core/cpu-topology.c new file mode 100644 index 000000000000..ca1361d13c16 --- /dev/null +++ b/hw/core/cpu-topology.c @@ -0,0 +1,56 @@ +/* + * QEMU CPU Topology Representation + * + * Copyright (c) 2024 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/core/cpu-topology.h" + +typedef struct CPUTopoInfo { + const char *name; +} CPUTopoInfo; + +CPUTopoInfo cpu_topo_descriptors[] =3D { + [CPU_TOPO_LEVEL_INVALID] =3D { .name =3D "invalid", }, + [CPU_TOPO_LEVEL_THREAD] =3D { .name =3D "thread", }, + [CPU_TOPO_LEVEL_CORE] =3D { .name =3D "core", }, + [CPU_TOPO_LEVEL_MODULE] =3D { .name =3D "module", }, + [CPU_TOPO_LEVEL_CLUSTER] =3D { .name =3D "cluster", }, + [CPU_TOPO_LEVEL_DIE] =3D { .name =3D "die", }, + [CPU_TOPO_LEVEL_SOCKET] =3D { .name =3D "socket", }, + [CPU_TOPO_LEVEL_BOOK] =3D { .name =3D "book", }, + [CPU_TOPO_LEVEL_DRAWER] =3D { .name =3D "drawer", }, + [CPU_TOPO_LEVEL_MAX] =3D { .name =3D NULL, }, +}; + +const char *cpu_topo_to_string(CPUTopoLevel topo) +{ + return cpu_topo_descriptors[topo].name; +} + +CPUTopoLevel string_to_cpu_topo(char *str) +{ + for (int i =3D 0; i < ARRAY_SIZE(cpu_topo_descriptors); i++) { + CPUTopoInfo *info =3D &cpu_topo_descriptors[i]; + + if (!strcmp(info->name, str)) { + return (CPUTopoLevel)i; + } + } + return CPU_TOPO_LEVEL_MAX; +} diff --git a/hw/core/meson.build b/hw/core/meson.build index 67dad04de559..3b1d5ffab3e3 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -23,6 +23,7 @@ else endif =20 common_ss.add(files('cpu-common.c')) +common_ss.add(files('cpu-topology.c')) common_ss.add(files('machine-smp.c')) system_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) system_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loade= r.c')) diff --git a/include/hw/core/cpu-topology.h b/include/hw/core/cpu-topology.h new file mode 100644 index 000000000000..cc6ca186ce3f --- /dev/null +++ b/include/hw/core/cpu-topology.h @@ -0,0 +1,40 @@ +/* + * QEMU CPU Topology Representation Header + * + * Copyright (c) 2024 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef CPU_TOPOLOGY_H +#define CPU_TOPOLOGY_H + +typedef enum CPUTopoLevel { + CPU_TOPO_LEVEL_INVALID, + CPU_TOPO_LEVEL_THREAD, + CPU_TOPO_LEVEL_CORE, + CPU_TOPO_LEVEL_MODULE, + CPU_TOPO_LEVEL_CLUSTER, + CPU_TOPO_LEVEL_DIE, + CPU_TOPO_LEVEL_SOCKET, + CPU_TOPO_LEVEL_BOOK, + CPU_TOPO_LEVEL_DRAWER, + CPU_TOPO_LEVEL_MAX, +} CPUTopoLevel; + +const char *cpu_topo_to_string(CPUTopoLevel topo); +CPUTopoLevel string_to_cpu_topo(char *str); + +#endif /* CPU_TOPOLOGY_H */ diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index dff49fce1154..c6ff75f23991 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -39,7 +39,7 @@ * CPUID Fn8000_0008_ECX[ApicIdCoreIdSize[3:0]] is set to apicid_core_wid= th(). */ =20 - +#include "hw/core/cpu-topology.h" #include "qemu/bitops.h" =20 /* @@ -62,22 +62,6 @@ typedef struct X86CPUTopoInfo { unsigned threads_per_core; } X86CPUTopoInfo; =20 -/* - * CPUTopoLevel is the general i386 topology hierarchical representation, - * ordered by increasing hierarchical relationship. - * Its enumeration value is not bound to the type value of Intel (CPUID[0x= 1F]) - * or AMD (CPUID[0x80000026]). - */ -enum CPUTopoLevel { - CPU_TOPO_LEVEL_INVALID, - CPU_TOPO_LEVEL_SMT, - CPU_TOPO_LEVEL_CORE, - CPU_TOPO_LEVEL_MODULE, - CPU_TOPO_LEVEL_DIE, - CPU_TOPO_LEVEL_PACKAGE, - CPU_TOPO_LEVEL_MAX, -}; - /* Return the bit width needed for 'count' IDs */ static unsigned apicid_bitwidth_for_count(unsigned count) { diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ac0a10abd45f..725d7e70182d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -247,7 +247,7 @@ static uint32_t max_thread_ids_for_cache(X86CPUTopoInfo= *topo_info, case CPU_TOPO_LEVEL_DIE: num_ids =3D 1 << apicid_die_offset(topo_info); break; - case CPU_TOPO_LEVEL_PACKAGE: + case CPU_TOPO_LEVEL_SOCKET: num_ids =3D 1 << apicid_pkg_offset(topo_info); break; default: @@ -304,7 +304,7 @@ static uint32_t num_threads_by_topo_level(X86CPUTopoInf= o *topo_info, enum CPUTopoLevel topo_level) { switch (topo_level) { - case CPU_TOPO_LEVEL_SMT: + case CPU_TOPO_LEVEL_THREAD: return 1; case CPU_TOPO_LEVEL_CORE: return topo_info->threads_per_core; @@ -313,7 +313,7 @@ static uint32_t num_threads_by_topo_level(X86CPUTopoInf= o *topo_info, case CPU_TOPO_LEVEL_DIE: return topo_info->threads_per_core * topo_info->cores_per_module * topo_info->modules_per_die; - case CPU_TOPO_LEVEL_PACKAGE: + case CPU_TOPO_LEVEL_SOCKET: return topo_info->threads_per_core * topo_info->cores_per_module * topo_info->modules_per_die * topo_info->dies_per_pkg; default: @@ -326,7 +326,7 @@ static uint32_t apicid_offset_by_topo_level(X86CPUTopoI= nfo *topo_info, enum CPUTopoLevel topo_level) { switch (topo_level) { - case CPU_TOPO_LEVEL_SMT: + case CPU_TOPO_LEVEL_THREAD: return 0; case CPU_TOPO_LEVEL_CORE: return apicid_core_offset(topo_info); @@ -334,7 +334,7 @@ static uint32_t apicid_offset_by_topo_level(X86CPUTopoI= nfo *topo_info, return apicid_module_offset(topo_info); case CPU_TOPO_LEVEL_DIE: return apicid_die_offset(topo_info); - case CPU_TOPO_LEVEL_PACKAGE: + case CPU_TOPO_LEVEL_SOCKET: return apicid_pkg_offset(topo_info); default: g_assert_not_reached(); @@ -347,7 +347,7 @@ static uint32_t cpuid1f_topo_type(enum CPUTopoLevel top= o_level) switch (topo_level) { case CPU_TOPO_LEVEL_INVALID: return CPUID_1F_ECX_TOPO_LEVEL_INVALID; - case CPU_TOPO_LEVEL_SMT: + case CPU_TOPO_LEVEL_THREAD: return CPUID_1F_ECX_TOPO_LEVEL_SMT; case CPU_TOPO_LEVEL_CORE: return CPUID_1F_ECX_TOPO_LEVEL_CORE; @@ -380,7 +380,7 @@ static void encode_topo_cpuid1f(CPUX86State *env, uint3= 2_t count, level =3D CPU_TOPO_LEVEL_INVALID; for (int i =3D 0; i <=3D count; i++) { level =3D find_next_bit(env->avail_cpu_topo, - CPU_TOPO_LEVEL_PACKAGE, + CPU_TOPO_LEVEL_SOCKET, level + 1); =20 /* @@ -388,7 +388,7 @@ static void encode_topo_cpuid1f(CPUX86State *env, uint3= 2_t count, * and it just encode the invalid level (all fields are 0) * into the last subleaf of 0x1f. */ - if (level =3D=3D CPU_TOPO_LEVEL_PACKAGE) { + if (level =3D=3D CPU_TOPO_LEVEL_SOCKET) { level =3D CPU_TOPO_LEVEL_INVALID; break; } @@ -401,7 +401,7 @@ static void encode_topo_cpuid1f(CPUX86State *env, uint3= 2_t count, unsigned long next_level; =20 next_level =3D find_next_bit(env->avail_cpu_topo, - CPU_TOPO_LEVEL_PACKAGE, + CPU_TOPO_LEVEL_SOCKET, level + 1); num_threads_next_level =3D num_threads_by_topo_level(topo_info, next_level); @@ -6290,7 +6290,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, =20 /* Share the cache at package level. */ *eax |=3D max_thread_ids_for_cache(&topo_info, - CPU_TOPO_LEVEL_PACKAGE) << 14; + CPU_TOPO_LEVEL_SOCKET) << 14; } } } else if (cpu->vendor_cpuid_only && IS_AMD_CPU(env)) { @@ -7756,9 +7756,9 @@ static void x86_cpu_init_default_topo(X86CPU *cpu) env->nr_dies =3D 1; =20 /* SMT, core and package levels are set by default. */ - set_bit(CPU_TOPO_LEVEL_SMT, env->avail_cpu_topo); + set_bit(CPU_TOPO_LEVEL_THREAD, env->avail_cpu_topo); set_bit(CPU_TOPO_LEVEL_CORE, env->avail_cpu_topo); - set_bit(CPU_TOPO_LEVEL_PACKAGE, env->avail_cpu_topo); + set_bit(CPU_TOPO_LEVEL_SOCKET, env->avail_cpu_topo); } =20 static void x86_cpu_initfn(Object *obj) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 4b4cc70c8859..fcbf278b49e6 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1596,7 +1596,7 @@ typedef struct CPUCacheInfo { * Used to encode CPUID[4].EAX[bits 25:14] or * CPUID[0x8000001D].EAX[bits 25:14]. */ - enum CPUTopoLevel share_level; + CPUTopoLevel share_level; } CPUCacheInfo; =20 =20 diff --git a/tests/unit/meson.build b/tests/unit/meson.build index cae925c13259..4fe0aaff3a5e 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -138,7 +138,8 @@ if have_system 'test-util-sockets': ['socket-helpers.c'], 'test-base64': [], 'test-bufferiszero': [], - 'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine= -smp.c'], + 'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine= -smp.c', + meson.project_source_root() / 'hw/core/cpu-topology= .c'], 'test-vmstate': [migration, io], 'test-yank': ['socket-helpers.c', qom, io, chardev] } --=20 2.34.1 From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420387; cv=none; d=zohomail.com; s=zohoarc; b=bZRM12WS4F8nAM9aRFRJd760cQaOGhvzm4QmjBtF72DsANJHQqSiWyjOLCrlVA/IS9/83xd5Vds85cSCzOvyx8f3hJzX640cJ2DJT6Y82CacXpNfikLSH5xOTikjNHPMv4szs9fYQljxhRK5C9aNQuvEWcj4jY/1yXwEmEkQ90c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420387; 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=ir8jeB9n9+PBa0rQd518/TPuwxf1PmDmskJayeq2oD8=; b=mXyLTLbhbyQPxcGuA0oMyhftdiwqOCUaMJiyAZehcud2NhhBiTSnb/o7PE4ntFWMGUdpAW0jY3R/FTXdGDMwqTMR/Eci8xnhOt8MI7ITKkAzt4++UUWALtBWkc7OiTJjSHJ0aTbCBRNvZUkmzgbJx1u2U7vDCHwLiTmsqg7QfQA= 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 1708420387874439.7918673333894; Tue, 20 Feb 2024 01:13:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMAY-0000jc-Pd; Tue, 20 Feb 2024 04:12:06 -0500 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 1rcMAW-0000il-Mp; Tue, 20 Feb 2024 04:12:04 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAU-0003Nd-Sg; Tue, 20 Feb 2024 04:12:04 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:12:01 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:11:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420323; x=1739956323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZUUAxB4sXVe45cGLGYGHp6RoRiuaOzKNjOeO96oXZvg=; b=k4xJPgy5morXTuYWqX+3yCo26JSMJ2CSPXRKvuR+TfbMwLcg/r8YV7jC mMrbArsoNrXfn1f/yuZWKF6kbLm1Nt+TLRbmf0l50BwwUm8gdfP95iZZg vyW54xLTxyemlyn/fYqdm1zTq3aAa0yF8XO4cpMBTFojMqRFkOZdQ0ymg 953C8sh98VZ3W8WK2QM5rHQFZ4OfbSF2ju1VUzmxpWh0zDiHzswwcVk83 ozpJjDAb2AjFR1N400Ch58Sj7nQdqLr5IVHJ/roJbCocyHORusaPCtppL XUfunMTUwS5oYNNriic4sBJhFM2tGf9DeAQoBKJTy5F3oq72IPLRIRBgy Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2374984" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2374984" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5012944" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 3/8] hw/core: Define cache topology for machine Date: Tue, 20 Feb 2024 17:24:59 +0800 Message-Id: <20240220092504.726064-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420388424100001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Define the cache topology based on CPU topology level for two reasons: 1. In practice, a cache will always be bound to the CPU container (either private in the CPU container or shared among multiple containers), and CPU container is often expressed in terms of CPU topology level. 2. The x86's cache-related CPUIDs encode cache topology based on APIC ID's CPU topology layout. And the ACPI PPTT table that ARM/RISCV relies on also requires CPU containers to help indicate the private shared hierarchy of the cache. Therefore, for SMP systems, it is natural to use the CPU topology hierarchy directly in QEMU to define the cache topology. Currently, separated L1 cache (L1 data cache and L1 instruction cache) with unified higher-level cache (e.g., unified L2 and L3 caches), is the most common cache architectures. Therefore, define the topology for L1 D-cache, L1 I-cache, L2 cache and L3 cache in machine as the basic cache topology support. Signed-off-by: Zhao Liu --- hw/core/machine.c | 5 +++++ include/hw/boards.h | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index b3199c710194..426f71770a84 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1163,6 +1163,11 @@ static void machine_initfn(Object *obj) ms->smp.cores =3D 1; ms->smp.threads =3D 1; =20 + ms->smp_cache.l1d =3D CPU_TOPO_LEVEL_INVALID; + ms->smp_cache.l1i =3D CPU_TOPO_LEVEL_INVALID; + ms->smp_cache.l2 =3D CPU_TOPO_LEVEL_INVALID; + ms->smp_cache.l3 =3D CPU_TOPO_LEVEL_INVALID; + machine_copy_boot_config(ms, &(BootConfiguration){ 0 }); } =20 diff --git a/include/hw/boards.h b/include/hw/boards.h index e63dec919da2..8558b88aea52 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -10,6 +10,7 @@ #include "qemu/module.h" #include "qom/object.h" #include "hw/core/cpu.h" +#include "hw/core/cpu-topology.h" =20 #define TYPE_MACHINE_SUFFIX "-machine" =20 @@ -144,6 +145,12 @@ typedef struct { * @books_supported - whether books are supported by the machine * @drawers_supported - whether drawers are supported by the machine * @modules_supported - whether modules are supported by the machine + * @l1_separated_cache_supported - whether l1 data and instruction cache + * topology are supported by the machine + * @l2_unified_cache_supported - whether l2 unified cache topology are + * supported by the machine + * @l3_unified_cache_supported - whether l3 unified cache topology are + * supported by the machine */ typedef struct { bool prefer_sockets; @@ -153,6 +160,9 @@ typedef struct { bool books_supported; bool drawers_supported; bool modules_supported; + bool l1_separated_cache_supported; + bool l2_unified_cache_supported; + bool l3_unified_cache_supported; } SMPCompatProps; =20 /** @@ -358,6 +368,20 @@ typedef struct CPUTopology { unsigned int max_cpus; } CPUTopology; =20 +/** + * CPUTopology: + * @l1d: the CPU topology hierarchy the L1 data cache is shared at. + * @l1i: the CPU topology hierarchy the L1 instruction cache is shared at. + * @l2: the CPU topology hierarchy the L2 (unified) cache is shared at. + * @l3: the CPU topology hierarchy the L3 (unified) cache is shared at. + */ +typedef struct CacheTopology { + CPUTopoLevel l1d; + CPUTopoLevel l1i; + CPUTopoLevel l2; + CPUTopoLevel l3; +} CacheTopology; + /** * MachineState: */ @@ -408,6 +432,7 @@ struct MachineState { AccelState *accelerator; CPUArchIdList *possible_cpus; CPUTopology smp; + CacheTopology smp_cache; struct NVDIMMState *nvdimms_state; struct NumaState *numa_state; }; --=20 2.34.1 From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420365; cv=none; d=zohomail.com; s=zohoarc; b=LHk8TuTxVB6duX/bUKhFccIoS2g+dra4G3MErkh+xTjC+2MUUBoKPX0IEr4hgSoOx9WyTz0aXi+jmI4Nmkf7B1rkhSG2FeeBgFKXPjipv0fietvRrJLiuMh5w3QQyqS9iie9UCWiGmt+ye68bmsc75C86AH6R2Uu5rWG4cpemN8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420365; 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=D5Xsl77weVcKdftp4tMS6kDjsGXoVYsy5tPS7upGRhw=; b=haYbQQfyB62j8EkCRBhcxrw7Zyxg0ODgp539Qx7REoslmGux4Xjfhyk9cSh8v1AWOQof2B3LmzjItSX9rn3Cb9w0LkY+qhHcFSEe9KUAfKZ2AAvmvMkIEBytMExaiVH4mjeHAFr4Q3dQRKb2M62MbH8RH/9jPsDWEfJB35fn3dA= 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 1708420365938449.25038285370863; Tue, 20 Feb 2024 01:12:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMAk-0000px-Bj; Tue, 20 Feb 2024 04:12:19 -0500 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 1rcMAd-0000kU-0P; Tue, 20 Feb 2024 04:12:11 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAb-0003Nd-2j; Tue, 20 Feb 2024 04:12:10 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:12:06 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:12:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420329; x=1739956329; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eqNjZBlNcC8WFXOhViSe+F312lyqzht+4UXK0ymAVGc=; b=lVFPRw7ViOnDrm2MDKS/5U7GvaDzFtErf6HrOfnt6i69oy4ATskLcxDY FRIMrBAeC7vhQDTQXEd3B2QpRzZs33JbpWqWJ2RNdXp4ha8Wt5x6jZWtz 2/IOCa1aFq/OsICeDWcV8w8sOcXQQKnOJale3LwGzr3tmJLe/wRWuokv7 Y6P8h4dov6YA1X/yyj4eGWp6bAZSnEj47fjiiGzxA7rL96+Z4x2Q7uSO6 nO64V0AqBLUxiEYF0REOWDtBoWnyxKzjmMxcvtvuts+P2imRDdWIEIZ+F S732rjDDDSwutwTqKpm9tPiypGO1yKixb87AZtpuG7CFZEaeDnHmpE9pC Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2374996" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2374996" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5012989" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 4/8] hw/core: Add cache topology options in -smp Date: Tue, 20 Feb 2024 17:25:00 +0800 Message-Id: <20240220092504.726064-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420367740100014 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Add "l1d-cache", "l1i-cache". "l2-cache", and "l3-cache" options in -smp to define the cache topology for SMP system. Signed-off-by: Zhao Liu --- hw/core/machine-smp.c | 128 ++++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 4 ++ qapi/machine.json | 14 ++++- system/vl.c | 15 +++++ 4 files changed, 160 insertions(+), 1 deletion(-) diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 8a8296b0d05b..2cbd19f4aa57 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -61,6 +61,132 @@ static char *cpu_hierarchy_to_string(MachineState *ms) return g_string_free(s, false); } =20 +static bool machine_check_topo_support(MachineState *ms, + CPUTopoLevel topo) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + + if (topo =3D=3D CPU_TOPO_LEVEL_MODULE && !mc->smp_props.modules_suppor= ted) { + return false; + } + + if (topo =3D=3D CPU_TOPO_LEVEL_CLUSTER && !mc->smp_props.clusters_supp= orted) { + return false; + } + + if (topo =3D=3D CPU_TOPO_LEVEL_DIE && !mc->smp_props.dies_supported) { + return false; + } + + if (topo =3D=3D CPU_TOPO_LEVEL_BOOK && !mc->smp_props.books_supported)= { + return false; + } + + if (topo =3D=3D CPU_TOPO_LEVEL_DRAWER && !mc->smp_props.drawers_suppor= ted) { + return false; + } + + return true; +} + +static int smp_cache_string_to_topology(MachineState *ms, + char *topo_str, + CPUTopoLevel *topo, + Error **errp) +{ + *topo =3D string_to_cpu_topo(topo_str); + + if (*topo =3D=3D CPU_TOPO_LEVEL_MAX || *topo =3D=3D CPU_TOPO_LEVEL_INV= ALID) { + error_setg(errp, "Invalid cache topology level: %s. The cache " + "topology should match the CPU topology level", topo_st= r); + return -1; + } + + if (!machine_check_topo_support(ms, *topo)) { + error_setg(errp, "Invalid cache topology level: %s. The topology " + "level is not supported by this machine", topo_str); + return -1; + } + + return 0; +} + +static void machine_parse_smp_cache_config(MachineState *ms, + const SMPConfiguration *config, + Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + + if (config->l1d_cache) { + if (!mc->smp_props.l1_separated_cache_supported) { + error_setg(errp, "L1 D-cache topology not " + "supported by this machine"); + return; + } + + if (smp_cache_string_to_topology(ms, config->l1d_cache, + &ms->smp_cache.l1d, errp)) { + return; + } + } + + if (config->l1i_cache) { + if (!mc->smp_props.l1_separated_cache_supported) { + error_setg(errp, "L1 I-cache topology not " + "supported by this machine"); + return; + } + + if (smp_cache_string_to_topology(ms, config->l1i_cache, + &ms->smp_cache.l1i, errp)) { + return; + } + } + + if (config->l2_cache) { + if (!mc->smp_props.l2_unified_cache_supported) { + error_setg(errp, "L2 cache topology not " + "supported by this machine"); + return; + } + + if (smp_cache_string_to_topology(ms, config->l2_cache, + &ms->smp_cache.l2, errp)) { + return; + } + + if (ms->smp_cache.l1d > ms->smp_cache.l2 || + ms->smp_cache.l1i > ms->smp_cache.l2) { + error_setg(errp, "Invalid L2 cache topology. " + "L2 cache topology level should not be " + "lower than L1 D-cache/L1 I-cache"); + return; + } + } + + if (config->l3_cache) { + if (!mc->smp_props.l2_unified_cache_supported) { + error_setg(errp, "L3 cache topology not " + "supported by this machine"); + return; + } + + if (smp_cache_string_to_topology(ms, config->l3_cache, + &ms->smp_cache.l3, errp)) { + return; + } + + if (ms->smp_cache.l1d > ms->smp_cache.l3 || + ms->smp_cache.l1i > ms->smp_cache.l3 || + ms->smp_cache.l2 > ms->smp_cache.l3) { + error_setg(errp, "Invalid L3 cache topology. " + "L3 cache topology level should not be " + "lower than L1 D-cache/L1 I-cache/L2 cache"); + return; + } + } +} + /* * machine_parse_smp_config: Generic function used to parse the given * SMP configuration @@ -249,6 +375,8 @@ void machine_parse_smp_config(MachineState *ms, mc->name, mc->max_cpus); return; } + + machine_parse_smp_cache_config(ms, config, errp); } =20 unsigned int machine_topo_get_cores_per_socket(const MachineState *ms) diff --git a/hw/core/machine.c b/hw/core/machine.c index 426f71770a84..cb5173927b0d 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -886,6 +886,10 @@ static void machine_get_smp(Object *obj, Visitor *v, c= onst char *name, .has_cores =3D true, .cores =3D ms->smp.cores, .has_threads =3D true, .threads =3D ms->smp.threads, .has_maxcpus =3D true, .maxcpus =3D ms->smp.max_cpus, + .l1d_cache =3D g_strdup(cpu_topo_to_string(ms->smp_cache.l1d)), + .l1i_cache =3D g_strdup(cpu_topo_to_string(ms->smp_cache.l1i)), + .l2_cache =3D g_strdup(cpu_topo_to_string(ms->smp_cache.l2)), + .l3_cache =3D g_strdup(cpu_topo_to_string(ms->smp_cache.l3)), }; =20 if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) { diff --git a/qapi/machine.json b/qapi/machine.json index d0e7f1f615f3..0a923ac38803 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1650,6 +1650,14 @@ # # @threads: number of threads per core # +# @l1d-cache: topology hierarchy of L1 data cache (since 9.0) +# +# @l1i-cache: topology hierarchy of L1 instruction cache (since 9.0) +# +# @l2-cache: topology hierarchy of L2 unified cache (since 9.0) +# +# @l3-cache: topology hierarchy of L3 unified cache (since 9.0) +# # Since: 6.1 ## { 'struct': 'SMPConfiguration', 'data': { @@ -1662,7 +1670,11 @@ '*modules': 'int', '*cores': 'int', '*threads': 'int', - '*maxcpus': 'int' } } + '*maxcpus': 'int', + '*l1d-cache': 'str', + '*l1i-cache': 'str', + '*l2-cache': 'str', + '*l3-cache': 'str' } } =20 ## # @x-query-irq: diff --git a/system/vl.c b/system/vl.c index a82555ae1558..ac95e5ddb656 100644 --- a/system/vl.c +++ b/system/vl.c @@ -741,6 +741,9 @@ static QemuOptsList qemu_smp_opts =3D { }, { .name =3D "clusters", .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "modules", + .type =3D QEMU_OPT_NUMBER, }, { .name =3D "cores", .type =3D QEMU_OPT_NUMBER, @@ -750,6 +753,18 @@ static QemuOptsList qemu_smp_opts =3D { }, { .name =3D "maxcpus", .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "l1d-cache", + .type =3D QEMU_OPT_STRING, + }, { + .name =3D "l1i-cache", + .type =3D QEMU_OPT_STRING, + }, { + .name =3D "l2-cache", + .type =3D QEMU_OPT_STRING, + }, { + .name =3D "l3-cache", + .type =3D QEMU_OPT_STRING, }, { /*End of list */ } }, --=20 2.34.1 From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420438; cv=none; d=zohomail.com; s=zohoarc; b=i1KYONCSPUN34GMj6roGsGisAyYp6JTAVSlZYqT7dD4c+85nJiD8zi/MDzGX721vkfExFbufTWGXXaEFhNI7glMzJzzHdYYErEfZ0XMn8or3r6tEUGcYRknYTUdvNZUveyFPUtfGB+g6+q26yzW8DQaGiIFTYE39RoPOouztTFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420438; 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=cUYeLAZW0KBw1vwajpBZMV3SU2/ZD+h09pXDANbjwB0=; b=PaAWXMkQGE5FxVwDu6I9Bm6RsuGqh5xlsZo8Pql96KQbKRi1XLODOotMF7j8BNrCIh6LYAIgkfb5a2jh1y5bfEFyWhjy3GiRPTiMrquzqpxo8EgI1kq5peTfq81efLa1Dff4KSp0DUcZxbFVNCN3qUDAaRJBFOBE8POLPUjI1bs= 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 1708420438156254.20434207252038; Tue, 20 Feb 2024 01:13:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMAr-0000vC-CQ; Tue, 20 Feb 2024 04:12:25 -0500 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 1rcMAj-0000pV-P8; Tue, 20 Feb 2024 04:12:17 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAg-0003Nd-R0; Tue, 20 Feb 2024 04:12:16 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:12:12 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:12:06 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420335; x=1739956335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nmSGxPZR9yko6kQTreGOACQxkbHYm1OXOe8DkqwHjxw=; b=XKaqLwq0ko/Oio7cv+9iZA8MGZEw0IJYsvE5kVu1t8nRLtgAGctNyJKX Sjve9UHWglmFsvjKxJp8loYY9DDz07KXWRhVfn14TWivz6t0eiWS/Ea81 HYQdN1QLGAYwsE1Flczpaub4sFwxS+mzS8Am/D1WF7MMUVjYUAus056Sq QWSKPiDB6y5UxQMz2rj67CY89XtPHEXUB1S/cyo3ieypUGQdypbSlxTBT LHkwbo1BSStaxWCbyJkUg4c/xrxBCyy7DAdxWXdik7Q8OhvPsDS3vay90 vPeQz57tjszZqcd9LfHu1t4Mqc7NTINVtJFhkxJtQSt3mbNQWgAceO57w Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2375008" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2375008" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5013025" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 5/8] i386/cpu: Support thread and module level cache topology Date: Tue, 20 Feb 2024 17:25:01 +0800 Message-Id: <20240220092504.726064-6-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420438536100001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Allows cache to be defined at the thread and module level. This increases flexibility for x86 users to customize their cache topology. Signed-off-by: Zhao Liu --- target/i386/cpu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 725d7e70182d..d7cb0f1e49b4 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -241,9 +241,15 @@ static uint32_t max_thread_ids_for_cache(X86CPUTopoInf= o *topo_info, uint32_t num_ids =3D 0; =20 switch (share_level) { + case CPU_TOPO_LEVEL_THREAD: + num_ids =3D 1; + break; case CPU_TOPO_LEVEL_CORE: num_ids =3D 1 << apicid_core_offset(topo_info); break; + case CPU_TOPO_LEVEL_MODULE: + num_ids =3D 1 << apicid_module_offset(topo_info); + break; case CPU_TOPO_LEVEL_DIE: num_ids =3D 1 << apicid_die_offset(topo_info); break; @@ -251,10 +257,6 @@ static uint32_t max_thread_ids_for_cache(X86CPUTopoInf= o *topo_info, num_ids =3D 1 << apicid_pkg_offset(topo_info); break; default: - /* - * Currently there is no use case for SMT and MODULE, so use - * assert directly to facilitate debugging. - */ g_assert_not_reached(); } =20 --=20 2.34.1 From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420371; cv=none; d=zohomail.com; s=zohoarc; b=PmMmndxF1eMVvCvTTcAYg2NtepXPjIOr2gGxi6I2GpM3wMpQI+fsaHslSRcEm2ez8WPNgzQEZGfV1NXMq6Gkz0wOl6d9fM4luIu0SeTpBPbMwAAj5De36NpeXmfnxbtwbJpmYj13ejTM8j6Nvf6nFR9fm+lILrvR4SnKeZMhAOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420371; 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=YzBFThZ9pCwWaiwtxTUYlOw7wI/O3P3b6nC9JLqcu2A=; b=kJDuWSP9UHR5qHzPGOjyrAyq2rEARlmW+ACiDX1u7w+G34ke4oQoR9q+CeCiwPjzIszu3tSs7aob3wp0izMGcQTBNFbEQOPaR3rSAVoOqu/zPeHxBqCiKnYi/UIRSlBdy6eC1kQw4O8tJqhI91LyOB40H6mr5OOAXd4xW6kigM8= 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 1708420371101140.62872228908816; Tue, 20 Feb 2024 01:12:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMAq-0000sb-JA; Tue, 20 Feb 2024 04:12:24 -0500 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 1rcMAn-0000rT-5y; Tue, 20 Feb 2024 04:12:22 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAl-0003Nd-Ay; Tue, 20 Feb 2024 04:12:20 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:12:17 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:12:11 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420339; x=1739956339; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sh2QkQ5wss3HOjZ8fhY8YalRgTw6t25jX5kKa/RtD7I=; b=BgM+jP6b0g3VoqDecxvtYsczNbqZ2Ev/g3KHu+9ioOkwlhyVugh6/TjP g9QmMH04g+JICvPWE6Xh0vpzZyzCUoIHlyrToxHNIrl3z9NJOT8AX0DTt ghHFfMBzgC/o3EjodkoJEqLLKav+9tB8+uHIcWygw3vKGDAOQuo+KIloh 4FuYRvl/owqBosg5t7z6VIw2MWxVnf2ZRcztBIav7oVC0wACLGhttSi3h /gitxlMQnR86yhuB2Mgw9cqMFisRfSm185EL4wtOVfyCXV13yJV3tB+Jk triCOQ+dqY31oUgvWlzcLTIvRJROFF9IrqTkON5M99CuOkFEtTUmQLkh5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2375017" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2375017" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5013057" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 6/8] i386/cpu: Update cache topology with machine's configuration Date: Tue, 20 Feb 2024 17:25:02 +0800 Message-Id: <20240220092504.726064-7-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420372334100001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu User will configure SMP cache topology via -smp. For this case, update the x86 CPUs' cache topology with user's configuration in MachineState. Signed-off-by: Zhao Liu --- target/i386/cpu.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d7cb0f1e49b4..4b5c551fe7f0 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7582,6 +7582,27 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) =20 #ifndef CONFIG_USER_ONLY MachineState *ms =3D MACHINE(qdev_get_machine()); + + if (ms->smp_cache.l1d !=3D CPU_TOPO_LEVEL_INVALID) { + env->cache_info_cpuid4.l1d_cache->share_level =3D ms->smp_cache.l1= d; + env->cache_info_amd.l1d_cache->share_level =3D ms->smp_cache.l1d; + } + + if (ms->smp_cache.l1i !=3D CPU_TOPO_LEVEL_INVALID) { + env->cache_info_cpuid4.l1i_cache->share_level =3D ms->smp_cache.l1= i; + env->cache_info_amd.l1i_cache->share_level =3D ms->smp_cache.l1i; + } + + if (ms->smp_cache.l2 !=3D CPU_TOPO_LEVEL_INVALID) { + env->cache_info_cpuid4.l2_cache->share_level =3D ms->smp_cache.l2; + env->cache_info_amd.l2_cache->share_level =3D ms->smp_cache.l2; + } + + if (ms->smp_cache.l3 !=3D CPU_TOPO_LEVEL_INVALID) { + env->cache_info_cpuid4.l3_cache->share_level =3D ms->smp_cache.l3; + env->cache_info_amd.l3_cache->share_level =3D ms->smp_cache.l3; + } + qemu_register_reset(x86_cpu_machine_reset_cb, cpu); =20 if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || ms->smp.cpus > 1) { --=20 2.34.1 From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420366; cv=none; d=zohomail.com; s=zohoarc; b=iyBMPwvR0nkCUZbFRDnJv41nMbkxPlZCsbARX89JJU/g5JE2314FuXnhq/VsjX5ek9KL+Y6PtBs207LNLmmQkva1XwcLqz3FhDOn7H2fe/U5h/tY2QtyYAaB4jYhwFN8TJlOhnfivcgyaCRDhPsxtSmAWxT64W7TSeIbiNCigVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420366; 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=ztZAu88Lpj5YkGi27K0oLaljmBoAEtp8/9AVpZ+GvPU=; b=VsloFNPy8OVb1tZ5ieTaj77hYG+25Ht0++2zJZTFk0FuoO3TmEPomZDlNP//xYFkuVg0cdfoHHx/It031zfD1FcNnhJZmbmXOm3CP0MSmY8zYgxwojjEyNM3gT28aBXeaL9ghUXdqz7hl9QxNzFYmk8pt1JfRyDdaEskzmQOfq0= 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 1708420366468790.2288052637617; Tue, 20 Feb 2024 01:12:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMAv-0000xn-8A; Tue, 20 Feb 2024 04:12:29 -0500 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 1rcMAt-0000wc-4M; Tue, 20 Feb 2024 04:12:27 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAr-0003Tv-OB; Tue, 20 Feb 2024 04:12:26 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:12:23 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:12:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420346; x=1739956346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N8NOOJ+pARZ8UH7DHP7I4LRh9UGou9oDu+xcL8Vc/Rs=; b=MLqbFD6HNiMEBg3S5LjV+mg1oJBcfv3VeaZmJfwSEdLJqzRfthwZN30G Dj+gh1pi6N14HhBbXtOP8rsr5QIFej74vEYc8x/rsgA9ASEuH5DuCPvyD pBQ+ePNnqYCnUsdOibgSljBSxpwu72NXf+5Od9v0tSRO6YiEnMbOTvTl+ 1I1rQpDOJN+JMf3B312RHCTxN98EghWB+4Y5DuMlc9TqK8ZCkAfOs5hpp RogsxdfIlSnv/JXf3MqVmg79dgVdlL89gas437J0mPomUaBxwYdDnvh+Q YuTD//mqg1D77cLvWEx5tf/AiVceoRP0yStm6kb28B++KJjybqaaqfFOW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2375033" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2375033" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5013100" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 7/8] i386/pc: Support cache topology in -smp for PC machine Date: Tue, 20 Feb 2024 17:25:03 +0800 Message-Id: <20240220092504.726064-8-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420368328100019 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Signed-off-by: Zhao Liu --- hw/i386/pc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 25124a077eea..76148c3337cf 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1848,6 +1848,9 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) mc->nvdimm_supported =3D true; mc->smp_props.dies_supported =3D true; mc->smp_props.modules_supported =3D true; + mc->smp_props.l1_separated_cache_supported =3D true; + mc->smp_props.l2_unified_cache_supported =3D true; + mc->smp_props.l3_unified_cache_supported =3D true; mc->default_ram_id =3D "pc.ram"; pcmc->default_smbios_ep_type =3D SMBIOS_ENTRY_POINT_TYPE_64; =20 --=20 2.34.1 From nobody Thu Nov 14 07:14:27 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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1708420406; cv=none; d=zohomail.com; s=zohoarc; b=M1pMlJIeTJSk60yngOoXT7saW1FjdLifyA4GiUkRpvGcGtwI5v6LgQFtnNl5zEjhg5ngz3DZEnWO0sVmL70OFzr2GelFrs5uP1U7c7+3LoiK/GqGLal7ro7v/Eq1HFkvh33OzwmmKxK5bUHiqQb3GjXg3PLJ1HmG20xYQ8ZVXqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708420406; 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=xlHVDIczWDzsqvnRJ1iEbajqyhhtoEAGnHkRgqd3qOk=; b=R0nIkqzYVCCnuxjq1sE096eCgpDVM1DczrseBeyBPBbMOqcpN04tMizjBR+GF55+4X9UxRVZ5TeFJGQKbISHrVa1NiRMiINX0MqkIX3hFDkkNtQbyNcgr5xJKQfniuzMWQ0WnsRtA6kvqUwzhMTsOWv9ObBsxm1Hp5FF3HDUsBU= 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 1708420406028855.0682605391528; Tue, 20 Feb 2024 01:13:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcMB0-0001Dh-6m; Tue, 20 Feb 2024 04:12:34 -0500 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 1rcMAy-00012Z-2d; Tue, 20 Feb 2024 04:12:32 -0500 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcMAw-0003Tv-0l; Tue, 20 Feb 2024 04:12:31 -0500 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 01:12:28 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 01:12:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708420350; x=1739956350; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0AbdOq+EtfWgzb7EW1UTRtjP/6zXcB3r698FBuEvgE=; b=GotJBlCOWiDbORUrFW9FJJP0MFSK+B1f7F/ibCay2WDFrsCEYfL7Lu5Q Se71/DNobx7db5OmZ4L0NsuLWLnY4VFS13qRPSd7cNZ6MSn+QhfoGAnbD MXm8Je/oAlVQuC6zHwsKn43f+y1c8syzoXjAEnbx65JU/GWMx8Dg3ygRx lgdj8WuCplKH+7UXhD8PhWiyXy0A26GZeyOgkdfSL/oYx5TXcO2WP+XjA ca87IWVT/J7yFJH22wkwuSonvWg3z0wjd+d5EzCIAmHkkV/hLpHj/aQ5z QdCxAx6DWBH7zcQKoyS0t5dlRcsjaYbWR1AeE94/eVgOtPHf6vvVaPVBl A==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2375048" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2375048" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="5013156" From: Zhao Liu To: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Zhenyu Wang , Dapeng Mi , Yongwei Ma , Zhao Liu Subject: [RFC 8/8] qemu-options: Add the cache topology description of -smp Date: Tue, 20 Feb 2024 17:25:04 +0800 Message-Id: <20240220092504.726064-9-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220092504.726064-1-zhao1.liu@linux.intel.com> References: <20240220092504.726064-1-zhao1.liu@linux.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: none client-ip=192.198.163.17; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.072, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1708420406500100001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Signed-off-by: Zhao Liu --- qemu-options.hx | 54 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index 70eaf3256685..85c78c99a3b0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -281,7 +281,9 @@ ERST =20 DEF("smp", HAS_ARG, QEMU_OPTION_smp, "-smp [[cpus=3D]n][,maxcpus=3Dmaxcpus][,drawers=3Ddrawers][,books=3Dbo= oks][,sockets=3Dsockets]\n" - " [,dies=3Ddies][,clusters=3Dclusters][,cores=3Dcores][,= threads=3Dthreads]\n" + " [,dies=3Ddies][,clusters=3Dclusters][,modules=3Dmodule= s][,cores=3Dcores]\n" + " [,threads=3Dthreads][,l1d-cache=3Dlevel][,l1i-cache=3D= level][,l2-cache=3Dlevel]\n" + " [,l3-cache=3Dlevel]\n" " set the number of initial CPUs to 'n' [default=3D1]\n" " maxcpus=3D maximum number of total CPUs, including\n" " offline CPUs for hotplug, etc\n" @@ -290,9 +292,14 @@ DEF("smp", HAS_ARG, QEMU_OPTION_smp, " sockets=3D number of sockets in one book\n" " dies=3D number of dies in one socket\n" " clusters=3D number of clusters in one die\n" - " cores=3D number of cores in one cluster\n" + " modules=3D number of modules in one cluster\n" + " cores=3D number of cores in one module\n" " threads=3D number of threads in one core\n" - "Note: Different machines may have different subsets of the CPU topolo= gy\n" + " l1d-cache=3D topology level of L1 D-cache\n" + " l1i-cache=3D topology level of L1 I-cache\n" + " l2-cache=3D topology level of L2 cache\n" + " l3-cache=3D topology level of L3 cache\n" + "Note: Different machines may have different subsets of the CPU and ca= che topology\n" " parameters supported, so the actual meaning of the supported pa= rameters\n" " will vary accordingly. For example, for a machine type that sup= ports a\n" " three-level CPU hierarchy of sockets/cores/threads, the paramet= ers will\n" @@ -306,7 +313,7 @@ DEF("smp", HAS_ARG, QEMU_OPTION_smp, " must be set as 1 in the purpose of correct parsing.\n", QEMU_ARCH_ALL) SRST -``-smp [[cpus=3D]n][,maxcpus=3Dmaxcpus][,sockets=3Dsockets][,dies=3Ddies][= ,clusters=3Dclusters][,cores=3Dcores][,threads=3Dthreads]`` +``-smp [[cpus=3D]n][,maxcpus=3Dmaxcpus][,drawers=3Ddrawers][,books=3Dbooks= ][,sockets=3Dsockets][,dies=3Ddies][,clusters=3Dclusters][,modules=3Dmodule= s][,cores=3Dcores][,threads=3Dthreads][,l1d-cache=3Dlevel][,l1i-cache=3Dlev= el][,l2-cache=3Dlevel][,l3-cache=3Dlevel]`` Simulate a SMP system with '\ ``n``\ ' CPUs initially present on the machine type board. On boards supporting CPU hotplug, the optional '\ ``maxcpus``\ ' parameter can be set to enable further CPUs to be @@ -320,15 +327,34 @@ SRST Both parameters are subject to an upper limit that is determined by the specific machine type chosen. =20 + CPU topology parameters include '\ ``drawers``\ ', '\ ``books``\ ', + '\ ``sockets``\ ', '\ ``dies``\ ', '\ ``clusters``\ ', '\ ``modules``\= ', + '\ ``cores``\ ' and '\ ``threads``\ '. These CPU parameters accept only + integers and are used to specify the number of specific topology domai= ns + under the corresponding topology level. + To control reporting of CPU topology information, values of the topolo= gy parameters can be specified. Machines may only support a subset of the - parameters and different machines may have different subsets supported - which vary depending on capacity of the corresponding CPU targets. So - for a particular machine type board, an expected topology hierarchy can + CPU topology parameters and different machines may have different subs= ets + supported which vary depending on capacity of the corresponding CPU ta= rgets. + So for a particular machine type board, an expected topology hierarchy= can be defined through the supported sub-option. Unsupported parameters can also be provided in addition to the sub-option, but their values must = be set as 1 in the purpose of correct parsing. =20 + Cache topology parameters include '\ ``l1d-cache``\ ', '\ ``l1i-cache`= `\ ', + '\ ``l2-cache``\ ' and '\ ``l3-cache``\ '. These cache topology parame= ters + accept the strings of CPU topology levels (such as '\ ``drawer``\ ', '= \ ``book``\ ', + '\ ``socket``\ ', '\ ``die``\ ', '\ ``cluster``\ ', '\ ``module``\ ', + '\ ``core``\ ' or '\ ``thread``\ '). Exactly which topology level stri= ngs + could be accepted as the parameter depends on the machine's support fo= r the + corresponding CPU topology level. + + Machines may also only support a subset of the cache topology paramete= rs. + Unsupported cache topology parameters will be omitted, and correspondi= ngly, + the target CPU's cache topology will use the its default cache topology + setting. + Either the initial CPU count, or at least one of the topology paramete= rs must be specified. The specified parameters must be greater than zero, explicit configuration like "cpus=3D0" is not allowed. Values for any @@ -354,6 +380,20 @@ SRST =20 -smp 32,sockets=3D2,dies=3D2,modules=3D2,cores=3D2,threads=3D2,max= cpus=3D32 =20 + The following sub-option defines a CPU topology hierarchy (2 sockets + totally on the machine, 2 dies per socket, 2 modules per die, 2 cores = per + module, 2 threads per core) with 3-level cache topology hierarchy (L1 + D-cache per core, L1 I-cache per core, L2 cache per core and L3 cache = per + die) for PC machines which support sockets/dies/modules/cores/threads. + Some members of the CPU topology option can be omitted but their values + will be automatically computed. Some members of the cache topology + option can also be omitted and target CPU will use the default topolog= y.: + + :: + + -smp 32,sockets=3D2,dies=3D2,modules=3D2,cores=3D2,threads=3D2,max= cpus=3D32,\ + l1d-cache=3Dcore,l1i-cache=3Dcore,l2-cache=3Dcore,l3-cache=3D= die + The following sub-option defines a CPU topology hierarchy (2 sockets totally on the machine, 2 clusters per socket, 2 cores per cluster, 2 threads per core) for ARM virt machines which support sockets/cluste= rs --=20 2.34.1