Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/debug_heap_allocs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Use this overlay to increase log verbosity for
# all runtime heap allocs.
#
# Logs are emitted from all heap types (system heap 'sof_heap',
# virtual heap allocator, vregions, ...)
#

CONFIG_SYS_HEAP_RUNTIME_STATS=y
CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS=y
Comment on lines +8 to +9
1 change: 1 addition & 0 deletions zephyr/include/sof/lib/regions_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void vmh_get_default_heap_config(const struct sys_mm_drv_region *region,
struct vmh_heap_config *cfg);
#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
void vmh_log_stats(struct vmh_heap *heap);
void vmh_log_alloc_stats(struct vmh_heap *heap);
#endif
/**
* @brief Checks if ptr is in range of given memory range
Expand Down
6 changes: 5 additions & 1 deletion zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ static void *virtual_heap_alloc(struct vmh_heap *heap, uint32_t flags, size_t by
assert(align == 0 || IS_ALIGNED(mem, align));

if (flags & SOF_MEM_FLAG_COHERENT)
return sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)mem);
mem = sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)mem);

#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
vmh_log_alloc_stats(heap);
#endif

return mem;
}
Expand Down
20 changes: 20 additions & 0 deletions zephyr/lib/regions_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,28 @@ void vmh_log_stats(struct vmh_heap *heap)
(stats.max_allocated_bytes / block_size),
heap->out_of_blocks[idx]);
}

heap->logged = true;
}

void vmh_log_alloc_stats(struct vmh_heap *heap)
{
size_t tot_allocated = 0, tot_free = 0;

for (int idx = 0; idx < MAX_MEMORY_ALLOCATORS_COUNT; idx++) {
if (!heap->physical_blocks_allocators[idx])
continue;

struct sys_memory_stats stats = {0};

sys_mem_blocks_runtime_stats_get(heap->physical_blocks_allocators[idx], &stats);

tot_allocated += stats.allocated_bytes;
tot_free += stats.free_bytes;
}

LOG_INF("allocated %zu free %zu", tot_allocated, tot_free);
}
#endif

/**
Expand Down
16 changes: 16 additions & 0 deletions zephyr/lib/vregion.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@ void *z_impl_vregion_alloc_align(struct vregion *vr,

k_mutex_unlock(&vr->lock);

#if CONFIG_SYS_HEAP_RUNTIME_STATS
if (vr->type == VREGION_MEM_TYPE_LIFETIME) {
LOG_INF("lifetime alloc of %zu, used %zu, free %zu",
size, vr->lifetime.used,
vr->lifetime.size - vr->lifetime.used);
Comment on lines +510 to +514
} else {
struct sys_memory_stats stats;

sys_heap_runtime_stats_get(&vr->interim.heap.heap, &stats);
Comment on lines +515 to +518

LOG_INF("interim alloc of %zu, used %u, free %u, max %u",
size, stats.allocated_bytes, stats.free_bytes, stats.max_allocated_bytes);

}
#endif

return p;
}
EXPORT_SYMBOL(z_impl_vregion_alloc_align);
Expand Down
Loading