Skip to contentSkip to conversation

xen/arm: Read the cacheline size from CTR register

PATCH In review Stefano Stabellini 2 participants 7 messages Mar 1, 2018 – Mar 2, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Read the cacheline size from CTR register

See the corresponding Linux commit as reference:

commit f91e2c3bd427239c198351f44814dd39db91afe0
Author: Catalin Marinas <[email protected]>
Date: Tue Dec 7 16:52:04 2010 +0100

ARM: 6527/1: Use CTR instead of CCSIDR for the D-cache line size on ARMv7

The current implementation of the dcache_line_size macro reads the L1 cache size from the CCSIDR register. This, however, is not guaranteed to be the smallest cache line in the cache hierarchy. The patch changes to the macro to use the more architecturally correct CTR register.

---

This patch depends on "unsafe big.LITTLE support".

Previously, we discussed the possibility of reading the cacheline size when needed from the register, instead of reading it from a variable, but going through the code it doesn't seem like a worthwhile optimization.

---
 xen/include/asm-arm/cpregs.h |  2 ++
 xen/include/asm-arm/page.h   | 11 +++++------
 2 files changed, 7 insertions(+), 6 deletions(-)
xen/include/asm-arm/cpregs.h +2 -0
index 9e13848..8db65d5 100644
@@ -106,6 +106,7 @@
 
 /* CP15 CR0: CPUID and Cache Type Registers */
 #define MIDR            p15,0,c0,c0,0   /* Main ID Register */
+#define CTR             p15,0,c0,c0,1   /* Cache Type Register */
 #define MPIDR           p15,0,c0,c0,5   /* Multiprocessor Affinity Register */
 #define ID_PFR0         p15,0,c0,c1,0   /* Processor Feature Register 0 */
 #define ID_PFR1         p15,0,c0,c1,1   /* Processor Feature Register 1 */
@@ -303,6 +304,7 @@
 #define CPACR_EL1               CPACR
 #define CPTR_EL2                HCPTR
 #define CSSELR_EL1              CSSELR
+#define CTR_EL0                 CTR
 #define DACR32_EL2              DACR
 #define ESR_EL1                 DFSR
 #define ESR_EL2                 HSR
xen/include/asm-arm/page.h +5 -6
index 9fbf232..4c81878 100644
@@ -140,14 +140,13 @@ extern size_t cacheline_bytes;
 
 static inline size_t read_cacheline_size(void)
 {
-    uint32_t ccsid;
+    uint32_t ctr;
 
-    /* Read the cache size ID register for the level-0 data cache */
-    WRITE_SYSREG32(0, CSSELR_EL1);
-    ccsid = READ_SYSREG32(CCSIDR_EL1);
+    /* Read CTR */
+    ctr = READ_SYSREG32(CTR_EL0);
 
-    /* Low 3 bits are log2(cacheline size in words) - 2. */
-    return (size_t) (1U << (4 + (ccsid & 0x7)));
+    /* Bits 16-19 are the log2 number of words in the cacheline. */
+    return (size_t) (4 << ((ctr >> 16) & 0xf));
 }
 
 /* Functions for flushing medium-sized areas.
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

Hi,

Quoted 17 lines · Stefano Stabellini

See the corresponding Linux commit as reference:

commit f91e2c3bd427239c198351f44814dd39db91afe0
Author: Catalin Marinas <[email protected]>
Date: Tue Dec 7 16:52:04 2010 +0100

ARM: 6527/1: Use CTR instead of CCSIDR for the D-cache line size on ARMv7

The current implementation of the dcache_line_size macro reads the L1 cache size from the CCSIDR register. This, however, is not guaranteed to be the smallest cache line in the cache hierarchy. The patch changes to the macro to use the more architecturally correct CTR register.

Quoted 6 lines

---

This patch depends on "unsafe big.LITTLE support".

I still really don't think this should depend on "unsafe big.LITTLE support". We want to backport this patch but I am still unconvinced that this is the case of the big.LITTLE one. So can you please reshuffle the patches?

Quoted 5 lines

Previously, we discussed the possibility of reading the cacheline size when needed from the register, instead of reading it from a variable, but going through the code it doesn't seem like a worthwhile optimization.

Well there are a couple of reasons I wanted this to avoid the a variable:
1) Potentially reading a system register + few instructions is faster
than a memory access
2) The name of the variable leads to confusing. It is named
cacheline_bytes but stores the minimum cacheline size of for the data cache.

1) is arguable and I don't much care whether it is done. However, I really want to avoid a wrong variable name that could lead to more misuse. So we should at least rename read_cacheline_size() and cacheline_bytes.

Cheers,

Quoted 50 lines
---
  xen/include/asm-arm/cpregs.h |  2 ++
  xen/include/asm-arm/page.h   | 11 +++++------
  2 files changed, 7 insertions(+), 6 deletions(-)
xen/include/asm-arm/cpregs.h +2 -0
index 9e13848..8db65d5 100644
@@ -106,6 +106,7 @@
 
  /* CP15 CR0: CPUID and Cache Type Registers */
  #define MIDR            p15,0,c0,c0,0   /* Main ID Register */
