NETOS 6 1 Training Cache API NETOS 6

  • Slides: 25
Download presentation
NET+OS 6. 1 Training

NET+OS 6. 1 Training

Cache API

Cache API

NET+OS 6. 1 Cache API • • • H/W Features NET+OS Cache Initialization Cache

NET+OS 6. 1 Cache API • • • H/W Features NET+OS Cache Initialization Cache and DMA Configuring Cache API Functions

NS 9750 Cache Features • • • Built into ARM 9 EJ-S CPU core

NS 9750 Cache Features • • • Built into ARM 9 EJ-S CPU core Has memory management unit (MMU) 4 K of data cache 8 K of instruction cache Main write buffer has 16 -word data buffer and four-address buffer • Data cache write-back buffer has eight data words and single address buffer • Memory controller has 4 16 -word buffers

MMU Functions • Controls what sections of the address space can be accessed. •

MMU Functions • Controls what sections of the address space can be accessed. • Determines cache mode for different sections of the address space. • Creates virtual address maps. This feature is not used by NET+OS.

Access Modes • MMU_CLIENT_RW: Any process can read and write to this address region.

Access Modes • MMU_CLIENT_RW: Any process can read and write to this address region. This access mode is used for all memory and registers. • MMU_NO_ACCESS: Any access to this address region causes an abort exception. NET+OS sets this address mode on all invalid addresses.

NS 9750 - Defect • The no-access mode is very important for NS 9750.

NS 9750 - Defect • The no-access mode is very important for NS 9750. • Revision 1 of the chip has a bug which will cause the processor to hang if software reads or writes to some invalid addresses. Setting invalid regions to no-access catches these accesses before they hang the processor.

Buffering vs. Caching • Cached data can be stored in the processor’s cache for

Buffering vs. Caching • Cached data can be stored in the processor’s cache for an indeterminate amount of time until the cache line is needed for another piece of memory, or the data value changes. • When a write is buffered, the data is only stored until the bus becomes available at which time it is written to memory. This prevents the processor from stalling when it writes to memory or a peripheral.

Data Cache Modes • Non-buffered: Data caching and buffering is disabled. • Buffered: Data

Data Cache Modes • Non-buffered: Data caching and buffering is disabled. • Buffered: Data cache is disabled, but writes are buffered. • Write-through: Reads are cached. Writes are buffered, but not cached. • Write-back: Reads are cached, writes are cached and buffered.

ARM 9 and Cache • ARM 9 was designed to use cache and write

ARM 9 and Cache • ARM 9 was designed to use cache and write buffers. It depends on it. • Performance is very bad when cache and buffering are disabled. • Instruction cache should always be on. • Write buffers should always be turned on.

Cache Initialization • Instruction cache enabled in ncc. Init() by the call to MCEnable.

Cache Initialization • Instruction cache enabled in ncc. Init() by the call to MCEnable. ICache(). • Data cache and MMU memory protection are set up in main() by NAEnable. Mmu(). • First call to non. Cache. Malloc() initializes non-cached memory region.

Cache and DMA • DMA transfers bypass cache. • Cache can become incoherent if

Cache and DMA • DMA transfers bypass cache. • Cache can become incoherent if DMA transfers data to or from memory that has been cached. • Either DMA must be limited to non-cached buffers, or care must be taken to invalidate or clean cache before starting DMA transfers to cached buffers.

Using Non-cached Buffers • A section of RAM is set up that is not

Using Non-cached Buffers • A section of RAM is set up that is not cached and can, therefore, be safely used with DMA. • Use non. Cached. Malloc() to allocate buffers. • Use non. Cached. Free() to release them.

Using Cached Buffers • Functions are provided to prepare a cached buffer for a

Using Cached Buffers • Functions are provided to prepare a cached buffer for a DMA transfer by either cleaning or invalidating the cache associated with it. • Call NABefore. DMA() to prepare a cached buffer for a DMA transfer. • Call NAAfter. DMA() when the transfer is complete (current implementation does nothing). • These functions can be used with buffers from the non-cached region (they will do nothing).

Configuration Parameters • mmu. Table in customize. Cache. c. • #defines in bsp. h.

Configuration Parameters • mmu. Table in customize. Cache. c. • #defines in bsp. h. • Constants in customize. ldr/lx.

mmu. Table • Sets cache mode for memory regions: not cached, buffered, write-through, or

mmu. Table • Sets cache mode for memory regions: not cached, buffered, write-through, or write back. • Sets memory protection level: read-write or no access. • Sets page sizes for memory regions: 1 Meg, 64 K, or 4 K.

