6

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.

Fake Name
  • 5,556
  • 5
  • 44
  • 66
  • I dont know why they would use the term flush when describing invalidate, invalidate is how they normally describe initializing the cache, prepping the tables so that you can start using it (without doing any writes) which they do say no dirty data is written. but reading these descriptions a few more times, I am as confused as you are... – old_timer Jun 07 '17 at 20:15
  • my general not specific to arm understanding of the terms is invalidate is to initialize the cache for use after a power on or if I want to swap applications and start over without caring what was in there. And flush means to take anything dirty in the cache and force it out to ram. clean doesnt make sense to me as a term. – old_timer Jun 07 '17 at 20:16
  • Could do an experiment with each to see what they do... – old_timer Jun 07 '17 at 20:19
  • your link is to an arm9 not a cortex-m7 BTW. – old_timer Jun 07 '17 at 20:19
  • `your link is to an arm9 not a cortex-m7 BTW.` Oh god dammit, when you navigate on their site, it doesn't update the url. Let me try to find the page I was on. – Fake Name Jun 07 '17 at 20:22
  • Anyways, yeah, you're seeing why I'm confused. They seem to have invented their own terminology. – Fake Name Jun 07 '17 at 20:24
  • the armv7-m arm has a big paragraph defining each term invalidate and clean and doesnt use the term flush. I think it is as I described an invalidate prepares the cache such that no matter what it thinks it had in it as far as updates for memory, those are now invalid. A clean from what I read will take any items in the cache that have not been written to memory and writes those to main or next level memory. – old_timer Jun 07 '17 at 20:25

1 Answers1

7

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...

old_timer
  • 69,149
  • 8
  • 89
  • 168
  • Ok, that pretty much nails it. What document is this from? – Fake Name Jun 07 '17 at 21:31
  • the armv7-m ARM ARM (architectural reference manual) one of the two manuals you need if developing for a cortex-m7 the other is the cortex-m7 TRM (technical reference manual) in the same rough area as the link you had, one is under reference manuals the other is under cortex-m. – old_timer Jun 07 '17 at 21:32
  • one of the two manuals from arm that is, you also need the documents from the chip vendor... – old_timer Jun 07 '17 at 21:34