This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add fields to struct gomp_thread for debugging purposes


This patch adds a new member named "pthread_id" to the gomp_thread
struct.  It is initialized in team.c.

It also adds a field named "parent" which is initialized to the thread
which created the thread in question.  For non-nested parallel
regions, this is always the master thread.

These new fields serve no purpose in a normally running OpenMP
program.  They are intended to be used by a debugger for identifying
threads and for finding the parent thread.

I've done a "make bootstrap" and have regression tested these changes
with no regressions found.

libgomp/ChangeLog:
    
    	* libgomp.h (struct gomp_thread): Add new member "pthread_id"
    	and "parent".
    	* team.c (struct gomp_thread_start_data): Add field "parent".
    	(gomp_thread_start): Set parent and pthread_id.
    	(gomp_team_start): Initialize master thread.  Initialize parent
    	in the start data.
---
 libgomp/libgomp.h |  7 +++++++
 libgomp/team.c    | 13 +++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 940b5b8..7fa64f7 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -611,6 +611,13 @@ struct gomp_thread
      to any place.  */
   unsigned int place;
 
+  /* The pthread id associated with this thread.  This is required for
+     debugging.  */
+  pthread_t pthread_id;
+
+  /* Thread which spawned this one.  This is required for debugging.  */
+  struct gomp_thread *parent;
+
   /* User pthread thread pool */
   struct gomp_thread_pool *thread_pool;
 };
diff --git a/libgomp/team.c b/libgomp/team.c
index 676614a..17a0b3d 100644
--- a/libgomp/team.c
+++ b/libgomp/team.c
@@ -58,6 +58,7 @@ struct gomp_thread_start_data
   struct gomp_thread_pool *thread_pool;
   unsigned int place;
   bool nested;
+  struct gomp_thread *parent;
 };
 
 
@@ -89,9 +90,12 @@ gomp_thread_start (void *xdata)
   thr->ts = data->ts;
   thr->task = data->task;
   thr->place = data->place;
+  thr->parent = data->parent;
 
   thr->ts.team->ordered_release[thr->ts.team_id] = &thr->release;
 
+  thr->pthread_id = pthread_self ();
+
   /* Make thread pool local. */
   pool = thr->thread_pool;
 
@@ -718,6 +722,14 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
       attr = &thread_attr;
     }
 
+  /* Add the master thread to threads[] and record its pthread id too.  */
+  if (pool->threads[0] == NULL)
+    {
+      pool->threads[0] = thr;
+      thr->pthread_id = pthread_self ();
+      thr->parent = NULL;
+    }
+
   start_data = gomp_alloca (sizeof (struct gomp_thread_start_data)
 			    * (nthreads-i));
 
@@ -812,6 +824,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
       team->implicit_task[i].icv.bind_var = bind_var;
       start_data->thread_pool = pool;
       start_data->nested = nested;
+      start_data->parent = thr;
 
       attr = gomp_adjust_thread_attr (attr, &thread_attr);
       err = pthread_create (&pt, attr, gomp_thread_start, start_data++);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]