[Openmp-commits] [PATCH] D47717: [OMPT] Make sure that OMPT is enabled in runtime entry points that access internals of the runtime

Simon Convent via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Jun 11 02:12:26 PDT 2018


sconvent updated this revision to Diff 150690.
sconvent added a comment.

Move `ompt_enabled.enabled` checks out of internal functions


https://reviews.llvm.org/D47717

Files:
  runtime/src/ompt-general.cpp


Index: runtime/src/ompt-general.cpp
===================================================================
--- runtime/src/ompt-general.cpp
+++ runtime/src/ompt-general.cpp
@@ -448,14 +448,17 @@
 
 OMPT_API_ROUTINE int ompt_get_callback(ompt_callbacks_t which,
                                        ompt_callback_t *callback) {
+  if (!ompt_enabled.enabled)
+    return ompt_get_callback_failure;
+
   switch (which) {
 
 #define ompt_event_macro(event_name, callback_type, event_id)                  \
   case event_name:                                                             \
     if (ompt_event_implementation_status(event_name)) {                        \
       ompt_callback_t mycb =                                                   \
           (ompt_callback_t)ompt_callbacks.ompt_callback(event_name);           \
-      if (mycb) {                                                              \
+      if (ompt_enabled.event_name && mycb) {                                   \
         *callback = mycb;                                                      \
         return ompt_get_callback_success;                                      \
       }                                                                        \
@@ -478,6 +481,8 @@
 OMPT_API_ROUTINE int ompt_get_parallel_info(int ancestor_level,
                                             ompt_data_t **parallel_data,
                                             int *team_size) {
+  if (!ompt_enabled.enabled)
+    return 0;
   return __ompt_get_parallel_info_internal(ancestor_level, parallel_data,
                                            team_size);
 }
@@ -497,14 +502,18 @@
  ****************************************************************************/
 
 OMPT_API_ROUTINE ompt_data_t *ompt_get_thread_data(void) {
+  if (!ompt_enabled.enabled)
+    return NULL;
   return __ompt_get_thread_data_internal();
 }
 
 OMPT_API_ROUTINE int ompt_get_task_info(int ancestor_level, int *type,
                                         ompt_data_t **task_data,
                                         omp_frame_t **task_frame,
                                         ompt_data_t **parallel_data,
                                         int *thread_num) {
+  if (!ompt_enabled.enabled)
+    return 0;
   return __ompt_get_task_info_internal(ancestor_level, type, task_data,
                                        task_frame, parallel_data, thread_num);
 }
@@ -573,7 +582,7 @@
 #if !KMP_AFFINITY_SUPPORTED
   return -1;
 #else
-  if (__kmp_get_gtid() < 0)
+  if (!ompt_enabled.enabled || __kmp_get_gtid() < 0)
     return -1;
 
   int gtid;
@@ -594,7 +603,7 @@
 #if !KMP_AFFINITY_SUPPORTED
   return 0;
 #else
-  if (__kmp_get_gtid() < 0)
+  if (!ompt_enabled.enabled || __kmp_get_gtid() < 0)
     return 0;
 
   int i, gtid, place_num, first_place, last_place, start, end;
@@ -630,7 +639,7 @@
 
 OMPT_API_ROUTINE int ompt_get_proc_id(void) {
 #if KMP_OS_LINUX
-  if (__kmp_get_gtid() < 0)
+  if (!ompt_enabled.enabled || __kmp_get_gtid() < 0)
     return -1;
 
   return sched_getcpu();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47717.150690.patch
Type: text/x-patch
Size: 3070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20180611/b6586032/attachment.bin>


More information about the Openmp-commits mailing list