-
Notifications
You must be signed in to change notification settings - Fork 348
zephyr: lib: alloc: Use cached memory for L3 Heap #8632
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
Merged
kv2019i
merged 2 commits into
thesofproject:main
from
jxstelter:lnl-rvp-fix-d3-save-restore
Feb 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,8 +116,7 @@ static inline uintptr_t get_l3_heap_start(void) | |
| * - main_fw_load_offset | ||
| * - main fw size in manifest | ||
| */ | ||
| return (uintptr_t)z_soc_uncached_ptr((__sparse_force void __sparse_cache *) | ||
| ROUND_UP(IMR_L3_HEAP_BASE, L3_MEM_PAGE_SIZE)); | ||
| return (uintptr_t)(ROUND_UP(IMR_L3_HEAP_BASE, L3_MEM_PAGE_SIZE)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -145,14 +144,50 @@ static bool is_l3_heap_pointer(void *ptr) | |
| uintptr_t l3_heap_start = get_l3_heap_start(); | ||
| uintptr_t l3_heap_end = l3_heap_start + get_l3_heap_size(); | ||
|
|
||
| if (is_cached(ptr)) | ||
| ptr = z_soc_uncached_ptr((__sparse_force void __sparse_cache *)ptr); | ||
|
|
||
| if ((POINTER_TO_UINT(ptr) >= l3_heap_start) && (POINTER_TO_UINT(ptr) < l3_heap_end)) | ||
| return true; | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| static void *l3_heap_alloc_aligned(struct k_heap *h, size_t min_align, size_t bytes) | ||
| { | ||
| k_spinlock_key_t key; | ||
| void *ret; | ||
| #if CONFIG_SYS_HEAP_RUNTIME_STATS && CONFIG_IPC_MAJOR_4 | ||
| struct sys_memory_stats stats; | ||
| #endif | ||
| if (!cpu_is_primary(arch_proc_id())) { | ||
| tr_err(&zephyr_tr, "L3_HEAP available only for primary core!"); | ||
| return NULL; | ||
| } | ||
|
|
||
| key = k_spin_lock(&h->lock); | ||
| ret = sys_heap_aligned_alloc(&h->heap, min_align, bytes); | ||
| k_spin_unlock(&h->lock, key); | ||
|
|
||
| #if CONFIG_SYS_HEAP_RUNTIME_STATS && CONFIG_IPC_MAJOR_4 | ||
| sys_heap_runtime_stats_get(&h->heap, &stats); | ||
| tr_info(&zephyr_tr, "heap allocated: %u free: %u max allocated: %u", | ||
| stats.allocated_bytes, stats.free_bytes, stats.max_allocated_bytes); | ||
| #endif | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static void l3_heap_free(struct k_heap *h, void *mem) | ||
| { | ||
| if (!cpu_is_primary(arch_proc_id())) { | ||
| tr_err(&zephyr_tr, "L3_HEAP available only for primary core!"); | ||
| return; | ||
| } | ||
|
|
||
| k_spinlock_key_t key = k_spin_lock(&h->lock); | ||
|
|
||
| sys_heap_free(&h->heap, mem); | ||
| k_spin_unlock(&h->lock, key); | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| static void *heap_alloc_aligned(struct k_heap *h, size_t min_align, size_t bytes) | ||
|
|
@@ -251,6 +286,17 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) | |
| if (caps & SOF_MEM_CAPS_L3) { | ||
| #if CONFIG_L3_HEAP | ||
| heap = &l3_heap; | ||
| /* Uncached L3_HEAP should be not used */ | ||
| if (!zone_is_cached(zone)) { | ||
| tr_err(&zephyr_tr, "L3_HEAP available for cached zones only!"); | ||
| return NULL; | ||
| } | ||
| ptr = (__sparse_force void *)l3_heap_alloc_aligned(heap, 0, bytes); | ||
|
|
||
| if (!ptr && zone == SOF_MEM_ZONE_SYS) | ||
| k_panic(); | ||
|
|
||
| return ptr; | ||
| #else | ||
| k_panic(); | ||
| #endif | ||
|
|
@@ -335,10 +381,24 @@ EXPORT_SYMBOL(rzalloc); | |
| void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, | ||
| uint32_t align) | ||
| { | ||
| struct k_heap *heap; | ||
|
|
||
| /* choose a heap */ | ||
| if (caps & SOF_MEM_CAPS_L3) { | ||
| #if CONFIG_L3_HEAP | ||
| heap = &l3_heap; | ||
| return (__sparse_force void *)l3_heap_alloc_aligned(heap, align, bytes); | ||
| #else | ||
| k_panic(); | ||
|
Collaborator
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. this is kind of theoretical, but maybe a small follow-up PR to convert this and line 301 above to
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. |
||
| #endif | ||
| } else { | ||
| heap = &sof_heap; | ||
| } | ||
|
|
||
| if (flags & SOF_MEM_FLAG_COHERENT) | ||
| return heap_alloc_aligned(&sof_heap, align, bytes); | ||
| return heap_alloc_aligned(heap, align, bytes); | ||
|
|
||
| return (__sparse_force void *)heap_alloc_aligned_cached(&sof_heap, align, bytes); | ||
| return (__sparse_force void *)heap_alloc_aligned_cached(heap, align, bytes); | ||
| } | ||
| EXPORT_SYMBOL(rballoc_align); | ||
|
|
||
|
|
@@ -352,7 +412,7 @@ void rfree(void *ptr) | |
|
|
||
| #if CONFIG_L3_HEAP | ||
| if (is_l3_heap_pointer(ptr)) { | ||
| heap_free(&l3_heap, ptr); | ||
| l3_heap_free(&l3_heap, ptr); | ||
| return; | ||
| } | ||
| #endif | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.