Skip to content

Commit 6590ef5

Browse files
committed
schedule: limit schedule_free() to testing only
schedule_free() is only called from testbench and stand-alone ztest. Remove it and all scheduler .scheduler_free() methods for all other builds. Also fix memory leaks in the Zephyr LL version. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent ad647b3 commit 6590ef5

5 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/include/sof/schedule/schedule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct scheduler_ops {
140140
*/
141141
int (*schedule_task_free)(void *data, struct task *task);
142142

143+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
143144
/**
144145
* Frees scheduler's resources.
145146
* @param data Private data of selected scheduler.
@@ -149,6 +150,7 @@ struct scheduler_ops {
149150
* This operation is optional.
150151
*/
151152
void (*scheduler_free)(void *data, uint32_t flags);
153+
#endif
152154

153155
/**
154156
* Initializes context
@@ -309,6 +311,8 @@ static inline int schedule_task_free(struct task *task)
309311
return sch->ops->schedule_task_free(sch->data, task);
310312
}
311313

314+
/* Only used in a stand-alone test and in a testbench test */
315+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
312316
/** See scheduler_ops::scheduler_free */
313317
static inline void schedule_free(uint32_t flags)
314318
{
@@ -322,6 +326,7 @@ static inline void schedule_free(uint32_t flags)
322326
sch->ops->scheduler_free(sch->data, flags);
323327
}
324328
}
329+
#endif
325330

326331
/** See scheduler_ops::scheduler_init_context */
327332
static inline struct k_thread *scheduler_init_context(struct task *task)

src/platform/library/schedule/edf_schedule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ static int schedule_edf_task(void *data, struct task *task, uint64_t start,
4949
return 0;
5050
}
5151

52+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
5253
static void edf_scheduler_free(void *data, uint32_t flags)
5354
{
5455
free(data);
5556
}
57+
#endif
5658

5759
static int schedule_edf_task_cancel(void *data, struct task *task)
5860
{
@@ -83,7 +85,9 @@ static struct scheduler_ops schedule_edf_ops = {
8385
.reschedule_task = NULL,
8486
.schedule_task_cancel = schedule_edf_task_cancel,
8587
.schedule_task_free = schedule_edf_task_free,
88+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
8689
.scheduler_free = edf_scheduler_free,
90+
#endif
8791
};
8892

8993
int schedule_task_init_edf(struct task *task, const struct sof_uuid_entry *uid,

src/platform/library/schedule/ll_schedule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ static int schedule_ll_task(void *data, struct task *task, uint64_t start,
6666
return 0;
6767
}
6868

69+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
6970
static void ll_scheduler_free(void *data, uint32_t flags)
7071
{
7172
free(data);
7273
}
74+
#endif
7375

7476
/* TODO: scheduler free and cancel APIs can merge as part of Zephyr */
7577
static int schedule_ll_task_cancel(void *data, struct task *task)
@@ -96,7 +98,9 @@ static struct scheduler_ops schedule_ll_ops = {
9698
.reschedule_task = NULL,
9799
.schedule_task_cancel = schedule_ll_task_cancel,
98100
.schedule_task_free = schedule_ll_task_free,
101+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
99102
.scheduler_free = ll_scheduler_free,
103+
#endif
100104
};
101105

102106
int schedule_task_init_ll(struct task *task,

src/schedule/ll_schedule_xtos.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ static int reschedule_ll_task(void *data, struct task *task, uint64_t start)
724724
}
725725
#endif
726726

727+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
727728
static void scheduler_free_ll(void *data, uint32_t flags)
728729
{
729730
struct ll_schedule_data *sch = data;
@@ -739,6 +740,7 @@ static void scheduler_free_ll(void *data, uint32_t flags)
739740

740741
irq_local_enable(irq_flags);
741742
}
743+
#endif
742744

743745
static void ll_scheduler_recalculate_tasks(struct ll_schedule_data *sch,
744746
struct clock_notify_data *clk_data)
@@ -807,6 +809,8 @@ static const struct scheduler_ops schedule_ll_ops = {
807809
.schedule_task_free = schedule_ll_task_free,
808810
.schedule_task_cancel = schedule_ll_task_cancel,
809811
.reschedule_task = reschedule_ll_task,
812+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
810813
.scheduler_free = scheduler_free_ll,
814+
#endif
811815
.schedule_task_running = NULL,
812816
};

src/schedule/zephyr_ll.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,25 +546,28 @@ static int zephyr_ll_task_cancel(void *data, struct task *task)
546546
return 0;
547547
}
548548

549-
/*
550-
* Runs on secondary cores in their shutdown sequence. In theory tasks can still
551-
* be active, but other schedulers ignore them too... And we don't need to free
552-
* the scheduler data - it's allocated in the SYS zone.
553-
*/
549+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
554550
static void zephyr_ll_scheduler_free(void *data, uint32_t flags)
555551
{
556552
struct zephyr_ll *sch = data;
557553

558554
zephyr_ll_assert_core(sch);
559555

556+
#if CONFIG_SOF_USERSPACE_LL
557+
zephyr_ll_locks[sch->core] = NULL;
558+
k_object_free(sch->lock);
559+
#endif
560+
560561
if (sch->n_tasks)
561562
tr_err(&ll_tr, "%u tasks are still active!",
562563
sch->n_tasks);
563564

564565
#if CONFIG_SOF_USERSPACE_LL
565566
domain_thread_free(sch->ll_domain, sch->n_tasks);
566567
#endif
568+
sof_heap_free(sch->heap, sch);
567569
}
570+
#endif
568571

569572
#if CONFIG_SOF_USERSPACE_LL
570573
struct k_thread *zephyr_ll_init_context(void *data, struct task *task)
@@ -601,7 +604,9 @@ static const struct scheduler_ops zephyr_ll_ops = {
601604
.schedule_task_after = zephyr_ll_task_schedule_after,
602605
.schedule_task_free = zephyr_ll_task_free,
603606
.schedule_task_cancel = zephyr_ll_task_cancel,
607+
#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY
604608
.scheduler_free = zephyr_ll_scheduler_free,
609+
#endif
605610
#if CONFIG_SOF_USERSPACE_LL
606611
.scheduler_init_context = zephyr_ll_init_context,
607612
#endif

0 commit comments

Comments
 (0)