Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/audio/pipeline/pipeline-params.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <sof/audio/buffer.h>
#include <sof/audio/component_ext.h>
#include <sof/audio/pipeline.h>
#include <sof/lib/memory.h>
#include <sof/lib/mm_heap.h>
#include <sof/list.h>
#include <sof/spinlock.h>
#include <ipc/stream.h>
Expand Down Expand Up @@ -235,6 +237,10 @@ int pipeline_params(struct pipeline *p, struct comp_dev *host,
ret, dev_comp_id(host));
}

#if CONFIG_DEBUG_HEAP
/* show heap status update with this pipeline run */
heap_trace_all(0);
#endif
return ret;
}

Expand Down
50 changes: 45 additions & 5 deletions src/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,14 @@ static void alloc_trace_heap(enum mem_zone zone, uint32_t caps, size_t bytes)
int count = 0;

switch (zone) {
case SOF_MEM_ZONE_SYS:
heap_base = memmap->system;
heap_count = PLATFORM_HEAP_SYSTEM;
break;
case SOF_MEM_ZONE_SYS_RUNTIME:
heap_base = memmap->system_runtime;
heap_count = PLATFORM_HEAP_SYSTEM_RUNTIME;
break;
case SOF_MEM_ZONE_RUNTIME:
heap_base = memmap->runtime;
heap_count = PLATFORM_HEAP_RUNTIME;
Expand All @@ -592,6 +600,25 @@ static void alloc_trace_heap(enum mem_zone zone, uint32_t caps, size_t bytes)
heap_base = memmap->buffer;
heap_count = PLATFORM_HEAP_BUFFER;
break;
#if CONFIG_CORE_COUNT > 1
case SOF_MEM_ZONE_RUNTIME_SHARED:
heap_base = memmap->runtime_shared;
heap_count = PLATFORM_HEAP_RUNTIME_SHARED;
break;
case SOF_MEM_ZONE_SYS_SHARED:
heap_base = memmap->system_shared;
heap_count = PLATFORM_HEAP_SYSTEM_SHARED;
break;
#else
case SOF_MEM_ZONE_RUNTIME_SHARED:
heap_base = memmap->runtime;
heap_count = PLATFORM_HEAP_RUNTIME;
break;
case SOF_MEM_ZONE_SYS_SHARED:
heap_base = memmap->system;
heap_count = PLATFORM_HEAP_SYSTEM;
break;
#endif
default:
tr_err(&mem_tr, "alloc trace: unsupported mem zone");
goto out;
Expand Down Expand Up @@ -620,14 +647,22 @@ static void alloc_trace_heap(enum mem_zone zone, uint32_t caps, size_t bytes)

#define DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags) \
do { \
if (!ptr) { \
tr_err(&mem_tr, "failed to alloc 0x%x bytes zone 0x%x caps 0x%x flags 0x%x", \
if (!(ptr)) { \
tr_err(&mem_tr, \
"failed to alloc 0x%x bytes zone 0x%x caps 0x%x flags 0x%x", \
bytes, zone, caps, flags); \
alloc_trace_heap(zone, caps, bytes); \
} \
} while (0)
#else
#define DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags)
#define DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags) \
do { \
if (!(ptr)) { \
tr_err(&mem_tr, \
"failed to alloc 0x%x bytes zone 0x%x caps 0x%x flags 0x%x", \
bytes, zone, caps, flags); \
} \
} while (0)
#endif

/* allocate single block for system runtime */
Expand Down Expand Up @@ -765,7 +800,6 @@ void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes)
if (ptr)
bzero(ptr, bytes);

DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags);
return ptr;
}

Expand Down Expand Up @@ -1073,7 +1107,7 @@ void heap_trace(struct mm_heap *heap, int size)
heap->info.free);

