Skip to content

Commit 629358c

Browse files
authored
Merge pull request #460 from tlauda/topic/smp-sys-alloc
alloc: change way of allocation core context for slave cores
2 parents d467268 + b561eb8 commit 629358c

8 files changed

Lines changed: 40 additions & 39 deletions

File tree

src/arch/xtensa/smp/cpu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,11 @@ void cpu_power_down_core(void)
107107

108108
free_system_workq();
109109

110-
free_core_context(arch_cpu_get_id());
111-
112-
dcache_writeback_invalidate_all();
113-
114110
/* free entire sys heap, an instance dedicated for this core */
115111
free_heap(RZONE_SYS);
116112

113+
dcache_writeback_invalidate_all();
114+
117115
/* arch_wait_for_interrupt() not used, because it will cause panic.
118116
* This code is executed on irq lvl > 0, which is expected.
119117
* Core will be put into reset by host anyway.

src/arch/xtensa/smp/include/arch/alloc.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,11 @@ static inline void alloc_core_context(int core)
5151
{
5252
struct core_context *core_ctx;
5353

54-
core_ctx = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(*core_ctx));
54+
core_ctx = rzalloc_core_sys(core, sizeof(*core_ctx));
5555
dcache_writeback_invalidate_region(core_ctx, sizeof(*core_ctx));
5656

57-
/* xtos_core_data is a big struct, so allocate it from system heap
58-
* and never free again. Allocating from runtime heap would be
59-
* a waste of a very big memory block.
60-
*/
61-
if (!core_data_ptr[core])
62-
core_data_ptr[core] = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM,
63-
sizeof(*core_data_ptr[core]));
64-
57+
core_data_ptr[core] = rzalloc_core_sys(core,
58+
sizeof(*core_data_ptr[core]));
6559
core_data_ptr[core]->thread_data_ptr = &core_ctx->td;
6660
dcache_writeback_invalidate_region(core_data_ptr[core],
6761
sizeof(*core_data_ptr[core]));
@@ -77,14 +71,4 @@ static inline void alloc_core_context(int core)
7771
dcache_writeback_region((void *)SOF_BSS_DATA_START, SOF_BSS_DATA_SIZE);
7872
}
7973

80-
/**
81-
* \brief Frees memory allocated for core specific data.
82-
* \param[in] core Slave core for which data needs to be freed.
83-
*/
84-
static inline void free_core_context(int core)
85-
{
86-
dcache_writeback_invalidate_region(core_ctx_ptr[core],
87-
sizeof(*core_ctx_ptr[core]));
88-
}
89-
9074
#endif

src/include/sof/alloc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ void rfree(void *ptr);
122122
/* heap allocation and free for buffers on 1k boundary */
123123
void *rballoc(int zone, uint32_t flags, size_t bytes);
124124

125+
/* system heap allocation for specific core */
126+
void *rzalloc_core_sys(int core, size_t bytes);
127+
125128
/* utility */
126129
void bzero(void *s, size_t n);
127130
void *memset(void *s, int c, size_t n);

src/lib/alloc.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ static void alloc_memset_region(void *ptr, uint32_t bytes, uint32_t val)
111111
#endif
112112

113113
/* allocate from system memory pool */
114-
static void *rmalloc_sys(int zone, size_t bytes)
114+
static void *rmalloc_sys(int zone, int core, size_t bytes)
115115
{
116116
void *ptr;
117117
struct mm_heap *cpu_heap;
118118
size_t alignment = 0;
119119

120-
/* use the heap dedicated for the current core */
121-
cpu_heap = memmap.system + cpu_get_id();
120+
/* use the heap dedicated for the selected core */
121+
cpu_heap = cache_to_uncache(memmap.system + core);
122122

123123
/* align address to dcache line size */
124124
if (cpu_heap->info.used % PLATFORM_DCACHE_ALIGN)
@@ -434,7 +434,7 @@ void *rmalloc(int zone, uint32_t caps, size_t bytes)
434434

435435
switch (zone & RZONE_TYPE_MASK) {
436436
case RZONE_SYS:
437-
ptr = rmalloc_sys(zone, bytes);
437+
ptr = rmalloc_sys(zone, cpu_get_id(), bytes);
438438
break;
439439
case RZONE_RUNTIME:
440440
ptr = rmalloc_runtime(zone, caps, bytes);
@@ -460,6 +460,22 @@ void *rzalloc(int zone, uint32_t caps, size_t bytes)
460460
return ptr;
461461
}
462462

463+
void *rzalloc_core_sys(int core, size_t bytes)
464+
{
465+
uint32_t flags;
466+
void *ptr = NULL;
467+
468+
spin_lock_irq(&memmap.lock, flags);
469+
470+
ptr = rmalloc_sys(RZONE_SYS, core, bytes);
471+
if (ptr)
472+
bzero(ptr, bytes);
473+
474+
spin_unlock_irq(&memmap.lock, flags);
475+
476+
return ptr;
477+
}
478+
463479
/* allocates continuous buffers */
464480
void *rballoc(int zone, uint32_t caps, size_t bytes)
465481
{
@@ -567,7 +583,7 @@ void free_heap(int zone)
567583
panic(SOF_IPC_PANIC_MEM);
568584
}
569585

570-
cpu_heap = memmap.system + cpu_get_id();
586+
cpu_heap = cache_to_uncache(memmap.system + cpu_get_id());
571587
cpu_heap->info.used = 0;
572588
cpu_heap->info.free = cpu_heap->size;
573589
}

