Skip to contentSkip to conversation

arm64: Expose CPUECTLR{,2}_EL1 via sysfs

PATCH In review Palmer Dabbelt 3 participants 7 messages Aug 6, 2025 – Aug 7, 2025 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Expose CPUECTLR{,2}_EL1 via sysfs

From: Palmer Dabbelt <[email protected]>

We've found that some of our workloads run faster when some of these fields are set to non-default values on some of the systems we're trying to run those workloads on. This allows us to set those values via sysfs, so we can do workload/system-specific tuning.

---
I've only really smoke tested this, but I figured I'd send it along because I'm not sure if this is even a sane thing to be doing -- these extended control registers have some wacky stuff in them, so maybe they're not exposed to userspace on purpose. IIUC firmware can gate these writes, though, so it should be possible for vendors to forbid the really scary values.

That said, we do see some performance improvements here on real workloads. So we're hoping to roll some of this tuning work out more widely, but we also don't want to adopt some internal interface. Thus it'd make our lives easier if we could twiddle these bits in a standard way.

Nobody's wed to sysfs, I just went with it because some of the other system registers are exposed there.

---
 arch/arm64/include/asm/cpu.h    |   2 +
 arch/arm64/include/asm/sysreg.h |   3 +
 arch/arm64/kernel/cpuinfo.c     | 192 +++++++++++++++++++++++++++++++-
 3 files changed, 194 insertions(+), 3 deletions(-)
