From 9f22d78808492503ae410754215a790b3bfa49e7 Mon Sep 17 00:00:00 2001 From: valentin petrov Date: Mon, 5 Sep 2022 09:44:57 +0300 Subject: [PATCH] SCHEDULE: fixes race on n_deps_satisfied (#618) A task can depend on 2 other tasks (e.g. from another frag of of schedule and prev task in a given frag). In that case when those 2 frags a progressed by mutliple threads ucc_dependency_handler may be called concurrently which results in a race on n_deps_satisfied. (cherry picked from commit b8c78d87047675becf5aba953d85f7d8250304f2) --- src/schedule/ucc_schedule_pipelined.c | 8 +++++--- src/utils/ucc_atomic.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/schedule/ucc_schedule_pipelined.c b/src/schedule/ucc_schedule_pipelined.c index f1399282ed..eefb015640 100644 --- a/src/schedule/ucc_schedule_pipelined.c +++ b/src/schedule/ucc_schedule_pipelined.c @@ -210,11 +210,13 @@ ucc_status_t ucc_dependency_handler(ucc_coll_task_t *parent, ucc_coll_task_t *task) { ucc_status_t status; + uint8_t n_deps_satisfied; + + n_deps_satisfied = ucc_atomic_fadd8(&task->n_deps_satisfied, 1); - task->n_deps_satisfied++; ucc_trace_req("task %p, n_deps %d, satisfied %d", task, task->n_deps, - task->n_deps_satisfied); - if (task->n_deps == task->n_deps_satisfied) { + n_deps_satisfied); + if (task->n_deps == n_deps_satisfied + 1) { task->start_time = parent->start_time; status = task->post(task); if (status >= 0) { diff --git a/src/utils/ucc_atomic.h b/src/utils/ucc_atomic.h index aaecf605ea..d5aabd1829 100644 --- a/src/utils/ucc_atomic.h +++ b/src/utils/ucc_atomic.h @@ -11,6 +11,7 @@ #define ucc_atomic_add32 ucs_atomic_add32 #define ucc_atomic_fadd32 ucs_atomic_fadd32 +#define ucc_atomic_fadd8 ucs_atomic_fadd8 #define ucc_atomic_sub32 ucs_atomic_sub32 #define ucc_atomic_add64 ucs_atomic_add64 #define ucc_atomic_sub64 ucs_atomic_sub64