From nobody Mon Nov 25 07:45:46 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=1717063354; cv=none; d=zohomail.com; s=zohoarc; b=cjMUE+Nu1H0Q8DdjStwW7kTTVVmmXOOYn2QNYKlA+WuW3VsN6XZjbOG4afwci/Cd7I++4cNozv2ghhwoQS5c2NCsLfnXqTRFJl044yP2Sbf1W4dmTxgjcGdM3C/7q4tJi4urNhe7IsymYHYchPyiW+eT0jWvS19tilKd053a1Mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717063354; 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=8rj07W1RruFADC0U9ntIwxtsFck7PBfaW+RGMq1CSKg=; b=G7M4dNJgr+oje5w4aNyAsAVH16Fv5goG5b6acCI2jO31XKjb7cqBHD/bj6k0iFwTA62atxHo0pfkDBbEElGll00rjI5rOX8hMoJrn3vrHs9XQbJ85+vswAfoEPj/d08UPJ/BahZuDAYH6jHTb46yvqiRuVGuAb+QSsdaTjpzh8U= 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 1717063354141747.8201525307114; Thu, 30 May 2024 03:02:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCcag-0002yc-Pm; Thu, 30 May 2024 06:00:58 -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 1sCcaU-0002v7-Oq; Thu, 30 May 2024 06:00:46 -0400 Received: from mgamail.intel.com ([198.175.65.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCcaS-0003SB-HN; Thu, 30 May 2024 06:00:46 -0400 Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2024 03:00:41 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orviesa010.jf.intel.com with ESMTP; 30 May 2024 03:00:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717063245; x=1748599245; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DM8SHXAESp5cUPfmMy9YxorSHMNJrW8VYCNoamCx3L0=; b=KTSsYeAsyeSPKNIeUnSkftNz8YCNEcat6ZVJoNjspTdTmO6pLyVh0zHS KuOwm3ArdRH/IFMSVL1pOQ2MaBmsY33XcMJzJuFOb2IvIRw/aDoluNNtE KYB/LtmUk3CoCWt9NO8gWlxfjctplJ2dbnc/uyQTcXbJt1MZwdET9mQPJ XZdJtRb9/MpsWh9T2j9pPUlN3jFbK4zIdvCpgiCEckCdpAsaaS5jZzzgm isTy164MWNfly0C0saL1WmapKF3jWZvLfvX0aJDy1PrwvDkIggY+3ajgP GB0BQyAlNk1H8xAxz//T6F9lPQHP3mtTHX63zQelBQZl4BEBUxkrQMZe4 w==; X-CSE-ConnectionGUID: sxIsMtR1SVmSbI8kbkYMjQ== X-CSE-MsgGUID: p/Bd1AZ6TKuevlYrEaV/NQ== X-IronPort-AV: E=McAfee;i="6600,9927,11087"; a="31032469" X-IronPort-AV: E=Sophos;i="6.08,201,1712646000"; d="scan'208";a="31032469" X-CSE-ConnectionGUID: /NjwT4NcRqGZr2YKdyF1wQ== X-CSE-MsgGUID: t6VNuZuoRAKAcrDirpQULA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,201,1712646000"; d="scan'208";a="35705049" 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 v2 3/7] hw/core: Add cache topology options in -smp Date: Thu, 30 May 2024 18:15:35 +0800 Message-Id: <20240530101539.768484-4-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240530101539.768484-1-zhao1.liu@intel.com> References: <20240530101539.768484-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=198.175.65.10; 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.036, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-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: 1717063356118100003 Content-Type: text/plain; charset="utf-8" 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 --- Changes since RFC v1: * Set has_*_cache field in machine_get_smp(). (JeeHeng) * Adjust string breaking style in error_setg() for more semantic sentence breaking conventions. (Jonathan) * Add more description about cache options. (Markus) * Now in v2, config->*_cache field stores topology enumeration instead of string, no need to parse, so just make machine_check_cache_topo() return boolean. --- hw/core/machine-smp.c | 146 +++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 20 ++++++ qapi/machine.json | 23 ++++++- system/vl.c | 12 ++++ tests/unit/meson.build | 3 +- 5 files changed, 202 insertions(+), 2 deletions(-) diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 5d8d7edcbd3f..c79464cf3d2c 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -61,6 +61,150 @@ 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 bool machine_check_cache_topo(MachineState *ms, + CPUTopoLevel topo, + Error **errp) +{ + if (topo =3D=3D CPU_TOPO_LEVEL__MAX || topo =3D=3D CPU_TOPO_LEVEL_INVA= LID) { + error_setg(errp, + "Invalid cache topology level: %s. " + "The cache topology should match the " + "valid CPU topology level", + cpu_topo_to_string(topo)); + return false; + } + + if (!machine_check_topo_support(ms, topo)) { + error_setg(errp, + "Invalid cache topology level: %s. " + "The topology level is not supported by this machine", + cpu_topo_to_string(topo)); + return false; + } + + return true; +} + +static void machine_parse_smp_cache_config(MachineState *ms, + const SMPConfiguration *config, + Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + + /* + * The cache topology does not support a default entry similar to + * CPU topology with parameters=3D1. So when the machine explicitly + * does not support cache topology, return the error. + */ + if (config->has_l1d_cache) { + if (!mc->smp_props.l1_separated_cache_supported) { + error_setg(errp, + "L1 D-cache topology not supported by this machine"= ); + return; + } + + if (!machine_check_cache_topo(ms, config->l1d_cache, errp)) { + return; + } + + ms->smp_cache.l1d =3D config->l1d_cache; + } + + if (config->has_l1i_cache) { + if (!mc->smp_props.l1_separated_cache_supported) { + error_setg(errp, + "L1 I-cache topology not supported by this machine"= ); + return; + } + + if (!machine_check_cache_topo(ms, config->l1i_cache, errp)) { + return; + } + + ms->smp_cache.l1i =3D config->l1i_cache; + } + + if (config->has_l2_cache) { + if (!mc->smp_props.l2_unified_cache_supported) { + error_setg(errp, + "L2 cache topology not supported by this machine"); + return; + } + + if (!machine_check_cache_topo(ms, config->l2_cache, errp)) { + return; + } + + ms->smp_cache.l2 =3D config->l2_cache; + + /* + * Cache topology is initialized by default to CPU_TOPO_LEVEL_INVA= LID, + * which is the lowest level, so such a check is OK, even if the c= onfig + * doesn't override that field. + */ + 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->has_l3_cache) { + if (!mc->smp_props.l2_unified_cache_supported) { + error_setg(errp, + "L3 cache topology not supported by this machine"); + return; + } + + if (!machine_check_cache_topo(ms, config->l3_cache, errp)) { + return; + } + + ms->smp_cache.l3 =3D config->l3_cache; + + 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 @@ -259,6 +403,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 e31d0f3cb4b0..f705485f83c0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -900,6 +900,26 @@ static void machine_get_smp(Object *obj, Visitor *v, c= onst char *name, .has_maxcpus =3D true, .maxcpus =3D ms->smp.max_cpus, }; =20 + if (ms->smp_cache.l1d !=3D CPU_TOPO_LEVEL_INVALID) { + config->has_l1d_cache =3D true; + config->l1d_cache =3D ms->smp_cache.l1d; + } + + if (ms->smp_cache.l1i !=3D CPU_TOPO_LEVEL_INVALID) { + config->has_l1i_cache =3D true; + config->l1i_cache =3D ms->smp_cache.l1i; + } + + if (ms->smp_cache.l2 !=3D CPU_TOPO_LEVEL_INVALID) { + config->has_l2_cache =3D true; + config->l2_cache =3D ms->smp_cache.l2; + } + + if (ms->smp_cache.l3 !=3D CPU_TOPO_LEVEL_INVALID) { + config->has_l3_cache =3D true; + config->l3_cache =3D ms->smp_cache.l3; + } + if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) { return; } diff --git a/qapi/machine.json b/qapi/machine.json index 7ac5a05bb9c9..8fa5af69b1bf 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1746,6 +1746,23 @@ # # @threads: number of threads per core # +# @l1d-cache: topology hierarchy of L1 data cache. It accepts the CPU +# topology enumeration as the parameter, i.e., CPUs in the same +# topology container share the same L1 data cache. (since 9.1) +# +# @l1i-cache: topology hierarchy of L1 instruction cache. It accepts +# the CPU topology enumeration as the parameter, i.e., CPUs in the +# same topology container share the same L1 instruction cache. +# (since 9.1) +# +# @l2-cache: topology hierarchy of L2 unified cache. It accepts the CPU +# topology enumeration as the parameter, i.e., CPUs in the same +# topology container share the same L2 unified cache. (since 9.1) +# +# @l3-cache: topology hierarchy of L3 unified cache. It accepts the CPU +# topology enumeration as the parameter, i.e., CPUs in the same +# topology container share the same L3 unified cache. (since 9.1) +# # Since: 6.1 ## { 'struct': 'SMPConfiguration', 'data': { @@ -1758,7 +1775,11 @@ '*modules': 'int', '*cores': 'int', '*threads': 'int', - '*maxcpus': 'int' } } + '*maxcpus': 'int', + '*l1d-cache': 'CPUTopoLevel', + '*l1i-cache': 'CPUTopoLevel', + '*l2-cache': 'CPUTopoLevel', + '*l3-cache': 'CPUTopoLevel' } } =20 ## # @x-query-irq: diff --git a/system/vl.c b/system/vl.c index a3eede5fa5b8..c7c94d41bd01 100644 --- a/system/vl.c +++ b/system/vl.c @@ -753,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 */ } }, diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 26c109c968ce..8877dbbc00c9 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