arm64: expose CPU prefetch and cache modulation controls
Subsystems (3)
v6 cover arm64: expose CPU prefetch and cache modulation controls
From: Koba Ko <[email protected]>
This series adds CONFIG_ARM64_CPUMOD, a default-off arm64 interface for controlled performance characterization of selected implementation-defined CPU prefetch and cache-management fields. It exposes a small set of named, per-CPU attributes under the path below, with writable control fields range-checked before register state is changed:
/sys/devices/system/cpu/cpuN/cpumod/
The directory is created for online CPUs whose MIDR matches a recognized Grace or Vera profile, with common and profile-specific attributes selected for that CPU. Register accesses execute on the CPU that owns the sysfs instance, and CPU hotplug creates or removes the per-CPU subtree as the CPU transitions online or offline. Unsupported CPU profiles are skipped without blocking module load or CPU hotplug.
The implementation keeps each dynamically allocated kobject in a private per-CPU pointer, avoiding use of the CPU device's shared driver-data slot. The documentation defines the ABI, firmware prerequisite, and hotplug lifecycle. The kselftest validates profile-specific layout, unsupported-CPU skipping, decimal affected_cpus reporting, value validation, optional writes, all-online-CPU coverage, and cleanup.
The controls require firmware to permit EL1 access to the relevant implementation control registers. This is an RFC interface for controlled evaluation, not a general raw-register or production-default tuning ABI.
Compile and static verification passed. DUT runtime validation was not run.
Koba Ko (3):
arm64: add CPU prefetch and cache modulation sysfs interface Documentation/arch/arm64: document arm_cpumod
selftests: arm64: add arm_cpumod kselftest
Documentation/arch/arm64/arm-cpumod.rst | 89 +++ Documentation/arch/arm64/index.rst | 1 + arch/arm64/Kconfig | 17 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/arm_cpumod.c | 471 ++++++++++++++++ arch/arm64/kernel/arm_cpumod_internal.h | 113 ++++ tools/testing/selftests/arm64/Makefile | 2 +- .../selftests/arm64/arm_cpumod/Makefile | 5 + .../selftests/arm64/arm_cpumod/arm_cpumod.sh | 526 ++++++++++++++++++ 9 files changed, 1224 insertions(+), 1 deletion(-) create mode 100644 Documentation/arch/arm64/arm-cpumod.rst create mode 100644 arch/arm64/kernel/arm_cpumod.c create mode 100644 arch/arm64/kernel/arm_cpumod_internal.h create mode 100644 tools/testing/selftests/arm64/arm_cpumod/Makefile create mode 100755 tools/testing/selftests/arm64/arm_cpumod/arm_cpumod.sh
Signature · 1 line
2.43.0
RFC PATCH v6 1/3 arm64: add CPU prefetch and cache modulation sysfs interface
From: Koba Ko <[email protected]>
Performance characterization on arm64 systems sometimes needs a way to inspect and bracket selected implementation-defined prefetch and cache controls without exposing raw register contents. Add an RFC-only arm64 cpumod interface that presents a small set of named, range-checked per-CPU sysfs attributes under each CPU device.
Establish the Kconfig and Makefile plumbing, CPU profile detection for Grace and Vera from the target CPU's MIDR, register-field descriptors, per-CPU kobject and attribute helpers, locking, and target-CPU read/write callbacks. Common attributes are exposed for all supported profiles, while Grace- and Vera-specific fields are exposed only for the matching profile. Place the option at the end of the top-level Kernel Features menu because these implementation controls are not tied to an Arm architecture revision.
Per-CPU cpumod sysfs state follows the CPU lifecycle. Module initialization populates subtrees for every online CPU while holding cpus_read_lock(), so initial enumeration and CPU hotplug state registration are serialized against concurrent topology changes. Offline CPUs are intentionally skipped during initial setup because target-CPU MIDR detection requires an IPI-capable online CPU; a later online callback creates their subtree.
Profile detection reads MIDR through a synchronous callback on the CPU owning the sysfs subtree and returns nonzero only when that dispatch fails, so no IPI error can be hidden. After a successful read, retain CPUMOD_PROFILE_UNKNOWN as the unsupported-profile sentinel. Subtree creation skips that profile during both initial online enumeration and later CPUHP online callbacks without blocking module load or CPU hotplug. Object and sysfs setup failures remain fatal and are propagated.
Keep the dynamically allocated kobject state in a private per-CPU pointer instead of the CPU device's generic driver-data slot. The online callback is idempotent when that pointer already records a subtree. The offline callback clears the private pointer before dropping the kobject reference, allowing the release callback to retain ownership of the final free.
Register the dynamic CPUHP state with cpuhp_setup_state_nocalls_cpuslocked(). The nocalls form avoids replaying startup callbacks for CPUs already initialized by the explicit online enumeration. On init failure, release the CPU read lock, destroy all subtrees created so far, and return the error. Module exit removes the CPUHP state with the matching nocalls helper and tears down all remaining per-CPU state across possible CPUs.
--- arch/arm64/Kconfig | 17 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/arm_cpumod.c | 471 ++++++++++++++++++++++++ arch/arm64/kernel/arm_cpumod_internal.h | 113 ++++++ 4 files changed, 602 insertions(+) create mode 100644 arch/arm64/kernel/arm_cpumod.c create mode 100644 arch/arm64/kernel/arm_cpumod_internal.h
arch/arm64/Kconfig +17 -0
@@ -2417,6 +2417,23 @@ config ARM64_CONTPTE bit, for any mappings that meet the size and alignment requirements. This reduces TLB pressure and improves performance. +config ARM64_CPUMOD + tristate "Arm CPU prefetch modulation sysfs controls" + help + Expose selected CPU implementation control register fields through + per-CPU sysfs attributes for performance characterization. + + The exposed controls allow hardware prefetch and cache-management + policy fields to be inspected and adjusted on CPUs where firmware + permits EL1 access to the relevant implementation control registers. + Systems where firmware traps or blocks these writes cannot use this + interface. + + This interface is intended for controlled performance evaluation and + should not be enabled by default on production systems. + + If unsure, say N. + endmenu # "Kernel Features" menu "Boot options"
arch/arm64/kernel/Makefile +1 -0
@@ -69,6 +69,7 @@ obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_ARM64_MPAM) += mpam.o +obj-$(CONFIG_ARM64_CPUMOD) += arm_cpumod.o obj-$(CONFIG_ARM64_MTE) += mte.o obj-y += vdso-wrap.o obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o
arch/arm64/kernel/arm_cpumod.c new file +471 -0
471 lines not on this page · raw message
arch/arm64/kernel/arm_cpumod_internal.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH v6 2/3 Documentation/arch/arm64: document arm_cpumod
In reply to KobaKFrom: Koba Ko <[email protected]>
Document the ABI intent and scope for the new arm64 cpumod interface. The sysfs directory is per-CPU and is created only for recognized Grace and Vera profiles:
/sys/devices/system/cpu/cpuN/cpumod/
CPUs with unsupported MIDRs are skipped without blocking module load or CPU hotplug and do not receive a cpumod directory.
Describe the common attributes, the Grace- and Vera-specific attributes, and the accepted range for each writable field. Out-of-range writes are documented as failing before either cached sysfs state or target CPU register state is changed.
Document the CPU hotplug lifecycle explicitly: the cpumod directory is present only while a supported CPU is online, is removed when that CPU goes offline, and is recreated when it returns online. Reads and writes therefore require an online target CPU.
Also document the firmware prerequisite: EL1 must be allowed to access the relevant implementation control registers. The interface remains an RFC for controlled performance characterization, is not a general production tuning ABI, and should stay disabled by default on production systems.
--- Documentation/arch/arm64/arm-cpumod.rst | 89 +++++++++++++++++++++++++ Documentation/arch/arm64/index.rst | 1 + 2 files changed, 90 insertions(+) create mode 100644 Documentation/arch/arm64/arm-cpumod.rst
Documentation/arch/arm64/arm-cpumod.rst new file +89 -0
@@ -0,0 +1,89 @@ +.. SPDX-License-Identifier: GPL-2.0 + +==================================== +Arm CPU prefetch modulation controls +==================================== + +``ARM64_CPUMOD`` exposes selected CPU implementation control register fields +through per-CPU sysfs attributes under:: + + /sys/devices/system/cpu/cpuN/cpumod/ + +The ``cpumod`` directory is created only when the CPU MIDR matches a recognized +Grace or Vera profile. CPUs with unsupported MIDRs are skipped without blocking +module load or CPU hotplug and do not have a ``cpumod`` directory. + +The interface is intended for controlled performance characterization and +evaluation. It is not intended as a general production tuning ABI, and the +configuration should remain disabled by default on production systems. + +Configuration and placement +=========================== + +The controls are built when ``CONFIG_ARM64_CPUMOD`` is enabled. The code lives +under ``arch/arm64/kernel/`` because the exposed state is CPU implementation +control state accessed by the arm64 kernel, similar in placement to other +architecture CPU-facing helpers. + +The ABI remains separate from the existing arm64 ``cpu*/regs`` sysfs files: +``cpumod`` exposes a small set of named, range-checked control fields rather +than a general raw register dump. + +CPU hotplug +=========== + +A ``cpumod`` directory is created only for online CPUs with a supported +profile. The directory is removed when a CPU goes offline and recreated when +the CPU comes back online, again only when its MIDR matches a supported +profile. Reads and writes require the target CPU to be online. + +Firmware requirement +==================== + +The controls require firmware to permit EL1 reads and writes to the relevant +CPU implementation control registers. On systems where firmware traps or +blocks those accesses, the interface cannot be used. + +Current ABI +=========== + +Common attributes: + +``affected_cpus`` + Read-only decimal CPU identifier for the sysfs instance. + +``pf_dis`` + Hardware prefetch disable control. Valid values are ``0`` and ``1``. + +``pf_mode`` + Hardware prefetch aggressiveness mode. Valid values are ``0`` through ``9``. + Values ``10`` through ``15`` are reserved and rejected. + +Grace-only attributes: + +``cbusy_filter_threshold`` + Valid values are ``0`` through ``3``. + +``cbusy_filter_window`` + Valid values are ``0`` through ``3``. + +``cmc_min_ways`` + Valid values are ``0`` through ``7``. + +Vera-only attributes: + +``l2spr_cmc_max_ways`` + Valid values are ``0`` through ``7``. + +Invalid writes +============== + +Writes outside the documented range fail with ``-EINVAL`` before the cached +sysfs state or remote CPU register state is updated. + +Open register inventory +======================= + +The first RFC intentionally exposes only the currently validated subset. A +complete documented-field inventory, including L2CDP, should be reviewed before +adding further ABI nodes.
Documentation/arch/arm64/index.rst +1 -0
@@ -8,6 +8,7 @@ ARM64 Architecture :maxdepth: 1 acpi_object_usage + arm-cpumod amu arm-acpi arm-cca
Signature · 1 line
2.43.0
RFC PATCH v6 3/3 selftests: arm64: add arm_cpumod kselftest
In reply to KobaKFrom: Koba Ko <[email protected]>
Add a kselftest for the arm_cpumod sysfs ABI. The test loads or reuses the module and selects either one target CPU or a snapshot of all online CPUs. In single-CPU mode, skip an offline target before module validation. Observe the per-CPU online attribute first. If it is absent, immediately require the CPU directory to still exist before treating the CPU as non-hotpluggable and online. If the attribute exists, it must be readable and contain 1.
After module load, recheck the online state before classifying a selected CPU without a cpumod directory as an unsupported profile. Fail if the CPU went offline or disappeared, log and skip CPUs that remain online without a directory, and require at least one selected CPU to expose a supported Grace or Vera profile. Return KSFT_SKIP if none do.
For supported CPUs, recognize the exposed Grace or Vera profile-specific layout and validate the matching attributes. Only ARM_CPUMOD_EXPECT_PROFILE supplies an external profile expectation.
Verify read paths by checking that attributes return decimal values and that affected_cpus identifies the current CPU as a decimal CPU number. Optional valid-write testing writes each current value back. Optional invalid-write testing checks selected out-of-range values and confirms that the prior value remains unchanged.
Both write paths are opt-in. Valid writeback can alter implementation-defined CPU controls; invalid-write checks exercise rejection through the same firmware-sensitive interface, but are expected not to update state. Cover all-online-CPU mode through /sys/devices/system/cpu/online and, when the test loaded the module, verify cleanup by removing it and checking that the selected CPU subtrees disappear. The test does not offline or online CPUs.
--- tools/testing/selftests/arm64/Makefile | 2 +- .../selftests/arm64/arm_cpumod/Makefile | 5 + .../selftests/arm64/arm_cpumod/arm_cpumod.sh | 526 ++++++++++++++++++ 3 files changed, 532 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/arm64/arm_cpumod/Makefile create mode 100755 tools/testing/selftests/arm64/arm_cpumod/arm_cpumod.sh
tools/testing/selftests/arm64/Makefile +1 -1
@@ -4,7 +4,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),aarch64 arm64)) -ARM64_SUBTARGETS ?= tags signal pauth fp mte bti abi gcs + ARM64_SUBTARGETS ?= tags signal pauth fp mte bti abi gcs arm_cpumod else ARM64_SUBTARGETS := endif
tools/testing/selftests/arm64/arm_cpumod/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +TEST_PROGS := arm_cpumod.sh + +include ../../lib.mk
tools/testing/selftests/arm64/arm_cpumod/arm_cpumod.sh new file +526 -0
526 lines not on this page · raw message
Signature · 1 line
2.43.0
From: Koba Ko <[email protected]>
Please ignore this series. I used the wrong version tag in the subject. I will resend it with the corrected subject.
Signature · 1 line
Koba Ko