mmu. Table • Table contains a list of address ranges and their cache/memory protection

mmu. Table • Table contains a list of address ranges and their cache/memory protection settings. • All address ranges not in the list are set to no-access. • Software can change cache mode and access level on the fly. • Page sizes cannot be changed on the fly.

Changing mmu. Table • Customer should adjust size of RAM and ROM regions to

Changing mmu. Table • Customer should adjust size of RAM and ROM regions to match their application. • Page sizes should be kept as large as possible for best performance.

Example mmu. Table. Type const mmu. Table[] = { /* Start End Page Size

Example mmu. Table. Type const mmu. Table[] = { /* Start End Page Size Cache Mode User Access */ /* ========== ======= */ {0 x 0000, 0 x 00 ffffff, MMU_PAGE_SIZE_1 M, MMU_WRITE_THROUGH, MMU_CLIENT_RW}, {0 x 50000000, 0 x 57 ffffff, MMU_PAGE_SIZE_1 M, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 80000000, 0 x 8 fffffff, MMU_PAGE_SIZE_1 M, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90000000, 0 x 900001 d 3, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90100000, 0 x 90103163, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90110000, 0 x 901101 d 3, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90200000, 0 x 9020007 b, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90300000, 0 x 9030007 b, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90400000, 0 x 9040017 b, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90500000, 0 x 9050000 F, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x 90600000, 0 x 90600093, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW},

Example mmu. Table cont. }; {0 x. A 0000000, 0 x. A 00 fffff,

Example mmu. Table cont. }; {0 x. A 0000000, 0 x. A 00 fffff, MMU_PAGE_SIZE_1 M, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0100000, 0 x. A 01 fffff, MMU_PAGE_SIZE_1 M, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0200000, 0 x. A 02 fffff, MMU_PAGE_SIZE_1 M, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0300000, 0 x. A 0301 FFF, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0400000, 0 x. A 040002 B, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0401000, 0 x. A 0401007, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0600000, 0 x. A 0601400, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0700000, 0 x. A 070027 c, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0800000, 0 x. A 08003 FF, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}, {0 x. A 0900000, 0 x. A 0900223, MMU_PAGE_SIZE_4 K, MMU_BUFFERED, MMU_CLIENT_RW}

Parameters in bsp. h • BSP_AUTOMATICALLY_ENABLE_INS TRUCTION_CACHE should always be TRUE. • BSP_CACHE_NETWORK_HEAP should

Parameters in bsp. h • BSP_AUTOMATICALLY_ENABLE_INS TRUCTION_CACHE should always be TRUE. • BSP_CACHE_NETWORK_HEAP should be FALSE for most applications. Caching packet buffers lowers overall performance because it causes other buffers to be bumped out of cache.

Linker Scripts • TTB_SIZE sets size of MMU Translation Table. Make this value larger

Linker Scripts • TTB_SIZE sets size of MMU Translation Table. Make this value larger if linker complains that. ttb section is full or has overflowed. • NON_CACHE_MALLOC_SIZE sets size of non-cached region. May need to increase if customer adds new drivers that use noncached buffers.

Cache API • NAEnable. Mmu(): Called from main() to build translation table and start

Cache API • NAEnable. Mmu(): Called from main() to build translation table and start MMU. • NASet. Cache. Access. Modes(): Can be used to change cache and access settings. • non. Cached. Malloc(): Get a buffer from the noncached region of memory. • non. Cached. Free(): Return buffer to non-cached region. • NABefore. Dma(): Prepare buffer for DMA. • NAAfter. Dma(): Process buffer after DMA.

Cache API cont. • NAInvalidate. Buffer(): Indicate that buffer contents have changed and contents

Cache API cont. • NAInvalidate. Buffer(): Indicate that buffer contents have changed and contents of cache are now invalid. • NAClean. Buffer(): Update buffer with contents of cached data. • NAFlush. Cache. Write. Buffers(): Stop processor until cache write buffers are empty. Use for self modifying code.

Cache API cont. • MCEnable. ICache(): Turn instruction cache on. MMU does not need

Cache API cont. • MCEnable. ICache(): Turn instruction cache on. MMU does not need to be enabled. • MCDisable. ICache(): Turn instruction cache off. • MCInit. MMU(): Program MMU to use translation table in. ttb section and turn it on. • MCEnable. DCache(): Turn data cache on. Translation table must be setup and MMU enabled before calling this function. • MCDisable. DCache(): Turn data cache off. Has side effect of disabling memory protection.