-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSRAM Cache Issue stills exist (IDFGH-31) #2892
Comments
@neoniousTR Hi, neoniousTR, thanks for reporting this, we will look into this and update if any feedbacks. Also there is a topic about the issue on our forum at http://bbs.esp32.com/viewtopic.php?f=13&t=8628&sid=1acc8bd897e72cf450ad9eb71491d732. Thanks. |
We updated the example project at https://github.com/neonious/memcrash-esp32 We think this problem is urgent to fix, as random crashes can occur to anyone using the PSRAM of the ESP32. There only seems to be two workarounds:
Please take a look at the project, and hopefully you have a better idea. |
Fyi, we're working on this. For what it's worth, it seems to be caused by an interrupt (in your example, the FreeRTOS tick interrupt) firing while some cache activity is going on. We have our digital team running simulations to see what exactly is going on in the hardware; we hope to create a better workaround than the memw solution from that. |
Good that you can reproduce this. |
We seem to be seeing this as a std::string memory corruption (all zeros, on a 4 byte boundary). In our case, disabling the top 2MB of SPIRAM didn't seem to work. But pre-allocating 2MB (which we then never use) seemed to workaround the problem. Our code runs primarily on core #1. This is impacting us quite badly. Lots of random corruptions and crashes with devices in the field. |
Maybe whether the top or bottom of the RAM works depends on the core used. |
Confirmed: running our test project from #3006 with that 2 MB allocation and also starting the test task on core 0 shows the corruptions again. It seems core 0 can only work reliably with the lower 2 MB and core 1 only with the higher 2 MB. |
@Spritetm or @Alvin1Zhang If so, we will try to switch low.js to single core mode, this might even be faster at the end, because the JavaScript itself is single core anyhow and has the most load. Also, how is the progress going? I'd think the chances are to get this fixed by modifying the interrupt handlers or the cache fetchers and savers (they are part of the ROM?). |
Hello, I wanted to add to the subject the error I observed in my application using PSRAM. Random error while retrieving the amount of free PSRAM memory. In my application, I check the amount of free PSRAM memory in the main loop, and differently I received in reply that, for example, 16 bytes of free memory, but at the next check, it actually answered ~ 4mb. In my opinion, there must have been an erroneous random reading from PSRAM. |
Our current status: Load to cache/Write from cache does not seem to be interrupt-based.. Might be 100% hardware-based? Added memw to interrupt handlers does not change anything. Currently we believe Dual Core + PSRAM is a broken combination. So we will completly switch to Unicore now. Please answer: |
I made such an experience, I rewrote the String class from the arduino project to use the PSRAM memory. I changed the name and changed the realloc in the changebuffer function. Suddenly, it turned out that my application did not regularly show 0x00 in one cell. |
I have to confirm that the original PSRAM workaround is still required in Unicore mode. So Workaround + Unicore is the only combination which works reliably with PSRAM. If I am wrong, I hope somebody will post. Otherwise we have to take this as a fact ... |
Can dual core chip be switched to unicore mode? |
Yes the CPU can be configured for unicore.
Pinning to one core does not help, as in dual core mode the other 2 MB are handled by the other core.
|
FWIW, we have a tentative solution for this; the existing workaround solution does actually seem to work but doesn't take calls/returns into account properly. We'll ship a toolchain with improved workaround code soon, but we want to have this fairly well tested so we don't have any other edge cases sneaking past us. I'll see if I can post a preliminary patch as soon as I have something halfway stable, |
Do have any idea of schedule for this, or an ability to get us a pre-release toolchain? This is impacting us quite badly. The 2MB pre-allocation solves the problem for our code, but just shifts the problem to wifi running on the first core (which now experiences random errors and throughput problems). |
I confirm, the error still occurs at random moments, even hangs completely. |
Do have any idea of schedule for this, or an ability to get us a pre-release toolchain? |
@Spritetm We do appreciate your efforts in making sure your patch is perfect. But meanwhile our system has to bear a huge performance hit by the workaround, while the stability is still impacted by the bug. We're more than willing to help you in beta testing your patch by using it on our project. Please do a pre-release or share some update on the status. Thanks! |
Also think an update is in place, we are awaiting to see if you are able to fix this bug or if it makes the PSRAM feature unusable. We need more RAM than internal available in the ESP32, so this is a deal breaker for our product. |
Just wondering why if the original workaround should work in this case that forcing nops does not resolve it.
Also I noticed the workaround will add the nops even when there is already a memw barrier.
|
From what I can see, the load-store inversion doesn't occur there exactly... the issue has something to do with a cache miss around that time that has delayed effects later. Because a cache miss takes a while to resolve, you can fix it with nops but you'd need to put a gazillion of them there. I also noticed the nop/memw interaction... will see if I can get rid of that as well, inasfar gcc marks it. (As in: I can probably detect volatiles that cause an implicit memw, but a literal asm("memw") is harder to spot.) |
Ok thanks. Other things I noticed when playing with the memcrash-esp32 example:
Assuming running NORMAL mode is valid workaround with a performance trade-off, how will it compare to performance of the planned workaround? |
More info: the memw in the example actually does not prevent the error when the routine is running in parallel on both cores. It is much more infrequent but still happens. Normal mode does have a performance cost as it is around 24% fewer tries/ms with the example on both cores, but no errors. |
Normal mode has cache coherency issues according to documentation, so not an option. |
Toolchain updated in release/v4.1 branch with c7ba54e. |
Hello @igrr we're working with v3.3 but also experience issues with regards to PSRAM. (Interestingly enough with ant without a PSRAM chip attached ) It only happens in release mode, debug build works just fine. |
v4.2 9f0c564 |
@AxelLin I started using the PSRAM a couple days ago and started having weird issues with MQTT (from the IDF) on version v3.3. Tried updating the compiler to the one from the linked commit, but that didn't help... after that I tried forcing the MQTT allocation to use the DMA ram and the issue disappeared. So my guess is the issues is not fixed :( |
@tmihovm2m Did you enable |
@dexterbg Hmm, I though it was enabled, but I guess I have accidentaly reverted the change when testing with the updated toolchain. |
Given that the toolchain has been updated in all currently maintained releases, I will close this issue. Please open a new issue if you are seeing a PSRAM-related problem. |
@igrr It seems premature to close this when the toolchain released contains a critical bug as described at https://github.com/espressif/esp-idf/releases/tag/v3.3.4. I will note that the Known Issue says "difficult to reproduce", but in my use case, which is heavy WiFi and BLE, it crashes within minutes and usually under a minute. I have had to revert to a prior revision to keep my app stable. |
@vonnieda Do you still see this with toolchain 1.22.0-97-gc752ad5? |
No, that means toolchain 97-gc752ad5 reverts the regression of the fix introduced in toolchain 96-g2852398 (see above). The fix is now supposed to be fully functional. |
Sorry that i didn't make it clear, all release branches now contain the fix, i.e. a commit which updates the toolchain version. These commits are:
The toolchain versions which contain the fix are |
@igrr do you happen to have any timeline when the v3.3.5 bugfix release is scheduled? |
At the moment QA is testing two bugfix releases: 4.1.1 and 3.3.5. Testing will be finished around Dec 25, if no issues are found we will proceed with the release. 4.1.1 currently has higher priority for us, so if the issues are found we will work on fixing them in release/v4.1 first. Early January is probably viable for the release. We'll try to keep you updated (cc @Alvin1Zhang). |
So, this has been a problem FOR TWO YEARS. How certain are you that the early January release you speak of will actually fix the problem permanently? It's early January now, by the way. |
Hi @Etherfi, some issues (unrelated to PSRAM) have been found while testing v4.1.1 release candidate, so the v3.3.5 release is still pending while we are working on fixing the issues in v4.1.1. To the best of our knowledge, no new PSRAM issue reports appeared since we have switched to this version of the compiler. That said, for new designs it is recommended to use ESP32 silicon revision 3 as it fixes the PSRAM cache issue in hardware. |
Thanks! |
FYI: there is a very strong indication the workaround in toolkit 1.22.0-97-gc752ad5-5.2.0 is not fully fixing the issue. I don't have the time to create a test case. If you want to investigate, use my reduced OVMS build as described here: Regards, |
We see this as well still with toolchain esp-2021r1-8.4.0 and IDF v4.3.1. The occurrence we have been able to identify revolves around the following pseudocode when growing a buffer:
The result invariably causing (from deduction) the first byte in the destination being 0, 1, or 2 (presumably 0) I am afraid you can safely reopen this issue, alas! For now, we will go unicore, which will hopefully alleviate our concrete pains. |
@ThomasRogg your website has a problem with the ssl certificate |
@christhomas: Well, the links are 4 years old. From my side, I believe the old ESP32 revisions are broken and cannot be reliably fixed for Dual Core as ESP-IDF interrupts whenever etc., and I'm not expecting Espressif to really try any longer. So I'm not really caring about what is happening here. Edit: oh and looking above the old ESP32 revisions might never work well with PSRAM even in Unicore mode |
Hi any update on this topic?! Not sure if it is related or not, but using ESP32 revision 1 with Dual core, all the current workaround fixes according to documentation and IDF v4.4, I’m getting random crashes (StoreProhibited and LoadProhibited) with PSRAM! Did we have any closure on fixing that in this discussion here ? |
We stumbled upon the fact that cache issue with PSRAM still exist, even in the newest development environment. This can produce random crashes, even if the code is 100 % valid.
This very small example program reproduces the problem easily, at least if compiled with newest ESP-IDF and toolchain under Mac OS X (did not try other environments):
https://github.com/neonious/memcrash-esp32/
(As a side note: We noticed this problem when we implemented the dlmalloc memory allocator in a fork of ESP-IDF. We worked around this problem (hopefully you can fix it correctly), and now have an ESP-IDF with far faster allocations. Take a look at the blog post here: https://www.neonious-basics.com/index.php/2018/12/27/faster-optimized-esp-idf-fork-psram-issues/ ).
The text was updated successfully, but these errors were encountered: