3 * kmp_itt.h -- ITT Notify interface.
6 //===----------------------------------------------------------------------===//
8 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9 // See https://llvm.org/LICENSE.txt for license information.
10 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12 //===----------------------------------------------------------------------===//
19 #define INTEL_ITTNOTIFY_API_PRIVATE
20 #include "ittnotify.h"
21 #include "legacy/ittnotify.h"
24 #define __kmp_inline // Turn off inlining in debug mode.
26 #define __kmp_inline static inline
30 extern kmp_int32 __kmp_itt_prepare_delay;
32 extern "C" void __kmp_itt_fini_ittlib(void);
34 extern void __kmp_itt_fini_ittlib(void);
38 // Simplify the handling of an argument that is only required when USE_ITT_BUILD
40 #define USE_ITT_BUILD_ARG(x) , x
42 void __kmp_itt_initialize();
43 void __kmp_itt_destroy();
44 void __kmp_itt_reset();
46 // -----------------------------------------------------------------------------
47 // New stuff for reporting high-level constructs.
49 // Note the naming convention:
50 // __kmp_itt_xxxing() function should be called before action, while
51 // __kmp_itt_xxxed() function should be called after action.
53 // --- Parallel region reporting ---
55 __kmp_itt_region_forking(int gtid, int team_size,
56 int barriers); // Master only, before forking threads.
58 __kmp_itt_region_joined(int gtid); // Master only, after joining threads.
59 // (*) Note: A thread may execute tasks after this point, though.
61 // --- Frame reporting ---
62 // region=0: no regions, region=1: parallel, region=2: serialized parallel
63 __kmp_inline void __kmp_itt_frame_submit(int gtid, __itt_timestamp begin,
64 __itt_timestamp end, int imbalance,
65 ident_t *loc, int team_size,
68 // --- Metadata reporting ---
69 // begin/end - begin/end timestamps of a barrier frame, imbalance - aggregated
70 // wait time value, reduction -if this is a reduction barrier
71 __kmp_inline void __kmp_itt_metadata_imbalance(int gtid, kmp_uint64 begin,
74 kmp_uint64 reduction);
75 // sched_type: 0 - static, 1 - dynamic, 2 - guided, 3 - custom (all others);
76 // iterations - loop trip count, chunk - chunk size
77 __kmp_inline void __kmp_itt_metadata_loop(ident_t *loc, kmp_uint64 sched_type,
78 kmp_uint64 iterations,
80 __kmp_inline void __kmp_itt_metadata_single(ident_t *loc);
82 // --- Barrier reporting ---
83 __kmp_inline void *__kmp_itt_barrier_object(int gtid, int bt, int set_name = 0,
85 __kmp_inline void __kmp_itt_barrier_starting(int gtid, void *object);
86 __kmp_inline void __kmp_itt_barrier_middle(int gtid, void *object);
87 __kmp_inline void __kmp_itt_barrier_finished(int gtid, void *object);
89 // --- Taskwait reporting ---
90 __kmp_inline void *__kmp_itt_taskwait_object(int gtid);
91 __kmp_inline void __kmp_itt_taskwait_starting(int gtid, void *object);
92 __kmp_inline void __kmp_itt_taskwait_finished(int gtid, void *object);
94 // --- Task reporting ---
95 __kmp_inline void __kmp_itt_task_starting(void *object);
96 __kmp_inline void __kmp_itt_task_finished(void *object);
98 // --- Lock reporting ---
99 #if KMP_USE_DYNAMIC_LOCK
100 __kmp_inline void __kmp_itt_lock_creating(kmp_user_lock_p lock,
103 __kmp_inline void __kmp_itt_lock_creating(kmp_user_lock_p lock);
105 __kmp_inline void __kmp_itt_lock_acquiring(kmp_user_lock_p lock);
106 __kmp_inline void __kmp_itt_lock_acquired(kmp_user_lock_p lock);
107 __kmp_inline void __kmp_itt_lock_releasing(kmp_user_lock_p lock);
108 __kmp_inline void __kmp_itt_lock_cancelled(kmp_user_lock_p lock);
109 __kmp_inline void __kmp_itt_lock_destroyed(kmp_user_lock_p lock);
111 // --- Critical reporting ---
112 #if KMP_USE_DYNAMIC_LOCK
113 __kmp_inline void __kmp_itt_critical_creating(kmp_user_lock_p lock,
116 __kmp_inline void __kmp_itt_critical_creating(kmp_user_lock_p lock);
118 __kmp_inline void __kmp_itt_critical_acquiring(kmp_user_lock_p lock);
119 __kmp_inline void __kmp_itt_critical_acquired(kmp_user_lock_p lock);
120 __kmp_inline void __kmp_itt_critical_releasing(kmp_user_lock_p lock);
121 __kmp_inline void __kmp_itt_critical_destroyed(kmp_user_lock_p lock);
123 // --- Single reporting ---
124 __kmp_inline void __kmp_itt_single_start(int gtid);
125 __kmp_inline void __kmp_itt_single_end(int gtid);
127 // --- Ordered reporting ---
128 __kmp_inline void __kmp_itt_ordered_init(int gtid);
129 __kmp_inline void __kmp_itt_ordered_prep(int gtid);
130 __kmp_inline void __kmp_itt_ordered_start(int gtid);
131 __kmp_inline void __kmp_itt_ordered_end(int gtid);
133 // --- Threads reporting ---
134 __kmp_inline void __kmp_itt_thread_ignore();
135 __kmp_inline void __kmp_itt_thread_name(int gtid);
137 // --- System objects ---
138 __kmp_inline void __kmp_itt_system_object_created(void *object,
141 // --- Stack stitching ---
142 __kmp_inline __itt_caller __kmp_itt_stack_caller_create(void);
143 __kmp_inline void __kmp_itt_stack_caller_destroy(__itt_caller);
144 __kmp_inline void __kmp_itt_stack_callee_enter(__itt_caller);
145 __kmp_inline void __kmp_itt_stack_callee_leave(__itt_caller);
147 // -----------------------------------------------------------------------------
148 // Old stuff for reporting low-level internal synchronization.
152 /* Support for SSC marks, which are used by SDE
153 http://software.intel.com/en-us/articles/intel-software-development-emulator
154 to mark points in instruction traces that represent spin-loops and are
155 therefore uninteresting when collecting traces for architecture simulation.
157 #ifndef INCLUDE_SSC_MARKS
158 #define INCLUDE_SSC_MARKS (KMP_OS_LINUX && KMP_ARCH_X86_64)
161 /* Linux 64 only for now */
162 #if (INCLUDE_SSC_MARKS && KMP_OS_LINUX && KMP_ARCH_X86_64)
163 // Portable (at least for gcc and icc) code to insert the necessary instructions
164 // to set %ebx and execute the unlikely no-op.
165 #if defined(__INTEL_COMPILER)
166 #define INSERT_SSC_MARK(tag) __SSC_MARK(tag)
168 #define INSERT_SSC_MARK(tag) \
169 __asm__ __volatile__("movl %0, %%ebx; .byte 0x64, 0x67, 0x90 " ::"i"(tag) \
173 #define INSERT_SSC_MARK(tag) ((void)0)
176 /* Markers for the start and end of regions that represent polling and are
177 therefore uninteresting to architectural simulations 0x4376 and 0x4377 are
178 arbitrary numbers that should be unique in the space of SSC tags, but there
179 is no central issuing authority rather randomness is expected to work. */
180 #define SSC_MARK_SPIN_START() INSERT_SSC_MARK(0x4376)
181 #define SSC_MARK_SPIN_END() INSERT_SSC_MARK(0x4377)
183 // Markers for architecture simulation.
184 // FORKING : Before the master thread forks.
185 // JOINING : At the start of the join.
186 // INVOKING : Before the threads invoke microtasks.
187 // DISPATCH_INIT: At the start of dynamically scheduled loop.
188 // DISPATCH_NEXT: After claming next iteration of dynamically scheduled loop.
189 #define SSC_MARK_FORKING() INSERT_SSC_MARK(0xd693)
190 #define SSC_MARK_JOINING() INSERT_SSC_MARK(0xd694)
191 #define SSC_MARK_INVOKING() INSERT_SSC_MARK(0xd695)
192 #define SSC_MARK_DISPATCH_INIT() INSERT_SSC_MARK(0xd696)
193 #define SSC_MARK_DISPATCH_NEXT() INSERT_SSC_MARK(0xd697)
195 // The object is an address that associates a specific set of the prepare,
196 // acquire, release, and cancel operations.
198 /* Sync prepare indicates a thread is going to start waiting for another thread
199 to send a release event. This operation should be done just before the
200 thread begins checking for the existence of the release event */
202 /* Sync cancel indicates a thread is cancelling a wait on another thread and
203 continuing execution without waiting for the other thread to release it */
205 /* Sync acquired indicates a thread has received a release event from another
206 thread and has stopped waiting. This operation must occur only after the
207 release event is received. */
209 /* Sync release indicates a thread is going to send a release event to another
210 thread so it will stop waiting and continue execution. This operation must
211 just happen before the release event. */
213 #define KMP_FSYNC_PREPARE(obj) __itt_fsync_prepare((void *)(obj))
214 #define KMP_FSYNC_CANCEL(obj) __itt_fsync_cancel((void *)(obj))
215 #define KMP_FSYNC_ACQUIRED(obj) __itt_fsync_acquired((void *)(obj))
216 #define KMP_FSYNC_RELEASING(obj) __itt_fsync_releasing((void *)(obj))
218 /* In case of waiting in a spin loop, ITT wants KMP_FSYNC_PREPARE() to be called
219 with a delay (and not called at all if waiting time is small). So, in spin
220 loops, do not use KMP_FSYNC_PREPARE(), but use KMP_FSYNC_SPIN_INIT() (before
221 spin loop), KMP_FSYNC_SPIN_PREPARE() (whithin the spin loop), and
222 KMP_FSYNC_SPIN_ACQUIRED(). See KMP_WAIT() for example. */
224 #undef KMP_FSYNC_SPIN_INIT
225 #define KMP_FSYNC_SPIN_INIT(obj, spin) \
226 int sync_iters = 0; \
227 if (__itt_fsync_prepare_ptr) { \
232 SSC_MARK_SPIN_START()
234 #undef KMP_FSYNC_SPIN_PREPARE
235 #define KMP_FSYNC_SPIN_PREPARE(obj) \
237 if (__itt_fsync_prepare_ptr && sync_iters < __kmp_itt_prepare_delay) { \
239 if (sync_iters >= __kmp_itt_prepare_delay) { \
240 KMP_FSYNC_PREPARE((void *)obj); \
244 #undef KMP_FSYNC_SPIN_ACQUIRED
245 #define KMP_FSYNC_SPIN_ACQUIRED(obj) \
247 SSC_MARK_SPIN_END(); \
248 if (sync_iters >= __kmp_itt_prepare_delay) { \
249 KMP_FSYNC_ACQUIRED((void *)obj); \
253 /* ITT will not report objects created within KMP_ITT_IGNORE(), e. g.:
255 ptr = malloc( size );
258 #define KMP_ITT_IGNORE(statement) \
260 __itt_state_t __itt_state_; \
261 if (__itt_state_get_ptr) { \
262 __itt_state_ = __itt_state_get(); \
263 __itt_obj_mode_set(__itt_obj_prop_ignore, __itt_obj_state_set); \
266 if (__itt_state_get_ptr) { \
267 __itt_state_set(__itt_state_); \
271 const int KMP_MAX_FRAME_DOMAINS =
272 512; // Maximum number of frame domains to use (maps to
273 // different OpenMP regions in the user source code).
274 extern kmp_int32 __kmp_barrier_domain_count;
275 extern kmp_int32 __kmp_region_domain_count;
276 extern __itt_domain *__kmp_itt_barrier_domains[KMP_MAX_FRAME_DOMAINS];
277 extern __itt_domain *__kmp_itt_region_domains[KMP_MAX_FRAME_DOMAINS];
278 extern __itt_domain *__kmp_itt_imbalance_domains[KMP_MAX_FRAME_DOMAINS];
279 extern kmp_int32 __kmp_itt_region_team_size[KMP_MAX_FRAME_DOMAINS];
280 extern __itt_domain *metadata_domain;
281 extern __itt_string_handle *string_handle_imbl;
282 extern __itt_string_handle *string_handle_loop;
283 extern __itt_string_handle *string_handle_sngl;
287 // Null definitions of the synchronization tracing functions.
288 #define KMP_FSYNC_PREPARE(obj) ((void)0)
289 #define KMP_FSYNC_CANCEL(obj) ((void)0)
290 #define KMP_FSYNC_ACQUIRED(obj) ((void)0)
291 #define KMP_FSYNC_RELEASING(obj) ((void)0)
293 #define KMP_FSYNC_SPIN_INIT(obj, spin) ((void)0)
294 #define KMP_FSYNC_SPIN_PREPARE(obj) ((void)0)
295 #define KMP_FSYNC_SPIN_ACQUIRED(obj) ((void)0)
297 #define KMP_ITT_IGNORE(stmt) \
302 #endif // USE_ITT_NOTIFY
305 // In release mode include definitions of inline functions.
306 #include "kmp_itt.inl"
311 #else /* USE_ITT_BUILD */
313 // Null definitions of the synchronization tracing functions.
314 // If USE_ITT_BULID is not enabled, USE_ITT_NOTIFY cannot be either.
315 // By defining these we avoid unpleasant ifdef tests in many places.
316 #define KMP_FSYNC_PREPARE(obj) ((void)0)
317 #define KMP_FSYNC_CANCEL(obj) ((void)0)
318 #define KMP_FSYNC_ACQUIRED(obj) ((void)0)
319 #define KMP_FSYNC_RELEASING(obj) ((void)0)
321 #define KMP_FSYNC_SPIN_INIT(obj, spin) ((void)0)
322 #define KMP_FSYNC_SPIN_PREPARE(obj) ((void)0)
323 #define KMP_FSYNC_SPIN_ACQUIRED(obj) ((void)0)
325 #define KMP_ITT_IGNORE(stmt) \
330 #define USE_ITT_BUILD_ARG(x)
332 #endif /* USE_ITT_BUILD */