ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes
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
@@ -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
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
@@ -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
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_V7implies 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.Signed-off-by Will Deacon <[email protected]>---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)arch/arm/mm/Kconfig +0
-0@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6
Quoted 4 lines
?config
ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 ifARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 ifARM_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.
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_V7implies 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.Signed-off-by Will Deacon <[email protected]>---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)arch/arm/mm/Kconfig +0
-0@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6
Quoted 7 lines
Quoted 4 lines
?config
ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 ifARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 ifARM_L1_CACHE_SHIFT_6||CPU_V7Will 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.
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_V7implies 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.Signed-off-by Will Deacon <[email protected]>---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)arch/arm/mm/Kconfig +0
-0@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6Quoted 7 lines
Quoted 4 lines
?config
ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 ifARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 ifARM_L1_CACHE_SHIFT_6||CPU_V7Will 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
PATCH 2/2 ARM: cache: assume 64-byte L1 cachelines for ARMv7 CPUs
In reply to Russell King - ARM LinuxQuoted 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_V7implies 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.Signed-off-by Will Deacon <[email protected]>---
?arch/arm/mm/Kconfig | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)arch/arm/mm/Kconfig +0
-0@@ -887,7 +887,7 @@ config ARM_L1_CACHE_SHIFT_6Quoted 7 lines
Quoted 4 lines
?config
ARM_L1_CACHE_SHIFT
? ? ? ?int
- ? ? ? default 6 ifARM_L1_CACHE_SHIFT_6
+ ? ? ? default 6 ifARM_L1_CACHE_SHIFT_6||CPU_V7Will 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 !!
PATCH 1/2 ARM: vmlinux.lds.S: do not hardcode cacheline size as 32 bytes
In reply to Will DeaconQuoted 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.Signed-off-by Will Deacon <[email protected]>---
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.
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
Signed-off-by Will Deacon <[email protected]>---
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
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.
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_BYTESfor 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
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_BYTESfor 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
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_BYTESfor 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