Skip to content
Open
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
20 changes: 18 additions & 2 deletions zephyr/lib/vregion.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct vregion {

/* current allocation mode */
enum vregion_mem_type type; /* LIFETIME at creation, switch to INTERIM */
bool interim_pending; /* vregion_set_interim() called, heap not yet created */

/* interim heap - created lazily on first interim allocation */
struct interim_heap interim; /* interim heap */
Expand Down Expand Up @@ -259,6 +260,7 @@ __cold struct vregion *vregion_create(size_t memsize)

/* start in lifetime allocation mode */
vr->type = VREGION_MEM_TYPE_LIFETIME;
vr->interim_pending = false;

k_mutex_init(&vr->lock);
/* The creator is the first user */
Expand Down Expand Up @@ -495,8 +497,17 @@ void z_impl_vregion_set_interim(struct vregion *vr)

k_mutex_lock(&vr->lock, K_FOREVER);

interim_heap_init(vr);
vregion_tel_sync_locked(vr);
/*
* Only mark the switch here, the interim heap is created on the
* next allocation. The heap metadata is in cached memory, so it
* must be initialized on the core that allocates from it, but this
* is called on the pipeline core, which can differ from the core of
* a DP module in the pipeline.
*/
if (vr->type == VREGION_MEM_TYPE_LIFETIME && !vr->interim_pending)
vr->interim_pending = true;
else
LOG_WRN("vregion %p already in interim mode", (void *)vr);

k_mutex_unlock(&vr->lock);
}
Expand Down Expand Up @@ -645,6 +656,11 @@ void *z_impl_vregion_alloc_align(struct vregion *vr,

k_mutex_lock(&vr->lock, K_FOREVER);

if (vr->interim_pending) {
vr->interim_pending = false;
interim_heap_init(vr);
}

switch (vr->type) {
case VREGION_MEM_TYPE_INTERIM:
p = interim_alloc(&vr->interim, size, alignment);
Expand Down
Loading