Skip to content
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

Fix PSRAM cache invalidation #9759

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Oct 25, 2024

The cache invalidation in #9752 needed to use volatile pointers to point to the cache maintenance entries so they would be set correctly and in the right order.

Note that the code from pico-sdk does use volatile:
https://github.com/earlephilhower/arduino-pico/pull/2551/files
It comes from the discussion here:
https://forums.raspberrypi.com/viewtopic.php?t=378249
That code also uses _compiler_memory_barrier(), which may not be needed, but it helps guarantee ordering.

Besides the example in #9755, this even simpler reproducer caused a hard fault on a Feather RP2350 with PSRAM before the fix:

import gc
gc.mem_free()

After the fix, this works, which is more like the example in #9755 (#9755 doesn't have the first gc.mem_free()):

>>> import gc
>>> gc.mem_free()
8264912
>>> a = bytearray(3500000)
>>> b = bytearray(3500000)
>>> gc.mem_free()
1175376
>>>
    [press reset]
>>> import gc
>>> gc.mem_free()
8264912

@tannewt Also, I don't think the extra 4 bytes is needed just below the PSRAM cache, so I took that out. I looked over the tlsf code, and I think it takes care not to write below the beginning of the pool. It does offset the first block by the size of a header. The first pool created is not passed a pointer one word up in free storage, so I think the second pool does not need to either. But you have spent a lot of time on tlsf, so maybe I am wrong.

@bill88t Could you test if you have a chance?

Copy link

@bill88t bill88t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes every test I threw at it. The only thing I didn't test is for corruption.
Everything in the issue is fixed with this commit, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RP2350 PSRAM inconsistency and crashes
2 participants