From nobody Thu Nov 14 18:12:18 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