Flush cache between cores?

User avatar
mvzxa5ltmvzdc
Posts: 5
Joined: Wed Feb 12, 2025 9:35 pm

Flush cache between cores?

Postby mvzxa5ltmvzdc » Wed Oct 01, 2025 7:37 am

From what I know, it is possible for one core of the ESP32 to read a different value from a memory address than the other, if either of them has the memory region in question in its cache.
Is there any available function that forces one or both cores to flush and/or reload all or some of the cached memory regions, or is there any other way to do so?
Also, how is it resolved internally when both cores write to the same address, or addresses within the same cache line, in quick succession?

Sprite
Espressif staff
Espressif staff
Posts: 10612
Joined: Thu Nov 26, 2015 4:08 am

Re: Flush cache between cores?

Postby Sprite » Wed Oct 01, 2025 9:09 am

From what I know, it is possible for one core of the ESP32 to read a different value from a memory address than the other, if either of them has the memory region in question in its cache.
How do you 'know' this? In normal situations (i.e. using esp-idf or another supported sdk and accessing psram or internal memory) both cores share the cache, so there won't be any inconsistency.

Also not sure what your second question is about... writes in quick succession aren't much different than writes with a longer time between the two; the memory value will simply change.

MicroController
Posts: 2669
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Flush cache between cores?

Postby MicroController » Wed Oct 01, 2025 10:39 am

Note that the ESP32 doesn't have a "CPU cache". Both cores operate directly on the shared SRAM. (I assume there's some hardware arbiter in place to serialize concurrent physical accesses, but that happens fully transparently.)
"The cache" on an ESP32 usually refers to the part of the SRAM which is used as a cache for "external" memory, i.e. flash and optional PSRAM.

User avatar
mvzxa5ltmvzdc
Posts: 5
Joined: Wed Feb 12, 2025 9:35 pm

Re: Flush cache between cores?

Postby mvzxa5ltmvzdc » Wed Oct 01, 2025 1:47 pm

Note that the ESP32 doesn't have a "CPU cache". Both cores operate directly on the shared SRAM. (I assume there's some hardware arbiter in place to serialize concurrent physical accesses, but that happens fully transparently.)
"The cache" on an ESP32 usually refers to the part of the SRAM which is used as a cache for "external" memory, i.e. flash and optional PSRAM.
Oh, thanks for clearing this up! I guess what I heard was just wrong then.

MicroController
Posts: 2669
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Flush cache between cores?

Postby MicroController » Wed Oct 01, 2025 6:58 pm

Maybe.
There are however cases where it may look like two concurrent tasks get out-of-sync with shared memory. This can happen when, in C or C++, memory is accessed concurrently without the compiler being made aware, in which case the compiler may remove memory accesses it deems unnecessary.

Who is online

Users browsing this forum: Applebot, Bing [Bot], Qwantbot, YisouSpider and 3 guests