src/platform/apollolake/include/platform/memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@
143143
#define HEAP_SYSTEM_0_BASE \
144144
(SOF_TEXT_BASE + SOF_TEXT_SIZE +\
145145
SOF_DATA_SIZE + SOF_BSS_DATA_SIZE)
146-
#define HEAP_SYSTEM_0_SIZE 0xe000
146+
#define HEAP_SYSTEM_0_SIZE 0x8000
147147

148148
#define HEAP_SYSTEM_1_BASE (HEAP_SYSTEM_0_BASE + HEAP_SYSTEM_0_SIZE)
149-
#define HEAP_SYSTEM_1_SIZE 0x1000
149+
#define HEAP_SYSTEM_1_SIZE 0x5000
150150

151151
#define HEAP_SYSTEM_T_SIZE (HEAP_SYSTEM_0_SIZE + HEAP_SYSTEM_1_SIZE)
152152

src/platform/cannonlake/include/platform/memory.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,16 @@
248248
#define HEAP_SYSTEM_0_BASE (SOF_TEXT_BASE + SOF_TEXT_SIZE + \
249249
SOF_DATA_SIZE + SOF_BSS_DATA_SIZE)
250250

251-
#define HEAP_SYSTEM_0_SIZE 0xe000
251+
#define HEAP_SYSTEM_0_SIZE 0x8000
252252

253253
#define HEAP_SYSTEM_1_BASE (HEAP_SYSTEM_0_BASE + HEAP_SYSTEM_0_SIZE)
254-
#define HEAP_SYSTEM_1_SIZE 0x1000
254+
#define HEAP_SYSTEM_1_SIZE 0x5000
255255

256256
#define HEAP_SYSTEM_2_BASE (HEAP_SYSTEM_1_BASE + HEAP_SYSTEM_1_SIZE)
257-
#define HEAP_SYSTEM_2_SIZE 0x1000
257+
#define HEAP_SYSTEM_2_SIZE 0x5000
258258

259259
#define HEAP_SYSTEM_3_BASE (HEAP_SYSTEM_2_BASE + HEAP_SYSTEM_2_SIZE)
260-
#define HEAP_SYSTEM_3_SIZE 0x1000
260+
#define HEAP_SYSTEM_3_SIZE 0x5000
261261

262262
#define HEAP_SYSTEM_T_SIZE (HEAP_SYSTEM_0_SIZE + HEAP_SYSTEM_1_SIZE + \
263263
HEAP_SYSTEM_2_SIZE + HEAP_SYSTEM_3_SIZE)

src/platform/icelake/include/platform/memory.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,16 @@
248248
#define HEAP_SYSTEM_0_BASE (SOF_TEXT_BASE + SOF_TEXT_SIZE + \
249249
SOF_DATA_SIZE + SOF_BSS_DATA_SIZE)
250250

251-
#define HEAP_SYSTEM_0_SIZE 0xe000
251+
#define HEAP_SYSTEM_0_SIZE 0x8000
252252

253253
#define HEAP_SYSTEM_1_BASE (HEAP_SYSTEM_0_BASE + HEAP_SYSTEM_0_SIZE)
254-
#define HEAP_SYSTEM_1_SIZE 0x1000
254+
#define HEAP_SYSTEM_1_SIZE 0x5000
255255

256256
#define HEAP_SYSTEM_2_BASE (HEAP_SYSTEM_1_BASE + HEAP_SYSTEM_1_SIZE)
257-
#define HEAP_SYSTEM_2_SIZE 0x1000
257+
#define HEAP_SYSTEM_2_SIZE 0x5000
258258

259259
#define HEAP_SYSTEM_3_BASE (HEAP_SYSTEM_2_BASE + HEAP_SYSTEM_2_SIZE)
260-
#define HEAP_SYSTEM_3_SIZE 0x1000
260+
#define HEAP_SYSTEM_3_SIZE 0x5000
261261

262262
#define HEAP_SYSTEM_T_SIZE (HEAP_SYSTEM_0_SIZE + HEAP_SYSTEM_1_SIZE + \
263263
HEAP_SYSTEM_2_SIZE + HEAP_SYSTEM_3_SIZE)

src/platform/suecreek/include/platform/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
#define HEAP_SYSTEM_0_SIZE 0x8000
214214

215215
#define HEAP_SYSTEM_1_BASE (HEAP_SYSTEM_0_BASE + HEAP_SYSTEM_0_SIZE)
216-
#define HEAP_SYSTEM_1_SIZE 0x1000
216+
#define HEAP_SYSTEM_1_SIZE 0x5000
217217

218218
#define HEAP_SYSTEM_T_SIZE (HEAP_SYSTEM_0_SIZE + HEAP_SYSTEM_1_SIZE)
219219

0 commit comments

Comments
 (0)