Skip to content

Commit 6b0ba55

Browse files
kv2019ilgirdwood
authored andcommitted
schedule: dp: look up the DP scheduler by core in the LL user thread
With CONFIG_SOF_USERSPACE_APPLICATION and CONFIG_SOF_USERSPACE_LL, scheduler_dp_ll_post_tick() runs in the LL user thread on every LL tick and finds the DP scheduler with scheduler_get_user_data(). This now reads the kernel-only copy of the user scheduler list, so the LL thread takes a load/store privilege exception (EXCCAUSE 26) as soon as audio starts. Pass the core of the calling LL scheduler to scheduler_dp_ll_post_tick() and look up the DP scheduler with arch_user_schedulers_get_for_core(), which is safe to call from user threads. Use the same core for the DP lock instead of cpu_get_id(), which reads a privileged register. Fixes: 91c2148 ("schedule: keep user scheduler descriptors read-only to user threads") Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 52c7405 commit 6b0ba55

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎src/include/sof/schedule/dp_schedule.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ static inline void scheduler_dp_check_deadline(uint16_t core, uint32_t deadline_
147147
* memory is writable by the DP threads, so the calculation runs in the calling
148148
* LL user thread, and only its results are passed to the kernel with
149149
* scheduler_dp_kick(). Otherwise this calls scheduler_dp_ll_tick().
150+
*
151+
* @param[in] core Core ID of the calling LL scheduler.
150152
*/
151-
void scheduler_dp_ll_post_tick(void);
153+
void scheduler_dp_ll_post_tick(unsigned int core);
152154

153155
#if CONFIG_SOF_BOOT_TEST_STANDALONE && CONFIG_SOF_USERSPACE_APPLICATION
154156
/* Test hooks: add and remove kernel-only DP task records without a DP task */

‎src/schedule/zephyr_dp_schedule.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ void scheduler_dp_unlock(unsigned int key)
5252

5353
#if CONFIG_SOF_USERSPACE_APPLICATION && CONFIG_SOF_USERSPACE_LL
5454
/* Runs in the LL user thread, see scheduler_dp_ll_post_tick() documentation */
55-
void scheduler_dp_ll_post_tick(void)
55+
void scheduler_dp_ll_post_tick(unsigned int core)
5656
{
57-
struct scheduler_dp_data *dp_sch = scheduler_get_user_data(SOF_SCHEDULE_DP);
57+
/* user context: the kernel-only lookup and cpu_get_id() are not usable */
58+
struct scheduler_dp_data *dp_sch =
59+
scheduler_list_get_data(*arch_user_schedulers_get_for_core(core),
60+
SOF_SCHEDULE_DP);
5861
unsigned int lock_key;
5962

6063
/*
@@ -64,12 +67,12 @@ void scheduler_dp_ll_post_tick(void)
6467
if (!dp_sch || list_is_empty(&dp_sch->tasks))
6568
return;
6669

67-
lock_key = scheduler_dp_lock(cpu_get_id());
70+
lock_key = scheduler_dp_lock(core);
6871
scheduler_dp_recalculate(dp_sch);
6972
scheduler_dp_unlock(lock_key);
7073
}
7174
#else
72-
void scheduler_dp_ll_post_tick(void)
75+
void scheduler_dp_ll_post_tick(unsigned int core)
7376
{
7477
scheduler_dp_ll_tick();
7578
}

‎src/schedule/zephyr_ll.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static void zephyr_ll_run(void *data)
302302
zephyr_ll_unlock(sch, &flags);
303303

304304
#ifdef CONFIG_ZEPHYR_DP_SCHEDULER
305-
scheduler_dp_ll_post_tick();
305+
scheduler_dp_ll_post_tick(sch->core);
306306
#endif
307307
}
308308

0 commit comments

Comments
 (0)