From patchwork Tue Nov 5 22:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 840822 Delivered-To: patch@linaro.org Received: by 2002:a5d:6307:0:b0:381:e71e:8f7b with SMTP id i7csp239711wru; Tue, 5 Nov 2024 14:49:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWLvAoIHPVmYdPHcacfmtpHscH29QoTgRX8zdWl2RQP/gazRlkruBPhPPqsoGFA0FIwuu0Jpg==@linaro.org X-Google-Smtp-Source: AGHT+IFNx55eAUdYmwKMTmrEgsIpDNWAPjRxpkfaFSrMC1xyoUMZ55Z8sOfdQdU1qTaMBNhUCnpI X-Received: by 2002:a05:620a:4590:b0:7b1:ae79:be00 with SMTP id af79cd13be357-7b2fb950a9amr2722825285a.7.1730846943203; Tue, 05 Nov 2024 14:49:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730846943; cv=none; d=google.com; s=arc-20240605; b=hkgRXbK01Fn2ywYU5H866RtRfiAAO65UNqhGzU8sOR2aWmaQ2LuPdfNaWEd0xN2lpE Y0YanKgt/Sk6f1Ciz7MJNydTfOO4EtLawhStHpr+feinhEvnIATJEtef6YlpbqvZJUN0 6S8VX0CfuHsQSHGCXESmA9Vl+NZOOLzksO463PL9PX4PvpUOGEL5feyZxo2e9wLR/MN/ C+lduH1i2kmMDbdzMaBiespjx4eca7N9nnCdt/e6ju8hwDuEZ0MzN2Ul/pwfEk8nCpOF 1oEWeYJ+/2zqssg74tqK0mp/7lWmCTvissBBV7/v1P4uG224CwBri+Ew5uyLpAgwP53c N+pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ePIKogat04ImvSGFaoDytp1FAL9Swm8B+71WhYbHHQI=; fh=wmSrkJq7pP7hflg/D8Mc4uRzbmtumNqUvCb70VX3amo=; b=cXfu7ARiYudoTZ3VAHWh38DUwWvSfiRgG98i6ddzwPAkyRmXc6Yo8s/TXpX62PY5Lr L39vwJG26dVurXgeyF0HGkE/YiEbS1MrlW2FvdVrX5VWE2o9mUvrUbl2Qyz68q+c/grT amOQbWufyrEnqyk5/BiAIy6Qp9JVO9Bcj6CgHMV6IpTsHh7GKkwHalTrH4TLx6sfap7K kPJ5IdyFZs6ZIcYlGQtkfFGbuj0ePN+f/tR6aBBVETVp3SA47KqDeRcDP1BpEW77c3Wt Jl0fXm0jJA9ToYj1WGFJ/HhKSO4IZsqfUiHKfebAhqtW+0h1noNPiUqjg15CRVnO4sVL Cq1g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TcouAbUm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b2f3ab1551si1474524285a.587.2024.11.05.14.49.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Nov 2024 14:49:03 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TcouAbUm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8SLa-00062B-VG; Tue, 05 Nov 2024 17:48:27 -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 1t8SLW-0005yM-8l for qemu-devel@nongnu.org; Tue, 05 Nov 2024 17:48:22 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t8SLU-0004DH-51 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 17:48:22 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-43152b79d25so51719985e9.1 for ; Tue, 05 Nov 2024 14:48:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730846898; x=1731451698; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ePIKogat04ImvSGFaoDytp1FAL9Swm8B+71WhYbHHQI=; b=TcouAbUmf0tm0mOhl+EgRGW+DcaJ5AcasNpEmLCpy4UWOrw012LB9so9GDpaY9cl5H k6v6uVVk5gdIiOmfMsNuocaOx3qfZdfE4y+M6PkCy7ORnM9cpJGEBY1DGkj8jZb5E/uy yrG8MbkEeVKs89yCOqeAccqVdhdfxyMtxtXmrZJfRuY0RKhefOsOkVQo9nlEC6kwpol/ kTHrDLgpt/jFyOJJrUgt6YZQmEu19VZOji8WFqSFjSB9r3OTgzvvEl/5x5PX9ytwbNnd m9uUTsJZOATtOC3YwruknQ+TOjSHQr44R45tjKOjK0Nm/R6s8xhm3lfaNohqFoTLZcy5 7OPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730846898; x=1731451698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ePIKogat04ImvSGFaoDytp1FAL9Swm8B+71WhYbHHQI=; b=Qo4uyLWHjzuwfgdkcCA/bSOJtmwjZgrJziT49RYGQZrf08AvTZEkEMCxDB8gdJJ2pk OZxQ95oRdurCgpMhu+fqifQm+iH6gEcRJi/H7MmRXx9wIj0RMlw9GJPPvQWI8ulaB9b1 La6MQepiiKPldoj3vnELstLznPRGMDfbvDvdVaJPm6PGq0MOEBnyWEV8hB2yePaDBged wIavntyb/MLYUWtfSVQ6YofgyAhgc3tx23CxLSOoUY6bl6rbfdMQWl3I1Ou7DbnIOnOZ MrbrprtF0ngJQ66PFXpq1T8bOaGWEDpmw7sgW6vpxMZXSvD26J8REoYonZmi6l/Jvvew oXsw== X-Gm-Message-State: AOJu0YzaqW/pQgsMmcyTds7q7tqy4dx3NJcZY4GcN7W/2zCbp4W7vYyG lH5KqAfjMThqhK8q/lTKe1Aumb1JN8sRl31h0KgkybEscNo4CEgedunCiclE3sqNEO+++uQn/fY 1Adxuqw== X-Received: by 2002:a05:600c:1f91:b0:430:57f2:bae5 with SMTP id 5b1f17b1804b1-4327b7eac96mr179772115e9.27.1730846898142; Tue, 05 Nov 2024 14:48:18 -0800 (PST) Received: from localhost.localdomain ([154.14.63.34]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432aa6da94fsm1022225e9.29.2024.11.05.14.48.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 05 Nov 2024 14:48:17 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Zhao Liu , "Daniel P . Berrange" , Yongwei Ma , Jonathan Cameron , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= Subject: [PULL 09/29] qapi/qom: Define cache enumeration and properties for machine Date: Tue, 5 Nov 2024 22:47:07 +0000 Message-ID: <20241105224727.53059-10-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241105224727.53059-1-philmd@linaro.org> References: <20241105224727.53059-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Zhao Liu The x86 and ARM need to allow user to configure cache properties (current only topology): * For x86, the default cache topology model (of max/host CPU) does not always match the Host's real physical cache topology. Performance can increase when the configured virtual topology is closer to the physical topology than a default topology would be. * For ARM, QEMU can't get the cache topology information from the CPU registers, then user configuration is necessary. Additionally, the cache information is also needed for MPAM emulation (for TCG) to build the right PPTT. Define smp-cache related enumeration and properties in QAPI, so that user could configure cache properties for SMP system through -machine in the subsequent patch. Cache enumeration (CacheLevelAndType) is implemented as the combination of cache level (level 1/2/3) and cache type (data/instruction/unified). 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, enumerate the L1 D-cache, L1 I-cache, L2 cache and L3 cache with smp-cache object to add the basic cache topology support. Other kinds of caches (e.g., L1 unified or L2/L3 separated caches) can be added directly into CacheLevelAndType if necessary. Cache properties (SmpCacheProperties) currently only contains cache topology information, and other cache properties can be added in it if necessary. Note, define cache topology based on CPU topology level with 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. With smp-cache QAPI support, add smp cache topology for machine by parsing the smp-cache object list. Also add the helper to access/update cache topology level of machine. Suggested-by: Daniel P. Berrange Signed-off-by: Zhao Liu Tested-by: Yongwei Ma Reviewed-by: Jonathan Cameron Message-ID: <20241101083331.340178-4-zhao1.liu@intel.com> Signed-off-by: Philippe Mathieu-Daudé --- qapi/machine-common.json | 50 ++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 12 ++++++++++ hw/core/machine-smp.c | 37 +++++++++++++++++++++++++++++ hw/core/machine.c | 44 +++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+) diff --git a/qapi/machine-common.json b/qapi/machine-common.json index 1a5687fb99f..298e51f373a 100644 --- a/qapi/machine-common.json +++ b/qapi/machine-common.json @@ -60,3 +60,53 @@ { 'enum': 'CpuTopologyLevel', 'data': [ 'thread', 'core', 'module', 'cluster', 'die', 'socket', 'book', 'drawer', 'default' ] } + +## +# @CacheLevelAndType: +# +# Caches a system may have. The enumeration value here is the +# combination of cache level and cache type. +# +# @l1d: L1 data cache. +# +# @l1i: L1 instruction cache. +# +# @l2: L2 (unified) cache. +# +# @l3: L3 (unified) cache +# +# Since: 9.2 +## +{ 'enum': 'CacheLevelAndType', + 'data': [ 'l1d', 'l1i', 'l2', 'l3' ] } + +## +# @SmpCacheProperties: +# +# Cache information for SMP system. +# +# @cache: Cache name, which is the combination of cache level +# and cache type. +# +# @topology: Cache topology level. It accepts the CPU topology +# enumeration as the parameter, i.e., CPUs in the same +# topology container share the same cache. +# +# Since: 9.2 +## +{ 'struct': 'SmpCacheProperties', + 'data': { + 'cache': 'CacheLevelAndType', + 'topology': 'CpuTopologyLevel' } } + +## +# @SmpCachePropertiesWrapper: +# +# List wrapper of SmpCacheProperties. +# +# @caches: the list of SmpCacheProperties. +# +# Since 9.2 +## +{ 'struct': 'SmpCachePropertiesWrapper', + 'data': { 'caches': ['SmpCacheProperties'] } } diff --git a/include/hw/boards.h b/include/hw/boards.h index a8f001fd21f..b3a8064ccc9 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -44,8 +44,15 @@ void machine_set_cpu_numa_node(MachineState *machine, Error **errp); void machine_parse_smp_config(MachineState *ms, const SMPConfiguration *config, Error **errp); +bool machine_parse_smp_cache(MachineState *ms, + const SmpCachePropertiesList *caches, + Error **errp); unsigned int machine_topo_get_cores_per_socket(const MachineState *ms); unsigned int machine_topo_get_threads_per_socket(const MachineState *ms); +CpuTopologyLevel machine_get_cache_topo_level(const MachineState *ms, + CacheLevelAndType cache); +void machine_set_cache_topo_level(MachineState *ms, CacheLevelAndType cache, + CpuTopologyLevel level); void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size); /** @@ -371,6 +378,10 @@ typedef struct CpuTopology { unsigned int max_cpus; } CpuTopology; +typedef struct SmpCache { + SmpCacheProperties props[CACHE_LEVEL_AND_TYPE__MAX]; +} SmpCache; + /** * MachineState: */ @@ -421,6 +432,7 @@ struct MachineState { AccelState *accelerator; CPUArchIdList *possible_cpus; CpuTopology smp; + SmpCache smp_cache; struct NVDIMMState *nvdimms_state; struct NumaState *numa_state; }; diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 5d8d7edcbd3..c6d90cd6d41 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -261,6 +261,31 @@ void machine_parse_smp_config(MachineState *ms, } } +bool machine_parse_smp_cache(MachineState *ms, + const SmpCachePropertiesList *caches, + Error **errp) +{ + const SmpCachePropertiesList *node; + DECLARE_BITMAP(caches_bitmap, CACHE_LEVEL_AND_TYPE__MAX); + + for (node = caches; node; node = node->next) { + /* Prohibit users from repeating settings. */ + if (test_bit(node->value->cache, caches_bitmap)) { + error_setg(errp, + "Invalid cache properties: %s. " + "The cache properties are duplicated", + CacheLevelAndType_str(node->value->cache)); + return false; + } + + machine_set_cache_topo_level(ms, node->value->cache, + node->value->topology); + set_bit(node->value->cache, caches_bitmap); + } + + return true; +} + unsigned int machine_topo_get_cores_per_socket(const MachineState *ms) { return ms->smp.cores * ms->smp.modules * ms->smp.clusters * ms->smp.dies; @@ -270,3 +295,15 @@ unsigned int machine_topo_get_threads_per_socket(const MachineState *ms) { return ms->smp.threads * machine_topo_get_cores_per_socket(ms); } + +CpuTopologyLevel machine_get_cache_topo_level(const MachineState *ms, + CacheLevelAndType cache) +{ + return ms->smp_cache.props[cache].topology; +} + +void machine_set_cache_topo_level(MachineState *ms, CacheLevelAndType cache, + CpuTopologyLevel level) +{ + ms->smp_cache.props[cache].topology = level; +} diff --git a/hw/core/machine.c b/hw/core/machine.c index fd3716b7dfd..e6c92faf73e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -907,6 +907,40 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name, machine_parse_smp_config(ms, config, errp); } +static void machine_get_smp_cache(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MachineState *ms = MACHINE(obj); + SmpCache *cache = &ms->smp_cache; + SmpCachePropertiesList *head = NULL; + SmpCachePropertiesList **tail = &head; + + for (int i = 0; i < CACHE_LEVEL_AND_TYPE__MAX; i++) { + SmpCacheProperties *node = g_new(SmpCacheProperties, 1); + + node->cache = cache->props[i].cache; + node->topology = cache->props[i].topology; + QAPI_LIST_APPEND(tail, node); + } + + visit_type_SmpCachePropertiesList(v, name, &head, errp); + qapi_free_SmpCachePropertiesList(head); +} + +static void machine_set_smp_cache(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MachineState *ms = MACHINE(obj); + SmpCachePropertiesList *caches; + + if (!visit_type_SmpCachePropertiesList(v, name, &caches, errp)) { + return; + } + + machine_parse_smp_cache(ms, caches, errp); + qapi_free_SmpCachePropertiesList(caches); +} + static void machine_get_boot(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { @@ -1067,6 +1101,11 @@ static void machine_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "smp", "CPU topology"); + object_class_property_add(oc, "smp-cache", "SmpCachePropertiesWrapper", + machine_get_smp_cache, machine_set_smp_cache, NULL, NULL); + object_class_property_set_description(oc, "smp-cache", + "Cache properties list for SMP machine"); + object_class_property_add(oc, "phandle-start", "int", machine_get_phandle_start, machine_set_phandle_start, NULL, NULL); @@ -1205,6 +1244,11 @@ static void machine_initfn(Object *obj) ms->smp.cores = 1; ms->smp.threads = 1; + for (int i = 0; i < CACHE_LEVEL_AND_TYPE__MAX; i++) { + ms->smp_cache.props[i].cache = (CacheLevelAndType)i; + ms->smp_cache.props[i].topology = CPU_TOPOLOGY_LEVEL_DEFAULT; + } + machine_copy_boot_config(ms, &(BootConfiguration){ 0 }); }