1/*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===* 2 * 3 * The LLVM Compiler Infrastructure 4 * 5 * This file is distributed under the University of Illinois Open Source 6 * License. See LICENSE.TXT for details. 7 * 8 *===----------------------------------------------------------------------===* 9 * 10 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time) 11 * Profiling API internal config. 12 * 13 *===----------------------------------------------------------------------===*/ 14#ifndef _ITTNOTIFY_CONFIG_H_ 15#define _ITTNOTIFY_CONFIG_H_ 16 17/** @cond exclude_from_documentation */ 18#ifndef ITT_OS_WIN 19# define ITT_OS_WIN 1 20#endif /* ITT_OS_WIN */ 21 22#ifndef ITT_OS_LINUX 23# define ITT_OS_LINUX 2 24#endif /* ITT_OS_LINUX */ 25 26#ifndef ITT_OS_MAC 27# define ITT_OS_MAC 3 28#endif /* ITT_OS_MAC */ 29 30#ifndef ITT_OS 31# if defined WIN32 || defined _WIN32 32# define ITT_OS ITT_OS_WIN 33# elif defined( __APPLE__ ) && defined( __MACH__ ) 34# define ITT_OS ITT_OS_MAC 35# else 36# define ITT_OS ITT_OS_LINUX 37# endif 38#endif /* ITT_OS */ 39 40#ifndef ITT_PLATFORM_WIN 41# define ITT_PLATFORM_WIN 1 42#endif /* ITT_PLATFORM_WIN */ 43 44#ifndef ITT_PLATFORM_POSIX 45# define ITT_PLATFORM_POSIX 2 46#endif /* ITT_PLATFORM_POSIX */ 47 48#ifndef ITT_PLATFORM 49# if ITT_OS==ITT_OS_WIN 50# define ITT_PLATFORM ITT_PLATFORM_WIN 51# else 52# define ITT_PLATFORM ITT_PLATFORM_POSIX 53# endif /* _WIN32 */ 54#endif /* ITT_PLATFORM */ 55 56#if defined(_UNICODE) && !defined(UNICODE) 57#define UNICODE 58#endif 59 60#include <stddef.h> 61#if ITT_PLATFORM==ITT_PLATFORM_WIN 62#include <tchar.h> 63#else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 64#include <stdint.h> 65#if defined(UNICODE) || defined(_UNICODE) 66#include <wchar.h> 67#endif /* UNICODE || _UNICODE */ 68#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 69 70#ifndef CDECL 71# if ITT_PLATFORM==ITT_PLATFORM_WIN 72# define CDECL __cdecl 73# else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 74# if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 75# define CDECL /* not actual on x86_64 platform */ 76# else /* _M_X64 || _M_AMD64 || __x86_64__ */ 77# define CDECL __attribute__ ((cdecl)) 78# endif /* _M_X64 || _M_AMD64 || __x86_64__ */ 79# endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 80#endif /* CDECL */ 81 82#ifndef STDCALL 83# if ITT_PLATFORM==ITT_PLATFORM_WIN 84# define STDCALL __stdcall 85# else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 86# if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 87# define STDCALL /* not supported on x86_64 platform */ 88# else /* _M_X64 || _M_AMD64 || __x86_64__ */ 89# define STDCALL __attribute__ ((stdcall)) 90# endif /* _M_X64 || _M_AMD64 || __x86_64__ */ 91# endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 92#endif /* STDCALL */ 93 94#define ITTAPI CDECL 95#define LIBITTAPI CDECL 96 97/* TODO: Temporary for compatibility! */ 98#define ITTAPI_CALL CDECL 99#define LIBITTAPI_CALL CDECL 100 101#if ITT_PLATFORM==ITT_PLATFORM_WIN 102/* use __forceinline (VC++ specific) */ 103#define ITT_INLINE __forceinline 104#define ITT_INLINE_ATTRIBUTE /* nothing */ 105#else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 106/* 107 * Generally, functions are not inlined unless optimization is specified. 108 * For functions declared inline, this attribute inlines the function even 109 * if no optimization level was specified. 110 */ 111#ifdef __STRICT_ANSI__ 112#define ITT_INLINE static 113#else /* __STRICT_ANSI__ */ 114#define ITT_INLINE static inline 115#endif /* __STRICT_ANSI__ */ 116#define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline)) 117#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 118/** @endcond */ 119 120#ifndef ITT_ARCH_IA32 121# define ITT_ARCH_IA32 1 122#endif /* ITT_ARCH_IA32 */ 123 124#ifndef ITT_ARCH_IA32E 125# define ITT_ARCH_IA32E 2 126#endif /* ITT_ARCH_IA32E */ 127 128#ifndef ITT_ARCH_IA64 129# define ITT_ARCH_IA64 3 130#endif /* ITT_ARCH_IA64 */ 131 132#ifndef ITT_ARCH 133# if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 134# define ITT_ARCH ITT_ARCH_IA32E 135# elif defined _M_IA64 || defined __ia64 136# define ITT_ARCH ITT_ARCH_IA64 137# else 138# define ITT_ARCH ITT_ARCH_IA32 139# endif 140#endif 141 142#ifdef __cplusplus 143# define ITT_EXTERN_C extern "C" 144#else 145# define ITT_EXTERN_C /* nothing */ 146#endif /* __cplusplus */ 147 148#define ITT_TO_STR_AUX(x) #x 149#define ITT_TO_STR(x) ITT_TO_STR_AUX(x) 150 151#define __ITT_BUILD_ASSERT(expr, suffix) do { \ 152 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \ 153 __itt_build_check_##suffix[0] = 0; \ 154} while(0) 155#define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix) 156#define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__) 157 158#define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 } 159 160/* Replace with snapshot date YYYYMMDD for promotion build. */ 161#define API_VERSION_BUILD 20111111 162 163#ifndef API_VERSION_NUM 164#define API_VERSION_NUM 0.0.0 165#endif /* API_VERSION_NUM */ 166 167#define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \ 168 " (" ITT_TO_STR(API_VERSION_BUILD) ")" 169 170/* OS communication functions */ 171#if ITT_PLATFORM==ITT_PLATFORM_WIN 172#include <windows.h> 173typedef HMODULE lib_t; 174typedef DWORD TIDT; 175typedef CRITICAL_SECTION mutex_t; 176#define MUTEX_INITIALIZER { 0 } 177#define strong_alias(name, aliasname) /* empty for Windows */ 178#else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 179#include <dlfcn.h> 180#if defined(UNICODE) || defined(_UNICODE) 181#include <wchar.h> 182#endif /* UNICODE */ 183#ifndef _GNU_SOURCE 184#define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */ 185#endif /* _GNU_SOURCE */ 186#include <pthread.h> 187typedef void* lib_t; 188typedef pthread_t TIDT; 189typedef pthread_mutex_t mutex_t; 190#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER 191#define _strong_alias(name, aliasname) \ 192 extern __typeof (name) aliasname __attribute__ ((alias (#name))); 193#define strong_alias(name, aliasname) _strong_alias(name, aliasname) 194#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 195 196#if ITT_PLATFORM==ITT_PLATFORM_WIN 197#define __itt_get_proc(lib, name) GetProcAddress(lib, name) 198#define __itt_mutex_init(mutex) InitializeCriticalSection(mutex) 199#define __itt_mutex_lock(mutex) EnterCriticalSection(mutex) 200#define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex) 201#define __itt_load_lib(name) LoadLibraryA(name) 202#define __itt_unload_lib(handle) FreeLibrary(handle) 203#define __itt_system_error() (int)GetLastError() 204#define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2) 205#define __itt_fstrlen(s) lstrlenA(s) 206#define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l) 207#define __itt_fstrdup(s) _strdup(s) 208#define __itt_thread_id() GetCurrentThreadId() 209#define __itt_thread_yield() SwitchToThread() 210#ifndef ITT_SIMPLE_INIT 211ITT_INLINE long 212__itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE; 213ITT_INLINE long __itt_interlocked_increment(volatile long* ptr) 214{ 215 return InterlockedIncrement(ptr); 216} 217#endif /* ITT_SIMPLE_INIT */ 218#else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */ 219#define __itt_get_proc(lib, name) dlsym(lib, name) 220#define __itt_mutex_init(mutex) {\ 221 pthread_mutexattr_t mutex_attr; \ 222 int error_code = pthread_mutexattr_init(&mutex_attr); \ 223 if (error_code) \ 224 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \ 225 error_code); \ 226 error_code = pthread_mutexattr_settype(&mutex_attr, \ 227 PTHREAD_MUTEX_RECURSIVE); \ 228 if (error_code) \ 229 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \ 230 error_code); \ 231 error_code = pthread_mutex_init(mutex, &mutex_attr); \ 232 if (error_code) \ 233 __itt_report_error(__itt_error_system, "pthread_mutex_init", \ 234 error_code); \ 235 error_code = pthread_mutexattr_destroy(&mutex_attr); \ 236 if (error_code) \ 237 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \ 238 error_code); \ 239} 240#define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex) 241#define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex) 242#define __itt_load_lib(name) dlopen(name, RTLD_LAZY) 243#define __itt_unload_lib(handle) dlclose(handle) 244#define __itt_system_error() errno 245#define __itt_fstrcmp(s1, s2) strcmp(s1, s2) 246#define __itt_fstrlen(s) strlen(s) 247#define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l) 248#define __itt_fstrdup(s) strdup(s) 249#define __itt_thread_id() pthread_self() 250#define __itt_thread_yield() sched_yield() 251#if ITT_ARCH==ITT_ARCH_IA64 252#ifdef __INTEL_COMPILER 253#define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val) 254#else /* __INTEL_COMPILER */ 255/* TODO: Add Support for not Intel compilers for IA64 */ 256#endif /* __INTEL_COMPILER */ 257#else /* ITT_ARCH!=ITT_ARCH_IA64 */ 258ITT_INLINE long 259__TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE; 260ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend) 261{ 262 long result; 263 __asm__ __volatile__("lock\nxadd %0,%1" 264 : "=r"(result),"=m"(*(long*)ptr) 265 : "0"(addend), "m"(*(long*)ptr) 266 : "memory"); 267 return result; 268} 269#endif /* ITT_ARCH==ITT_ARCH_IA64 */ 270#ifndef ITT_SIMPLE_INIT 271ITT_INLINE long 272__itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE; 273ITT_INLINE long __itt_interlocked_increment(volatile long* ptr) 274{ 275 return __TBB_machine_fetchadd4(ptr, 1) + 1L; 276} 277#endif /* ITT_SIMPLE_INIT */ 278#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 279 280typedef enum { 281 __itt_collection_normal = 0, 282 __itt_collection_paused = 1 283} __itt_collection_state; 284 285typedef enum { 286 __itt_thread_normal = 0, 287 __itt_thread_ignored = 1 288} __itt_thread_state; 289 290#pragma pack(push, 8) 291 292typedef struct ___itt_thread_info 293{ 294 const char* nameA; /*!< Copy of original name in ASCII. */ 295#if defined(UNICODE) || defined(_UNICODE) 296 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */ 297#else /* UNICODE || _UNICODE */ 298 void* nameW; 299#endif /* UNICODE || _UNICODE */ 300 TIDT tid; 301 __itt_thread_state state; /*!< Thread state (paused or normal) */ 302 int extra1; /*!< Reserved to the runtime */ 303 void* extra2; /*!< Reserved to the runtime */ 304 struct ___itt_thread_info* next; 305} __itt_thread_info; 306 307#include "ittnotify_types.h" /* For __itt_group_id definition */ 308 309typedef struct ___itt_api_info_20101001 310{ 311 const char* name; 312 void** func_ptr; 313 void* init_func; 314 __itt_group_id group; 315} __itt_api_info_20101001; 316 317typedef struct ___itt_api_info 318{ 319 const char* name; 320 void** func_ptr; 321 void* init_func; 322 void* null_func; 323 __itt_group_id group; 324} __itt_api_info; 325 326struct ___itt_domain; 327struct ___itt_string_handle; 328 329typedef struct ___itt_global 330{ 331 unsigned char magic[8]; 332 unsigned long version_major; 333 unsigned long version_minor; 334 unsigned long version_build; 335 volatile long api_initialized; 336 volatile long mutex_initialized; 337 volatile long atomic_counter; 338 mutex_t mutex; 339 lib_t lib; 340 void* error_handler; 341 const char** dll_path_ptr; 342 __itt_api_info* api_list_ptr; 343 struct ___itt_global* next; 344 /* Joinable structures below */ 345 __itt_thread_info* thread_list; 346 struct ___itt_domain* domain_list; 347 struct ___itt_string_handle* string_list; 348 __itt_collection_state state; 349} __itt_global; 350 351#pragma pack(pop) 352 353#define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \ 354 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \ 355 if (h != NULL) { \ 356 h->tid = t; \ 357 h->nameA = NULL; \ 358 h->nameW = n ? _wcsdup(n) : NULL; \ 359 h->state = s; \ 360 h->extra1 = 0; /* reserved */ \ 361 h->extra2 = NULL; /* reserved */ \ 362 h->next = NULL; \ 363 if (h_tail == NULL) \ 364 (gptr)->thread_list = h; \ 365 else \ 366 h_tail->next = h; \ 367 } \ 368} 369 370#define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \ 371 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \ 372 if (h != NULL) { \ 373 h->tid = t; \ 374 h->nameA = n ? __itt_fstrdup(n) : NULL; \ 375 h->nameW = NULL; \ 376 h->state = s; \ 377 h->extra1 = 0; /* reserved */ \ 378 h->extra2 = NULL; /* reserved */ \ 379 h->next = NULL; \ 380 if (h_tail == NULL) \ 381 (gptr)->thread_list = h; \ 382 else \ 383 h_tail->next = h; \ 384 } \ 385} 386 387#define NEW_DOMAIN_W(gptr,h,h_tail,name) { \ 388 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \ 389 if (h != NULL) { \ 390 h->flags = 0; /* domain is disabled by default */ \ 391 h->nameA = NULL; \ 392 h->nameW = name ? _wcsdup(name) : NULL; \ 393 h->extra1 = 0; /* reserved */ \ 394 h->extra2 = NULL; /* reserved */ \ 395 h->next = NULL; \ 396 if (h_tail == NULL) \ 397 (gptr)->domain_list = h; \ 398 else \ 399 h_tail->next = h; \ 400 } \ 401} 402 403#define NEW_DOMAIN_A(gptr,h,h_tail,name) { \ 404 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \ 405 if (h != NULL) { \ 406 h->flags = 0; /* domain is disabled by default */ \ 407 h->nameA = name ? __itt_fstrdup(name) : NULL; \ 408 h->nameW = NULL; \ 409 h->extra1 = 0; /* reserved */ \ 410 h->extra2 = NULL; /* reserved */ \ 411 h->next = NULL; \ 412 if (h_tail == NULL) \ 413 (gptr)->domain_list = h; \ 414 else \ 415 h_tail->next = h; \ 416 } \ 417} 418 419#define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \ 420 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \ 421 if (h != NULL) { \ 422 h->strA = NULL; \ 423 h->strW = name ? _wcsdup(name) : NULL; \ 424 h->extra1 = 0; /* reserved */ \ 425 h->extra2 = NULL; /* reserved */ \ 426 h->next = NULL; \ 427 if (h_tail == NULL) \ 428 (gptr)->string_list = h; \ 429 else \ 430 h_tail->next = h; \ 431 } \ 432} 433 434#define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \ 435 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \ 436 if (h != NULL) { \ 437 h->strA = name ? __itt_fstrdup(name) : NULL; \ 438 h->strW = NULL; \ 439 h->extra1 = 0; /* reserved */ \ 440 h->extra2 = NULL; /* reserved */ \ 441 h->next = NULL; \ 442 if (h_tail == NULL) \ 443 (gptr)->string_list = h; \ 444 else \ 445 h_tail->next = h; \ 446 } \ 447} 448 449#endif /* _ITTNOTIFY_CONFIG_H_ */ 450