Skip to contentSkip to conversation

Add Kconfig to disable cache ops

PATCH New Vignesh Raghavendra 2 participants 5 messages Apr 22, 2019 – May 6, 2019 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v2 cover Add Kconfig to disable cache ops

This series adds a Kconfig to disable cache maintenance operations on a coherent architectures. And disable cache flush/invalidate ops for SPL/U-Boot code running on A53 core of AM654 SoC(which is IO coherent)

v2:
Allow flush_dcache_all() and invalidate_dcache_all() that are used before enabling/disabling dcache by U-Boot and are special case.

Vignesh Raghavendra (2):
arch: armv8: Provide a way to disable cache maintenance ops
board: ti: am654: select SYS_DISABLE_DCACHE_OPS for arm64 build

 arch/Kconfig                  |  9 +++++++++
 arch/arm/cpu/armv8/cache_v8.c | 10 ++++++++++
 board/ti/am65x/Kconfig        |  1 +
 3 files changed, 20 insertions(+)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v2 1/2 arch: armv8: Provide a way to disable cache maintenance ops

On AM654 SoC(arm64) which is IO coherent and has L3 Cache, cache maintenance operations being done to support non-coherent platforms causes issues.

For example, here is how U-Boot prepares/handles a buffer to receive data from a device (DMA Write). This may vary slightly depending on the driver framework:

Start DMA to write to destination buffer
Wait for DMA to be done (dma_receive()/dma_memcpy()) Invalidate destination buffer (invalidate_dcache_range()) Read from destination buffer

The invalidate after the DMA is needed in order to read latest data from memory that’s updated by DMA write. Also, in case random prefetch has pulled in buffer data during the “wait for DMA” before the DMA has written to it. This works well for non-coherent architectures.

In case of coherent architecture with L3 cache, DMA write would directly update L3 cache contents (assuming cacheline is present in L3) without updating the DDR memory. So invalidate after “wait for DMA” in above sequence would discard latest data and read will cause stale data to be fetched from DDR. Therefore invalidate after “wait for DMA” is not always correct on coherent architecture.

Therefore, provide a Kconfig option to disable cache maintenance ops on coherent architectures. This has added benefit of improving the performance of DMA transfers as we no longer need to invalidate/flush individual cache lines(especially for buffer thats several KBs in size).

In order to facilitate use of same Kconfig across different architecture, I have added the symbol to top level arch/Kconfig file. Patch currently disables cache maintenance ops for arm64 only. flush_dcache_all() and invalidate_dcache_all() are exclusively used during enabling/disabling dcache and hence are not disabled.

---
 arch/Kconfig                  |  9 +++++++++
 arch/arm/cpu/armv8/cache_v8.c | 10 ++++++++++
 2 files changed, 19 insertions(+)
arch/Kconfig +9 -0
index 2f3d07c13a18..760023b19a81 100644
@@ -227,6 +227,15 @@ config SYS_CONFIG_NAME
 	  The header file include/configs/<CONFIG_SYS_CONFIG_NAME>.h
 	  should be included from include/config.h.
 
+config SYS_DISABLE_DCACHE_OPS
+	bool
+	help
+	 This option disables dcache flush and dcache invalidation
+	 operations. For example, on coherent systems where cache
+	 operatios are not required, enable this option to avoid them.
+	 Note that, its up to the individual architectures to implement
+	 this functionality.
+
 source "arch/arc/Kconfig"
 source "arch/arm/Kconfig"
 source "arch/m68k/Kconfig"
arch/arm/cpu/armv8/cache_v8.c +10 -0
index 038405173eb1..9ca397e73c9b 100644
@@ -443,6 +443,7 @@ inline void flush_dcache_all(void)
 		debug("flushing dcache successfully.\n");
 }
 
+#ifndef CONFIG_SYS_DISABLE_DCACHE_OPS
 /*
  * Invalidates range in all levels of D-cache/unified cache
  */
@@ -458,6 +459,15 @@ void flush_dcache_range(unsigned long start, unsigned long stop)
 {
 	__asm_flush_dcache_range(start, stop);
 }
+#else
+void invalidate_dcache_range(unsigned long start, unsigned long stop)
+{
+}
+
+void flush_dcache_range(unsigned long start, unsigned long stop)
+{
+}
+#endif /* CONFIG_SYS_DISABLE_DCACHE_OPS */
 
 void dcache_enable(void)
 {
Signature · 1 line
2.21.0
#2 lore raw

PATCH v2 1/2 arch: armv8: Provide a way to disable cache maintenance ops

Quoted 30 lines · Vignesh Raghavendra

On AM654 SoC(arm64) which is IO coherent and has L3 Cache, cache maintenance operations being done to support non-coherent platforms causes issues.

For example, here is how U-Boot prepares/handles a buffer to receive data from a device (DMA Write). This may vary slightly depending on the driver framework:

Start DMA to write to destination buffer
Wait for DMA to be done (dma_receive()/dma_memcpy()) Invalidate destination buffer (invalidate_dcache_range()) Read from destination buffer

The invalidate after the DMA is needed in order to read latest data from memory that’s updated by DMA write. Also, in case random prefetch has pulled in buffer data during the “wait for DMA” before the DMA has written to it. This works well for non-coherent architectures.

In case of coherent architecture with L3 cache, DMA write would directly update L3 cache contents (assuming cacheline is present in L3) without updating the DDR memory. So invalidate after “wait for DMA” in above sequence would discard latest data and read will cause stale data to be fetched from DDR. Therefore invalidate after “wait for DMA” is not always correct on coherent architecture.

Therefore, provide a Kconfig option to disable cache maintenance ops on coherent architectures. This has added benefit of improving the performance of DMA transfers as we no longer need to invalidate/flush individual cache lines(especially for buffer thats several KBs in size).

Quoted 7 lines

In order to facilitate use of same Kconfig across different architecture, I have added the symbol to top level arch/Kconfig file. Patch currently disables cache maintenance ops for arm64 only. flush_dcache_all() and invalidate_dcache_all() are exclusively used during enabling/disabling dcache and hence are not disabled.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190506/e30f1737/attachment.sig>
#3 lore raw

PATCH v2 2/2 board: ti: am654: select SYS_DISABLE_DCACHE_OPS for arm64 build

In reply to Vignesh Raghavendra

AM654 SoC is IO coherent wrt A53 cores, therefore enable SYS_DISABLE_DCACHE_OPS to avoid cache operations in A53 SPL/U-Boot.

---
 board/ti/am65x/Kconfig | 1 +
 1 file changed, 1 insertion(+)
board/ti/am65x/Kconfig +1 -0
index d4b36dbb42f3..98172c28f5d3 100644
@@ -11,6 +11,7 @@ config TARGET_AM654_A53_EVM
 	bool "TI K3 based AM654 EVM running on A53"
 	select ARM64
 	select SOC_K3_AM6
+	select SYS_DISABLE_DCACHE_OPS
 
 config TARGET_AM654_R5_EVM
 	bool "TI K3 based AM654 EVM running on R5"
Signature · 1 line
2.21.0
#4 lore raw

PATCH v2 2/2 board: ti: am654: select SYS_DISABLE_DCACHE_OPS for arm64 build

Quoted 5 lines · Vignesh Raghavendra

AM654 SoC is IO coherent wrt A53 cores, therefore enable SYS_DISABLE_DCACHE_OPS to avoid cache operations in A53 SPL/U-Boot.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190506/f9b7ca87/attachment.sig>