+#define CTR             p15,0,c0,c0,1   /* Cache Type Register */
  #define MPIDR           p15,0,c0,c0,5   /* Multiprocessor Affinity Register */
  #define ID_PFR0         p15,0,c0,c1,0   /* Processor Feature Register 0 */
  #define ID_PFR1         p15,0,c0,c1,1   /* Processor Feature Register 1 */
@@ -303,6 +304,7 @@
  #define CPACR_EL1               CPACR
  #define CPTR_EL2                HCPTR
  #define CSSELR_EL1              CSSELR
+#define CTR_EL0                 CTR
  #define DACR32_EL2              DACR
  #define ESR_EL1                 DFSR
  #define ESR_EL2                 HSR
xen/include/asm-arm/page.h +5 -6
index 9fbf232..4c81878 100644
@@ -140,14 +140,13 @@ extern size_t cacheline_bytes;
 
  static inline size_t read_cacheline_size(void)
  {
-    uint32_t ccsid;
+    uint32_t ctr;
 
-    /* Read the cache size ID register for the level-0 data cache */
-    WRITE_SYSREG32(0, CSSELR_EL1);
-    ccsid = READ_SYSREG32(CCSIDR_EL1);
+    /* Read CTR */
+    ctr = READ_SYSREG32(CTR_EL0);
 
-    /* Low 3 bits are log2(cacheline size in words) - 2. */
-    return (size_t) (1U << (4 + (ccsid & 0x7)));
+    /* Bits 16-19 are the log2 number of words in the cacheline. */
+    return (size_t) (4 << ((ctr >> 16) & 0xf));
  }
 
  /* Functions for flushing medium-sized areas.
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw
Quoted 26 lines · Julien Grall

Hi,

Quoted 23 lines · Stefano Stabellini

See the corresponding Linux commit as reference:

commit f91e2c3bd427239c198351f44814dd39db91afe0
Author: Catalin Marinas <[email protected]>
Date: Tue Dec 7 16:52:04 2010 +0100

ARM: 6527/1: Use CTR instead of CCSIDR for the D-cache line size on
ARMv7

The current implementation of the dcache_line_size macro reads the L1 cache size from the CCSIDR register. This, however, is not guaranteed
to
be the smallest cache line in the cache hierarchy. The patch changes
to
the macro to use the more architecturally correct CTR register.

Quoted 7 lines
Quoted 3 lines

---

This patch depends on "unsafe big.LITTLE support".

I still really don't think this should depend on "unsafe big.LITTLE support". We want to backport this patch but I am still unconvinced that this is the case of the big.LITTLE one. So can you please reshuffle the patches?

I'll move it earlier. For simplicity, I'll make it the first patch of "unsafe big.LITTLE support", althought I understand that they are separate fixes.

Quoted 12 lines
Quoted 5 lines

Previously, we discussed the possibility of reading the cacheline size when needed from the register, instead of reading it from a variable, but going through the code it doesn't seem like a worthwhile optimization.

Well there are a couple of reasons I wanted this to avoid the a variable:
1) Potentially reading a system register + few instructions is faster
than a memory access
2) The name of the variable leads to confusing. It is named
cacheline_bytes but stores the minimum cacheline size of for the data cache.

Quoted 3 lines

1) is arguable and I don't much care whether it is done. However, I really want to avoid a wrong variable name that could lead to more misuse. So we should at least rename read_cacheline_size() and cacheline_bytes.

Sure, I can rename. Would min_cacheline_bytes and read_min_cacheline_bytes() be clearer? Otherwise, please suggest an alternative naming scheme.

Quoted 39 lines
Quoted 39 lines
---
  xen/include/asm-arm/cpregs.h |  2 ++
  xen/include/asm-arm/page.h   | 11 +++++------
  2 files changed, 7 insertions(+), 6 deletions(-)
xen/include/asm-arm/cpregs.h +1 -0
index 9e13848..8db65d5 100644
@@ -106,6 +106,7 @@
    /* CP15 CR0: CPUID and Cache Type Registers */
  #define MIDR            p15,0,c0,c0,0   /* Main ID Register */