arch/arm64/include/asm/cpu.h +2 -0
index 71493b760b83..275d24da962b 100644
@@ -39,6 +39,8 @@ struct cpuinfo_32bit {
 
 struct cpuinfo_arm64 {
 	struct kobject	kobj;
+	unsigned int cpu;
+
 	u64		reg_ctr;
 	u64		reg_cntfrq;
 	u64		reg_dczid;
arch/arm64/include/asm/sysreg.h +3 -0
index d5b5f2ae1afa..17dfbf640a2a 100644
@@ -412,6 +412,9 @@
 
 #define SYS_AIDR_EL1			sys_reg(3, 1, 0, 0, 7)
 
+#define SYS_CPUECTRL_EL1		sys_reg(3, 0, 15, 1, 4)
+#define SYS_CPUECTRL2_EL1		sys_reg(3, 0, 15, 1, 5)
+
 #define SYS_RNDR_EL0			sys_reg(3, 3, 2, 4, 0)
 #define SYS_RNDRRS_EL0			sys_reg(3, 3, 2, 4, 1)
 
arch/arm64/kernel/cpuinfo.c +189 -3

226 lines not on this page · raw message

Signature · 1 line
2.50.1
#1 lore raw
Quoted 8 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

We've found that some of our workloads run faster when some of these fields are set to non-default values on some of the systems we're trying to run those workloads on. This allows us to set those values via sysfs, so we can do workload/system-specific tuning.

Quoted 7 lines

---
I've only really smoke tested this, but I figured I'd send it along because I'm not sure if this is even a sane thing to be doing -- these extended control registers have some wacky stuff in them, so maybe they're not exposed to userspace on purpose. IIUC firmware can gate these writes, though, so it should be possible for vendors to forbid the really scary values.

That's really wrong.

For a start, these encodings fall into the IMPDEF range. They won't exist on non-ARM implementations.

Next, this will catch fire as a guest, either because the hypervisor will simply refuse to entertain letting it access registers that have no definition, or because the VM has been migrated from one implementation to another, and you have no idea this is doing on the new target.

Quoted 5 lines

That said, we do see some performance improvements here on real workloads. So we're hoping to roll some of this tuning work out more widely, but we also don't want to adopt some internal interface. Thus it'd make our lives easier if we could twiddle these bits in a standard way.

Honestly, this is the sort of bring-up stuff that is better kept in your private sandbox, and doesn't really help in general.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#2 lore raw
Quoted 18 lines · Marc Zyngier
Quoted 8 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

We've found that some of our workloads run faster when some of these fields are set to non-default values on some of the systems we're trying to run those workloads on. This allows us to set those values via sysfs, so we can do workload/system-specific tuning.

Quoted 7 lines

---
I've only really smoke tested this, but I figured I'd send it along because I'm not sure if this is even a sane thing to be doing -- these extended control registers have some wacky stuff in them, so maybe they're not exposed to userspace on purpose. IIUC firmware can gate these writes, though, so it should be possible for vendors to forbid the really scary values.

Quoted 4 lines

That's really wrong.

For a start, these encodings fall into the IMPDEF range. They won't exist on non-ARM implementations.

OK, and that's because it says "Provides additional IMPLEMENTATION DEFINED configuration and control options for the processor." at the start of the manual page? Sorry, I'm kind of new to trying to read the Arm specs -- I thought just the meaning of the values was changing, but I probably just didn't read enough specs.

Quoted 5 lines

Next, this will catch fire as a guest, either because the hypervisor will simply refuse to entertain letting it access registers that have no definition, or because the VM has been migrated from one implementation to another, and you have no idea this is doing on the new target.

Ya, makes sense.

Quoted 7 lines
Quoted 4 lines

That said, we do see some performance improvements here on real workloads. So we're hoping to roll some of this tuning work out more widely, but we also don't want to adopt some internal interface. Thus it'd make our lives easier if we could twiddle these bits in a standard way.

Honestly, this is the sort of bring-up stuff that is better kept in your private sandbox, and doesn't really help in general.

So we're not doing bringup (or at least not doing what I'd call bringup) here, the theory is that we just get better performance on different workloads with different tunings. That's all still a little early, but if the data holds we'd want to be setting these based on what workload is running (ie, not just some static tuning for everything).

That said, part of the reason I just sent this as-is is because I was sort of expecting the answer to be "no" here. No big deal if that's the case, we can figure out some other way to solve the problem. Happy to throw some time in to making some more generic flavor of this, though...

Quoted 3 lines

Thanks,

	M.
#3 lore raw
Quoted 10 lines · Palmer Dabbelt
Quoted 2 lines · Marc Zyngier

For a start, these encodings fall into the IMPDEF range. They won't exist on non-ARM implementations.

OK, and that's because it says "Provides additional IMPLEMENTATION DEFINED configuration and control options for the processor." at the start of the manual page? Sorry, I'm kind of new to trying to read the Arm specs -- I thought just the meaning of the values was changing, but I probably just didn't read enough specs.

Yes, pretty much and also because this is in a range of registers reserved for use by the specific implementation. See DDI0487 (the ARM) version L.a sections D23.3.2 and D24.2.162 which specify the IMPLEMENTATION DEFINED system register range, and the definition of the term IMPLEMENTATION DEFINED in the glossary of DDI0487. If you see a small upper case term like that in a spec related to the architecture then it'll have a specific architectural defintion.

Quoted 4 lines

That said, part of the reason I just sent this as-is is because I was sort of expecting the answer to be "no" here. No big deal if that's the case, we can figure out some other way to solve the problem. Happy to throw some time in to making some more generic flavor of this, though...

It's something that does come up, working out a way to make use of the tuning in the IMPDEF registers in a way that generic software can safely and sensibly make use of is rather non-trivial though.

#4 lore raw
Quoted 12 lines · On Thu, 07 Aug 2025 10:57:26 PDT (-0700), [email protected] wrote:
Quoted 10 lines · Palmer Dabbelt
Quoted 2 lines · Marc Zyngier

For a start, these encodings fall into the IMPDEF range. They won't exist on non-ARM implementations.

OK, and that's because it says "Provides additional IMPLEMENTATION DEFINED configuration and control options for the processor." at the start of the manual page? Sorry, I'm kind of new to trying to read the Arm specs -- I thought just the meaning of the values was changing, but I probably just didn't read enough specs.

Quoted 7 lines

Yes, pretty much and also because this is in a range of registers reserved for use by the specific implementation. See DDI0487 (the ARM) version L.a sections D23.3.2 and D24.2.162 which specify the IMPLEMENTATION DEFINED system register range, and the definition of the term IMPLEMENTATION DEFINED in the glossary of DDI0487. If you see a small upper case term like that in a spec related to the architecture then it'll have a specific architectural defintion.

Thanks!

Quoted 8 lines
Quoted 4 lines

That said, part of the reason I just sent this as-is is because I was sort of expecting the answer to be "no" here. No big deal if that's the case, we can figure out some other way to solve the problem. Happy to throw some time in to making some more generic flavor of this, though...

It's something that does come up, working out a way to make use of the tuning in the IMPDEF registers in a way that generic software can safely and sensibly make use of is rather non-trivial though.

Ya, I'd expect it to be a bit of a time sink -- even if something like this patch had gone in we would have had a pile of ugliness in userspace. I think there's no way around some amount of ugliness when it comes to implemnetation-specific, though.

That said, if our nubers do pan out here then we'll likely need to do something. So if a more generic solution is interesting to people then I'm happy to throw some time at it, shouldn't be too hard to justify on my end.

#5 lore raw
In reply to Palmer Dabbelt
Quoted 22 lines · Palmer Dabbelt
Quoted 20 lines · Marc Zyngier
Quoted 8 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

We've found that some of our workloads run faster when some of these fields are set to non-default values on some of the systems we're trying to run those workloads on. This allows us to set those values via sysfs, so we can do workload/system-specific tuning.

Quoted 7 lines

---
I've only really smoke tested this, but I figured I'd send it along because I'm not sure if this is even a sane thing to be doing -- these extended control registers have some wacky stuff in them, so maybe they're not exposed to userspace on purpose. IIUC firmware can gate these writes, though, so it should be possible for vendors to forbid the really scary values.

That's really wrong.

Quoted 8 lines
Quoted 2 lines

For a start, these encodings fall into the IMPDEF range. They won't exist on non-ARM implementations.

OK, and that's because it says "Provides additional IMPLEMENTATION DEFINED configuration and control options for the processor." at the start of the manual page? Sorry, I'm kind of new to trying to read the Arm specs -- I thought just the meaning of the values was changing, but I probably just didn't read enough specs.

The architecture defines a range described in D24.2.162 (in the L.b revision of the ARM ARM) which is reserved for IMPDEF purposes.

What these registers do is not defined, and there is no standard across implementations. This really is for chicken bits and other fun stuff. Most of them will simply generate an UNDEF, because they don't pass the decode stage. But for all we know, there is a bit in there that turns NOP into the HCF instruction -- or better.

So exposing any of that stuff for any given CPU is dangerous. And exposing any of it on *all* CPUs is a bit like swallowing a powered chainsaw (don't).

Quoted 17 lines
Quoted 6 lines

Next, this will catch fire as a guest, either because the hypervisor will simply refuse to entertain letting it access registers that have no definition, or because the VM has been migrated from one implementation to another, and you have no idea this is doing on the new target.

Ya, makes sense.

Quoted 7 lines
Quoted 4 lines

That said, we do see some performance improvements here on real workloads. So we're hoping to roll some of this tuning work out more widely, but we also don't want to adopt some internal interface. Thus it'd make our lives easier if we could twiddle these bits in a standard way.

Honestly, this is the sort of bring-up stuff that is better kept in your private sandbox, and doesn't really help in general.

Quoted 6 lines

So we're not doing bringup (or at least not doing what I'd call bringup) here, the theory is that we just get better performance on different workloads with different tunings. That's all still a little early, but if the data holds we'd want to be setting these based on what workload is running (ie, not just some static tuning for everything).

In general, none of that crap is safe to turn on and off at random times. You really want to talk to your implementer to find out. And if it is, the firmware is probably the place to handle that.

Quoted 5 lines

That said, part of the reason I just sent this as-is is because I was sort of expecting the answer to be "no" here. No big deal if that's the case, we can figure out some other way to solve the problem. Happy to throw some time in to making some more generic flavor of this, though...

I have no idea how we can achieve that, given that there is no architected definition for any of these registers.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#6 lore raw
Quoted 42 lines · Marc Zyngier
Quoted 22 lines · Palmer Dabbelt
Quoted 20 lines · Marc Zyngier
Quoted 8 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

We've found that some of our workloads run faster when some of these fields are set to non-default values on some of the systems we're trying to run those workloads on. This allows us to set those values via sysfs, so we can do workload/system-specific tuning.

Quoted 7 lines

---
I've only really smoke tested this, but I figured I'd send it along because I'm not sure if this is even a sane thing to be doing -- these extended control registers have some wacky stuff in them, so maybe they're not exposed to userspace on purpose. IIUC firmware can gate these writes, though, so it should be possible for vendors to forbid the really scary values.

That's really wrong.

Quoted 8 lines
Quoted 2 lines

For a start, these encodings fall into the IMPDEF range. They won't exist on non-ARM implementations.

OK, and that's because it says "Provides additional IMPLEMENTATION DEFINED configuration and control options for the processor." at the start of the manual page? Sorry, I'm kind of new to trying to read the Arm specs -- I thought just the meaning of the values was changing, but I probably just didn't read enough specs.

The architecture defines a range described in D24.2.162 (in the L.b revision of the ARM ARM) which is reserved for IMPDEF purposes.

What these registers do is not defined, and there is no standard across implementations. This really is for chicken bits and other fun stuff. Most of them will simply generate an UNDEF, because they don't pass the decode stage. But for all we know, there is a bit in there that turns NOP into the HCF instruction -- or better.

Quoted 3 lines

So exposing any of that stuff for any given CPU is dangerous. And exposing any of it on *all* CPUs is a bit like swallowing a powered chainsaw (don't).

OK, makes sense.

Quoted 23 lines
Quoted 16 lines
Quoted 5 lines

Next, this will catch fire as a guest, either because the hypervisor will simply refuse to entertain letting it access registers that have no definition, or because the VM has been migrated from one implementation to another, and you have no idea this is doing on the new target.

Ya, makes sense.

Quoted 7 lines
Quoted 4 lines

That said, we do see some performance improvements here on real workloads. So we're hoping to roll some of this tuning work out more widely, but we also don't want to adopt some internal interface. Thus it'd make our lives easier if we could twiddle these bits in a standard way.

Honestly, this is the sort of bring-up stuff that is better kept in your private sandbox, and doesn't really help in general.

Quoted 6 lines

So we're not doing bringup (or at least not doing what I'd call bringup) here, the theory is that we just get better performance on different workloads with different tunings. That's all still a little early, but if the data holds we'd want to be setting these based on what workload is running (ie, not just some static tuning for everything).

Quoted 3 lines

In general, none of that crap is safe to turn on and off at random times. You really want to talk to your implementer to find out. And if it is, the firmware is probably the place to handle that.

Ya, if it's generally not expected to be sane to runtime modify these then it seems sane to just hide them behind a firmare interface. Then it's really up to the firmware to proactively expose the bits that are useful, and it's inherently vendor-specific.

Quoted 8 lines
Quoted 5 lines

That said, part of the reason I just sent this as-is is because I was sort of expecting the answer to be "no" here. No big deal if that's the case, we can figure out some other way to solve the problem. Happy to throw some time in to making some more generic flavor of this, though...

I have no idea how we can achieve that, given that there is no architected definition for any of these registers.

I'd basically have some interface for getting/setting the registers that the kernel exposes (gated behind whatever tests we'd need to make sure the registers are accessible), and then some userspace program that deal with the implementation-specific behavior. It'd probably just devolve into some database of known implementations with what the bits do, with some attempt at mapping them to generic behavior -- though even that's kind of clunky, as something like "this tunes some prefetcher to smell different" doesn't really help a ton.

If it's a firmware-gated thing, though, then it's probably going to just end up as some vendor-specific firmware widget that we go fumble around in ACPI to mangle...

Quoted 2 lines
	M.