Skip to contentSkip to conversation

target-arm/helper.c: Don't flush the TLB if SCTLR is rewritten unchanged

PATCH In review Peter Maydell 2 participants 2 messages May 8, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm/helper.c: Don't flush the TLB if SCTLR is rewritten unchanged

Linux makes a habit of writing the same value to the SCTLR that it already holds. In a sample boot of the kernel to a shell prompt it wrote the SCTLR with the value it already held 325465 times, and wrote different values just 3 times.

Skip flushing the TLB if the SCTLR value isn't actually being changed; this speeds up my sample boot by 3-5%.

---
I believe there are kernel patches in the works to avoid being quite so profligate with SCTLR writes, but there are still a lot of older kernels out in the world, so this is worth having IMHO.

 target-arm/helper.c | 7 +++++++
 1 file changed, 7 insertions(+)
target-arm/helper.c +7 -0
index 3be917c..417161e 100644
@@ -2081,6 +2081,13 @@ static void sctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
 {
     ARMCPU *cpu = arm_env_get_cpu(env);
 
+    if (env->cp15.c1_sys == value) {
+        /* Skip the TLB flush if nothing actually changed; Linux likes
+         * to do a lot of pointless SCTLR writes.
+         */
+        return;
+    }
+
     env->cp15.c1_sys = value;
     /* ??? Lots of these bits are not implemented.  */
     /* This may enable/disable the MMU, so do a TLB flush.  */
Signature · 1 line
1.9.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Peter Maydell

Linux makes a habit of writing the same value to the SCTLR that it already holds. In a sample boot of the kernel to a shell prompt it wrote the SCTLR with the value it already held 325465 times, and wrote different values just 3 times.

Skip flushing the TLB if the SCTLR value isn't actually being changed; this speeds up my sample boot by 3-5%.

Thanks,

Laurent

Quoted 29 lines

---
I believe there are kernel patches in the works to avoid being quite so profligate with SCTLR writes, but there are still a lot of older kernels out in the world, so this is worth having IMHO.

 target-arm/helper.c | 7 +++++++
 1 file changed, 7 insertions(+)
target-arm/helper.c +7 -1
index 3be917c..417161e 100644
@@ -2081,6 +2081,13 @@ static void sctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
 {
     ARMCPU *cpu = arm_env_get_cpu(env);
 
+    if (env->cp15.c1_sys == value) {
+        /* Skip the TLB flush if nothing actually changed; Linux likes
+         * to do a lot of pointless SCTLR writes.
+         */
+        return;
+    }
+
     env->cp15.c1_sys = value;
     /* ??? Lots of these bits are not implemented.  */
     /* This may enable/disable the MMU, so do a TLB flush.  */
--

1.9.2