Skip to content

Commit

Permalink
src: common: update itt to 3.23.0
Browse files Browse the repository at this point in the history
This solves the problem with library loading on Windows.
  • Loading branch information
dzarukin committed Nov 2, 2022
1 parent 365ac20 commit d23cc95
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
7 changes: 7 additions & 0 deletions src/common/ittnotify/ittnotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -3985,6 +3985,13 @@ ITT_STUBV(ITTAPI, void, histogram_submit, (__itt_histogram* hist, size_t length,
* @return collection state as a enum __itt_collection_state
*/
__itt_collection_state __itt_get_collection_state(void);

/**
* @brief function releases resources allocated by ITT API static part
* this API should be called from the library destructor
* @return void
*/
void __itt_release_resources(void);
/** @endcond */

#ifdef __cplusplus
Expand Down
18 changes: 17 additions & 1 deletion src/common/ittnotify/ittnotify_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
#define API_VERSION_BUILD 20180723

#ifndef API_VERSION_NUM
#define API_VERSION_NUM 3.22.5
#define API_VERSION_NUM 3.23.0
#endif /* API_VERSION_NUM */

#define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
Expand Down Expand Up @@ -243,6 +243,7 @@ typedef pthread_mutex_t mutex_t;
#define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
#define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
#define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
#define __itt_mutex_destroy(mutex) DeleteCriticalSection(mutex)
#define __itt_load_lib(name) LoadLibraryA(name)
#define __itt_unload_lib(handle) FreeLibrary(handle)
#define __itt_system_error() (int)GetLastError()
Expand All @@ -258,6 +259,13 @@ ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
{
return InterlockedIncrement(ptr);
}
ITT_INLINE long
__itt_interlocked_compare_exchange(volatile long* ptr, long exchange, long comperand) ITT_INLINE_ATTRIBUTE;
ITT_INLINE long
__itt_interlocked_compare_exchange(volatile long* ptr, long exchange, long comperand)
{
return InterlockedCompareExchange(ptr, exchange, comperand);
}
#endif /* ITT_SIMPLE_INIT */

#define DL_SYMBOLS (1)
Expand Down Expand Up @@ -287,6 +295,7 @@ ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
}
#define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
#define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
#define __itt_mutex_destroy(mutex) pthread_mutex_destroy(mutex)
#define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
#define __itt_unload_lib(handle) dlclose(handle)
#define __itt_system_error() errno
Expand Down Expand Up @@ -343,6 +352,13 @@ ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
{
return __TBB_machine_fetchadd4(ptr, 1) + 1L;
}
ITT_INLINE long
__itt_interlocked_compare_exchange(volatile long* ptr, long exchange, long comperand) ITT_INLINE_ATTRIBUTE;
ITT_INLINE long
__itt_interlocked_compare_exchange(volatile long* ptr, long exchange, long comperand)
{
return __sync_val_compare_and_swap(ptr, exchange, comperand);
}
#endif /* ITT_SIMPLE_INIT */

void* dlopen(const char*, int) __attribute__((weak));
Expand Down
47 changes: 34 additions & 13 deletions src/common/ittnotify/ittnotify_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static const char api_version[] = API_VERSION "\0\n@(#) $Revision$\n";
#define ITT_ATTRIBUTE_FALLTHROUGH [[gnu::fallthrough]]
#elif HAS_CPP_ATTR(clang::fallthrough)
#define ITT_ATTRIBUTE_FALLTHROUGH [[clang::fallthrough]]
#elif HAS_GNU_ATTR(fallthrough) && !defined(__INTEL_COMPILER)
#elif HAS_GNU_ATTR(fallthrough) && !__INTEL_COMPILER
#define ITT_ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
#else
#define ITT_ATTRIBUTE_FALLTHROUGH
Expand Down Expand Up @@ -127,7 +127,7 @@ static const char* ittnotify_lib_name = "libittnotify.dylib";
{ \
if (!p.mutex_initialized) \
{ \
if (__itt_interlocked_increment(&p.atomic_counter) == 1) \
if (__itt_interlocked_compare_exchange(&p.atomic_counter, 1, 0) == 0) \
{ \
__itt_mutex_init(&p.mutex); \
p.mutex_initialized = 1; \
Expand All @@ -140,6 +140,20 @@ static const char* ittnotify_lib_name = "libittnotify.dylib";
} \
}

#define ITT_MUTEX_DESTROY(p) { \
if (PTHREAD_SYMBOLS) \
{ \
if (p.mutex_initialized) \
{ \
if (__itt_interlocked_compare_exchange(&p.atomic_counter, 0, 1) == 1) \
{ \
__itt_mutex_destroy(&p.mutex); \
p.mutex_initialized = 0; \
} \
} \
} \
}

#define ITT_MODULE_OBJECT_VERSION 1

typedef int (__itt_init_ittlib_t)(const char*, __itt_group_id);
Expand Down Expand Up @@ -1255,21 +1269,17 @@ static void __itt_nullify_all_pointers(void)

static int __itt_is_collector_available(void)
{
int is_available;

ITT_MUTEX_INIT_AND_LOCK(_N_(_ittapi_global));
if (_N_(_ittapi_global).api_initialized)
if (_N_(_ittapi_global).state == __itt_collection_uninitialized)
{
__itt_mutex_unlock(&_N_(_ittapi_global).mutex);
return _N_(_ittapi_global).state == __itt_collection_init_successful;
_N_(_ittapi_global).state = (NULL == __itt_get_lib_name()) ? __itt_collection_collector_absent : __itt_collection_collector_exists;
}
if (_N_(_ittapi_global).state != __itt_collection_collector_exists && NULL == __itt_get_lib_name())
{
_N_(_ittapi_global).state = __itt_collection_collector_absent;
__itt_mutex_unlock(&_N_(_ittapi_global).mutex);
return 0;
}
_N_(_ittapi_global).state = __itt_collection_collector_exists;
is_available = (_N_(_ittapi_global).state == __itt_collection_collector_exists ||
_N_(_ittapi_global).state == __itt_collection_init_successful);
__itt_mutex_unlock(&_N_(_ittapi_global).mutex);
return 1;
return is_available;
}

#if ITT_PLATFORM==ITT_PLATFORM_WIN
Expand Down Expand Up @@ -1572,3 +1582,14 @@ ITT_EXTERN_C __itt_collection_state (_N_(get_collection_state))(void)
return _N_(_ittapi_global).state;
}