+#define CTR             p15,0,c0,c0,1   /* Cache Type Register */
  #define MPIDR           p15,0,c0,c0,5   /* Multiprocessor Affinity

Register */

  #define ID_PFR0         p15,0,c0,c1,0   /* Processor Feature Register 0 */
  #define ID_PFR1         p15,0,c0,c1,1   /* Processor Feature Register 1 */
xen/include/asm-arm/cpregs.h +1 -0
@@ -303,6 +304,7 @@
  #define CPACR_EL1               CPACR
  #define CPTR_EL2                HCPTR
  #define CSSELR_EL1              CSSELR
+#define CTR_EL0                 CTR
  #define DACR32_EL2              DACR
  #define ESR_EL1                 DFSR
  #define ESR_EL2                 HSR
xen/include/asm-arm/page.h +2 -3
index 9fbf232..4c81878 100644
@@ -140,14 +140,13 @@ extern size_t cacheline_bytes;
    static inline size_t read_cacheline_size(void)
  {
-    uint32_t ccsid;
+    uint32_t ctr;
  -    /* Read the cache size ID register for the level-0 data cache */
-    WRITE_SYSREG32(0, CSSELR_EL1);
-    ccsid = READ_SYSREG32(CCSIDR_EL1);
+    /* Read CTR */
Quoted 12 lines
Quoted 8 lines
xen/include/asm-arm/page.h +3 -1
+    ctr = READ_SYSREG32(CTR_EL0);
  -    /* Low 3 bits are log2(cacheline size in words) - 2. */
-    return (size_t) (1U << (4 + (ccsid & 0x7)));
+    /* Bits 16-19 are the log2 number of words in the cacheline. */
+    return (size_t) (4 << ((ctr >> 16) & 0xf));
  }
    /* Functions for flushing medium-sized areas.
 
Signature · 1 line
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 52 lines · Stefano Stabellini
Quoted 26 lines · Julien Grall

Hi,

Quoted 23 lines · Stefano Stabellini

See the corresponding Linux commit as reference:

commit f91e2c3bd427239c198351f44814dd39db91afe0
Author: Catalin Marinas <[email protected]>
Date: Tue Dec 7 16:52:04 2010 +0100

ARM: 6527/1: Use CTR instead of CCSIDR for the D-cache line size on
ARMv7

The current implementation of the dcache_line_size macro reads the L1 cache size from the CCSIDR register. This, however, is not guaranteed
to
be the smallest cache line in the cache hierarchy. The patch changes
to
the macro to use the more architecturally correct CTR register.

Quoted 7 lines
Quoted 3 lines

---

This patch depends on "unsafe big.LITTLE support".

I still really don't think this should depend on "unsafe big.LITTLE support". We want to backport this patch but I am still unconvinced that this is the case of the big.LITTLE one. So can you please reshuffle the patches?

I'll move it earlier. For simplicity, I'll make it the first patch of "unsafe big.LITTLE support", althought I understand that they are separate fixes.

Quoted 12 lines
Quoted 5 lines

Previously, we discussed the possibility of reading the cacheline size when needed from the register, instead of reading it from a variable, but going through the code it doesn't seem like a worthwhile optimization.

Well there are a couple of reasons I wanted this to avoid the a variable:
1) Potentially reading a system register + few instructions is faster
than a memory access
2) The name of the variable leads to confusing. It is named
cacheline_bytes but stores the minimum cacheline size of for the data cache.

Quoted 7 lines
Quoted 3 lines

1) is arguable and I don't much care whether it is done. However, I really want to avoid a wrong variable name that could lead to more misuse. So we should at least rename read_cacheline_size() and cacheline_bytes.

Sure, I can rename. Would min_cacheline_bytes and read_min_cacheline_bytes() be clearer? Otherwise, please suggest an alternative naming scheme.

Or min_dcache_line_bytes ?

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
---
  xen/include/asm-arm/cpregs.h |  2 ++
  xen/include/asm-arm/page.h   | 11 +++++------
  2 files changed, 7 insertions(+), 6 deletions(-)
xen/include/asm-arm/cpregs.h +1 -0
index 9e13848..8db65d5 100644
@@ -106,6 +106,7 @@
    /* CP15 CR0: CPUID and Cache Type Registers */
  #define MIDR            p15,0,c0,c0,0   /* Main ID Register */
