1 #include "kmp_config.h" 2 3 #if USE_ITT_BUILD 4 /* 5 * kmp_itt.cpp -- ITT Notify interface. 6 */ 7 8 //===----------------------------------------------------------------------===// 9 // 10 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 11 // See https://llvm.org/LICENSE.txt for license information. 12 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 13 // 14 //===----------------------------------------------------------------------===// 15 16 #include "kmp_itt.h" 17 18 #if KMP_DEBUG 19 #include "kmp_itt.inl" 20 #endif 21 22 #if USE_ITT_NOTIFY 23 24 #include "ittnotify_config.h" 25 __itt_global __kmp_ittapi_clean_global; 26 extern __itt_global __kmp_itt__ittapi_global; 27 28 kmp_itthash_t __kmp_itt_barrier_domains = {{0}, 0}; 29 kmp_itthash_t __kmp_itt_region_domains = {{0}, 0}; 30 __itt_domain *metadata_domain = NULL; 31 __itt_string_handle *string_handle_imbl = NULL; 32 __itt_string_handle *string_handle_loop = NULL; 33 __itt_string_handle *string_handle_sngl = NULL; 34 35 #include "kmp_i18n.h" 36 #include "kmp_str.h" 37 #include "kmp_version.h" 38 39 KMP_BUILD_ASSERT(sizeof(kmp_itt_mark_t) == sizeof(__itt_mark_type)); 40 41 /* Previously used warnings: 42 43 KMP_WARNING( IttAllNotifDisabled ); 44 KMP_WARNING( IttObjNotifDisabled ); 45 KMP_WARNING( IttMarkNotifDisabled ); 46 KMP_WARNING( IttUnloadLibFailed, libittnotify ); 47 */ 48 49 kmp_int32 __kmp_itt_prepare_delay = 0; 50 kmp_bootstrap_lock_t __kmp_itt_debug_lock = 51 KMP_BOOTSTRAP_LOCK_INITIALIZER(__kmp_itt_debug_lock); 52 53 #endif // USE_ITT_NOTIFY 54 55 void __kmp_itt_reset() { 56 #if USE_ITT_NOTIFY 57 __kmp_itt__ittapi_global = __kmp_ittapi_clean_global; 58 #endif 59 } 60 61 void __kmp_itt_initialize() { 62 63 // ITTNotify library is loaded and initialized at first call to any ittnotify 64 // function, so we do not need to explicitly load it any more. Just report OMP 65 // RTL version to ITTNotify. 66 67 #if USE_ITT_NOTIFY 68 // Backup a clean global state 69 __kmp_ittapi_clean_global = __kmp_itt__ittapi_global; 70 71 // Report OpenMP RTL version. 72 kmp_str_buf_t buf; 73 __itt_mark_type version; 74 __kmp_str_buf_init(&buf); 75 __kmp_str_buf_print(&buf, "OMP RTL Version %d.%d.%d", __kmp_version_major, 76 __kmp_version_minor, __kmp_version_build); 77 if (__itt_api_version_ptr != NULL) { 78 __kmp_str_buf_print(&buf, ":%s", __itt_api_version()); 79 } 80 version = __itt_mark_create(buf.str); 81 __itt_mark(version, NULL); 82 __kmp_str_buf_free(&buf); 83 #endif 84 85 } // __kmp_itt_initialize 86 87 void __kmp_itt_destroy() { 88 #if USE_ITT_NOTIFY 89 __kmp_itt_fini_ittlib(); 90 #endif 91 } // __kmp_itt_destroy 92 93 extern "C" void __itt_error_handler(__itt_error_code err, va_list args) { 94 95 switch (err) { 96 case __itt_error_no_module: { 97 char const *library = va_arg(args, char const *); 98 #if KMP_OS_WINDOWS 99 int sys_err = va_arg(args, int); 100 kmp_msg_t err_code = KMP_SYSERRCODE(sys_err); 101 __kmp_msg(kmp_ms_warning, KMP_MSG(IttLoadLibFailed, library), err_code, 102 __kmp_msg_null); 103 if (__kmp_generate_warnings == kmp_warnings_off) { 104 __kmp_str_free(&err_code.str); 105 } 106 #else 107 char const *sys_err = va_arg(args, char const *); 108 kmp_msg_t err_code = KMP_SYSERRMESG(sys_err); 109 __kmp_msg(kmp_ms_warning, KMP_MSG(IttLoadLibFailed, library), err_code, 110 __kmp_msg_null); 111 if (__kmp_generate_warnings == kmp_warnings_off) { 112 __kmp_str_free(&err_code.str); 113 } 114 #endif 115 } break; 116 case __itt_error_no_symbol: { 117 char const *library = va_arg(args, char const *); 118 char const *symbol = va_arg(args, char const *); 119 KMP_WARNING(IttLookupFailed, symbol, library); 120 } break; 121 case __itt_error_unknown_group: { 122 char const *var = va_arg(args, char const *); 123 char const *group = va_arg(args, char const *); 124 KMP_WARNING(IttUnknownGroup, var, group); 125 } break; 126 case __itt_error_env_too_long: { 127 char const *var = va_arg(args, char const *); 128 size_t act_len = va_arg(args, size_t); 129 size_t max_len = va_arg(args, size_t); 130 KMP_WARNING(IttEnvVarTooLong, var, (unsigned long)act_len, 131 (unsigned long)max_len); 132 } break; 133 case __itt_error_cant_read_env: { 134 char const *var = va_arg(args, char const *); 135 int sys_err = va_arg(args, int); 136 kmp_msg_t err_code = KMP_ERR(sys_err); 137 __kmp_msg(kmp_ms_warning, KMP_MSG(CantGetEnvVar, var), err_code, 138 __kmp_msg_null); 139 if (__kmp_generate_warnings == kmp_warnings_off) { 140 __kmp_str_free(&err_code.str); 141 } 142 } break; 143 case __itt_error_system: { 144 char const *func = va_arg(args, char const *); 145 int sys_err = va_arg(args, int); 146 kmp_msg_t err_code = KMP_SYSERRCODE(sys_err); 147 __kmp_msg(kmp_ms_warning, KMP_MSG(IttFunctionError, func), err_code, 148 __kmp_msg_null); 149 if (__kmp_generate_warnings == kmp_warnings_off) { 150 __kmp_str_free(&err_code.str); 151 } 152 } break; 153 default: { 154 KMP_WARNING(IttUnknownError, err); 155 } 156 } 157 } // __itt_error_handler 158 159 #endif /* USE_ITT_BUILD */ 160