Add cache line alignment support
Subsystems (3)
cover Add cache line alignment support
The cache line alignment issue has gone around a couple of times now. This patch set implements all of the details that we have discussed about the implementation of ALLOC_CACHE_ALIGN_BUFFER other than the switch to the Linux style L1_CACHE_BYTES, L1_CACHE_SHIFT, and ARCH_DMA_MINALIGN defines mentioned by Mike Frysinger. It also includes patches that use the macro to fix MMC and ext2 buffers, as well as define the CONFIG_SYS_CACHELINE_SIZE value for Tegra and add a default value for CONFIG_SYS_CACHELINE_SIZE with a warning if it is used.
About the Linux defines that Mike suggests. It may make sense to move these patches over to use that mechanism, especially since there are only a few configs that define CONFIG_SYS_CACHELINE_SIZE anyway. Also, since this is an architecture specific parameter and not a board specific one it makes sense that these configs would be architecture specific. I am also not supper happy with the fact that most boards generate a warning with this patchset, because they don't set CONFIG_SYS_CACHELINE_SIZE. But I'm not sure that silently providing a default is a good idea.
I think we can discuss the relative merrits of that move independently of the implementation of this fix though, and I wanted to get this discussion going again.
Thanks,
Anton
---
Anton Staaf (5):
cache: add ALLOC_CACHE_ALIGN_BUFFER macro
cache: add default setting for CONFIG_SYS_CACHELINE_SIZE
tegra: define CONFIG_SYS_CACHELINE_SIZE for tegra
mmc: dcache: allocate cache aligned buffer for scr and switch_status
ext2: Cache line aligned partial sector bounce buffer
doc/README.arm-caches | 2 + drivers/mmc/mmc.c | 10 +++--- fs/ext2/dev.c | 2 +- include/common.h | 67 +++++++++++++++++++++++++++++++++++++++ include/configs/tegra2-common.h | 2 + 5 files changed, 77 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.3.1
PATCH 1/5 cache: add ALLOC_CACHE_ALIGN_BUFFER macro
This macro is used to allocate cache line size aligned stack buffers for use with DMA hardware.
Change-Id: I2c2b3b9bf6a3a5fd1f2e45d65373026bdd76b0a8
--- doc/README.arm-caches | 2 + include/common.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 0 deletions(-)
doc/README.arm-caches +2 -0
@@ -40,6 +40,8 @@ Buffer Requirements: - If the buffer is not cache-line aligned invalidation will be restricted to the aligned part. That is, one cache-line at the respective boundary may be left out while doing invalidation. +- A suitable buffer can be alloced on the stack using the + ALLOC_CACHE_ALIGN_BUFFER macro. Cleanup Before Linux: - cleanup_before_linux() should flush the D-cache, invalidate I-cache, and
include/common.h +59 -0
65 lines not on this page · raw message
Signature · 1 line
1.7.3.1
PATCH 2/5 cache: add default setting for CONFIG_SYS_CACHELINE_SIZE
In reply to Anton StaafCONFIG_SYS_CACHELINE_SIZE is supposed to be defined for all configs. But most configs do not specify it. This patch will set CONFIG_SYS_CACHELINE_SIZE to a default value equal to the GCC builtin macro __BIGGEST_ALIGNMENT__. This is not strictly correct, so it also generates a warning if the default is used.
Change-Id: I346afb6c417ccc9bbb353940e1819e209405986e
--- include/common.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
include/common.h +8 -0
@@ -790,6 +790,14 @@ int cpu_release(int nr, int argc, char * const argv[]);#define __ALIGN_MASK (x,mask) (((x)+(mask))&~(mask))/* +* +*/ +#if !defined(CONFIG_SYS_CACHELINE_SIZE ) +#warning CONFIG_SYS_CACHELINE_SIZE not defined, using __BIGGEST_ALIGNMENT__ +#define CONFIG_SYS_CACHELINE_SIZE __BIGGEST_ALIGNMENT__ +#endif + +/* * The ALLOC_CACHE_ALIGN_BUFFER macro is used to allocate a cache line size * aligned buffer on the stack. Such a buffer is useful for DMA operations * where flushing and invalidating the cache before and after a read and/or
Signature · 1 line
1.7.3.1
PATCH 3/5 tegra: define CONFIG_SYS_CACHELINE_SIZE for tegra
In reply to Anton StaafChange-Id: I5c4bcfc0bfe59158ff249fe3be6640eec6d3cc76
--- include/configs/tegra2-common.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/configs/tegra2-common.h +2 -0
@@ -33,6 +33,8 @@#define CONFIG_MACH_TEGRA_GENERIC /* which is a Tegra generic machine */ #define CONFIG_SYS_L2CACHE_OFF /* No L2 cache */ +#define CONFIG_SYS_CACHELINE_SIZE 32 +#define CONFIG_ENABLE_CORTEXA9 /* enable CPU (A9 complex) */ #include <asm/arch/tegra2.h> /* get chip and board defs */
Signature · 1 line
1.7.3.1
PATCH 4/5 mmc: dcache: allocate cache aligned buffer for scr and switch_status
In reply to Anton StaafCurrently the sd_change_freq function allocates two buffers on the stack that it passes down to the MMC device driver. These buffers could be unaligned to the L1 dcache line size. This causes problems when using DMA and with caches enabled.
This patch correctly cache alignes the buffers used for reading the scr register and switch status values from an MMC device.
--- drivers/mmc/mmc.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/mmc/mmc.c +5 -5
@@ -702,8 +702,8 @@ int sd_change_freq(struct mmc *mmc) {int err;struct mmc_cmd cmd; -uint scr[2 ]; -uint switch_status[16 ]; +ALLOC_CACHE_ALIGN_BUFFER (uint, scr,2 ); +ALLOC_CACHE_ALIGN_BUFFER (uint, switch_status,16 );struct mmc_data data;int timeout;
@@ -731,7 +731,7 @@ int sd_change_freq(struct mmc *mmc) timeout =3 ; retry_scr: - data.dest = (char *)&scr; + data.dest = (char *)scr; data.blocksize =8 ; data.blocks =1 ; data.flags =MMC_DATA_READ ;
@@ -773,7 +773,7 @@ retry_scr: timeout =4 ;while (timeout--) { err =sd_switch (mmc,SD_SWITCH_CHECK ,0 ,1 , - (u8 *)&switch_status); + (u8 *)switch_status);if (err)return err;
@@ -787,7 +787,7 @@ retry_scr:if (!(__be32_to_cpu (switch_status[3 ]) &SD_HIGHSPEED_SUPPORTED ))return 0 ; - err =sd_switch (mmc,SD_SWITCH_SWITCH ,0 ,1 , (u8 *)&switch_status); + err =sd_switch (mmc,SD_SWITCH_SWITCH ,0 ,1 , (u8 *)switch_status);if (err)return err;
Signature · 1 line
1.7.3.1
PATCH 5/5 ext2: Cache line aligned partial sector bounce buffer
In reply to Anton StaafCurrently, if a device read request is done that does not begin or end on a sector boundary a stack allocated bounce buffer is used to perform the read, and then just the part of the sector that is needed is copied into the users buffer. This stack allocation can mean that the bounce buffer will not be aligned to the dcache line size. This is a problem when caches are enabled because unaligned cache invalidates are not safe.
This patch uses ALLOC_CACHE_ALIGN_BUFFER to create a stack allocated cache line size aligned bounce buffer.
Change-Id: I32e1594d90ef039137bb219b0f7ced55768744ff
--- fs/ext2/dev.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext2/dev.c +1 -1
@@ -52,7 +52,7 @@ int ext2fs_set_blk_dev(block_dev_desc_t *rbdd, int part)int ext2fs_devread (int sector,int byte_offset,int byte_len,char *buf) { -char sec_buf[SECTOR_SIZE ]; +ALLOC_CACHE_ALIGN_BUFFER (char, sec_buf,SECTOR_SIZE );unsigned sectors;/*
Signature · 1 line
1.7.3.1
cover Add cache line alignment support
In reply to Anton StaafQuoted 9 lines · On Monday, October 03, 2011 19:54:55 Anton Staaf wrote:
The cache line alignment issue has gone around a couple of times now. This patch set implements all of the details that we have discussed about the implementation of
ALLOC_CACHE_ALIGN_BUFFERother than the switch to the Linux styleL1_CACHE_BYTES,L1_CACHE_SHIFT, andARCH_DMA_MINALIGNdefines mentioned by Mike Frysinger. It also includes patches that use the macro to fix MMC and ext2 buffers, as well as define theCONFIG_SYS_CACHELINE_SIZEvalue for Tegra and add a default value forCONFIG_SYS_CACHELINE_SIZEwith a warning if it is used.
Quoted 8 lines
About the Linux defines that Mike suggests. It may make sense to move these patches over to use that mechanism, especially since there are only a few configs that define
CONFIG_SYS_CACHELINE_SIZEanyway. Also, since this is an architecture specific parameter and not a board specific one it makes sense that these configs would be architecture specific. I am also not supper happy with the fact that most boards generate a warning with this patchset, because they don't setCONFIG_SYS_CACHELINE_SIZE. But I'm not sure that silently providing a default is a good idea.
this looks good to me. my only complaint really has nothing to do with this patchset, but with CONFIG_SYS_CACHELINE_SIZE and the L1_CACHE_xxx defines. but we can address that separately since the current law of the land in u-boot appears to be CONFIG_SYS_CACHELINE_SIZE.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111004/31fc34ed/attachment.pgp
PATCH 1/5 cache: add ALLOC_CACHE_ALIGN_BUFFER macro
In reply to Anton Staaf-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111004/21043994/attachment.pgp
PATCH 2/5 cache: add default setting for CONFIG_SYS_CACHELINE_SIZE
In reply to Anton Staafinclude/common.h int cpu_release(int nr, int argc, char * const argv[]); · line 794
Quoted 6 lines · On Monday, October 03, 2011 19:54:57 Anton Staaf wrote:
include/common.h +2
-0/* +* +*/
no comment ? :)
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111004/92eccfce/attachment.pgp
PATCH 3/5 tegra: define CONFIG_SYS_CACHELINE_SIZE for tegra
In reply to Anton Staaf-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111004/ade57f65/attachment.pgp
PATCH 4/5 mmc: dcache: allocate cache aligned buffer for scr and switch_status
In reply to Anton Staaf-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111004/81716d2f/attachment.pgp
PATCH 5/5 ext2: Cache line aligned partial sector bounce buffer
In reply to Anton Staaf-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111004/783d4bd7/attachment.pgp
PATCH 2/5 cache: add default setting for CONFIG_SYS_CACHELINE_SIZE
In reply to Mike FrysingerQuoted 9 lines · Mike Frysinger
Quoted 6 lines · On Monday, October 03, 2011 19:54:57 Anton Staaf wrote:
include/common.h +0
-0?/*
+ *
+ */no comment ? :)
Doh, I knew I was forgetting something. I'll fix this today with a v2.
Thanks,
Anton
Quoted 2 lines
-mike