Repository navigation
[RFC] allocator: unify alloc API #1155
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -555,36 +555,65 @@ static void *rmalloc_runtime(int zone, uint32_t caps, size_t bytes) | |
| return get_ptr_from_heap(heap, zone, caps, bytes); | ||
| } | ||
|
|
||
| static void *rballoc(int zone, uint32_t caps, size_t bytes) | ||
| { | ||
| void *ptr; | ||
|
|
||
| ptr = _balloc(zone, caps, bytes); | ||
|
|
||
| #if CONFIG_DEBUG_HEAP | ||
| if (!ptr) { | ||
| trace_error(TRACE_CLASS_MEM, | ||
| "failed to alloc 0x%x bytes caps 0x%x", | ||
| bytes, caps); | ||
|
|
||
| alloc_trace_buffer_heap(zone, caps, bytes); | ||
| } | ||
| #endif | ||
|
|
||
| return ptr; | ||
| } | ||
|
|
||
| /* allocates memory - not for direct use, clients use rmalloc() */ | ||
| void *_malloc(int zone, uint32_t caps, size_t bytes) | ||
| { | ||
| uint32_t flags; | ||
| void *ptr = NULL; | ||
|
|
||
| if (bytes >= PLATFORM_BUFFER_BLOCK_SIZE) | ||
| return rballoc(zone, caps, bytes); | ||
|
|
||
| spin_lock_irq(&memmap.lock, flags); | ||
|
|
||
| switch (zone & RZONE_TYPE_MASK) { | ||
| case RZONE_SYS: | ||
| ptr = rmalloc_sys(zone, caps, cpu_get_id(), bytes); | ||
| break; | ||
| case RZONE_SYS_RUNTIME: | ||
| ptr = rmalloc_sys_runtime(zone, caps, cpu_get_id(), bytes); | ||
| ptr = rmalloc_sys_runtime(zone, caps, cpu_get_id(), | ||
| bytes); | ||
| break; | ||
| case RZONE_RUNTIME: | ||
| ptr = rmalloc_runtime(zone, caps, bytes); | ||
| break; | ||
| default: | ||
| trace_mem_error("rmalloc() error: invalid zone"); | ||
| panic(SOF_IPC_PANIC_MEM); /* logic non recoverable problem */ | ||
|
|
||
| /* logic non recoverable problem */ | ||
| panic(SOF_IPC_PANIC_MEM); | ||
| break; | ||
| } | ||
|
|
||
| spin_unlock_irq(&memmap.lock, flags); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you are unlocking before another try to alloc. |
||
|
|
||
| if (!ptr) | ||
| ptr = _balloc(zone, caps, bytes); | ||
|
|
||
| #if DEBUG_BLOCK_FREE | ||
| if (ptr) | ||
| bzero(ptr, bytes); | ||
| #endif | ||
|
|
||
| spin_unlock_irq(&memmap.lock, flags); | ||
| memmap.heap_trace_updated = 1; | ||
| return ptr; | ||
| } | ||
|
|
@@ -618,7 +647,7 @@ void *rzalloc_core_sys(int core, size_t bytes) | |
| return ptr; | ||
| } | ||
|
|
||
| /* allocates continuous buffers - not for direct use, clients use rballoc() */ | ||
| /* allocates continuous buffers - not for direct use, clients use rmalloc() */ | ||
| static void *alloc_heap_buffer(struct mm_heap *heap, int zone, uint32_t caps, | ||
| size_t bytes) | ||
| { | ||
|
|
@@ -667,7 +696,7 @@ static void *alloc_heap_buffer(struct mm_heap *heap, int zone, uint32_t caps, | |
| return ptr; | ||
| } | ||
|
|
||
| /* allocates continuous buffers - not for direct use, clients use rballoc() */ | ||
| /* allocates continuous buffers - not for direct use, clients use rmalloc() */ | ||
|
lgirdwood marked this conversation as resolved.
Resolved
|
||
| void *_balloc(int zone, uint32_t caps, size_t bytes) | ||
| { | ||
| struct mm_heap *heap; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,20 +135,24 @@ | |
|
|
||
| /* Heap section sizes for system runtime heap for master core */ | ||
| #define HEAP_SYS_RT_0_COUNT64 64 | ||
| #define HEAP_SYS_RT_0_COUNT512 16 | ||
| #define HEAP_SYS_RT_0_COUNT1024 4 | ||
| #define HEAP_SYS_RT_0_COUNT128 16 | ||
| #define HEAP_SYS_RT_0_COUNT192 8 | ||
| #define HEAP_SYS_RT_0_COUNT256 4 | ||
| #define HEAP_SYS_RT_0_COUNT320 4 | ||
|
|
||
| /* Heap section sizes for system runtime heap for slave core */ | ||
| #define HEAP_SYS_RT_X_COUNT64 32 | ||
| #define HEAP_SYS_RT_X_COUNT512 8 | ||
| #define HEAP_SYS_RT_X_COUNT1024 4 | ||
| #define HEAP_SYS_RT_X_COUNT128 8 | ||
| #define HEAP_SYS_RT_X_COUNT192 4 | ||
| #define HEAP_SYS_RT_X_COUNT256 4 | ||
| #define HEAP_SYS_RT_X_COUNT320 4 | ||
|
|
||
| /* Heap section sizes for module pool */ | ||
| #define HEAP_RT_COUNT64 128 | ||
| #define HEAP_RT_COUNT128 64 | ||
| #define HEAP_RT_COUNT256 128 | ||
| #define HEAP_RT_COUNT512 8 | ||
| #define HEAP_RT_COUNT1024 4 | ||
| #define HEAP_RT_COUNT192 32 | ||
| #define HEAP_RT_COUNT256 16 | ||
| #define HEAP_RT_COUNT320 8 | ||
|
|
||
| #define L2_VECTOR_SIZE 0x1000 | ||
|
|
||
|
|
@@ -165,12 +169,14 @@ | |
| ((PLATFORM_CORE_COUNT - 1) * HEAP_SYSTEM_S_SIZE)) | ||
|
|
||
| #define HEAP_SYS_RUNTIME_M_SIZE \ | ||
| (HEAP_SYS_RT_0_COUNT64 * 64 + HEAP_SYS_RT_0_COUNT512 * 512 + \ | ||
| HEAP_SYS_RT_0_COUNT1024 * 1024) | ||
| (HEAP_SYS_RT_0_COUNT64 * 64 + HEAP_SYS_RT_0_COUNT128 * 128 + \ | ||
| HEAP_SYS_RT_0_COUNT192 * 192 + HEAP_SYS_RT_0_COUNT256 * 256 + \ | ||
| HEAP_SYS_RT_0_COUNT320 * 320) | ||
|
|
||
| #define HEAP_SYS_RUNTIME_S_SIZE \ | ||
| (HEAP_SYS_RT_X_COUNT64 * 64 + HEAP_SYS_RT_X_COUNT512 * 512 + \ | ||
| HEAP_SYS_RT_X_COUNT1024 * 1024) | ||
| (HEAP_SYS_RT_X_COUNT64 * 64 + HEAP_SYS_RT_X_COUNT128 * 128 + \ | ||
| HEAP_SYS_RT_X_COUNT192 * 192 + HEAP_SYS_RT_X_COUNT256 * 256 + \ | ||
| HEAP_SYS_RT_X_COUNT320 * 320) | ||
|
|
||
| #define HEAP_SYS_RUNTIME_T_SIZE \ | ||
| (HEAP_SYS_RUNTIME_M_SIZE + ((PLATFORM_CORE_COUNT - 1) * \ | ||
|
|
@@ -182,14 +188,16 @@ | |
|
|
||
| #define HEAP_RUNTIME_SIZE \ | ||
| (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ | ||
| HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ | ||
| HEAP_RT_COUNT1024 * 1024) | ||
| HEAP_RT_COUNT192 * 192 + HEAP_RT_COUNT256 * 256 + \ | ||
| HEAP_RT_COUNT320 * 320) | ||
|
|
||
| #define HEAP_BUFFER_BASE (HEAP_RUNTIME_BASE + HEAP_RUNTIME_SIZE) | ||
| #define HEAP_BUFFER_SIZE (SOF_STACK_END - HEAP_BUFFER_BASE) | ||
| #define HEAP_BUFFER_BLOCK_SIZE 0x180 | ||
| #define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) | ||
|
|
||
| #define PLATFORM_BUFFER_BLOCK_SIZE (HEAP_BUFFER_BLOCK_SIZE - 64) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tlauda , please ignore this for I may rework the PR since The memory structure is significant different with the one on which I made this PR based |
||
|
|
||
| #define LOG_ENTRY_ELF_BASE 0x20000000 | ||
| #define LOG_ENTRY_ELF_SIZE 0x2000000 | ||
|
|
||
|
|
@@ -352,14 +360,11 @@ | |
| #define LP_SRAM_BASE 0xBE800000 | ||
|
|
||
| /* Heap section sizes for module pool */ | ||
| #define HEAP_RT_LP_COUNT8 0 | ||
| #define HEAP_RT_LP_COUNT16 256 | ||
| #define HEAP_RT_LP_COUNT32 128 | ||
| #define HEAP_RT_LP_COUNT64 64 | ||
| #define HEAP_RT_LP_COUNT64 128 | ||
| #define HEAP_RT_LP_COUNT128 64 | ||
| #define HEAP_RT_LP_COUNT256 96 | ||
| #define HEAP_RT_LP_COUNT512 8 | ||
| #define HEAP_RT_LP_COUNT1024 4 | ||
| #define HEAP_RT_LP_COUNT192 32 | ||
| #define HEAP_RT_LP_COUNT256 16 | ||
| #define HEAP_RT_LP_COUNT320 8 | ||
|
|
||
| /* Heap configuration */ | ||
| #define SOF_LP_DATA_SIZE 0x4000 | ||
|
|
@@ -370,10 +375,9 @@ | |
| #define HEAP_LP_RUNTIME_BASE \ | ||
| (HEAP_LP_SYSTEM_BASE + HEAP_LP_SYSTEM_SIZE) | ||
| #define HEAP_LP_RUNTIME_SIZE \ | ||
| (HEAP_RT_LP_COUNT8 * 8 + HEAP_RT_LP_COUNT16 * 16 + \ | ||
| HEAP_RT_LP_COUNT32 * 32 + HEAP_RT_LP_COUNT64 * 64 + \ | ||
| HEAP_RT_LP_COUNT128 * 128 + HEAP_RT_LP_COUNT256 * 256 + \ | ||
| HEAP_RT_LP_COUNT512 * 512 + HEAP_RT_LP_COUNT1024 * 1024) | ||
| (HEAP_RT_LP_COUNT64 * 64 + HEAP_RT_LP_COUNT128 * 128 + \ | ||
| HEAP_RT_LP_COUNT192 * 192 + HEAP_RT_LP_COUNT256 * 256 + \ | ||
| HEAP_RT_LP_COUNT320 * 320) | ||
|
|
||
| #define HEAP_LP_BUFFER_BASE LP_SRAM_BASE | ||
| #define HEAP_LP_BUFFER_SIZE LP_SRAM_SIZE | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,21 +105,23 @@ void platform_init_memmap(void); | |
| * +---------------------+----------------+-----------------------------------+ | ||
| */ | ||
|
|
||
|
|
||
| /* Heap section sizes for module pool */ | ||
| #define HEAP_RT_COUNT8 0 | ||
| #define HEAP_RT_COUNT16 48 | ||
| #define HEAP_RT_COUNT32 48 | ||
| #define HEAP_RT_COUNT64 32 | ||
| #define HEAP_RT_COUNT128 32 | ||
| #define HEAP_RT_COUNT256 32 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you making block 256 count smaller ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lgirdwood This is the summary of allocation on BYT with nocodec. So I decreased the size of 256. Do you prefer to change the block number of other size ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RanderWang why do you have blocks defined for 384 ? when this is the buffer block size ? i.e. it's not needed as code will use buffer heap here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lgirdwood we have got agreement at this 4 days ago, right ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RanderWang I mean you dont need to add any blocks of size 384 to the non buffer heap map since all blocks of 384 size will be in buffer heap.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lgirdwood yes, but I talk about allocation size (.eg 360 )< 384 and > 320. For this kind of allocation, It will be not allocated from buffer heap but it is not supported by other non buffer heap without 384 included. block of sized 384 is for allocation size < 384 && > 320
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is there is a gap between 320 and 384
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, now I see to fill this gap, but it would be better to remove and catch all allocations above the largest block size (in this case 320) to us the buffer heap.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked there is no free block of 384 sized on apollolake and whiskylake, icelake, so I will remove 384 on Baytray and haswell only. Thanks!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RanderWang have you pushed the updated branch, I'm still seeing block size 384 for some heaps (not all) |
||
| #define HEAP_RT_COUNT512 4 | ||
| #define HEAP_RT_COUNT1024 4 | ||
| #define HEAP_RT_COUNT128 16 | ||
| #define HEAP_RT_COUNT192 16 | ||
| #define HEAP_RT_COUNT256 24 | ||
| #define HEAP_RT_COUNT320 2 | ||
|
|
||
| /* Heap section sizes for system runtime heap */ | ||
| #define HEAP_SYS_RT_COUNT32 64 | ||
| #define HEAP_SYS_RT_COUNT64 64 | ||
| #define HEAP_SYS_RT_COUNT512 8 | ||
| #define HEAP_SYS_RT_COUNT1024 4 | ||
| #define HEAP_SYS_RT_COUNT128 8 | ||
| #define HEAP_SYS_RT_COUNT192 4 | ||
| #define HEAP_SYS_RT_COUNT256 4 | ||
| #define HEAP_SYS_RT_COUNT320 2 | ||
|
|
||
| /* Heap configuration */ | ||
| #define SOF_DATA_SIZE 0x6800 | ||
|
|
@@ -131,15 +133,16 @@ void platform_init_memmap(void); | |
|
|
||
| #define HEAP_SYS_RUNTIME_BASE (HEAP_SYSTEM_BASE + HEAP_SYSTEM_SIZE) | ||
| #define HEAP_SYS_RUNTIME_SIZE \ | ||
| (HEAP_SYS_RT_COUNT64 * 64 + HEAP_SYS_RT_COUNT512 * 512 + \ | ||
| HEAP_SYS_RT_COUNT1024 * 1024) | ||
| (HEAP_SYS_RT_COUNT32 * 32 + HEAP_SYS_RT_COUNT64 * 64 + \ | ||
| HEAP_SYS_RT_COUNT128 * 128 + HEAP_SYS_RT_COUNT192 * 192 + \ | ||
| HEAP_SYS_RT_COUNT256 * 256 + HEAP_SYS_RT_COUNT320 * 320) | ||
|
|
||
| #define HEAP_RUNTIME_BASE (HEAP_SYS_RUNTIME_BASE + HEAP_SYS_RUNTIME_SIZE) | ||
| #define HEAP_RUNTIME_SIZE \ | ||
| (HEAP_RT_COUNT8 * 8 + HEAP_RT_COUNT16 * 16 + \ | ||
| HEAP_RT_COUNT32 * 32 + HEAP_RT_COUNT64 * 64 + \ | ||
| HEAP_RT_COUNT128 * 128 + HEAP_RT_COUNT256 * 256 + \ | ||
| HEAP_RT_COUNT512 * 512 + HEAP_RT_COUNT1024 * 1024) | ||
| HEAP_RT_COUNT128 * 128 + HEAP_RT_COUNT192 * 192 + \ | ||
| HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT320 * 320) | ||
|
|
||
| #define HEAP_BUFFER_BASE (HEAP_RUNTIME_BASE + HEAP_RUNTIME_SIZE) | ||
| #define HEAP_BUFFER_SIZE \ | ||
|
|
@@ -149,6 +152,8 @@ void platform_init_memmap(void); | |
| #define HEAP_BUFFER_BLOCK_SIZE 0x180 | ||
| #define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) | ||
|
|
||
| #define PLATFORM_BUFFER_BLOCK_SIZE (HEAP_BUFFER_BLOCK_SIZE - 64) | ||
|
|
||
| #define PLATFORM_HEAP_SYSTEM 1 /* one per core */ | ||
| #define PLATFORM_HEAP_SYSTEM_RUNTIME 1 /* one per core */ | ||
| #define PLATFORM_HEAP_RUNTIME 1 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.