Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM Cache behaviour: is "Clean" or "Invalidate" the correct command to flush cache memory?

Tags:

arm

cortex-m

This is probably a dumb question, but I'm a bit stuck on the wording of the ARM CMSIS Cache manipulation functions.

The ARM CMSIS exposes functions that can "clean" cache, functions that can "invalidate" cache, and a set of functions that do both.

What these actually do is not clear, and the arm documentation is frankly confusing me:

  • You can invalidate the whole data cache (flush data cache) in one operation without writing back dirty data.
  • You can invalidate individual lines without writing back any dirty data (flush data cache single entry).
  • You can perform cleaning on a line-by-line basis. The data is only written back through the write buffer when a dirty line is encountered, and the cleaned line remains in the cache (clean data cache single entry). You can clean cache lines using either their index within the data cache, or their address within memory.
  • You can clean and flush individual lines in one operation, using either their index within the data cache, or their address within memory.

My understanding is that "flushing" data in cache will result in it being written back to main memory, and "invalidating" data in cache will cause the processor to re-read the main memory on the next attempt to access the data in question.

However, the ARM docs seem to be be implying that a flush operation is actually an invalidation operation, and what I've been thinking is a flush operation is actually a "clean" operation.

I assume I'm just grossly misinterpreting the documentation. Can someone point me in the right direction?

I'm specifically developing for a cortex M7, if it's relevant.

like image 314
Fake Name Avatar asked Jun 07 '17 19:06

Fake Name


People also ask

How will you flush the instruction cache in ARM processor?

You can flush the entire instruction cache by software in one operation, or you can flush individual cache lines by writing to the CP15 Cache Operations Register (register 7). The instruction cache is automatically flushed during reset.

What is cache flush and cache invalidate?

Invalidation of a cache or cache line means to clear it of data. This is done by clearing the valid bit of one or more cache lines. The cache must always be invalidated after reset as its contents will be undefined. If the cache contains dirty data, it is generally incorrect to invalidate it.

What is flushing in cache?

When the amount of unwritten data in the cache reaches a certain level, the controller periodically writes cached data to a drive. This write process is called "flushing." The controller uses two algorithms for flushing cache: demand-based and age-based.

What is cache memory in arm?

In many ARM processor-based systems, access to external memory takes tens or even hundreds of core cycles. A cache is a small, fast block of memory that sits between the core and main memory. It holds copies of items in main memory. Accesses to the cache memory occur significantly faster than those to main memory.


1 Answers

from the armv7-m ARM ARM they have this text.

The definitions of these operations are:

Clean

A cache clean operation ensures that updates made by an observer that controls the cache are made visible to other observers that can access memory at the point to which the operation is performed. Once the Clean has completed, the new memory values are guaranteed to be visible to the point to which the operation is performed, for example to the point of unification. The cleaning of a cache entry from a cache can overwrite memory that has been written by another observer only if the entry contains a location that has been written to by an observer in the shareability domain of that memory location.

Invalidate

A cache invalidate operation ensures that updates made visible by observers that access memory at the point to which the invalidate is defined are made visible to an observer that controls the cache. This might result in the loss of updates to the locations affected by the invalidate operation that have been written by observers that access the cache. If the address of an entry on which the invalidate operates does not have a Normal Cacheable attribute, or if the cache is disabled, then an invalidate operation also ensures that this address is not present in the cache.

I read that as saying a clean will take the items in that cache that have not been saved to the next level memory and will write those out (some folks like myself call a flush). Invalidate doest care if there are unwritten values or not, it prepares the cache as if there are no values to be saved, ready to accept new addresses and data.

Thats how I read it...

like image 92
old_timer Avatar answered Nov 11 '22 14:11

old_timer