Skip to content

Commit eef2044

Browse files
authored
Merge pull request #64 from tlauda/topic/multicore_alloc
alloc: share memory map with slave cores
2 parents c07ba31 + bb75204 commit eef2044

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/lib/alloc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ static void *rmalloc_sys(size_t bytes)
117117
alloc_memset_region(ptr, bytes, DEBUG_BLOCK_ALLOC_VALUE);
118118
#endif
119119

120+
dcache_writeback_invalidate_region(&memmap.system,
121+
sizeof(memmap.system));
122+
120123
return ptr;
121124
}
122125

@@ -135,6 +138,7 @@ static void *alloc_block(struct mm_heap *heap, int level,
135138
hdr->used = 1;
136139
heap->info.used += map->block_size;
137140
heap->info.free -= map->block_size;
141+
dcache_writeback_invalidate_region(hdr, sizeof(*hdr));
138142

139143
/* find next free */
140144
for (i = map->first_free; i < map->count; ++i) {
@@ -151,6 +155,9 @@ static void *alloc_block(struct mm_heap *heap, int level,
151155
alloc_memset_region(ptr, map->block_size, DEBUG_BLOCK_ALLOC_VALUE);
152156
#endif
153157

158+
dcache_writeback_invalidate_region(map, sizeof(*map));
159+
dcache_writeback_invalidate_region(heap, sizeof(*heap));
160+
154161
return ptr;
155162
}
156163

@@ -201,11 +208,13 @@ static void *alloc_cont_blocks(struct mm_heap *heap, int level,
201208
hdr->size = count;
202209
heap->info.used += count * map->block_size;
203210
heap->info.free -= count * map->block_size;
211+
dcache_writeback_invalidate_region(hdr, sizeof(*hdr));
204212

205213
/* allocate each block */
206214
for (current = start; current < end; current++) {
207215
hdr = &map->block[current];
208216
hdr->used = 1;
217+
dcache_writeback_invalidate_region(hdr, sizeof(*hdr));
209218
}
210219

211220
/* do we need to find a new first free block ? */
@@ -227,6 +236,9 @@ static void *alloc_cont_blocks(struct mm_heap *heap, int level,
227236
alloc_memset_region(ptr, bytes, DEBUG_BLOCK_ALLOC_VALUE);
228237
#endif
229238

239+
dcache_writeback_invalidate_region(map, sizeof(*map));
240+
dcache_writeback_invalidate_region(heap, sizeof(*heap));
241+
230242
return ptr;
231243
}
232244

@@ -334,6 +346,7 @@ static void free_block(void *ptr)
334346
block_map->free_count++;
335347
heap->info.used -= block_map->block_size;
336348
heap->info.free += block_map->block_size;
349+
dcache_writeback_invalidate_region(hdr, sizeof(*hdr));
337350
}
338351

339352
/* set first free block */
@@ -343,6 +356,9 @@ static void free_block(void *ptr)
343356
#if DEBUG_BLOCK_FREE
344357
alloc_memset_region(ptr, block_map->block_size * (i - 1), DEBUG_BLOCK_FREE_VALUE);
345358
#endif
359+
360+
dcache_writeback_invalidate_region(block_map, sizeof(*block_map));
361+
dcache_writeback_invalidate_region(heap, sizeof(*heap));
346362
}
347363

348364
/* allocate single block for runtime */
@@ -612,13 +628,17 @@ void init_heap(struct sof *sof)
612628

613629
current_map = &heap->map[j];
614630
current_map->base = heap->heap;
631+
dcache_writeback_region(current_map,
632+
sizeof(*current_map));
615633

616634
for (k = 1; k < heap->blocks; k++) {
617635
next_map = &heap->map[k];
618636
next_map->base = current_map->base +
619637
current_map->block_size *
620638
current_map->count;
621639
current_map = &heap->map[k];
640+
dcache_writeback_region(current_map,
641+
sizeof(*current_map));
622642
}
623643
}
624644
}
@@ -631,13 +651,17 @@ void init_heap(struct sof *sof)
631651

632652
current_map = &heap->map[j];
633653
current_map->base = heap->heap;
654+
dcache_writeback_region(current_map,
655+
sizeof(*current_map));
634656

635657
for (k = 1; k < heap->blocks; k++) {
636658
next_map = &heap->map[k];
637659
next_map->base = current_map->base +
638660
current_map->block_size *
639661
current_map->count;
640662
current_map = &heap->map[k];
663+
dcache_writeback_region(current_map,
664+
sizeof(*current_map));
641665
}
642666
}
643667
}

0 commit comments

Comments
 (0)