diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-05-25 11:10:41 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-05-25 11:10:41 +0200 |
commit | c125f504c43a1d863b040375872b6696a6c2b681 (patch) | |
tree | a6072dcca785fe49b7fc4257b604216641b7df1b /libgomp/task.c | |
parent | a1c9f779f75283427316b5c670c1e01ff8ce9ced (diff) | |
download | gcc-c125f504c43a1d863b040375872b6696a6c2b681.tar.gz |
libgomp: Fix occassional hangs with taskwait nowait depend
Richi reported occassional hangs with taskwait-depend-nowait-1.*
tests and I've finally manged to reproduce. The problem is if
taskwait depend without nowait is encountered soon after
taskwait depend nowait and the former depends on the latter and there
is no other work to do, the taskwait depend without nowait is put
to sleep, but the empty_task optimization in
gomp_task_run_post_handle_dependers wouldn't wake it up in that
case. gomp_task_run_post_handle_dependers normally does some wakeups
because it schedules more work (another task), which is not the
case of empty_task, but we need to do the wakeups that would be done
upon task completion so that we awake sleeping threads when the
last child is done.
So, the taskwait-depend-nowait-1.* testcase is fixed with the
else if (__builtin_expect (task->parent_depends_on, 0) part of
the patch.
The new testcase can hang on another problem, if the empty task
is the last task of a taskgroup, we need to use atomic store
like elsewhere to decrease the counter to 0, and wake up taskgroup
end if needed.
Yet another spot which can sleep is normal taskwait (without depend),
but I believe nothing needs to be done for that - in that case we
await solely until the children's queue has no tasks, tasks still
waiting for dependencies aren't accounted in that, but the reason
is that if taskwait should wait for something, there needs to be at least
one active child doing something (in the children queue), which then
possibly awakes some of its siblings when the dependencies are met,
or in the empty task case awakes further dependencies, but in any
case the child that finished is still handled as active child and
will awake taskwait at the end if there is nothing further to
do.
Last sleeping case are barriers, but that is handled by ++ret and
awaking the barrier.
2022-05-25 Jakub Jelinek <jakub@redhat.com>
* task.c (gomp_task_run_post_handle_dependers): If empty_task
is the last task taskwait depend depends on, wake it up.
Similarly if it is the last child of a taskgroup, use atomic
store instead of decrement and awak taskgroup wait if any.
* testsuite/libgomp.c-c++-common/taskwait-depend-nowait-2.c: New test.
Diffstat (limited to 'libgomp/task.c')
-rw-r--r-- | libgomp/task.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libgomp/task.c b/libgomp/task.c index 7925e5873c4..30cd046df2a 100644 --- a/libgomp/task.c +++ b/libgomp/task.c @@ -1382,10 +1382,30 @@ gomp_task_run_post_handle_dependers (struct gomp_task *child_task, { if (!parent) task->parent = NULL; + else if (__builtin_expect (task->parent_depends_on, 0) + && --parent->taskwait->n_depend == 0 + && parent->taskwait->in_depend_wait) + { + parent->taskwait->in_depend_wait = false; + gomp_sem_post (&parent->taskwait->taskwait_sem); + } if (gomp_task_run_post_handle_depend (task, team)) ++ret; if (taskgroup) - taskgroup->num_children--; + { + if (taskgroup->num_children > 1) + --taskgroup->num_children; + else + { + __atomic_store_n (&taskgroup->num_children, 0, + MEMMODEL_RELEASE); + if (taskgroup->in_taskgroup_wait) + { + taskgroup->in_taskgroup_wait = false; + gomp_sem_post (&taskgroup->taskgroup_sem); + } + } + } gomp_finish_task (task); free (task); continue; |