From a5cc6f47b5a17eabdc270a3bf1cf78e9ee1c9c90 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 14 May 2021 08:21:48 +0200 Subject: [PATCH] ll-scheduler: fix the wrong use of atomic operations A sequence of atomic_sub(); atomic_read() breaks atomicity. A single atomic_sub() should be used instead. Signed-off-by: Guennadi Liakhovetski --- src/schedule/ll_schedule.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/schedule/ll_schedule.c b/src/schedule/ll_schedule.c index c3416c9f0..3f23aaa5d 100644 --- a/src/schedule/ll_schedule.c +++ b/src/schedule/ll_schedule.c @@ -104,11 +104,11 @@ static void schedule_ll_task_done(struct ll_schedule_data *sch, /* the task finished, decrease the count */ atomic_sub(&sch->domain->total_num_tasks, 1); - /* decrease task number of the core */ - atomic_sub(&sch->num_tasks, 1); - - /* the last task of the core, unregister the client/core */ - if (!atomic_read(&sch->num_tasks) && + /* + * Decrement the number of tasks on the core + * If this was the last task of the core, unregister the client/core + */ + if (atomic_sub(&sch->num_tasks, 1) == 1 && sch->domain->registered[cpu_get_id()]) { sch->domain->registered[cpu_get_id()] = false; atomic_sub(&sch->domain->registered_cores, 1); @@ -338,11 +338,11 @@ static void schedule_ll_domain_clear(struct ll_schedule_data *sch, spin_lock(&domain->lock); - /* decrease task number of the core */ - atomic_sub(&sch->num_tasks, 1); - - /* disable domain on the core if needed */ - if (!atomic_read(&sch->num_tasks)) + /* + * Decrement the number of tasks on the core. + * Disable domain on the core if needed + */ + if (atomic_sub(&sch->num_tasks, 1) == 1) domain_disable(domain, cpu_get_id()); /* unregister the task */