Skip to content

Commit bf0615b

Browse files
committed
sp: application: switch memory domains to object pools
A hard-coded memory domain per core was a reasonable starting implementation, but it certainly isn't suitable for the final version. This commit removes per-core domains and allocates them dynamically using the objpool API. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 7287446 commit bf0615b

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

src/include/module/module/base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum module_processing_type {
7575
};
7676

7777
struct userspace_context;
78+
struct k_mem_domain;
7879

7980
/*
8081
* A pointer to this structure is passed to module API functions (from struct module_interface).
@@ -189,6 +190,9 @@ struct processing_module {
189190
#if CONFIG_USERSPACE
190191
struct userspace_context *user_ctx;
191192
#endif /* CONFIG_USERSPACE */
193+
#if CONFIG_SOF_USERSPACE_APPLICATION
194+
struct k_mem_domain *mdom;
195+
#endif
192196
#endif /* SOF_MODULE_PRIVATE */
193197
};
194198

src/schedule/zephyr_dp_schedule.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ int scheduler_dp_init(void)
387387

388388
notifier_register(NULL, NULL, NOTIFIER_ID_LL_POST_RUN, scheduler_dp_ll_tick, 0);
389389

390-
scheduler_dp_domain_init();
391-
392390
return 0;
393391
}
394392

src/schedule/zephyr_dp_schedule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
6060
uint16_t core, size_t stack_size, uint32_t options);
6161
#if CONFIG_SOF_USERSPACE_APPLICATION
6262
void scheduler_dp_domain_free(struct processing_module *pmod);
63-
int scheduler_dp_domain_init(void);
6463
#else
6564
static inline void scheduler_dp_domain_free(struct processing_module *pmod) {}
66-
static inline int scheduler_dp_domain_init(void) {return 0;}
6765
#endif

src/schedule/zephyr_dp_schedule_application.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sof/common.h>
1212
#include <sof/list.h>
1313
#include <sof/llext_manager.h>
14+
#include <sof/objpool.h>
1415
#include <sof/schedule/dp_schedule.h>
1516
#include <sof/schedule/ll_schedule_domain.h>
1617

@@ -27,7 +28,7 @@
2728
LOG_MODULE_DECLARE(dp_schedule, CONFIG_SOF_LOG_LEVEL);
2829
extern struct tr_ctx dp_tr;
2930

30-
static struct k_mem_domain dp_mdom[CONFIG_CORE_COUNT];
31+
static struct objpool_head dp_mdom_head = {.list = LIST_INIT(dp_mdom_head.list)};
3132

3233
/* Synchronization semaphore for the scheduler thread to wait for DP startup */
3334
#define DP_SYNC_INIT(i, _) Z_SEM_INITIALIZER(dp_sync[i], 0, 1)
@@ -384,14 +385,17 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
384385
*/
385386
void scheduler_dp_domain_free(struct processing_module *pmod)
386387
{
387-
unsigned int core = pmod->dev->task->core;
388+
struct k_mem_domain *mdom = pmod->mdom;
388389

389-
llext_manager_rm_domain(pmod->dev->ipc_config.id, dp_mdom + core);
390+
llext_manager_rm_domain(pmod->dev->ipc_config.id, mdom);
390391

391392
struct task_dp_pdata *pdata = pmod->dev->task->priv_data;
392393

393-
k_mem_domain_remove_partition(dp_mdom + core, pdata->mpart + SOF_DP_PART_HEAP);
394-
k_mem_domain_remove_partition(dp_mdom + core, pdata->mpart + SOF_DP_PART_CFG);
394+
k_mem_domain_remove_partition(mdom, pdata->mpart + SOF_DP_PART_HEAP);
395+
k_mem_domain_remove_partition(mdom, pdata->mpart + SOF_DP_PART_CFG);
396+
397+
pmod->mdom = NULL;
398+
objpool_free(&dp_mdom_head, mdom);
395399
}
396400

397401
/* Called only in IPC context */
@@ -497,6 +501,19 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
497501
unsigned int pidx;
498502
size_t size;
499503
uintptr_t start;
504+
struct k_mem_domain *mdom = objpool_alloc(&dp_mdom_head, sizeof(*mdom),
505+
SOF_MEM_FLAG_COHERENT);
506+
507+
if (!mdom)
508+
goto e_thread;
509+
510+
if (!mdom->arch.ptables) {
511+
ret = k_mem_domain_init(mdom, 0, NULL);
512+
if (ret < 0)
513+
goto e_dom;
514+
}
515+
516+
mod->mdom = mdom;
500517

501518
/* Module heap partition */
502519
mod_heap_info(mod, &size, &start);
@@ -513,12 +530,12 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
513530
};
514531

515532
for (pidx = 0; pidx < SOF_DP_PART_TYPE_COUNT; pidx++) {
516-
ret = k_mem_domain_add_partition(dp_mdom + core, pdata->mpart + pidx);
533+
ret = k_mem_domain_add_partition(mdom, pdata->mpart + pidx);
517534
if (ret < 0)
518535
goto e_dom;
519536
}
520537

521-
ret = llext_manager_add_domain(mod->dev->ipc_config.id, dp_mdom + core);
538+
ret = llext_manager_add_domain(mod->dev->ipc_config.id, mdom);
522539
if (ret < 0) {
523540
tr_err(&dp_tr, "failed to add LLEXT to domain %d", ret);
524541
goto e_dom;
@@ -528,7 +545,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
528545
* Keep this call last, able to fail, otherwise domain will be removed
529546
* before its thread
530547
*/
531-
ret = k_mem_domain_add_thread(dp_mdom + core, pdata->thread_id);
548+
ret = k_mem_domain_add_thread(mdom, pdata->thread_id);
532549
if (ret < 0) {
533550
tr_err(&dp_tr, "failed to add thread to domain %d", ret);
534551
goto e_dom;
@@ -542,6 +559,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
542559

543560
e_dom:
544561
scheduler_dp_domain_free(mod);
562+
objpool_free(&dp_mdom_head, mdom);
545563
e_thread:
546564
k_thread_abort(pdata->thread_id);
547565
e_kobj:
@@ -554,8 +572,3 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
554572
mod_free(mod, task_memory);
555573
return ret;
556574
}
557-
558-
int scheduler_dp_domain_init(void)
559-
{
560-
return k_mem_domain_init(dp_mdom + cpu_get_id(), 0, NULL);
561-
}

0 commit comments

Comments
 (0)