cache.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_CACHE_H
  15. #define _ASM_TILE_CACHE_H
  16. #include <arch/chip.h>
  17. /* bytes per L1 data cache line */
  18. #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
  19. #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  20. /* bytes per L2 cache line */
  21. #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
  22. #define L2_CACHE_BYTES (1 << L2_CACHE_SHIFT)
  23. #define L2_CACHE_ALIGN(x) (((x)+(L2_CACHE_BYTES-1)) & -L2_CACHE_BYTES)
  24. /*
  25. * TILEPro I/O is not always coherent (networking typically uses coherent
  26. * I/O, but PCI traffic does not) and setting ARCH_DMA_MINALIGN to the
  27. * L2 cacheline size helps ensure that kernel heap allocations are aligned.
  28. * TILE-Gx I/O is always coherent when used on hash-for-home pages.
  29. *
  30. * However, it's possible at runtime to request not to use hash-for-home
  31. * for the kernel heap, in which case the kernel will use flush-and-inval
  32. * to manage coherence. As a result, we use L2_CACHE_BYTES for the
  33. * DMA minimum alignment to avoid false sharing in the kernel heap.
  34. */
  35. #define ARCH_DMA_MINALIGN L2_CACHE_BYTES
  36. /* use the cache line size for the L2, which is where it counts */
  37. #define SMP_CACHE_BYTES_SHIFT L2_CACHE_SHIFT
  38. #define SMP_CACHE_BYTES L2_CACHE_BYTES
  39. #define INTERNODE_CACHE_SHIFT L2_CACHE_SHIFT
  40. #define INTERNODE_CACHE_BYTES L2_CACHE_BYTES
  41. /* Group together read-mostly things to avoid cache false sharing */
  42. #define __read_mostly __attribute__((__section__(".data..read_mostly")))
  43. /*
  44. * Originally we used small TLB pages for kernel data and grouped some
  45. * things together as "write once", enforcing the property at the end
  46. * of initialization by making those pages read-only and non-coherent.
  47. * This allowed better cache utilization since cache inclusion did not
  48. * need to be maintained. However, to do this requires an extra TLB
  49. * entry, which on balance is more of a performance hit than the
  50. * non-coherence is a performance gain, so we now just make "read
  51. * mostly" and "write once" be synonyms. We keep the attribute
  52. * separate in case we change our minds at a future date.
  53. */
  54. #define __write_once __read_mostly
  55. #endif /* _ASM_TILE_CACHE_H */