Message ID | 1437569775-17198-1-git-send-email-sebastian.huber@embedded-brains.de |
---|---|
State | New |
Headers | show |
Ping. This is a pre-requisite for: https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02347.html On 22/07/15 14:56, Sebastian Huber wrote: > 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 <sebastian.huber@embedded-brains.de> > > * 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. > ---
Ping. On 28/07/15 13:06, Sebastian Huber wrote: > Ping. > > This is a pre-requisite for: > > https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02347.html > > On 22/07/15 14:56, Sebastian Huber wrote: >> 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 <sebastian.huber@embedded-brains.de> >> >> * 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. >> --- >
On Wed, Jul 22, 2015 at 02:56:15PM +0200, Sebastian Huber wrote: > 2015-07-22 Sebastian Huber <sebastian.huber@embedded-brains.de> > > * 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 * Please make this static inline struct gomp_thread_pool * (unlike the gomp_new_thread_pool call which has been solely cold path, this one has a hot path and thus we want to either inline it fully or inline it partially at least). Ok with that change. Jakub
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;