4

I am using a MCF5253 controller which is based on Coldfire Architecture. It has 8KB of Instruction Cache. Everything was working fine till I enabled it's Instruction Cache. Now what's happening is Adapter is getting reset randomly. When I debug it, It resets due to exception of "Illegal Instruction", No such exception comes if I run by disabling the Instruction Cache.

Is it necessary that periodically one should clear the cache? and if it is then at what frequency.

Another thing I would like to know is how can I calculate Cache Hit/Miss Ratio?

Thanks!

Swanand
  • 3,245
  • 5
  • 28
  • 45

2 Answers2

2

I suspect what happens is that your cache is uninitialized, which means it could contain any garbage - including valid addresses and invalid instructions. There's typically a little bit of metadata also indicating whether the data is valid, and this is what you need to reset - typically there's an invalidation operation for the cache. Do this before enabling the cache, and it should start fetching rather than executing noise. A second reason to invalidate code cache is if you just wrote some code, i.e. in a JIT compiler or self-modifying code; then invalidating specific ranges typically works.

Other than that, once running, there's rarely a reason to repeat invalidation. Data caches may need to be flushed, however, to interact with other memory accesses (DMA, bus masters, or possibly memory mapped devices).

The linked reference manual contains relevant information in section 5.4.3, Cache Coherency and Invalidation. Note that while it's just a single bit to invalidate the whole cache, this operation takes a long time to complete.

Yann Vernier
  • 2,814
  • 17
  • 15
  • But I have already invalidated the cache! That didn't help! Will try to flush DMA and all! Thanks! – Swanand Sep 27 '11 at 05:04
  • Sorry it didn't help. I'm afraid I can't go much further with what's provided; could you show the initialization code? – Yann Vernier Sep 27 '11 at 05:23
0

The only reason to clear the cache is if it has virtual addresses in it. Then you need to clear/invalidate it when you change contexts. Probably not your problem unless you are running a sufficiently advanced OS (e.g., Linux, not uLinux).

Brian Carlton
  • 13,252
  • 5
  • 43
  • 64