-
Notifications
You must be signed in to change notification settings - Fork 141
Interrupt and multicore safe allocator #469
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really great, but an allocator is going to need unit tests, just a few for this PR and we can follow up later as well.
I have a test suit that I used. |
Looking closer, I'm not sure how to proceed with adding tests. |
I don't think we have a place for that now, but we do want to get HIL testing in place, so at the very least I'd say hold on to it. We could commit here, but I'd be afraid it would bit rot with nothing running it. |
OK. I'm planning on using it for some stuff I'm doing, but I can just use my fork of microzig for that. I'll keep the PR open, and when there is a plan for building tests I'll add what's needed. |
7ef2634
to
a9bda42
Compare
There is an example program in |
7ccbf36
to
1fbd048
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have some unit tests that run on a host?
And do we really want to make a global heap in the linkerscript? Why not just make a static buffer?
If by "run on a host," you mean to run on the machine where the code is compiled, the problem is that the mutex code suspends interrupts and, since that accesses harware registers, those routines won't compile on the host. I suppose I could do some comptime magick to exclude the mutex from the host build, but that would prevent testing allocation from different exectuion threads. The code does allow accessing from a static buffer, it also has a function to make such a buffer from the remaining heap. On a lot of systems I've used that was standard practice, the stack grows down from the top of the heap and dynamic allocations grow up from the bottom. It just seemed reasonable provide a method to be able to use whatever memory a particular chip had avaiable. |
Good point, in that case we are good to go, just fix the conflicts and then we're good to go! |
@Uthedris ping, there are conflicts still |
This PR supplies an implementation of a std.mem.Allocator.
It can be use to allocate memory from a specified buffer, or from the otherwise unused ram that follows the .bss section.
Unlike std.heap.FixedBufferAllocator it supports re-use of freed memory, coalescing adjacent freed blocks to lessen fragmentation.
It can be safely used from multiple cores or from an interrupt service routine.
It has been tested on RP2040, RP2350 (both amd and riscv) and on an esp-c3.