alloc: xtos: remove xtos memory zones. by lgirdwood · Pull Request #10088 · thesofproject/sof · GitHub
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
61 changes: 19 additions & 42 deletions posix/include/rtos/alloc.h
2 changes: 1 addition & 1 deletion posix/include/sof/lib/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static inline void dma_sg_init(struct dma_sg_elem_array *ea)
}

int dma_sg_alloc(struct dma_sg_elem_array *ea,
enum mem_zone zone,
uint32_t flags,
uint32_t direction,
uint32_t buffer_count, uint32_t buffer_bytes,
uintptr_t dma_buffer_addr, uintptr_t external_addr);
Expand Down
4 changes: 2 additions & 2 deletions posix/include/sof/lib/mm_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ uint32_t mm_pm_context_size(void);
void init_heap(struct sof *sof);

/* frees entire heap (supported for secondary core system heap atm) */
void free_heap(enum mem_zone zone);
void free_heap(void);

/* status */
void heap_trace_all(int force);
Expand All @@ -101,7 +101,7 @@ void heap_trace(struct mm_heap *heap, int size);
* @param out output variable
* @return error code or zero
*/
int heap_info(enum mem_zone zone, int index, struct mm_info *out);
int heap_info(int index, struct mm_info *out);
#endif

/* retrieve memory map pointer */
Expand Down
4 changes: 2 additions & 2 deletions src/audio/aria/aria.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static int aria_init(struct processing_module *mod)
list_init(&dev->bsource_list);
list_init(&dev->bsink_list);

cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd));
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
if (!cd) {
return -ENOMEM;
}
Expand All @@ -145,7 +145,7 @@ static int aria_init(struct processing_module *mod)
}
mod_data->private = cd;

buf = rballoc(0, SOF_MEM_CAPS_RAM, req_mem);
buf = rballoc(SOF_MEM_FLAG_USER, req_mem);

if (!buf) {
rfree(cd);
Expand Down
10 changes: 5 additions & 5 deletions src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static int asrc_init(struct processing_module *mod)
return -EINVAL;
}

cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd));
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
if (!cd)
return -ENOMEM;

Expand Down Expand Up @@ -261,7 +261,7 @@ static int asrc_initialize_buffers(struct asrc_farrow *src_obj)
buffer_size = src_obj->buffer_length * sizeof(int32_t);

for (ch = 0; ch < src_obj->num_channels; ch++) {
buf_32 = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, buffer_size);
buf_32 = rzalloc(SOF_MEM_FLAG_USER, buffer_size);

if (!buf_32)
return -ENOMEM;
Expand All @@ -272,7 +272,7 @@ static int asrc_initialize_buffers(struct asrc_farrow *src_obj)
buffer_size = src_obj->buffer_length * sizeof(int16_t);

for (ch = 0; ch < src_obj->num_channels; ch++) {
buf_16 = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, buffer_size);
buf_16 = rzalloc(SOF_MEM_FLAG_USER, buffer_size);

