Invalidate cache

administrator
Posts: 1
Joined: Sat Aug 05, 2023 8:04 pm

Invalidate cache

Postby administrator » Sat Aug 05, 2023 8:11 pm

I am trying to understand a way to invalidate the cache whenever i want to read some data from PSRAM.
for example.

byte *memory = (byte *)ps_malloc(1024*64);
loop:
memcpy(memory, memory, 1024);
goto loop:

The first access takes around ~600us and consequent memcpy takes only 80us. I think the value is loaded to the cache and the operation happens in the dcache rather than on the psram hardware. This is for a research purpose. so there is no practical need for this option.
but I want to know if i can disable the cache for such memcpy operation so the operation happens on the PSRAM directly and not through the cache. I dont care about the execution time. i want to have direct access to the psram without any cache.

xthal_dcache_line_invalidate() this has no effect

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Invalidate cache

Postby ESP_igrr » Tue Aug 08, 2023 1:42 pm

Which IDF version and which chip are you using? We have added an API "esp_cache_msync" in IDF v5.1, but it only works on ESP32-S2 and later chips.

ESP32 doesn't have a hardware feature to write back all the cache contents. (It can invalidate the cache, but invalidating cache when the program is running is not safe since writes previously done into PSRAM by other parts of the code may get lost.)
On ESP32, the only way to do this is to read around 64kB of data from some location in PSRAM other than the one where your buffer is. This will cause the cache to be refilled with that new data, and old data will be written back.

Who is online

Users browsing this forum: Baidu [Spider], MicroController and 83 guests