From patchwork Wed Jul 22 12:56:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 498522 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 C6E731402C7 for ; Wed, 22 Jul 2015 22:56:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=DAxjzRwQ; 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:from :to:cc:subject:date:message-id; q=dns; s=default; b=xwFKpNLg2s+8 8rJTRsFLgmX8WP/Bw5VOP5qawPcGuH5+IOebp430x9Q8YYk803ju8MNbR4BN71DS aCYES2XdqaQpBddcnjVwoi6gy1XgifgpJvUO2VR+dTf99lMedpDDIChBHTlp/GwB GvOcks7VMKlIeY9FxAZa3eTuG13iNwk= 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:from :to:cc:subject:date:message-id; s=default; bh=3phx6yvBHLyc0667AQ B6nItF3dY=; b=DAxjzRwQwyEeeB2NL6hhYcLRrTaEHAc64LhR+DqHALFnAz80Gn Wwvst+K4WKwRzqVYTy5SVfT/4dP+1G91W8re5bx/TzLTnzV0DxAXO8ezCBdjkHWS ikdf5feH3coB5ctY8QdFSaH3+U6Us1381YoCsX9zqsC8SRS8zXckgsfIU= Received: (qmail 87068 invoked by alias); 22 Jul 2015 12:56:24 -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 87052 invoked by uid 89); 22 Jul 2015 12:56:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.6 required=5.0 tests=AWL, BAYES_20, KAM_LAZY_DOMAIN_SECURITY, RDNS_DYNAMIC autolearn=no version=3.3.2 X-HELO: mail.embedded-brains.de Received: from host-82-135-62-35.customer.m-online.net (HELO mail.embedded-brains.de) (82.135.62.35) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 22 Jul 2015 12:56:21 +0000 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 9D9E22A1611 for ; Wed, 22 Jul 2015 14:56:20 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Qhq89uO9rcjr; Wed, 22 Jul 2015 14:56:20 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 2BB1F2A109C; Wed, 22 Jul 2015 14:56:20 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ujVRTy4evJPI; Wed, 22 Jul 2015 14:56:20 +0200 (CEST) Received: from huber-linux.eb.localhost (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTP id 04AD12A005D; Wed, 22 Jul 2015 14:56:20 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Cc: Sebastian Huber Subject: [PATCH] [gomp] Simplify thread pool initialization Date: Wed, 22 Jul 2015 14:56:15 +0200 Message-Id: <1437569775-17198-1-git-send-email-sebastian.huber@embedded-brains.de> X-IsSubscribed: yes Move the thread pool initialization from the team start to the team creation. This eliminates one conditional expression. In addition this is a preparation patch to enable shared thread pools which I would like to use for RTEMS later. No unexpected failures on x86_64-unknown-linux-gnu. libgomp/ChangeLog 2015-07-22 Sebastian Huber * team.c (gomp_new_thread_pool): Delete and move content to ... (gomp_get_thread_pool): ... new function. Allocate and initialize thread pool on demand. (get_last_team): Use gomp_get_thread_pool(). (gomp_team_start): Delete thread pool initialization. --- libgomp/team.c | 56 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/libgomp/team.c b/libgomp/team.c index 7671b05..5c56182 100644 --- a/libgomp/team.c +++ b/libgomp/team.c @@ -134,22 +134,39 @@ gomp_thread_start (void *xdata) return NULL; } +/* Get the thread pool, allocate and initialize it on demand. */ + +static struct gomp_thread_pool * +gomp_get_thread_pool (struct gomp_thread *thr, unsigned nthreads) +{ + struct gomp_thread_pool *pool = thr->thread_pool; + if (__builtin_expect (pool == NULL, 0)) + { + pool = gomp_malloc (sizeof (*pool)); + pool->threads = NULL; + pool->threads_size = 0; + pool->threads_used = 0; + pool->last_team = NULL; + pool->threads_busy = nthreads; + thr->thread_pool = pool; + pthread_setspecific (gomp_thread_destructor, thr); + } + return pool; +} + static inline struct gomp_team * get_last_team (unsigned nthreads) { struct gomp_thread *thr = gomp_thread (); if (thr->ts.team == NULL) { - struct gomp_thread_pool *pool = thr->thread_pool; - if (pool != NULL) - { - struct gomp_team *last_team = pool->last_team; - if (last_team != NULL && last_team->nthreads == nthreads) - { - pool->last_team = NULL; - return last_team; - } - } + struct gomp_thread_pool *pool = gomp_get_thread_pool (thr, nthreads); + struct gomp_team *last_team = pool->last_team; + if (last_team != NULL && last_team->nthreads == nthreads) + { + pool->last_team = NULL; + return last_team; + } } return NULL; } @@ -219,19 +236,6 @@ free_team (struct gomp_team *team) free (team); } -/* Allocate and initialize a thread pool. */ - -static struct gomp_thread_pool *gomp_new_thread_pool (void) -{ - struct gomp_thread_pool *pool - = gomp_malloc (sizeof(struct gomp_thread_pool)); - pool->threads = NULL; - pool->threads_size = 0; - pool->threads_used = 0; - pool->last_team = NULL; - return pool; -} - static void gomp_free_pool_helper (void *thread_pool) { @@ -316,12 +320,6 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads, thr = gomp_thread (); nested = thr->ts.team != NULL; - if (__builtin_expect (thr->thread_pool == NULL, 0)) - { - thr->thread_pool = gomp_new_thread_pool (); - thr->thread_pool->threads_busy = nthreads; - pthread_setspecific (gomp_thread_destructor, thr); - } pool = thr->thread_pool; task = thr->task; icv = task ? &task->icv : &gomp_global_icv;