2 This file is provided under a dual BSD/GPLv2 license. When using or
3 redistributing this file, you may do so under either license.
7 Copyright (c) 2005-2012 Intel Corporation. All rights reserved.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of version 2 of the GNU General Public License as
11 published by the Free Software Foundation.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 The full GNU General Public License is included in this distribution
22 in the file called LICENSE.GPL.
25 http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
29 Copyright (c) 2005-2012 Intel Corporation. All rights reserved.
32 Redistribution and use in source and binary forms, with or without
33 modification, are permitted provided that the following conditions
36 * Redistributions of source code must retain the above copyright
37 notice, this list of conditions and the following disclaimer.
38 * Redistributions in binary form must reproduce the above copyright
39 notice, this list of conditions and the following disclaimer in
40 the documentation and/or other materials provided with the
42 * Neither the name of Intel Corporation nor the names of its
43 contributors may be used to endorse or promote products derived
44 from this software without specific prior written permission.
46 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
49 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
50 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 #ifndef _ITTNOTIFY_CONFIG_H_
59 #define _ITTNOTIFY_CONFIG_H_
61 /** @cond exclude_from_documentation */
64 #endif /* ITT_OS_WIN */
67 # define ITT_OS_LINUX 2
68 #endif /* ITT_OS_LINUX */
72 #endif /* ITT_OS_MAC */
75 # if defined WIN32 || defined _WIN32
76 # define ITT_OS ITT_OS_WIN
77 # elif defined( __APPLE__ ) && defined( __MACH__ )
78 # define ITT_OS ITT_OS_MAC
80 # define ITT_OS ITT_OS_LINUX
84 #ifndef ITT_PLATFORM_WIN
85 # define ITT_PLATFORM_WIN 1
86 #endif /* ITT_PLATFORM_WIN */
88 #ifndef ITT_PLATFORM_POSIX
89 # define ITT_PLATFORM_POSIX 2
90 #endif /* ITT_PLATFORM_POSIX */
93 # if ITT_OS==ITT_OS_WIN
94 # define ITT_PLATFORM ITT_PLATFORM_WIN
96 # define ITT_PLATFORM ITT_PLATFORM_POSIX
98 #endif /* ITT_PLATFORM */
100 #if defined(_UNICODE) && !defined(UNICODE)
105 #if ITT_PLATFORM==ITT_PLATFORM_WIN
107 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
109 #if defined(UNICODE) || defined(_UNICODE)
111 #endif /* UNICODE || _UNICODE */
112 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
115 # if ITT_PLATFORM==ITT_PLATFORM_WIN
116 # define CDECL __cdecl
117 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
118 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
119 # define CDECL /* not actual on x86_64 platform */
120 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
121 # define CDECL __attribute__ ((cdecl))
122 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
123 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
127 # if ITT_PLATFORM==ITT_PLATFORM_WIN
128 # define STDCALL __stdcall
129 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
130 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
131 # define STDCALL /* not supported on x86_64 platform */
132 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
133 # define STDCALL __attribute__ ((stdcall))
134 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
135 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
139 #define LIBITTAPI CDECL
141 /* TODO: Temporary for compatibility! */
142 #define ITTAPI_CALL CDECL
143 #define LIBITTAPI_CALL CDECL
145 #if ITT_PLATFORM==ITT_PLATFORM_WIN
146 /* use __forceinline (VC++ specific) */
147 #define ITT_INLINE __forceinline
148 #define ITT_INLINE_ATTRIBUTE /* nothing */
149 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
151 * Generally, functions are not inlined unless optimization is specified.
152 * For functions declared inline, this attribute inlines the function even
153 * if no optimization level was specified.
155 #ifdef __STRICT_ANSI__
156 #define ITT_INLINE static
157 #else /* __STRICT_ANSI__ */
158 #define ITT_INLINE static inline
159 #endif /* __STRICT_ANSI__ */
160 #define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))
161 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
164 #ifndef ITT_ARCH_IA32
165 # define ITT_ARCH_IA32 1
166 #endif /* ITT_ARCH_IA32 */
168 #ifndef ITT_ARCH_IA32E
169 # define ITT_ARCH_IA32E 2
170 #endif /* ITT_ARCH_IA32E */
172 #ifndef ITT_ARCH_IA64
173 # define ITT_ARCH_IA64 3
174 #endif /* ITT_ARCH_IA64 */
177 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
178 # define ITT_ARCH ITT_ARCH_IA32E
179 # elif defined _M_IA64 || defined __ia64
180 # define ITT_ARCH ITT_ARCH_IA64
182 # define ITT_ARCH ITT_ARCH_IA32
187 # define ITT_EXTERN_C extern "C"
189 # define ITT_EXTERN_C /* nothing */
190 #endif /* __cplusplus */
192 #define ITT_TO_STR_AUX(x) #x
193 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
195 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
196 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
197 __itt_build_check_##suffix[0] = 0; \
199 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
200 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
202 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
204 /* Replace with snapshot date YYYYMMDD for promotion build. */
205 #define API_VERSION_BUILD 20111111
207 #ifndef API_VERSION_NUM
208 #define API_VERSION_NUM 0.0.0
209 #endif /* API_VERSION_NUM */
211 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
212 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
214 /* OS communication functions */
215 #if ITT_PLATFORM==ITT_PLATFORM_WIN
217 typedef HMODULE lib_t
;
219 typedef CRITICAL_SECTION mutex_t
;
220 #define MUTEX_INITIALIZER { 0 }
221 #define strong_alias(name, aliasname) /* empty for Windows */
222 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
224 #if defined(UNICODE) || defined(_UNICODE)
228 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
229 #endif /* _GNU_SOURCE */
232 typedef pthread_t TIDT
;
233 typedef pthread_mutex_t mutex_t
;
234 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
235 #define _strong_alias(name, aliasname) \
236 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
237 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
238 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
240 #if ITT_PLATFORM==ITT_PLATFORM_WIN
241 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
242 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
243 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
244 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
245 #define __itt_load_lib(name) LoadLibraryA(name)
246 #define __itt_unload_lib(handle) FreeLibrary(handle)
247 #define __itt_system_error() (int)GetLastError()
248 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
249 #define __itt_fstrlen(s) lstrlenA(s)
250 #define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l)
251 #define __itt_fstrdup(s) _strdup(s)
252 #define __itt_thread_id() GetCurrentThreadId()
253 #define __itt_thread_yield() SwitchToThread()
254 #ifndef ITT_SIMPLE_INIT
256 __itt_interlocked_increment(volatile long* ptr
) ITT_INLINE_ATTRIBUTE
;
257 ITT_INLINE
long __itt_interlocked_increment(volatile long* ptr
)
259 return InterlockedIncrement(ptr
);
261 #endif /* ITT_SIMPLE_INIT */
262 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
263 #define __itt_get_proc(lib, name) dlsym(lib, name)
264 #define __itt_mutex_init(mutex) {\
265 pthread_mutexattr_t mutex_attr; \
266 int error_code = pthread_mutexattr_init(&mutex_attr); \
268 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
270 error_code = pthread_mutexattr_settype(&mutex_attr, \
271 PTHREAD_MUTEX_RECURSIVE); \
273 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
275 error_code = pthread_mutex_init(mutex, &mutex_attr); \
277 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
279 error_code = pthread_mutexattr_destroy(&mutex_attr); \
281 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
284 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
285 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
286 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
287 #define __itt_unload_lib(handle) dlclose(handle)
288 #define __itt_system_error() errno
289 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
290 #define __itt_fstrlen(s) strlen(s)
291 #define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l)
292 #define __itt_fstrdup(s) strdup(s)
293 #define __itt_thread_id() pthread_self()
294 #define __itt_thread_yield() sched_yield()
295 #if ITT_ARCH==ITT_ARCH_IA64
296 #ifdef __INTEL_COMPILER
297 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void*)addr, val)
298 #else /* __INTEL_COMPILER */
299 /* TODO: Add Support for not Intel compilers for IA64 */
300 #endif /* __INTEL_COMPILER */
301 #else /* ITT_ARCH!=ITT_ARCH_IA64 */
303 __TBB_machine_fetchadd4(volatile void* ptr
, long addend
) ITT_INLINE_ATTRIBUTE
;
304 ITT_INLINE
long __TBB_machine_fetchadd4(volatile void* ptr
, long addend
)
307 __asm__
__volatile__("lock\nxadd %0,%1"
308 : "=r"(result
),"=m"(*(long*)ptr
)
309 : "0"(addend
), "m"(*(long*)ptr
)
313 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
314 #ifndef ITT_SIMPLE_INIT
316 __itt_interlocked_increment(volatile long* ptr
) ITT_INLINE_ATTRIBUTE
;
317 ITT_INLINE
long __itt_interlocked_increment(volatile long* ptr
)
319 return __TBB_machine_fetchadd4(ptr
, 1) + 1L;
321 #endif /* ITT_SIMPLE_INIT */
322 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
325 __itt_collection_normal
= 0,
326 __itt_collection_paused
= 1
327 } __itt_collection_state
;
330 __itt_thread_normal
= 0,
331 __itt_thread_ignored
= 1
332 } __itt_thread_state
;
334 #pragma pack(push, 8)
336 typedef struct ___itt_thread_info
338 const char* nameA
; /*!< Copy of original name in ASCII. */
339 #if defined(UNICODE) || defined(_UNICODE)
340 const wchar_t* nameW
; /*!< Copy of original name in UNICODE. */
341 #else /* UNICODE || _UNICODE */
343 #endif /* UNICODE || _UNICODE */
345 __itt_thread_state state
; /*!< Thread state (paused or normal) */
346 int extra1
; /*!< Reserved to the runtime */
347 void* extra2
; /*!< Reserved to the runtime */
348 struct ___itt_thread_info
* next
;
351 #include "ittnotify_types.h" /* For __itt_group_id definition */
353 typedef struct ___itt_api_info_20101001
358 __itt_group_id group
;
359 } __itt_api_info_20101001
;
361 typedef struct ___itt_api_info
367 __itt_group_id group
;
370 struct ___itt_domain
;
371 struct ___itt_string_handle
;
373 typedef struct ___itt_global
375 unsigned char magic
[8];
376 unsigned long version_major
;
377 unsigned long version_minor
;
378 unsigned long version_build
;
379 volatile long api_initialized
;
380 volatile long mutex_initialized
;
381 volatile long atomic_counter
;
385 const char** dll_path_ptr
;
386 __itt_api_info
* api_list_ptr
;
387 struct ___itt_global
* next
;
388 /* Joinable structures below */
389 __itt_thread_info
* thread_list
;
390 struct ___itt_domain
* domain_list
;
391 struct ___itt_string_handle
* string_list
;
392 __itt_collection_state state
;
397 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
398 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
402 h->nameW = n ? _wcsdup(n) : NULL; \
404 h->extra1 = 0; /* reserved */ \
405 h->extra2 = NULL; /* reserved */ \
407 if (h_tail == NULL) \
408 (gptr)->thread_list = h; \
414 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
415 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
418 h->nameA = n ? __itt_fstrdup(n) : NULL; \
421 h->extra1 = 0; /* reserved */ \
422 h->extra2 = NULL; /* reserved */ \
424 if (h_tail == NULL) \
425 (gptr)->thread_list = h; \
431 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
432 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
434 h->flags = 0; /* domain is disabled by default */ \
436 h->nameW = name ? _wcsdup(name) : NULL; \
437 h->extra1 = 0; /* reserved */ \
438 h->extra2 = NULL; /* reserved */ \
440 if (h_tail == NULL) \
441 (gptr)->domain_list = h; \
447 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
448 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
450 h->flags = 0; /* domain is disabled by default */ \
451 h->nameA = name ? __itt_fstrdup(name) : NULL; \
453 h->extra1 = 0; /* reserved */ \
454 h->extra2 = NULL; /* reserved */ \
456 if (h_tail == NULL) \
457 (gptr)->domain_list = h; \
463 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
464 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
467 h->strW = name ? _wcsdup(name) : NULL; \
468 h->extra1 = 0; /* reserved */ \
469 h->extra2 = NULL; /* reserved */ \
471 if (h_tail == NULL) \
472 (gptr)->string_list = h; \
478 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
479 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
481 h->strA = name ? __itt_fstrdup(name) : NULL; \
483 h->extra1 = 0; /* reserved */ \
484 h->extra2 = NULL; /* reserved */ \
486 if (h_tail == NULL) \
487 (gptr)->string_list = h; \
493 #endif /* _ITTNOTIFY_CONFIG_H_ */