From patchwork Tue Aug 25 17:35:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 510574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 504051401DE for ; Wed, 26 Aug 2015 03:35:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=uK+D2zX8; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=ZxgigWclziUvW6SgW+TnI4xAeWgXmHd1OJ3IoC66TgJiw6nSUh sq4NCVbCpJIEv8grV4Ory1206RAnQL5NiJRKaG9PS/pODNsy5p1bHteHxEw+GAiO Zv6npxAanFlhMQ0DLut7f5lmKTRKUw7CfaQaK78Ahe6FQ9/bTU+rx1tcM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=0G/soozVmTRTiSqJk59F+/iPG2o=; b=uK+D2zX8wSz0rTLFVECm uoHQDBXt99WS+JBi9Y8l2Mw/dWD79zAVizhrdHhgglJHhH17fM69N97e89lulEWb XPEDueWqCaJrORS1VbccMTDYVGFumBHgkoHbnve3Z+VdY8bhpLuN+CRpeQSH7dkb Gr1BrvzcYSTrEViHZb87BDg= Received: (qmail 13368 invoked by alias); 25 Aug 2015 17:35:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 13355 invoked by uid 89); 25 Aug 2015 17:35:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 25 Aug 2015 17:35:40 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 05B2A461C2 for ; Tue, 25 Aug 2015 17:35:39 +0000 (UTC) Received: from reynosa.quesejoda.com (vpn-53-23.rdu2.redhat.com [10.10.53.23]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7PHZb4G015674; Tue, 25 Aug 2015 13:35:38 -0400 To: Jakub Jelinek , gcc-patches From: Aldy Hernandez Subject: [gomp4.1] comment some stuff Message-ID: <55DCA769.3070305@redhat.com> Date: Tue, 25 Aug 2015 10:35:37 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 I'm obviously not smart enough to understand libgomp's tasking runtime, and rth and you get 0 for commenting skills ;-). I had some notes scribbled down while reading the code, and figured someone else might read this code some day. It's still in dire need of commenting, but this mildly helps. OK for branch? commit 5fc2816946c9250c4cca43d002b364b2d6400919 Author: Aldy Hernandez Date: Tue Aug 25 10:32:48 2015 -0700 * env.c: Make gomp_max_task_priority_var static. * libgomp.h (struct gomp_task_depend_entry): Add comment. * task.c (gomp_clear_parent): Document function. (GOMP_task): Same. (gomp_task_run_pre): Add comments. (gomp_task_run_post_handle_dependers): Same. (gomp_task_run_post_remove_parent): Same. (gomp_task_run_post_remove_taskgroup): Same. (GOMP_taskwait): Same. (gomp_task_maybe_wait_for_dependencies): Same. diff --git a/libgomp/env.c b/libgomp/env.c index 65a6851..0569521 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -69,7 +69,7 @@ struct gomp_task_icv gomp_global_icv = { unsigned long gomp_max_active_levels_var = INT_MAX; bool gomp_cancel_var = false; -int gomp_max_task_priority_var = 0; +static int gomp_max_task_priority_var = 0; #ifndef HAVE_SYNC_BUILTINS gomp_mutex_t gomp_managed_threads_lock; #endif diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index 9031649..3d705ef 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -279,6 +279,7 @@ struct gomp_task_depend_entry struct gomp_task_depend_entry *next; struct gomp_task_depend_entry *prev; struct gomp_task *task; + /* Depend entry is of type "IN". */ bool is_in; bool redundant; bool redundant_out; diff --git a/libgomp/task.c b/libgomp/task.c index f2a0fae..7c7bae4 100644 --- a/libgomp/task.c +++ b/libgomp/task.c @@ -92,6 +92,8 @@ gomp_end_task (void) thr->task = task->parent; } +/* Orphan the task in CHILDREN and all its siblings. */ + static inline void gomp_clear_parent (struct gomp_task *children) { @@ -110,7 +112,12 @@ static void gomp_task_maybe_wait_for_dependencies (void **depend); /* Called when encountering an explicit task directive. If IF_CLAUSE is false, then we must not delay in executing the task. If UNTIED is true, - then the task may be executed by any member of the team. */ + then the task may be executed by any member of the team. + + DEPEND is an array containing: + depend[0]: number of depend elements. + depend[1]: number of depend elements of type "out". + depend[N+2]: address of [0..N]th depend element. */ void GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *), @@ -444,8 +451,10 @@ gomp_task_run_pre (struct gomp_task *child_task, struct gomp_task *parent, { if (parent) { + /* Remove child_task from parent. */ if (parent->children == child_task) parent->children = child_task->next_child; + if (__builtin_expect (child_task->parent_depends_on, 0) && parent->taskwait->last_parent_depends_on == child_task) { @@ -456,8 +465,10 @@ gomp_task_run_pre (struct gomp_task *child_task, struct gomp_task *parent, parent->taskwait->last_parent_depends_on = NULL; } } + /* Remove child_task from taskgroup. */ if (taskgroup && taskgroup->children == child_task) taskgroup->children = child_task->next_taskgroup; + child_task->prev_queue->next_queue = child_task->next_queue; child_task->next_queue->prev_queue = child_task->prev_queue; if (team->task_queue == child_task) @@ -528,6 +539,7 @@ gomp_task_run_post_handle_dependers (struct gomp_task *child_task, if (parent->taskwait && parent->taskwait->last_parent_depends_on && !task->parent_depends_on) { + /* Put task in last_parent_depends_on. */ struct gomp_task *last_parent_depends_on = parent->taskwait->last_parent_depends_on; task->next_child = last_parent_depends_on->next_child; @@ -535,6 +547,7 @@ gomp_task_run_post_handle_dependers (struct gomp_task *child_task, } else { + /* Put task at the top of the sibling list. */ task->next_child = parent->children; task->prev_child = parent->children->prev_child; parent->children = task; @@ -544,6 +557,7 @@ gomp_task_run_post_handle_dependers (struct gomp_task *child_task, } else { + /* Put task in the sibling list. */ task->next_child = task; task->prev_child = task; parent->children = task; @@ -628,12 +642,18 @@ gomp_task_run_post_handle_depend (struct gomp_task *child_task, return gomp_task_run_post_handle_dependers (child_task, team); } +/* Remove CHILD_TASK from its parent. */ + static inline void gomp_task_run_post_remove_parent (struct gomp_task *child_task) { struct gomp_task *parent = child_task->parent; if (parent == NULL) return; + + /* If this was the last task the parent was depending on, + synchronize with gomp_task_maybe_wait_for_dependencies so it can + clean up and return. */ if (__builtin_expect (child_task->parent_depends_on, 0) && --parent->taskwait->n_depend == 0 && parent->taskwait->in_depend_wait) @@ -641,6 +661,8 @@ gomp_task_run_post_remove_parent (struct gomp_task *child_task) parent->taskwait->in_depend_wait = false; gomp_sem_post (&parent->taskwait->taskwait_sem); } + + /* Remove CHILD_TASK from its sibling list. */ child_task->prev_child->next_child = child_task->next_child; child_task->next_child->prev_child = child_task->prev_child; if (parent->children != child_task) @@ -663,6 +685,8 @@ gomp_task_run_post_remove_parent (struct gomp_task *child_task) } } +/* Remove CHILD_TASK from its taskgroup. */ + static inline void gomp_task_run_post_remove_taskgroup (struct gomp_task *child_task) { @@ -889,6 +913,9 @@ GOMP_taskwait (void) finish_cancelled:; size_t new_tasks = gomp_task_run_post_handle_depend (child_task, team); + + /* Remove child_task from children list, and set up the next + sibling to be run. */ child_task->prev_child->next_child = child_task->next_child; child_task->next_child->prev_child = child_task->prev_child; if (task->children == child_task) @@ -898,8 +925,12 @@ GOMP_taskwait (void) else task->children = NULL; } + /* Orphan all the children of CHILD_TASK. */ gomp_clear_parent (child_task->children); + + /* Remove CHILD_TASK from its taskgroup. */ gomp_task_run_post_remove_taskgroup (child_task); + to_free = child_task; child_task = NULL; team->task_count--; @@ -915,7 +946,9 @@ GOMP_taskwait (void) } /* This is like GOMP_taskwait, but we only wait for tasks that the - upcoming task depends on. */ + upcoming task depends on. + + DEPEND is as in GOMP_task. */ static void gomp_task_maybe_wait_for_dependencies (void **depend) @@ -956,8 +989,10 @@ gomp_task_maybe_wait_for_dependencies (void **depend) to front, so that we run it as soon as possible. */ if (last_parent_depends_on) { + /* Remove tsk from the sibling list... */ tsk->prev_child->next_child = tsk->next_child; tsk->next_child->prev_child = tsk->prev_child; + /* ...and insert it into last_parent_depends_on. */ tsk->prev_child = last_parent_depends_on; tsk->next_child = last_parent_depends_on->next_child; tsk->prev_child->next_child = tsk; @@ -965,8 +1000,11 @@ gomp_task_maybe_wait_for_dependencies (void **depend) } else if (tsk != task->children) { + /* Remove tsk from the sibling list... */ tsk->prev_child->next_child = tsk->next_child; tsk->next_child->prev_child = tsk->prev_child; + /* ...and insert it into the running task's + children. */ tsk->prev_child = task->children; tsk->next_child = task->children->next_child; task->children = tsk; @@ -1054,6 +1092,8 @@ gomp_task_maybe_wait_for_dependencies (void **depend) = gomp_task_run_post_handle_depend (child_task, team); if (child_task->parent_depends_on) --taskwait.n_depend; + + /* Remove child_task from sibling list. */ child_task->prev_child->next_child = child_task->next_child; child_task->next_child->prev_child = child_task->prev_child; if (task->children == child_task) @@ -1063,6 +1103,7 @@ gomp_task_maybe_wait_for_dependencies (void **depend) else task->children = NULL; } + gomp_clear_parent (child_task->children); gomp_task_run_post_remove_taskgroup (child_task); to_free = child_task;