Skip to contentSkip to conversation

ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

PATCH Superseded Will Deacon 5 participants 12 messages Jan 16, 2012 – Jan 17, 2012 Arm (32-bit)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

The linker script assumes a cacheline size of 32 bytes when aligning the .data..cacheline_aligned and .data..percpu sections.

This patch updates the script to use L1_CACHE_BYTES, which should be set to 64 on platforms that require it.

---

v2: incorporated suggestions from Stephen Boyd

 arch/arm/kernel/vmlinux.lds.S |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/arm/kernel/vmlinux.lds.S +4 -3
index f76e755..1077e4f 100644
@@ -4,6 +4,7 @@
  */
 
 #include <asm-generic/vmlinux.lds.h>
+#include <asm/cache.h>
 #include <asm/thread_info.h>
 #include <asm/memory.h>
 #include <asm/page.h>
@@ -181,7 +182,7 @@ SECTIONS
 	}
 #endif
 
-	PERCPU_SECTION(32)
+	PERCPU_SECTION(L1_CACHE_BYTES)
 
 #ifdef CONFIG_XIP_KERNEL
 	__data_loc = ALIGN(4);		/* location in binary */
@@ -212,8 +213,8 @@ SECTIONS
 #endif
 
 		NOSAVE_DATA
-		CACHELINE_ALIGNED_DATA(32)
-		READ_MOSTLY_DATA(32)
+		CACHELINE_ALIGNED_DATA(L1_CACHE_BYTES)
+		READ_MOSTLY_DATA(L1_CACHE_BYTES)
 
 		/*
 		 * The exception fixup table (might need resorting at runtime)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 2/2 ARM: cache: assume 64-byte L1 cachelines for ARMv7 CPUs

To ensure correct alignment of cacheline-aligned data, the maximum cacheline size needs to be known at compile time.

Since Cortex-A8 and Cortex-A15 have 64-byte cachelines (and it is likely that there will be future ARMv7 implementations with the same line size) then it makes sense to assume that CPU_V7 implies a 64-byte L1 cacheline size. For CPUs with smaller caches, this will result in some harmless padding but will help with single zImage work and avoid hitting subtle bugs with misaligned data structures.

---
 arch/arm/mm/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/mm/Kconfig +1 -1
index 4cefb57..493e5ea5 100644
@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6
 
 config ARM_L1_CACHE_SHIFT
 	int
-	default 6 if ARM_L1_CACHE_SHIFT_6
+	default 6 if ARM_L1_CACHE_SHIFT_6 || CPU_V7
 	default 5
 
 config ARM_DMA_MEM_BUFFERABLE
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/2 ARM: cache: assume 64-byte L1 cachelines for ARMv7 CPUs

Will,

Quoted 21 lines · Will Deacon

To ensure correct alignment of cacheline-aligned data, the maximum cacheline size needs to be known at compile time.

Since Cortex-A8 and Cortex-A15 have 64-byte cachelines (and it is likely that there will be future ARMv7 implementations with the same line size) then it makes sense to assume that CPU_V7 implies a 64-byte L1 cacheline size. For CPUs with smaller caches, this will result in some harmless padding but will help with single zImage work and avoid hitting subtle bugs with misaligned data structures.

---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)

arch/arm/mm/Kconfig +0 -0
index 4cefb57..493e5ea5 100644
@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6
 
Quoted 4 lines

?config ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6 || CPU_V7

Will be really harmless on A9 ? We have L2 also to be considered here which hard codes the line size as 32.

#3 lore raw

PATCH 2/2 ARM: cache: assume 64-byte L1 cachelines for ARMv7 CPUs

Quoted 23 lines · Santosh

Will,

Quoted 21 lines · Will Deacon

To ensure correct alignment of cacheline-aligned data, the maximum cacheline size needs to be known at compile time.

Since Cortex-A8 and Cortex-A15 have 64-byte cachelines (and it is likely that there will be future ARMv7 implementations with the same line size) then it makes sense to assume that CPU_V7 implies a 64-byte L1 cacheline size. For CPUs with smaller caches, this will result in some harmless padding but will help with single zImage work and avoid hitting subtle bugs with misaligned data structures.

---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)

arch/arm/mm/Kconfig +0 -0
index 4cefb57..493e5ea5 100644
@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6
 
Quoted 7 lines
Quoted 4 lines

?config ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6 || CPU_V7

Will be really harmless on A9 ? We have L2 also to be considered here which hard codes the line size as 32.

Going for a larger cache line size is safe: this is used for aligning data structures and similar, and aligning to 64-byte means that it's also 32-byte aligned.

#4 lore raw

PATCH 2/2 ARM: cache: assume 64-byte L1 cachelines for ARMv7 CPUs

Quoted 32 lines · Russell King - ARM Linux
Quoted 23 lines · Santosh

Will,

Quoted 21 lines · Will Deacon

To ensure correct alignment of cacheline-aligned data, the maximum cacheline size needs to be known at compile time.

Since Cortex-A8 and Cortex-A15 have 64-byte cachelines (and it is likely that there will be future ARMv7 implementations with the same line size) then it makes sense to assume that CPU_V7 implies a 64-byte L1 cacheline size. For CPUs with smaller caches, this will result in some harmless padding but will help with single zImage work and avoid hitting subtle bugs with misaligned data structures.

---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)

arch/arm/mm/Kconfig +0 -0
index 4cefb57..493e5ea5 100644
@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6
 
Quoted 7 lines
Quoted 4 lines

?config ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6 || CPU_V7

Will be really harmless on A9 ? We have L2 also to be considered here which hard codes the line size as 32.

Quoted 3 lines

Going for a larger cache line size is safe: this is used for aligning data structures and similar, and aligning to 64-byte means that it's also 32-byte aligned.

Indeed, it should be fine. As for L2, that's something that should only affect the L2CC code so we don't need a compile-time definition for that.

I might rework this code anyway (this was just to see what people think of the idea) so that ARM_L1_CACHE_SHIFT_6 is selected by CPU_V7. Then I can remove the explicit selects of the config option by platforms that already select CPU_V7.

Will

#5 lore raw

PATCH 2/2 ARM: cache: assume 64-byte L1 cachelines for ARMv7 CPUs

In reply to Russell King - ARM Linux
Quoted 32 lines · Russell King - ARM Linux
Quoted 23 lines · Santosh

Will,

Quoted 21 lines · Will Deacon

To ensure correct alignment of cacheline-aligned data, the maximum cacheline size needs to be known at compile time.

Since Cortex-A8 and Cortex-A15 have 64-byte cachelines (and it is likely that there will be future ARMv7 implementations with the same line size) then it makes sense to assume that CPU_V7 implies a 64-byte L1 cacheline size. For CPUs with smaller caches, this will result in some harmless padding but will help with single zImage work and avoid hitting subtle bugs with misaligned data structures.

---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)

arch/arm/mm/Kconfig +0 -0
index 4cefb57..493e5ea5 100644
@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6
 
Quoted 7 lines
Quoted 4 lines

?config ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 if ARM_L1_CACHE_SHIFT_6 || CPU_V7

Will be really harmless on A9 ? We have L2 also to be considered here which hard codes the line size as 32.

Quoted 3 lines

Going for a larger cache line size is safe: this is used for aligning data structures and similar, and aligning to 64-byte means that it's also 32-byte aligned.

Got it. Thanks !!

#6 lore raw

PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

In reply to Will Deacon
Quoted 10 lines · Will Deacon

The linker script assumes a cacheline size of 32 bytes when aligning the .data..cacheline_aligned and .data..percpu sections.

This patch updates the script to use L1_CACHE_BYTES, which should be set to 64 on platforms that require it.

---

v2: incorporated suggestions from Stephen Boyd

What do you think about aligning the exception fixup table to the same value?

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#7 lore raw

PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

Hi Stephen,

Quoted 7 lines · Stephen Boyd
Quoted 6 lines · Will Deacon

The linker script assumes a cacheline size of 32 bytes when aligning the .data..cacheline_aligned and .data..percpu sections.

This patch updates the script to use L1_CACHE_BYTES, which should be set to 64 on platforms that require it.

Quoted 7 lines
Quoted 4 lines

---

v2: incorporated suggestions from Stephen Boyd

What do you think about aligning the exception fixup table to the same value?

Hmm, I'm not sure I see what that gains us over the current 32-byte alignment. Are you seeing any measurable performance difference with it being cacheline-aligned?

Will

#8 lore raw

PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

Quoted 8 lines · Will Deacon
Quoted 3 lines · Stephen Boyd

What do you think about aligning the exception fixup table to the same value?

Hmm, I'm not sure I see what that gains us over the current 32-byte alignment. Are you seeing any measurable performance difference with it being cacheline-aligned?

I haven't measured anything yet. I just see that it's another value hard-coded to 32 in the linker script and that tile has decided to use L1_CACHE_BYTES for it.

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#9 lore raw

PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

Quoted 5 lines · Stephen Boyd
Quoted 4 lines · Will Deacon
Quoted 3 lines · Stephen Boyd

What do you think about aligning the exception fixup table to the same value?

Quoted 8 lines
Quoted 4 lines

Hmm, I'm not sure I see what that gains us over the current 32-byte alignment. Are you seeing any measurable performance difference with it being cacheline-aligned?

I haven't measured anything yet. I just see that it's another value hard-coded to 32 in the linker script and that tile has decided to use L1_CACHE_BYTES for it.

Hmm, that's intriguing. The exception table entries are 8 bytes on ARM and are aligned as such by things like the USER macro, so I'm not sure why we align the section to 32 bytes. I guess it must be for performance reasons, but whether that's due to cacheline size, I don't know.

Nico, can you enlighten us please (it was introduced in 13b1f64c ("[ARM] 3008/1: the exception table is not read-only"))?

Cheers,

Will

#10 lore raw

PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

Quoted 15 lines · Will Deacon
Quoted 5 lines · Stephen Boyd
Quoted 4 lines · Will Deacon
Quoted 3 lines · Stephen Boyd

What do you think about aligning the exception fixup table to the same value?

Quoted 8 lines
Quoted 4 lines

Hmm, I'm not sure I see what that gains us over the current 32-byte alignment. Are you seeing any measurable performance difference with it being cacheline-aligned?

I haven't measured anything yet. I just see that it's another value hard-coded to 32 in the linker script and that tile has decided to use L1_CACHE_BYTES for it.

Quoted 7 lines

Hmm, that's intriguing. The exception table entries are 8 bytes on ARM and are aligned as such by things like the USER macro, so I'm not sure why we align the section to 32 bytes. I guess it must be for performance reasons, but whether that's due to cacheline size, I don't know.

Nico, can you enlighten us please (it was introduced in 13b1f64c ("[ARM] 3008/1: the exception table is not read-only"))?

It probably was due to the fact that the surrounding data was also cache line aligned. I don't think there is any particular reason why it should be aligned to a cache line boundary given that the list is accessed with a binary search. The minimum required alignment would be __alignof__(struct exception_table_entry).

Nicolas

#11 lore raw

PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes

Quoted 11 lines · Nicolas Pitre
Quoted 10 lines · Will Deacon
Quoted 3 lines · Stephen Boyd

I haven't measured anything yet. I just see that it's another value hard-coded to 32 in the linker script and that tile has decided to use L1_CACHE_BYTES for it.

Hmm, that's intriguing. The exception table entries are 8 bytes on ARM and are aligned as such by things like the USER macro, so I'm not sure why we align the section to 32 bytes. I guess it must be for performance reasons, but whether that's due to cacheline size, I don't know.

Quoted 8 lines
Quoted 2 lines

Nico, can you enlighten us please (it was introduced in 13b1f64c ("[ARM] 3008/1: the exception table is not read-only"))?

It probably was due to the fact that the surrounding data was also cache line aligned. I don't think there is any particular reason why it should be aligned to a cache line boundary given that the list is accessed with a binary search. The minimum required alignment would be __alignof__(struct exception_table_entry).

Given that the struct just contains two unsigned longs, we should be alright with 4 byte alignment here. I can add a follow-on patch to change that.

Thanks,

Will