/* !!! should be called from the library destructor !!!
* this function destroys the mutex and frees resources
* allocated by ITT API static part
*/
ITT_EXTERN_C void (_N_(release_resources))(void)
{
ITT_MUTEX_INIT_AND_LOCK(_N_(_ittapi_global));
__itt_free_allocated_resources();
if (PTHREAD_SYMBOLS) __itt_mutex_unlock(&_N_(_ittapi_global).mutex);
ITT_MUTEX_DESTROY(_N_(_ittapi_global));
}
15 changes: 0 additions & 15 deletions src/common/ittnotify/jitprofiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ static const char rcsid[] = "\n@(#) $Revision$\n";
#endif /* NEW_DLL_ENVIRONMENT_VAR */

#if ITT_PLATFORM==ITT_PLATFORM_WIN
#define DEFAULT_DLLNAME "JitPI.dll"
HINSTANCE m_libHandle = NULL;
#elif ITT_PLATFORM==ITT_PLATFORM_MAC
#define DEFAULT_DLLNAME "libJitPI.dylib"
void* m_libHandle = NULL;
#else
#define DEFAULT_DLLNAME "libJitPI.so"
void* m_libHandle = NULL;
#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */

Expand Down Expand Up @@ -206,18 +203,6 @@ static int loadiJIT_Funcs()
}
#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */

if (!m_libHandle)
{
#if ITT_PLATFORM==ITT_PLATFORM_WIN
m_libHandle = LoadLibraryA(DEFAULT_DLLNAME);
#else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
if (DL_SYMBOLS)
{
m_libHandle = dlopen(DEFAULT_DLLNAME, RTLD_LAZY);
}
#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
}

/* if the dll wasn't loaded - exit. */
if (!m_libHandle)
{
Expand Down

0 comments on commit d23cc95

Please sign in to comment.