Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/arch/xtensa/include/arch/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static inline int32_t arch_atomic_add(atomic_t *a, int32_t value)
: "a" (&a->value), "a" (value)
: "memory");

return (*(volatile int32_t *)&a->value);
return current;
}

static inline int32_t arch_atomic_sub(atomic_t *a, int32_t value)
Expand All @@ -62,7 +62,7 @@ static inline int32_t arch_atomic_sub(atomic_t *a, int32_t value)
: "a" (&a->value), "a" (value)
: "memory");

return (*(volatile int32_t *)&a->value);
return current;
}

#endif /* __ARCH_ATOMIC_H__ */
Expand Down
28 changes: 18 additions & 10 deletions src/schedule/ll_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ static void schedule_ll_tasks_execute(struct ll_schedule_data *sch,
atomic_sub(&sch->domain->total_num_tasks, 1);

/* don't enable irq, if no more tasks to do */
if (!atomic_sub(&sch->num_tasks, 1))
atomic_sub(&sch->num_tasks, 1);
if (!atomic_read(&sch->num_tasks))
sch->domain->registered[cpu] = false;
tr_info(&ll_tr, "task complete %p %s", (uintptr_t)task,
task->uid);
Expand Down Expand Up @@ -172,7 +173,8 @@ static void schedule_ll_tasks_run(void *data)
/* TODO: no need for atomic operations,
* already protected by spin_lock
*/
num_clients = atomic_sub(&sch->domain->num_clients, 1);
atomic_sub(&sch->domain->num_clients, 1);
num_clients = atomic_read(&sch->domain->num_clients);
if (!num_clients)
domain_clear(sch->domain);

Expand Down Expand Up @@ -224,10 +226,12 @@ static int schedule_ll_domain_set(struct ll_schedule_data *sch,
spin_lock(&sch->domain->lock);

registered = sch->domain->registered[core];
if (atomic_add(&sch->num_tasks, 1) == 1)
atomic_add(&sch->num_tasks, 1);
if (atomic_read(&sch->num_tasks) == 1)
sch->domain->registered[core] = true;

total = atomic_add(&sch->domain->total_num_tasks, 1);
atomic_add(&sch->domain->total_num_tasks, 1);
total = atomic_read(&sch->domain->total_num_tasks);

if (total == 1)
/* First task in domain over all cores: actiivate it */
Expand Down Expand Up @@ -256,19 +260,23 @@ static void schedule_ll_domain_clear(struct ll_schedule_data *sch,
{
spin_lock(&sch->domain->lock);

if (!atomic_sub(&sch->domain->total_num_tasks, 1)) {
atomic_sub(&sch->domain->total_num_tasks, 1);
if (!atomic_read(&sch->domain->total_num_tasks)) {
domain_clear(sch->domain);
sch->domain->last_tick = 0;
}

if (!atomic_sub(&sch->num_tasks, 1)) {
atomic_sub(&sch->num_tasks, 1);
if (!atomic_read(&sch->num_tasks)) {
sch->domain->registered[cpu_get_id()] = false;

/* reschedule if we are the last client */
if (atomic_read(&sch->domain->num_clients) &&
!atomic_sub(&sch->domain->num_clients, 1)) {
domain_clear(sch->domain);
schedule_ll_clients_reschedule(sch);
if (atomic_read(&sch->domain->num_clients)) {
atomic_sub(&sch->domain->num_clients, 1);
if (!atomic_read(&sch->domain->num_clients)) {
domain_clear(sch->domain);
schedule_ll_clients_reschedule(sch);
}
}
}

Expand Down