diff options
author | Joachim Protze <protze@itc.rwth-aachen.de> | 2019-01-16 08:58:17 +0000 |
---|---|---|
committer | Joachim Protze <protze@itc.rwth-aachen.de> | 2019-01-16 08:58:17 +0000 |
commit | e03153add51c105a5b6423dd2eb9bbb2c60528a3 (patch) | |
tree | ec77c2c1fdb6a1e0098c53253fcc87edc7452441 /openmp/runtime/src/ompt-general.cpp | |
parent | 831ea46f1a7dd41e8d674a59d7413837f151dc7b (diff) |
[OMPT] Make sure that OMPT is enabled when accessing internals of the runtime
Make sure that OMPT is enabled in runtime entry points that access internals
of the runtime. Else, return an appropiate value indicating an error or that
the data is not available.
Patch provided by @sconvent
Reviewers: jlpeyton, omalyshe, hbae, Hahnfeld, joachim.protze
Reviewed By: joachim.protze
Tags: #openmp, #ompt
Differential Revision: https://reviews.llvm.org/D47717
Diffstat (limited to 'openmp/runtime/src/ompt-general.cpp')
-rw-r--r-- | openmp/runtime/src/ompt-general.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/openmp/runtime/src/ompt-general.cpp b/openmp/runtime/src/ompt-general.cpp index 80a859196e6..595bf556dff 100644 --- a/openmp/runtime/src/ompt-general.cpp +++ b/openmp/runtime/src/ompt-general.cpp @@ -450,6 +450,9 @@ OMPT_API_ROUTINE ompt_set_result_t ompt_set_callback(ompt_callbacks_t which, 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) \ @@ -457,7 +460,7 @@ OMPT_API_ROUTINE int ompt_get_callback(ompt_callbacks_t which, 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; \ } \ @@ -480,11 +483,15 @@ OMPT_API_ROUTINE int ompt_get_callback(ompt_callbacks_t which, 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); } OMPT_API_ROUTINE int ompt_get_state(ompt_wait_id_t *wait_id) { + if (!ompt_enabled.enabled) + return omp_state_work_serial; int thread_state = __ompt_get_state_internal(wait_id); if (thread_state == ompt_state_undefined) { @@ -499,6 +506,8 @@ OMPT_API_ROUTINE int ompt_get_state(ompt_wait_id_t *wait_id) { ****************************************************************************/ OMPT_API_ROUTINE ompt_data_t *ompt_get_thread_data(void) { + if (!ompt_enabled.enabled) + return NULL; return __ompt_get_thread_data_internal(); } @@ -507,6 +516,8 @@ OMPT_API_ROUTINE int ompt_get_task_info(int ancestor_level, int *type, ompt_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); } @@ -581,7 +592,7 @@ OMPT_API_ROUTINE int ompt_get_place_num(void) { #if !KMP_AFFINITY_SUPPORTED return -1; #else - if (__kmp_get_gtid() < 0) + if (!ompt_enabled.enabled || __kmp_get_gtid() < 0) return -1; int gtid; @@ -602,7 +613,7 @@ OMPT_API_ROUTINE int ompt_get_partition_place_nums(int place_nums_size, #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; @@ -637,7 +648,7 @@ OMPT_API_ROUTINE int ompt_get_partition_place_nums(int place_nums_size, ****************************************************************************/ OMPT_API_ROUTINE int ompt_get_proc_id(void) { - if (__kmp_get_gtid() < 0) + if (!ompt_enabled.enabled || __kmp_get_gtid() < 0) return -1; #if KMP_OS_LINUX return sched_getcpu(); |