+#define CTR             p15,0,c0,c0,1   /* Cache Type Register */
  #define MPIDR           p15,0,c0,c0,5   /* Multiprocessor Affinity

Register */

  #define ID_PFR0         p15,0,c0,c1,0   /* Processor Feature Register 0 */
  #define ID_PFR1         p15,0,c0,c1,1   /* Processor Feature Register 1 */
xen/include/asm-arm/cpregs.h +1 -0
@@ -303,6 +304,7 @@
  #define CPACR_EL1               CPACR
  #define CPTR_EL2                HCPTR
  #define CSSELR_EL1              CSSELR
+#define CTR_EL0                 CTR
  #define DACR32_EL2              DACR
  #define ESR_EL1                 DFSR
  #define ESR_EL2                 HSR
xen/include/asm-arm/page.h +4 -4
index 9fbf232..4c81878 100644
@@ -140,14 +140,13 @@ extern size_t cacheline_bytes;
    static inline size_t read_cacheline_size(void)
  {
-    uint32_t ccsid;
+    uint32_t ctr;
  -    /* Read the cache size ID register for the level-0 data cache */
-    WRITE_SYSREG32(0, CSSELR_EL1);
-    ccsid = READ_SYSREG32(CCSIDR_EL1);
+    /* Read CTR */
+    ctr = READ_SYSREG32(CTR_EL0);
  -    /* Low 3 bits are log2(cacheline size in words) - 2. */
-    return (size_t) (1U << (4 + (ccsid & 0x7)));
+    /* Bits 16-19 are the log2 number of words in the cacheline. */
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
xen/include/asm-arm/page.h +1 -0
+    return (size_t) (4 << ((ctr >> 16) & 0xf));
  }
    /* Functions for flushing medium-sized areas.
 
Signature · 1 line
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 57 lines · Stefano Stabellini
Quoted 56 lines · Stefano Stabellini
Quoted 26 lines · Julien Grall

Hi,

Quoted 23 lines · Stefano Stabellini

See the corresponding Linux commit as reference:

commit f91e2c3bd427239c198351f44814dd39db91afe0
Author: Catalin Marinas <[email protected]>
Date: Tue Dec 7 16:52:04 2010 +0100

ARM: 6527/1: Use CTR instead of CCSIDR for the D-cache line size on
ARMv7

The current implementation of the dcache_line_size macro reads the L1 cache size from the CCSIDR register. This, however, is not guaranteed
to
be the smallest cache line in the cache hierarchy. The patch changes
to
the macro to use the more architecturally correct CTR register.

Quoted 7 lines
Quoted 3 lines

---

This patch depends on "unsafe big.LITTLE support".

I still really don't think this should depend on "unsafe big.LITTLE support". We want to backport this patch but I am still unconvinced that this is the case of the big.LITTLE one. So can you please reshuffle the patches?

I'll move it earlier. For simplicity, I'll make it the first patch of "unsafe big.LITTLE support", althought I understand that they are separate fixes.

Quoted 15 lines
Quoted 5 lines

Previously, we discussed the possibility of reading the cacheline size when needed from the register, instead of reading it from a variable, but going through the code it doesn't seem like a worthwhile optimization.

Well there are a couple of reasons I wanted this to avoid the a variable:
1) Potentially reading a system register + few instructions is faster
than a memory access
2) The name of the variable leads to confusing. It is named
cacheline_bytes but stores the minimum cacheline size of for the data cache.

1) is arguable and I don't much care whether it is done. However, I really want to avoid a wrong variable name that could lead to more misuse. So we should at least rename read_cacheline_size() and cacheline_bytes.

Quoted 5 lines
Quoted 3 lines

Sure, I can rename. Would min_cacheline_bytes and read_min_cacheline_bytes() be clearer? Otherwise, please suggest an alternative naming scheme.

Or min_dcache_line_bytes ?

I would reduce to dcache_line_bytes to avoid lengthy name.
That would go inline with the macro dcache_line_size we currently have in arm64.

What matters is the 'd' for data cache. To avoid confusion which 'i' for instruction cache that we may need in the future.

Anyway, I am happy with both.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw
In reply to Stefano Stabellini

Hi,

I forgot to mention in the title:

You read the minimum D-Cache line size. The minimum I-Cache line size is read from CTR_EL0.IminLine.

Cheers,

Quoted 78 lines · Stefano Stabellini

See the corresponding Linux commit as reference:

commit f91e2c3bd427239c198351f44814dd39db91afe0
Author: Catalin Marinas <[email protected]>
Date: Tue Dec 7 16:52:04 2010 +0100

ARM: 6527/1: Use CTR instead of CCSIDR for the D-cache line size on ARMv7

The current implementation of the dcache_line_size macro reads the L1 cache size from the CCSIDR register. This, however, is not guaranteed to be the smallest cache line in the cache hierarchy. The patch changes to the macro to use the more architecturally correct CTR register.

---

This patch depends on "unsafe big.LITTLE support".

Previously, we discussed the possibility of reading the cacheline size when needed from the register, instead of reading it from a variable, but going through the code it doesn't seem like a worthwhile optimization.

---
  xen/include/asm-arm/cpregs.h |  2 ++
  xen/include/asm-arm/page.h   | 11 +++++------
  2 files changed, 7 insertions(+), 6 deletions(-)
xen/include/asm-arm/cpregs.h +2 -0
index 9e13848..8db65d5 100644
@@ -106,6 +106,7 @@
 
  /* CP15 CR0: CPUID and Cache Type Registers */
  #define MIDR            p15,0,c0,c0,0   /* Main ID Register */