/* map[j]'s base is calculated based on map[j-1] */
for (j = 1; j < heap->blocks; j++) {
for (j = 0; j < heap->blocks; j++) {
current_map = &heap->map[j];

tr_info(&mem_tr, " block %d base 0x%x size %d",
Expand All @@ -1094,13 +1128,19 @@ void heap_trace_all(int force)

/* has heap changed since last shown */
if (memmap->heap_trace_updated || force) {
tr_info(&mem_tr, "heap: system status");
heap_trace(memmap->system, PLATFORM_HEAP_SYSTEM);
tr_info(&mem_tr, "heap: system runtime status");
heap_trace(memmap->system_runtime, PLATFORM_HEAP_SYSTEM_RUNTIME);
tr_info(&mem_tr, "heap: buffer status");
heap_trace(memmap->buffer, PLATFORM_HEAP_BUFFER);
tr_info(&mem_tr, "heap: runtime status");
heap_trace(memmap->runtime, PLATFORM_HEAP_RUNTIME);
#if CONFIG_CORE_COUNT > 1
tr_info(&mem_tr, "heap: runtime shared status");
heap_trace(memmap->runtime_shared, PLATFORM_HEAP_RUNTIME_SHARED);
tr_info(&mem_tr, "heap: system shared status");
heap_trace(memmap->system_shared, PLATFORM_HEAP_SYSTEM_SHARED);
#endif
}

Expand Down
67 changes: 40 additions & 27 deletions src/platform/intel/cavs/lib/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,40 @@ static SHARED_DATA struct block_map sys_rt_heap_map[CONFIG_CORE_COUNT][3] = {
};

/* Heap blocks for modules */
static SHARED_DATA struct block_hdr mod_block64[HEAP_RT_COUNT64];
static SHARED_DATA struct block_hdr mod_block128[HEAP_RT_COUNT128];
static SHARED_DATA struct block_hdr mod_block256[HEAP_RT_COUNT256];
static SHARED_DATA struct block_hdr mod_block512[HEAP_RT_COUNT512];
static SHARED_DATA struct block_hdr mod_block1024[HEAP_RT_COUNT1024];
static SHARED_DATA struct block_hdr mod_block2048[HEAP_RT_COUNT2048];
static SHARED_DATA struct block_hdr mod_block4096[HEAP_RT_COUNT4096];
static SHARED_DATA struct block_hdr mod_block64[HEAP_COUNT64 * RT_COUNT_MAX];
static SHARED_DATA struct block_hdr mod_block128[HEAP_COUNT128 * RT_COUNT_MAX];
static SHARED_DATA struct block_hdr mod_block256[HEAP_COUNT256 * RT_COUNT_MAX];
static SHARED_DATA struct block_hdr mod_block512[HEAP_COUNT512 * RT_COUNT_MAX];
static SHARED_DATA struct block_hdr mod_block1024[HEAP_COUNT1024 * RT_COUNT_MAX];
static SHARED_DATA struct block_hdr mod_block2048[HEAP_COUNT2048 * RT_COUNT_MAX];
static SHARED_DATA struct block_hdr mod_block4096[HEAP_COUNT4096 * RT_COUNT_MAX];

/* Heap memory map for modules */
static SHARED_DATA struct block_map rt_heap_map[] = {
BLOCK_DEF(64, HEAP_RT_COUNT64, uncached_block_hdr(mod_block64)),
BLOCK_DEF(128, HEAP_RT_COUNT128, uncached_block_hdr(mod_block128)),
BLOCK_DEF(256, HEAP_RT_COUNT256, uncached_block_hdr(mod_block256)),
BLOCK_DEF(512, HEAP_RT_COUNT512, uncached_block_hdr(mod_block512)),
BLOCK_DEF(1024, HEAP_RT_COUNT1024, uncached_block_hdr(mod_block1024)),
BLOCK_DEF(2048, HEAP_RT_COUNT2048, uncached_block_hdr(mod_block2048)),
BLOCK_DEF(4096, HEAP_RT_COUNT4096, uncached_block_hdr(mod_block4096)),
BLOCK_DEF(64, HEAP_COUNT64, uncached_block_hdr(mod_block64)),
BLOCK_DEF(128, HEAP_COUNT128, uncached_block_hdr(mod_block128)),
BLOCK_DEF(256, HEAP_COUNT256, uncached_block_hdr(mod_block256)),
BLOCK_DEF(512, HEAP_COUNT512, uncached_block_hdr(mod_block512)),
BLOCK_DEF(1024, HEAP_COUNT1024, uncached_block_hdr(mod_block1024)),
BLOCK_DEF(2048, HEAP_COUNT2048, uncached_block_hdr(mod_block2048)),
BLOCK_DEF(4096, HEAP_COUNT4096, uncached_block_hdr(mod_block4096)),
};

#if CONFIG_CORE_COUNT > 1
/* Heap blocks for runtime shared */
static SHARED_DATA struct block_hdr rt_shared_block64[HEAP_RUNTIME_SHARED_COUNT64];
static SHARED_DATA struct block_hdr rt_shared_block128[HEAP_RUNTIME_SHARED_COUNT128];
static SHARED_DATA struct block_hdr rt_shared_block256[HEAP_RUNTIME_SHARED_COUNT256];
static SHARED_DATA struct block_hdr rt_shared_block512[HEAP_RUNTIME_SHARED_COUNT512];
static SHARED_DATA struct block_hdr rt_shared_block1024[HEAP_RUNTIME_SHARED_COUNT1024];
static SHARED_DATA struct block_hdr rt_shared_block64[HEAP_COUNT64 * RT_SHARED_COUNT];
static SHARED_DATA struct block_hdr rt_shared_block128[HEAP_COUNT128 * RT_SHARED_COUNT];
static SHARED_DATA struct block_hdr rt_shared_block256[HEAP_COUNT256 * RT_SHARED_COUNT];
static SHARED_DATA struct block_hdr rt_shared_block512[HEAP_COUNT512 * RT_SHARED_COUNT];
static SHARED_DATA struct block_hdr rt_shared_block1024[HEAP_COUNT1024 * RT_SHARED_COUNT];

/* Heap memory map for runtime shared */
static SHARED_DATA struct block_map rt_shared_heap_map[] = {
BLOCK_DEF(64, HEAP_RUNTIME_SHARED_COUNT64, uncached_block_hdr(rt_shared_block64)),
BLOCK_DEF(128, HEAP_RUNTIME_SHARED_COUNT128, uncached_block_hdr(rt_shared_block128)),
BLOCK_DEF(256, HEAP_RUNTIME_SHARED_COUNT256, uncached_block_hdr(rt_shared_block256)),
BLOCK_DEF(512, HEAP_RUNTIME_SHARED_COUNT512, uncached_block_hdr(rt_shared_block512)),
BLOCK_DEF(1024, HEAP_RUNTIME_SHARED_COUNT1024, uncached_block_hdr(rt_shared_block1024)),
BLOCK_DEF(64, HEAP_COUNT64 * RT_SHARED_COUNT, uncached_block_hdr(rt_shared_block64)),
BLOCK_DEF(128, HEAP_COUNT128 * RT_SHARED_COUNT, uncached_block_hdr(rt_shared_block128)),
BLOCK_DEF(256, HEAP_COUNT256 * RT_SHARED_COUNT, uncached_block_hdr(rt_shared_block256)),
BLOCK_DEF(512, HEAP_COUNT512 * RT_SHARED_COUNT, uncached_block_hdr(rt_shared_block512)),
BLOCK_DEF(1024, HEAP_COUNT1024 * RT_SHARED_COUNT, uncached_block_hdr(rt_shared_block1024)),
};
#endif

Expand All @@ -130,6 +130,8 @@ static SHARED_DATA struct mm memmap;

void platform_init_memmap(struct sof *sof)
{
uint32_t heap_runtime_size = SOF_FW_END - (uint32_t)&_module_heap;
uint32_t rt_count;
int i;

/* access memory map through uncached region */
Expand All @@ -155,6 +157,17 @@ void platform_init_memmap(struct sof *sof)
SOF_MEM_CAPS_EXT | SOF_MEM_CAPS_CACHE |
SOF_MEM_CAPS_DMA;

/* calculate the runtime heap size */
rt_count = heap_runtime_size / HEAP_RUNTIME_UNIT_SIZE;
heap_runtime_size = rt_count * HEAP_RUNTIME_UNIT_SIZE;

for (i = 0; i < ARRAY_SIZE(rt_heap_map); i++) {
rt_heap_map[i].count *= rt_count;
rt_heap_map[i].free_count *= rt_count;
}
dcache_writeback_region(rt_heap_map,
sizeof(struct block_map) * ARRAY_SIZE(rt_heap_map));

/* .system and .system_runtime secondary core initialization */
for (i = 1; i < CONFIG_CORE_COUNT; i++) {
/* .system init */
Expand Down Expand Up @@ -207,8 +220,8 @@ void platform_init_memmap(struct sof *sof)
sof->memory_map->runtime[0].blocks = ARRAY_SIZE(rt_heap_map);
sof->memory_map->runtime[0].map = uncached_block_map(rt_heap_map);
sof->memory_map->runtime[0].heap = (uintptr_t)&_module_heap;
sof->memory_map->runtime[0].size = HEAP_RUNTIME_SIZE;
sof->memory_map->runtime[0].info.free = HEAP_RUNTIME_SIZE;
sof->memory_map->runtime[0].size = heap_runtime_size;
sof->memory_map->runtime[0].info.free = heap_runtime_size;
sof->memory_map->runtime[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT |
SOF_MEM_CAPS_CACHE;

Expand All @@ -232,7 +245,7 @@ void platform_init_memmap(struct sof *sof)

/* .total init */
sof->memory_map->total.free = HEAP_SYSTEM_T_SIZE +
HEAP_SYS_RUNTIME_T_SIZE + HEAP_RUNTIME_SIZE + HEAP_BUFFER_SIZE +
HEAP_SYS_RUNTIME_T_SIZE + heap_runtime_size + HEAP_BUFFER_SIZE +
HEAP_LP_BUFFER_SIZE;

}
Loading