-
Notifications
You must be signed in to change notification settings - Fork 176
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
Rework main pool to use alloc only pool logic #859
base: develop/3.0.0
Are you sure you want to change the base?
Conversation
src/boot/memory.c
Outdated
} | ||
return addr; | ||
// takes the at least first 'size' bytes from 'region' and return pointer aligned on 'alignment' | ||
static void* main_pool_region_try_alloc_from_start_aligned(struct MainPoolRegion* region, u32 size, u32 alignment) { |
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.
all these functions seem quite messy and repetitive. there must be a way to consolidate some of these into fewer functions, perhaps with macros or whatnot. also where is main_pool_alloc
defined now, i may be blind but i cant find it
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.
main_pool_alloc
is static inline in the header file. It is incredibly fast compiling to roughly 4 instructions.
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.
Gotcha. Do you think the functions defined here could be cleaned up a little? The names and quantity of them are quite confusing
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.
Will work on it
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.
Yeah while I'd prefer long function names over poorly named ones, 9-word function names is a bit on the large side.
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.
I added one "big" function that makes allocation with FORCEINLINE to enable const propagations. I hope it is good enough although there is still a bit of "7-word" functioning here. I'd rather be explicit with names because reading memory code tends to be complicated.
@@ -352,10 +361,17 @@ void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u32 side, u8 *bssStart | |||
void *load_to_fixed_pool_addr(u8 *destAddr, u8 *srcStart, u8 *srcEnd) { | |||
void *dest = NULL; | |||
u32 srcSize = ALIGN16(srcEnd - srcStart); | |||
u32 destSize = ALIGN16((u8 *) sPoolListHeadR - destAddr); | |||
u32 destSize = ALIGN16((u8 *) RAM_END - destAddr); |
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.
is this assuming that main pool ends at end of ram? i think there might be a better variable to use here although not sure
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.
load_to_fixed_pool_addr
is loading at fixed address in the end of RAM.
14281d6
to
4d0e6a4
Compare
struct MainPoolRegion* region = &gMainPool.regions[region_idx]; | ||
char errmsg[70]; | ||
sprintf(errmsg, "%salloc failed for %d bytes in region %d\n%x-%x", freeable ? "freeable " : "", size, region_idx, region->start, region->end); | ||
__n64Assert((char*) file, line, errmsg); |
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.
nit: use the error
macro to simplify this (and to make replacing these with assert_args
or similar easier to find once 2.4 gets merged into 3.0)
Nevermind, I see what's going on here. Add a TODO then for replacing errmsg
with gAssertionStr
once 2.4 is merged.
void *main_pool_alloc_ex(int region, u32 size, u32 alignment) { | ||
void* buf = region ? main_pool_region_alloc_from_start(region, size, alignment, MAIN_POOL_ALLOC_TRY) : NULL; | ||
return buf ?: main_pool_region_alloc_from_start(0, size, alignment, MAIN_POOL_ALLOC_FORCE); |
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.
nit: I feel like this is needlessly difficult to read
Main pool initial state is a multiple regions of memory: | ||
|-------| |----| |-------------------| | ||
If alloc(sizeof(+++++)), first region is used and the state becomes: | ||
|+++++--| |----| |-------------------| | ||
^ | ||
returned pointer, no extra memory overhead |
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.
The segmented portion was removed, but this comment still poses more questions than answers. Can I still allocate to the other memory regions? Are the other regions even supported in the first place?
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.
Yes, it can if you explicitly call main_pool_region_alloc_from_start
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.
I would add an example to this then to demonstrate that use case.
u8* end; | ||
}; | ||
|
||
#define MAIN_POOL_REGIONS_COUNT 2 |
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.
If regions are still specifiable and involve more than one use in HackerSM64, then we should still be using enums to specify region IDs.
This is refactored logic from PR #737 that implements new main pool logic.