+#define CTR             p15,0,c0,c0,1   /* Cache Type Register */
  #define MPIDR           p15,0,c0,c0,5   /* Multiprocessor Affinity Register */
  #define ID_PFR0         p15,0,c0,c1,0   /* Processor Feature Register 0 */
  #define ID_PFR1         p15,0,c0,c1,1   /* Processor Feature Register 1 */
@@ -303,6 +304,7 @@
  #define CPACR_EL1               CPACR
  #define CPTR_EL2                HCPTR
  #define CSSELR_EL1              CSSELR
+#define CTR_EL0                 CTR
  #define DACR32_EL2              DACR
  #define ESR_EL1                 DFSR
  #define ESR_EL2                 HSR
xen/include/asm-arm/page.h +5 -6
index 9fbf232..4c81878 100644
@@ -140,14 +140,13 @@ extern size_t cacheline_bytes;
 
  static inline size_t read_cacheline_size(void)
  {
-    uint32_t ccsid;
+    uint32_t ctr;
 
-    /* Read the cache size ID register for the level-0 data cache */
-    WRITE_SYSREG32(0, CSSELR_EL1);
-    ccsid = READ_SYSREG32(CCSIDR_EL1);
+    /* Read CTR */
+    ctr = READ_SYSREG32(CTR_EL0);
 
-    /* Low 3 bits are log2(cacheline size in words) - 2. */
-    return (size_t) (1U << (4 + (ccsid & 0x7)));
+    /* Bits 16-19 are the log2 number of words in the cacheline. */
+    return (size_t) (4 << ((ctr >> 16) & 0xf));
  }
 
  /* Functions for flushing medium-sized areas.
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Thanks, I'll mention it in the commit message.

Quoted 79 lines · Julien Grall

Hi,

I forgot to mention in the title:

You read the minimum D-Cache line size. The minimum I-Cache line size is read from CTR_EL0.IminLine.

Cheers,

Quoted 69 lines · Stefano Stabellini

See the corresponding Linux commit as reference:

commit f91e2c3bd427239c198351f44814dd39db91afe0
Author: Catalin Marinas <[email protected]>
Date: Tue Dec 7 16:52:04 2010 +0100

ARM: 6527/1: Use CTR instead of CCSIDR for the D-cache line size on
ARMv7

The current implementation of the dcache_line_size macro reads the L1 cache size from the CCSIDR register. This, however, is not guaranteed
to
be the smallest cache line in the cache hierarchy. The patch changes
to
the macro to use the more architecturally correct CTR register.

---

This patch depends on "unsafe big.LITTLE support".

Previously, we discussed the possibility of reading the cacheline size when needed from the register, instead of reading it from a variable, but going through the code it doesn't seem like a worthwhile optimization.

---
  xen/include/asm-arm/cpregs.h |  2 ++
  xen/include/asm-arm/page.h   | 11 +++++------
  2 files changed, 7 insertions(+), 6 deletions(-)
xen/include/asm-arm/cpregs.h +1 -0
index 9e13848..8db65d5 100644
@@ -106,6 +106,7 @@
    /* CP15 CR0: CPUID and Cache Type Registers */
  #define MIDR            p15,0,c0,c0,0   /* Main ID Register */
