[OpenMP] Fix incorrect barrier imbalance reporting in ITTNOTIFY
authorJonathan Peyton <jonathan.l.peyton@intel.com>
Fri, 24 Aug 2018 18:03:27 +0000 (18:03 +0000)
committerJonathan Peyton <jonathan.l.peyton@intel.com>
Fri, 24 Aug 2018 18:03:27 +0000 (18:03 +0000)
Exclude nested explicit tasks from timing, only outer level explicit task
counted and its time added to barrier arrive time for the thread.

Differential Revision: https://reviews.llvm.org/D50584

llvm-svn: 340628

openmp/runtime/src/kmp_barrier.cpp
openmp/runtime/src/kmp_tasking.cpp

index e817549..51c6e3e 100644 (file)
@@ -1458,8 +1458,8 @@ int __kmp_barrier(enum barrier_type bt, int gtid, int is_split,
     if (__kmp_tasking_mode != tskm_immediate_exec) {
 #if OMP_45_ENABLED
       if (this_thr->th.th_task_team != NULL) {
-        void *itt_sync_obj = NULL;
 #if USE_ITT_NOTIFY
+        void *itt_sync_obj = NULL;
         if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
           itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
           __kmp_itt_barrier_starting(gtid, itt_sync_obj);
index 5a4df0c..d9220c5 100644 (file)
@@ -1266,6 +1266,7 @@ kmp_task_t *__kmpc_omp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
 static void __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
                               kmp_taskdata_t *current_task) {
   kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
+  kmp_info_t *thread;
 #if OMP_40_ENABLED
   int discard = 0 /* false */;
 #endif
@@ -1293,20 +1294,10 @@ static void __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
   }
 #endif
 
-#if USE_ITT_BUILD && USE_ITT_NOTIFY
-  kmp_uint64 cur_time;
-  if (__kmp_forkjoin_frames_mode == 3) {
-    // Get the current time stamp to measure task execution time to correct
-    // barrier imbalance time
-    cur_time = __itt_get_timestamp();
-  }
-#endif
-
 #if OMPT_SUPPORT
   // For untied tasks, the first task executed only calls __kmpc_omp_task and
   // does not execute code.
   ompt_thread_info_t oldInfo;
-  kmp_info_t *thread;
   if (UNLIKELY(ompt_enabled.enabled)) {
     // Store the threads states and restore them after the task
     thread = __kmp_threads[gtid];
@@ -1334,8 +1325,8 @@ static void __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
   // TODO: check if this sequence can be hoisted above __kmp_task_start
   // if cancellation has been enabled for this run ...
   if (__kmp_omp_cancellation) {
-    kmp_info_t *this_thr = __kmp_threads[gtid];
-    kmp_team_t *this_team = this_thr->th.th_team;
+    thread = __kmp_threads[gtid];
+    kmp_team_t *this_team = thread->th.th_team;
     kmp_taskgroup_t *taskgroup = taskdata->td_taskgroup;
     if ((taskgroup && taskgroup->cancel_request) ||
         (this_team->t.t_cancel_request == cancel_parallel)) {
@@ -1395,6 +1386,21 @@ static void __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
       __ompt_task_start(task, current_task, gtid);
 #endif
 
+#if USE_ITT_BUILD && USE_ITT_NOTIFY
+    kmp_uint64 cur_time;
+    kmp_int32 kmp_itt_count_task =
+        __kmp_forkjoin_frames_mode == 3 && !taskdata->td_flags.task_serial &&
+        current_task->td_flags.tasktype == TASK_IMPLICIT;
+    if (kmp_itt_count_task) {
+      thread = __kmp_threads[gtid];
+      // Time outer level explicit task on barrier for adjusting imbalance time
+      if (thread->th.th_bar_arrive_time)
+        cur_time = __itt_get_timestamp();
+      else
+        kmp_itt_count_task = 0; // thread is not on a barrier - skip timing
+    }
+#endif
+
 #ifdef KMP_GOMP_COMPAT
     if (taskdata->td_flags.native) {
       ((void (*)(void *))(*(task->routine)))(task->shareds);
@@ -1405,6 +1411,13 @@ static void __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
     }
     KMP_POP_PARTITIONED_TIMER();
 
+#if USE_ITT_BUILD && USE_ITT_NOTIFY
+    if (kmp_itt_count_task) {
+      // Barrier imbalance - adjust arrive time with the task duration
+      thread->th.th_bar_arrive_time += (__itt_get_timestamp() - cur_time);
+    }
+#endif
+
 #if OMP_40_ENABLED
   }
 #endif // OMP_40_ENABLED
@@ -1429,15 +1442,6 @@ static void __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
   }
 #endif
 
-#if USE_ITT_BUILD && USE_ITT_NOTIFY
-  // Barrier imbalance - correct arrive time after the task finished
-  if (__kmp_forkjoin_frames_mode == 3) {
-    kmp_info_t *this_thr = __kmp_threads[gtid];
-    if (this_thr->th.th_bar_arrive_time) {
-      this_thr->th.th_bar_arrive_time += (__itt_get_timestamp() - cur_time);
-    }
-  }
-#endif
   KA_TRACE(
       30,
       ("__kmp_invoke_task(exit): T#%d completed task %p, resuming task %p\n",