if (!buf_16)
return -ENOMEM;
Expand Down Expand Up @@ -614,7 +614,7 @@ static int asrc_prepare(struct processing_module *mod,
cd->buf_size = (cd->source_frames_max + cd->sink_frames_max) *
frame_bytes;

cd->buf = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
cd->buf = rzalloc(SOF_MEM_FLAG_USER,
cd->buf_size);
if (!cd->buf) {
cd->buf_size = 0;
Expand All @@ -640,7 +640,7 @@ static int asrc_prepare(struct processing_module *mod,
goto err_free_buf;
}

cd->asrc_obj = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
cd->asrc_obj = rzalloc(SOF_MEM_FLAG_USER,
cd->asrc_size);
if (!cd->asrc_obj) {
comp_err(dev, "asrc_prepare(), allocation fail for size %d",
Expand Down
6 changes: 5 additions & 1 deletion src/audio/base_fw_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ __cold static int basefw_mem_state_info(uint32_t *data_offset, char *data)
info.page_alloc_struct.page_alloc_count * sizeof(uint32_t);
size = ALIGN(size, 4);
/* size is also saved as tuple length */
tuple_data = rballoc(0, SOF_MEM_CAPS_RAM, size);
tuple_data = rballoc(SOF_MEM_FLAG_USER, size);
if (!tuple_data) {
LOG_ERR("basefw_mem_state_info(): allocation failed");
return IPC4_ERROR_INVALID_PARAM;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think there's an IPC4 error for "out of memory"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I initially thought that too, but no.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@lgirdwood IPC4_OUT_OF_MEMORY

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@lgirdwood should we update this one while fixing rfree()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll followup in another PR - I want to change it to IPC4_ERROR_ prefix, this was why it was not grep-able

}

/* save memory info in data array since info length is variable */
index = 0;
Expand Down
54 changes: 28 additions & 26 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,24 +181,25 @@ static const struct audio_buffer_ops audio_buffer_ops = {
.set_alignment_constants = comp_buffer_set_alignment_constants
};

static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, uint32_t caps,
static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size,
uint32_t flags, bool is_shared)
{
struct comp_buffer *buffer;

tr_dbg(&buffer_tr, "buffer_alloc_struct()");

/* allocate new buffer */
enum mem_zone zone = is_shared ? SOF_MEM_ZONE_RUNTIME_SHARED : SOF_MEM_ZONE_RUNTIME;
/* allocate new buffer, but add coherent if shared with other cores */
if (is_shared)
flags |= SOF_MEM_FLAG_COHERENT;

buffer = rzalloc(zone, 0, SOF_MEM_CAPS_RAM, sizeof(*buffer));
buffer = rzalloc(flags, sizeof(*buffer));

if (!buffer) {
tr_err(&buffer_tr, "buffer_alloc_struct(): could not alloc structure");
return NULL;
}

buffer->caps = caps;
buffer->flags = flags;
/* Force channels to 2 for init to prevent bad call to clz in buffer_init_stream */
buffer->stream.runtime_stream_params.channels = 2;

Expand All @@ -219,7 +220,7 @@ static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, u
return buffer;
}

struct comp_buffer *buffer_alloc(size_t size, uint32_t caps, uint32_t flags, uint32_t align,
struct comp_buffer *buffer_alloc(size_t size, uint32_t flags, uint32_t align,
bool is_shared)
{
struct comp_buffer *buffer;
Expand All @@ -233,14 +234,14 @@ struct comp_buffer *buffer_alloc(size_t size, uint32_t caps, uint32_t flags, uin
return NULL;
}

stream_addr = rballoc_align(0, caps, size, align);
stream_addr = rballoc_align(flags, size, align);
if (!stream_addr) {
tr_err(&buffer_tr, "buffer_alloc(): could not alloc size = %zu bytes of type = %u",
size, caps);
tr_err(&buffer_tr, "buffer_alloc(): could not alloc size = %zu bytes of flags = 0x%x",
size, flags);
return NULL;
}

buffer = buffer_alloc_struct(stream_addr, size, caps, flags, is_shared);
buffer = buffer_alloc_struct(stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "buffer_alloc(): could not alloc buffer structure");
rfree(stream_addr);
Expand All @@ -249,7 +250,7 @@ struct comp_buffer *buffer_alloc(size_t size, uint32_t caps, uint32_t flags, uin
return buffer;
}

struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size, uint32_t caps,
struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size,
uint32_t flags, uint32_t align, bool is_shared)
{
struct comp_buffer *buffer;
Expand All @@ -270,20 +271,20 @@ struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_siz
preferred_size += minimum_size - preferred_size % minimum_size;

for (size = preferred_size; size >= minimum_size; size -= minimum_size) {
stream_addr = rballoc_align(0, caps, size, align);
stream_addr = rballoc_align(flags, size, align);
if (stream_addr)
break;
}

tr_dbg(&buffer_tr, "buffer_alloc_range(): allocated %zu bytes", size);

if (!stream_addr) {
tr_err(&buffer_tr, "buffer_alloc_range(): could not alloc size = %zu bytes of type = %u",
minimum_size, caps);
tr_err(&buffer_tr, "buffer_alloc_range(): could not alloc size = %zu bytes of type = 0x%x",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

'bytes of flags'

minimum_size, flags);
return NULL;
}

buffer = buffer_alloc_struct(stream_addr, size, caps, flags, is_shared);
buffer = buffer_alloc_struct(stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "buffer_alloc_range(): could not alloc buffer structure");
rfree(stream_addr);
Expand All @@ -298,7 +299,7 @@ void buffer_zero(struct comp_buffer *buffer)
CORE_CHECK_STRUCT(&buffer->audio_buffer);

bzero(audio_stream_get_addr(&buffer->stream), audio_stream_get_size(&buffer->stream));
if (buffer->caps & SOF_MEM_CAPS_DMA)
if (buffer->flags & SOF_MEM_FLAG_DMA)
dcache_writeback_region((__sparse_force void __sparse_cache *)
audio_stream_get_addr(&buffer->stream),
audio_stream_get_size(&buffer->stream));
Expand All @@ -320,16 +321,17 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
return 0;

if (!alignment)
new_ptr = rbrealloc(audio_stream_get_addr(&buffer->stream), SOF_MEM_FLAG_NO_COPY,
buffer->caps, size, audio_stream_get_size(&buffer->stream));
new_ptr = rbrealloc(audio_stream_get_addr(&buffer->stream),
buffer->flags | SOF_MEM_FLAG_NO_COPY,
size, audio_stream_get_size(&buffer->stream));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

need buffer->flags or buffer->dma

else
new_ptr = rbrealloc_align(audio_stream_get_addr(&buffer->stream),
SOF_MEM_FLAG_NO_COPY, buffer->caps, size,
buffer->flags | SOF_MEM_FLAG_NO_COPY, size,
audio_stream_get_size(&buffer->stream), alignment);
/* we couldn't allocate bigger chunk */
if (!new_ptr && size > audio_stream_get_size(&buffer->stream)) {
buf_err(buffer, "resize can't alloc %u bytes type %u",
audio_stream_get_size(&buffer->stream), buffer->caps);
buf_err(buffer, "resize can't alloc %u bytes type 0x%x",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

'bytes of flags'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed all of these in a new PR.

audio_stream_get_size(&buffer->stream), buffer->flags);
return -ENOMEM;
}

Expand Down Expand Up @@ -369,24 +371,24 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
if (!alignment) {
for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
new_ptr = rbrealloc(ptr, SOF_MEM_FLAG_NO_COPY, buffer->caps, new_size,
actual_size);
new_ptr = rbrealloc(ptr, buffer->flags | SOF_MEM_FLAG_NO_COPY,
new_size, actual_size);
if (new_ptr)
break;
}
} else {
for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
new_ptr = rbrealloc_align(ptr, SOF_MEM_FLAG_NO_COPY, buffer->caps, new_size,
actual_size, alignment);
new_ptr = rbrealloc_align(ptr, buffer->flags | SOF_MEM_FLAG_NO_COPY,
new_size, actual_size, alignment);
if (new_ptr)
break;
}
}

/* we couldn't allocate bigger chunk */
if (!new_ptr && new_size > actual_size) {
buf_err(buffer, "resize can't alloc %zu bytes type %u", new_size, buffer->caps);
buf_err(buffer, "resize can't alloc %zu bytes type 0x%x", new_size, buffer->flags);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

'bytes of flags'

return -ENOMEM;
}

Expand Down
7 changes: 3 additions & 4 deletions src/audio/buffers/ring_buffer.c
Loading
Loading