Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/audio/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct comp_buffer *buffer_new(struct sof_ipc_buffer *desc)
return NULL;
}

buffer->addr = rballoc(RZONE_BUFFER, desc->caps, desc->size);
buffer->addr = rmalloc(RZONE_BUFFER, desc->caps, desc->size);
if (!buffer->addr) {
rfree(buffer);
trace_buffer_error("buffer_new() error: "
Expand Down
2 changes: 1 addition & 1 deletion src/audio/detect_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static int alloc_mem_load(struct comp_data *cd, uint32_t size)
if (!size)
return 0;

cd->load_memory = rballoc(RZONE_BUFFER, SOF_MEM_CAPS_RAM, size);
cd->load_memory = rmalloc(RZONE_BUFFER, SOF_MEM_CAPS_RAM, size);

if (!cd->load_memory) {
trace_keyword_error("alloc_mem_load() alloc failed");
Expand Down
6 changes: 3 additions & 3 deletions src/audio/eq_fir.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static int eq_fir_setup(struct comp_data *cd, int nch)
return 0;

/* Allocate all FIR channels data in a big chunk and clear it */
cd->fir_delay = rballoc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, size_sum);
cd->fir_delay = rmalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, size_sum);
if (!cd->fir_delay) {
trace_eq_error("eq_fir_setup() error: alloc failed, size = %u",
size_sum);
Expand Down Expand Up @@ -434,7 +434,7 @@ static struct comp_dev *eq_fir_new(struct sof_ipc_comp *comp)
* the EQ is configured later in run-time the size is zero.
*/
if (bs) {
cd->config = rballoc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, bs);
cd->config = rmalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, bs);
if (!cd->config) {
rfree(dev);
rfree(cd);
Expand Down Expand Up @@ -598,7 +598,7 @@ static int fir_cmd_set_data(struct comp_dev *dev,
eq_fir_free_parameters(&cd->config);

/* Allocate buffer for copy of the blob. */
cd->config = rballoc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM,
cd->config = rmalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM,
cdata->num_elems +
cdata->elems_remaining);

Expand Down
2 changes: 1 addition & 1 deletion src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static size_t kpb_allocate_history_buffer(struct comp_data *kpb)
/* Try to allocate ca_size (current allocation size). At first
* attempt it will be equal to hb_size (history buffer size).
*/
new_mem_block = rballoc(RZONE_RUNTIME, hb_mcp[i], ca_size);
new_mem_block = rmalloc(RZONE_RUNTIME, hb_mcp[i], ca_size);

if (new_mem_block) {
/* We managed to allocate a block of ca_size.
Expand Down
2 changes: 1 addition & 1 deletion src/audio/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ static int src_params(struct comp_dev *dev)
if (cd->delay_lines)
rfree(cd->delay_lines);

cd->delay_lines = rballoc(RZONE_BUFFER, SOF_MEM_CAPS_RAM,
cd->delay_lines = rmalloc(RZONE_BUFFER, SOF_MEM_CAPS_RAM,
delay_lines_size);
if (!cd->delay_lines) {
trace_src_error("src_params() error: "
Expand Down
5 changes: 0 additions & 5 deletions src/host/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ void rfree(void *ptr)
free(ptr);
}

void *rballoc(int zone, uint32_t caps, size_t bytes)
{
return malloc(bytes);
}

void heap_trace(struct mm_heap *heap, int size)
{
malloc_info(0, stdout);
Expand Down
18 changes: 0 additions & 18 deletions src/include/sof/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ void *_balloc(int zone, uint32_t caps, size_t bytes);
void rfree(void *ptr);

#if CONFIG_DEBUG_HEAP

#define rmalloc(zone, caps, bytes) \
({void *_ptr; \
do { \
Expand All @@ -157,28 +156,11 @@ void rfree(void *ptr);
} while (0); \
_ptr; })

#define rballoc(zone, caps, bytes) \
({void *_ptr; \
do { \
_ptr = _balloc(zone, caps, bytes); \
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); \
} \
} while (0); \
_ptr; })

void alloc_trace_runtime_heap(int zone, uint32_t caps, size_t bytes);
void alloc_trace_buffer_heap(int zone, uint32_t caps, size_t bytes);

#else

#define rmalloc(zone, caps, bytes) _malloc(zone, caps, bytes)
#define rzalloc(zone, caps, bytes) _zalloc(zone, caps, bytes)
#define rballoc(zone, caps, bytes) _balloc(zone, caps, bytes)
Comment thread
lgirdwood marked this conversation as resolved.
Resolved

#endif

/* system heap allocation for specific core */
Expand Down
39 changes: 34 additions & 5 deletions src/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are unlocking before another try to alloc.
It can possibly create race condition.


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;
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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() */
Comment thread
lgirdwood marked this conversation as resolved.
Resolved
void *_balloc(int zone, uint32_t caps, size_t bytes)
{
struct mm_heap *heap;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dma-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static int dma_trace_buffer_init(struct dma_trace_data *d)
struct dma_trace_buf *buffer = &d->dmatb;

/* allocate new buffer */
buffer->addr = rballoc(RZONE_BUFFER,
buffer->addr = rmalloc(RZONE_BUFFER,
SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA,
DMA_TRACE_LOCAL_SIZE);
if (!buffer->addr) {
Expand Down
52 changes: 28 additions & 24 deletions src/platform/apollolake/include/platform/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) * \
Expand All @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 16 additions & 11 deletions src/platform/baytrail/include/platform/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you making block 256 count smaller ?

@RanderWang RanderWang Mar 25, 2019 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 ?

841     heap: runtime status
815      heap: 0xff317080 size 17664 blocks 8 caps 0x61
817       used 8704 free 8960
825       block 1 base 0xff317380 size 32
828        count 48 free 48
825       block 2 base 0xff317980 size 64
828        count 32 free 32
825       block 3 base 0xff318180 size 128
828        count 16 free 3 
825       block 4 base 0xff318980 size 192
828        count 16 free 5 
825       block 5 base 0xff319580 size 256
828        count 24 free 8 
825       block 6 base 0xff31ad80 size 320
828        count 2 free 1  
825       block 7 base 0xff31b280 size 384
828        count 2 free 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood we have got agreement at this 4 days ago, right ?

 lgirdwood 4 days ago Member

Why are you adding 384 when it's the buffer block size ?
@RanderWang
RanderWang 4 days ago •
Author Member

Now the algorithm is:

   if (size >= 384)
        ptr =  rballoc
   else
        ptr = _malloc

    if (!ptr)
        ptr = rballoc

Without 384 block, for the allocation 256 < size < 384, it can't be supported by _malloc but wastes
 cpu time in _malloc. So I add this to fix it
@lgirdwood
lgirdwood 4 days ago Member

There is opportunity now (since we have save memory by deleting 512 and 1024 blocks) to add 
more step sizes here. You could also add 320 block size. It does need a macro though for your 
largest block size before rballoc blocks for the logic statement above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

@RanderWang RanderWang Mar 27, 2019 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is there is a gap between 320 and 384

---------------                        -----------------------
               320                     384

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

#define HEAP_RT_LP_COUNT384		4

and catch all allocations above the largest block size (in this case 320) to us the buffer heap.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
Expand All @@ -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 \
Expand All @@ -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
Expand Down
Loading