From patchwork Sun Sep 8 12:59:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13795440 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 776F36CDBA for ; Sun, 8 Sep 2024 12:43:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725799409; cv=none; b=GjTaUAcZ1N9RBBXD0dFapOupQ6rzEzo1jBzfCcuaEIWuCt1L2kLJbXQtDMXRXr3xqknGaQMKyEhwDKO4L/uJBTXkvvbshR3+1zAuXkOy/ixg+FToHCCC767Zx+2Hl93asSuNjY8DBlp+zIz5QBc7yPgi/CGg0tbDtkbJY3NFGvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725799409; c=relaxed/simple; bh=BoRZmDFSyV2mqYLCh9CopRCSnLh6p2jwwrbsvnqOMEY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=VKykADbZM76vd9YMbqk9SWM9OL9W7ZChb6oZbdnO4H7zokBhTghFcJMMmJy8fIXpWLSN/9ghaMaWK8lyq5QhABsTAIz/pkQ5+SScL2Iio4/pJxgtE8J7m2qtKe2nPTtcyYmroEL56LU61NYyBlv/7vm36PW+gfsu0dmXMAyPq6k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Qkh+DHJs; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Qkh+DHJs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725799408; x=1757335408; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BoRZmDFSyV2mqYLCh9CopRCSnLh6p2jwwrbsvnqOMEY=; b=Qkh+DHJsenz8uPHaNJT7onK0uJ6Q4PbiTbutFns9G+tNdyTW9r0LI/LC Qxx8hBmSeMEn448QMGdnbnArsAjxfgMWrbCpTpkGyd6yU1Da2+i6YRHBx lgzlTxenwsjJOOBrsWTCpOy2WyQ6r/JlpnG+0HmfHhzNwmnUFe4ObkJWY rnRywwVUJJaFpRxBzFKRDYysPQOa3OWJqC0b09PItc2a4JQt4k5NsZ2zP LzYOgHwpF1sYQHLapUObRetQ60TKzxg7uL9LqAJ42AlD75yknk2e11WJ9 aJ/Y8bWZ0AMyx+Av5cC5QnVjYhplFGLtTK85+ReO9HwNIPyRAGrp+UGil Q==; X-CSE-ConnectionGUID: 09Pr5DTOQG2/2hGhuzQX2w== X-CSE-MsgGUID: HI/elbICS+SdWYYKcFPbRQ== X-IronPort-AV: E=McAfee;i="6700,10204,11189"; a="28238098" X-IronPort-AV: E=Sophos;i="6.10,212,1719903600"; d="scan'208";a="28238098" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2024 05:43:27 -0700 X-CSE-ConnectionGUID: d/rhpYHgS4em0LAuGrlaJQ== X-CSE-MsgGUID: FSUCJbt4QfG2OSDdwDfZ+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,212,1719903600"; d="scan'208";a="97196482" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 08 Sep 2024 05:43:21 -0700 From: Zhao Liu To: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , "Michael S . Tsirkin" , Paolo Bonzini , Richard Henderson , Eric Blake , Markus Armbruster , Marcelo Tosatti , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , Jonathan Cameron , Sia Jee Heng , Alireza Sanaee 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: [PATCH v2 0/7] Introduce SMP Cache Topology Date: Sun, 8 Sep 2024 20:59:13 +0800 Message-Id: <20240908125920.1160236-1-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hi all, Compared with previous Patch v1 [1], I've put the cache properties list into -machine, this is to meet current needs and also remain compatible with my future topology support (more discussion details, pls refer [2]). This series is based on the commit 1581a0bc928d ("Merge tag 'pull-ufs- 20240906' of https://gitlab.com/jeuk20.kim/qemu into staging ufs queue"). Background ========== The x86 and ARM (RISCV) 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. (Originally from Jonathan) About smp-cache =============== In this version, smp-cache is implemented as a array integrated in -machine. Though -machine currently can't support JSON format, this is the one of the directions of future. An example is as follows: smp_cache=smp-cache.0.cache=l1i,smp-cache.0.topology=core,smp-cache.1.cache=l1d,smp-cache.1.topology=core,smp-cache.2.cache=l2,smp-cache.2.topology=module,smp-cache.3.cache=l3,smp-cache.3.topology=die "cache" specifies the cache that the properties will be applied on. This field is the combination of cache level and cache type. Now it supports "l1d" (L1 data cache), "l1i" (L1 instruction cache), "l2" (L2 unified cache) and "l3" (L3 unified cache). "topology" field accepts CPU topology levels including "thread", "core", "module", "cluster", "die", "socket", "book", "drawer" and a special value "default". The "default" is introduced to make it easier for libvirt to set a default parameter value without having to care about the specific machine (because currently there is no proper way for machine to expose supported topology levels and caches). If "default" is set, then the cache topology will follow the architecture's default cache topology model. If other CPU topology level is set, the cache will be shared at corresponding CPU topology level. Welcome your comment! [1]: Patch v1: https://lore.kernel.org/qemu-devel/20240704031603.1744546-1-zhao1.liu@intel.com/ [2]: API disscussion: https://lore.kernel.org/qemu-devel/8734ndj33j.fsf@pond.sub.org/ Thanks and Best Regards, Zhao --- Changelog: Main changes since Patch v1: * Dropped handwriten smp-cache object and integrated cache properties list into MachineState and used -machine to configure SMP cache properties. (Markus) * Dropped prefix of CpuTopologyLevel enumeration. (Markus) * Rename CPU_TOPO_LEVEL_* to CPU_TOPOLOGY_LEVEL_* to match the QAPI's generated code. (Markus) * Renamed SMPCacheProperty/SMPCacheProperties (QAPI structures) to SmpCacheProperties/SmpCachePropertiesWrapper. (Markus) * Renamed SMPCacheName (QAPI structure) to SmpCacheLevelAndType and dropped prefix. (Markus) * Renamed 'name' field in SmpCacheProperties to 'cache', since the type and level of the cache in SMP system could be able to specify all of these kinds of cache explicitly enough. * Renamed 'topo' field in SmpCacheProperties to 'topology'. (Markus) * Returned error information when user repeats setting cache properties. (Markus) * Renamed SmpCacheLevelAndType to CacheLevelAndType, since this representation is general across SMP or hybrid system. * Dropped machine_check_smp_cache_support() and did the check when -machine parses smp-cache in machine_parse_smp_cache(). Main changes since RFC v2: * Dropped cpu-topology.h and cpu-topology.c since QAPI has the helper (CpuTopologyLevel_str) to convert enum to string. (Markus) * Fixed text format in machine.json (CpuTopologyLevel naming, 2 spaces between sentences). (Markus) * Added a new level "default" to de-compatibilize some arch-specific topo settings. (Daniel) * Moved CpuTopologyLevel to qapi/machine-common.json, at where the cache enumeration and smp-cache object would be added. - If smp-cache object is defined in qapi/machine.json, storage-daemon will complain about the qmp cmds in qapi/machine.json during compiling. * Referred to Daniel's suggestion to introduce cache JSON list, though as a standalone object since -smp/-machine can't support JSON. * Linked machine's smp_cache to smp-cache object instead of a builtin structure. This is to get around the fact that the keyval format of -machine can't support JSON. * Wrapped the cache topology level access into a helper. * Split as a separate commit to just include compatibility checking and topology checking. * Allow setting "default" topology level even though the cache isn't supported by machine. (Daniel) * Rewrote the document of smp-cache object. Main changes since RFC v1: * Split CpuTopology renaimg out of this RFC. * Use QAPI to enumerate CPU topology levels. * Drop string_to_cpu_topo() since QAPI will help to parse the topo levels. * Set has_*_cache field in machine_get_smp(). (JeeHeng) * Use "*_cache=topo_level" as -smp example as the original "level" term for a cache has a totally different meaning. (Jonathan) --- Zhao Liu (7): hw/core: Make CPU topology enumeration arch-agnostic qapi/qom: Define cache enumeration and properties hw/core: Add smp cache topology for machine hw/core: Check smp cache topology support for machine i386/cpu: Support thread and module level cache topology i386/cpu: Update cache topology with machine's configuration i386/pc: Support cache topology in -machine for PC machine hw/core/machine-smp.c | 119 +++++++++++++++++++++++ hw/core/machine.c | 44 +++++++++ hw/i386/pc.c | 4 + hw/i386/x86-common.c | 4 +- include/hw/boards.h | 13 +++ include/hw/i386/topology.h | 22 +---- qapi/machine-common.json | 96 ++++++++++++++++++- qemu-options.hx | 28 +++++- target/i386/cpu.c | 191 ++++++++++++++++++++++--------------- target/i386/cpu.h | 4 +- 10 files changed, 425 insertions(+), 100 deletions(-)