+#define CTR             p15,0,c0,c0,1   /* Cache Type Register */
  #define MPIDR           p15,0,c0,c0,5   /* Multiprocessor Affinity

Register */

  #define ID_PFR0         p15,0,c0,c1,0   /* Processor Feature Register 0 */
  #define ID_PFR1         p15,0,c0,c1,1   /* Processor Feature Register 1 */
xen/include/asm-arm/cpregs.h +1 -0
@@ -303,6 +304,7 @@
  #define CPACR_EL1               CPACR
  #define CPTR_EL2                HCPTR
  #define CSSELR_EL1              CSSELR
+#define CTR_EL0                 CTR
  #define DACR32_EL2              DACR
  #define ESR_EL1                 DFSR
  #define ESR_EL2                 HSR
xen/include/asm-arm/page.h +2 -3
index 9fbf232..4c81878 100644
@@ -140,14 +140,13 @@ extern size_t cacheline_bytes;
    static inline size_t read_cacheline_size(void)
  {
-    uint32_t ccsid;
+    uint32_t ctr;
  -    /* Read the cache size ID register for the level-0 data cache */
-    WRITE_SYSREG32(0, CSSELR_EL1);
-    ccsid = READ_SYSREG32(CCSIDR_EL1);
+    /* Read CTR */
Quoted 12 lines
Quoted 8 lines
xen/include/asm-arm/page.h +3 -1
+    ctr = READ_SYSREG32(CTR_EL0);
  -    /* Low 3 bits are log2(cacheline size in words) - 2. */
-    return (size_t) (1U << (4 + (ccsid & 0x7)));
+    /* Bits 16-19 are the log2 number of words in the cacheline. */
+    return (size_t) (4 << ((ctr >> 16) & 0xf));
  }
    /* Functions for flushing medium-sized areas.
 
Signature · 1 line
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel