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

Support multiple allocators, add TLSF allocator and create cmake switches #83

Draft
wants to merge 128 commits into
base: master
Choose a base branch
from

Conversation

EngineersBox
Copy link
Contributor

@EngineersBox EngineersBox commented Feb 7, 2024

Changes

This adds support for multiple allocator implementations in tandem with a CMake switch -D PSN00BSDK_LIBC_ALLOCATOR with the current implementations:

  • CUSTOM - Weakly linked symbols for placeholders for inline custom implementations.
  • AFF - Existing implementation using allocated first-fit.
  • TLSF - Two-level segregated-fit using @mattconte's TLSF implementation.

To Consider

In order to directly support the TLSF allocator repo, might be better to add it as a submodule with an include wrapper for the necessary coupling to the SDK's expected malloc interface. On the other hand this might not be a good idea, since I plan to cut down the TLSF implementation to only support 32-bit and change the alignment from 4 to 8 bytes.

I'd imagine that there might be some discussion to be had around the implementation of the CMake side of things. I'm really not overly familiar with CMake so there may well be better ways of doing what I've done in this PR.

Something else to think about is adding performance tests/benchmarking in the form of a standard suite to run against a given allocator implementation. This gives both SDK devs and users a decent idea of how the supported allocators run and their practical usage.

TODO

  • Implement void TrackHeapUsage(ptrdiff_t alloc_incr) for TLSF
  • Implement void GetHeapUsage(HeapUsage* usage) for TLSF.
  • Migrate TLSF to a git submodule and create interfacing wrapper (option 1).
  • Refactor TLSF to support only 32-bit and 8-byte alignment (option 2).
  • Write documentation for CMake variable usage and supporting a new allocator.
  • Write documentation for implementing a new allocator into the SDK or overriding the CUSTOM one.
  • Remove the mention of needing to support multiple allocators in README.md.
  • Squash commits to make the changes and history more palatable.
  • Fix formatting
  • Remove SMD defines
  • Make CMake flag naming consistent

Notes

I've used TLSF before a while ago for an undergrad thesis project and it showed promise over the standard GlibC allocator and will subsequently perform much better than the current implementation in the SDK.

@EngineersBox EngineersBox marked this pull request as draft February 7, 2024 14:27
@EngineersBox EngineersBox changed the title Support multiple allocators and cmake switches Support multiple allocators, add TLSF allocator and create cmake switches Feb 7, 2024
libpsn00b/libc/tlsf.c Outdated Show resolved Hide resolved
@EngineersBox EngineersBox force-pushed the multiple-allocators branch 3 times, most recently from 4601449 to 3f98423 Compare July 29, 2024 12:43
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.

2 participants