Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Uthedris
Copy link
Contributor

@Uthedris Uthedris commented Apr 21, 2025

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.

@Uthedris Uthedris marked this pull request as ready for review May 4, 2025 18:30
@Uthedris Uthedris marked this pull request as draft May 4, 2025 21:27
@Uthedris Uthedris marked this pull request as ready for review May 6, 2025 11:45
Copy link
Contributor

@mattnite mattnite left a 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.

@Uthedris
Copy link
Contributor Author

Uthedris commented May 7, 2025

I have a test suit that I used. Is there someplace where I should put it in the microzig directory? I'll move it into the test directory.

@Uthedris
Copy link
Contributor Author

Uthedris commented May 7, 2025

Looking closer, I'm not sure how to proceed with adding tests. I'm adding a zig test case to the allocator itself. That would run on the machine doing the compilation, but should validate the allocator itself. Do you also want some sort of test program to run under microzig on the microcontrollers. I'd guess that would go in the test direcory, but I'm unsure of the details of how I should do that.

@Grazfather
Copy link
Collaborator

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.

@Uthedris
Copy link
Contributor Author

Uthedris commented May 7, 2025

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.

@Uthedris Uthedris force-pushed the allocator branch 2 times, most recently from 7ef2634 to a9bda42 Compare May 13, 2025 16:34
@Uthedris
Copy link
Contributor Author

There is an example program in examples/raspberrypi/rp2xxx/src/allocator.zig that tests the allocator.

@Uthedris Uthedris force-pushed the allocator branch 2 times, most recently from 456e0a0 to 7ccbf36 Compare May 20, 2025 13:40
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.

3 participants