Skip to content

Commit 7dbe9b5

Browse files
committed
dp: switch the lock to use sys_sem
sys_sem semaphores don't invoke a syscall in uncongested cases. Switch over to it to reduce syscall number. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent c29d2dd commit 7dbe9b5

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

src/schedule/zephyr_dp_schedule.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,33 @@ SOF_DEFINE_REG_UUID(dp_sched);
3333

3434
DECLARE_TR_CTX(dp_tr, SOF_UUID(dp_sched_uuid), LOG_LEVEL_INFO);
3535

36-
#define DP_LOCK_INIT(i, _) Z_SEM_INITIALIZER(dp_lock[i], 1, 1)
36+
#ifdef CONFIG_USERSPACE
37+
#define SYS_SEM_INITIALIZER(obj, n_init, n_max) {.futex = {n_init}, .limit = n_max}
38+
#else
39+
#define SYS_SEM_INITIALIZER(obj, n_init, n_max) {Z_SEM_INITIALIZER(obj.kernel_sem, 1, 1)}
40+
#endif
41+
42+
#define DP_LOCK_INIT(i, _) SYS_SEM_INITIALIZER(dp_lock[i], 1, 1)
3743
#define DP_LOCK_INIT_LIST LISTIFY(CONFIG_MP_MAX_NUM_CPUS, DP_LOCK_INIT, (,))
3844

39-
/* User threads don't need access to this array. Access is performed from
40-
* the kernel space via a syscall. Array must be placed in special section
41-
* to be qualified as initialized by the gen_kobject_list.py script.
42-
*/
43-
static
44-
STRUCT_SECTION_ITERABLE_ARRAY(k_sem, dp_lock, CONFIG_MP_MAX_NUM_CPUS) = { DP_LOCK_INIT_LIST };
45+
static struct sys_sem dp_lock[CONFIG_MP_MAX_NUM_CPUS] = {
46+
DP_LOCK_INIT_LIST
47+
};
4548

4649
/* Each per-core instance of DP scheduler has separate structures; hence, locks are per-core.
4750
*
4851
* TODO: consider using cpu_get_id() instead of supplying core as a parameter.
4952
*/
5053
unsigned int scheduler_dp_lock(uint16_t core)
5154
{
52-
k_sem_take(&dp_lock[core], K_FOREVER);
55+
sys_sem_take(&dp_lock[core], K_FOREVER);
56+
5357
return core;
5458
}
5559

5660
void scheduler_dp_unlock(unsigned int key)
5761
{
58-
k_sem_give(&dp_lock[key]);
59-
}
60-
61-
void scheduler_dp_grant(k_tid_t thread_id, uint16_t core)
62-
{
63-
#if CONFIG_USERSPACE
64-
k_thread_access_grant(thread_id, &dp_lock[core]);
65-
#endif
62+
sys_sem_give(&dp_lock[key]);
6663
}
6764

6865
/* dummy LL task - to start LL on secondary cores */

src/schedule/zephyr_dp_schedule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_
5555
void dp_thread_fn(void *p1, void *p2, void *p3);
5656
unsigned int scheduler_dp_lock(uint16_t core);
5757
void scheduler_dp_unlock(unsigned int key);
58-
void scheduler_dp_grant(k_tid_t thread_id, uint16_t core);
5958
int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
6059
const struct task_ops *ops, struct processing_module *mod,
6160
uint16_t core, size_t stack_size, uint32_t options);

src/schedule/zephyr_dp_schedule_application.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
505505

506506
#if CONFIG_USERSPACE
507507
k_thread_access_grant(pdata->thread_id, pdata->sem, &dp_sync[core]);
508-
scheduler_dp_grant(pdata->thread_id, core);
509508

510509
unsigned int pidx;
511510
size_t size;

src/schedule/zephyr_dp_schedule_thread.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ int scheduler_dp_task_init(struct task **task,
270270
CONFIG_DP_THREAD_PRIORITY, (*task)->flags, K_FOREVER);
271271

272272
k_thread_access_grant(pdata->thread_id, pdata->event);
273-
scheduler_dp_grant(pdata->thread_id, cpu_get_id());
274273

275274
/* pin the thread to specific core */
276275
ret = k_thread_cpu_pin(pdata->thread_id, core);

0 commit comments

Comments
 (0)