LLVM OpenMP* Runtime Library
kmp_itt.h
1 #if USE_ITT_BUILD
2 /*
3  * kmp_itt.h -- ITT Notify interface.
4  */
5 
6 
7 //===----------------------------------------------------------------------===//
8 //
9 // The LLVM Compiler Infrastructure
10 //
11 // This file is dual licensed under the MIT and the University of Illinois Open
12 // Source Licenses. See LICENSE.txt for details.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 
17 #ifndef KMP_ITT_H
18 #define KMP_ITT_H
19 
20 #include "kmp_lock.h"
21 
22 #define INTEL_ITTNOTIFY_API_PRIVATE
23 #include "ittnotify.h"
24 #include "legacy/ittnotify.h"
25 
26 #if KMP_DEBUG
27 #define __kmp_inline // Turn off inlining in debug mode.
28 #else
29 #define __kmp_inline static inline
30 #endif
31 
32 #if USE_ITT_NOTIFY
33 extern kmp_int32 __kmp_itt_prepare_delay;
34 #ifdef __cplusplus
35 extern "C" void __kmp_itt_fini_ittlib(void);
36 #else
37 extern void __kmp_itt_fini_ittlib(void);
38 #endif
39 #endif
40 
41 // Simplify the handling of an argument that is only required when USE_ITT_BUILD
42 // is enabled.
43 #define USE_ITT_BUILD_ARG(x) , x
44 
45 void __kmp_itt_initialize();
46 void __kmp_itt_destroy();
47 
48 // -----------------------------------------------------------------------------
49 // New stuff for reporting high-level constructs.
50 
51 // Note the naming convention:
52 // __kmp_itt_xxxing() function should be called before action, while
53 // __kmp_itt_xxxed() function should be called after action.
54 
55 // --- Parallel region reporting ---
56 __kmp_inline void
57 __kmp_itt_region_forking(int gtid, int team_size,
58  int barriers); // Master only, before forking threads.
59 __kmp_inline void
60 __kmp_itt_region_joined(int gtid); // Master only, after joining threads.
61 // (*) Note: A thread may execute tasks after this point, though.
62 
63 // --- Frame reporting ---
64 // region=0: no regions, region=1: parallel, region=2: serialized parallel
65 __kmp_inline void __kmp_itt_frame_submit(int gtid, __itt_timestamp begin,
66  __itt_timestamp end, int imbalance,
67  ident_t *loc, int team_size,
68  int region = 0);
69 
70 // --- Metadata reporting ---
71 // begin/end - begin/end timestamps of a barrier frame, imbalance - aggregated
72 // wait time value, reduction -if this is a reduction barrier
73 __kmp_inline void __kmp_itt_metadata_imbalance(int gtid, kmp_uint64 begin,
74  kmp_uint64 end,
75  kmp_uint64 imbalance,
76  kmp_uint64 reduction);
77 // sched_type: 0 - static, 1 - dynamic, 2 - guided, 3 - custom (all others);
78 // iterations - loop trip count, chunk - chunk size
79 __kmp_inline void __kmp_itt_metadata_loop(ident_t *loc, kmp_uint64 sched_type,
80  kmp_uint64 iterations,
81  kmp_uint64 chunk);
82 __kmp_inline void __kmp_itt_metadata_single(ident_t *loc);
83 
84 // --- Barrier reporting ---
85 __kmp_inline void *__kmp_itt_barrier_object(int gtid, int bt, int set_name = 0,
86  int delta = 0);
87 __kmp_inline void __kmp_itt_barrier_starting(int gtid, void *object);
88 __kmp_inline void __kmp_itt_barrier_middle(int gtid, void *object);
89 __kmp_inline void __kmp_itt_barrier_finished(int gtid, void *object);
90 
91 // --- Taskwait reporting ---
92 __kmp_inline void *__kmp_itt_taskwait_object(int gtid);
93 __kmp_inline void __kmp_itt_taskwait_starting(int gtid, void *object);
94 __kmp_inline void __kmp_itt_taskwait_finished(int gtid, void *object);
95 
96 // --- Task reporting ---
97 __kmp_inline void __kmp_itt_task_starting(void *object);
98 __kmp_inline void __kmp_itt_task_finished(void *object);
99 
100 // --- Lock reporting ---
101 #if KMP_USE_DYNAMIC_LOCK
102 __kmp_inline void __kmp_itt_lock_creating(kmp_user_lock_p lock,
103  const ident_t *);
104 #else
105 __kmp_inline void __kmp_itt_lock_creating(kmp_user_lock_p lock);
106 #endif
107 __kmp_inline void __kmp_itt_lock_acquiring(kmp_user_lock_p lock);
108 __kmp_inline void __kmp_itt_lock_acquired(kmp_user_lock_p lock);
109 __kmp_inline void __kmp_itt_lock_releasing(kmp_user_lock_p lock);
110 __kmp_inline void __kmp_itt_lock_cancelled(kmp_user_lock_p lock);
111 __kmp_inline void __kmp_itt_lock_destroyed(kmp_user_lock_p lock);
112 
113 // --- Critical reporting ---
114 #if KMP_USE_DYNAMIC_LOCK
115 __kmp_inline void __kmp_itt_critical_creating(kmp_user_lock_p lock,
116  const ident_t *);
117 #else
118 __kmp_inline void __kmp_itt_critical_creating(kmp_user_lock_p lock);
119 #endif
120 __kmp_inline void __kmp_itt_critical_acquiring(kmp_user_lock_p lock);
121 __kmp_inline void __kmp_itt_critical_acquired(kmp_user_lock_p lock);
122 __kmp_inline void __kmp_itt_critical_releasing(kmp_user_lock_p lock);
123 __kmp_inline void __kmp_itt_critical_destroyed(kmp_user_lock_p lock);
124 
125 // --- Single reporting ---
126 __kmp_inline void __kmp_itt_single_start(int gtid);
127 __kmp_inline void __kmp_itt_single_end(int gtid);
128 
129 // --- Ordered reporting ---
130 __kmp_inline void __kmp_itt_ordered_init(int gtid);
131 __kmp_inline void __kmp_itt_ordered_prep(int gtid);
132 __kmp_inline void __kmp_itt_ordered_start(int gtid);
133 __kmp_inline void __kmp_itt_ordered_end(int gtid);
134 
135 // --- Threads reporting ---
136 __kmp_inline void __kmp_itt_thread_ignore();
137 __kmp_inline void __kmp_itt_thread_name(int gtid);
138 
139 // --- System objects ---
140 __kmp_inline void __kmp_itt_system_object_created(void *object,
141  char const *name);
142 
143 // --- Stack stitching ---
144 __kmp_inline __itt_caller __kmp_itt_stack_caller_create(void);
145 __kmp_inline void __kmp_itt_stack_caller_destroy(__itt_caller);
146 __kmp_inline void __kmp_itt_stack_callee_enter(__itt_caller);
147 __kmp_inline void __kmp_itt_stack_callee_leave(__itt_caller);
148 
149 // -----------------------------------------------------------------------------
150 // Old stuff for reporting low-level internal synchronization.
151 
152 #if USE_ITT_NOTIFY
153 
154 /* Support for SSC marks, which are used by SDE
155  http://software.intel.com/en-us/articles/intel-software-development-emulator
156  to mark points in instruction traces that represent spin-loops and are
157  therefore uninteresting when collecting traces for architecture simulation.
158  */
159 #ifndef INCLUDE_SSC_MARKS
160 #define INCLUDE_SSC_MARKS (KMP_OS_LINUX && KMP_ARCH_X86_64)
161 #endif
162 
163 /* Linux 64 only for now */
164 #if (INCLUDE_SSC_MARKS && KMP_OS_LINUX && KMP_ARCH_X86_64)
165 // Portable (at least for gcc and icc) code to insert the necessary instructions
166 // to set %ebx and execute the unlikely no-op.
167 #if defined(__INTEL_COMPILER)
168 #define INSERT_SSC_MARK(tag) __SSC_MARK(tag)
169 #else
170 #define INSERT_SSC_MARK(tag) \
171  __asm__ __volatile__("movl %0, %%ebx; .byte 0x64, 0x67, 0x90 " ::"i"(tag) \
172  : "%ebx")
173 #endif
174 #else
175 #define INSERT_SSC_MARK(tag) ((void)0)
176 #endif
177 
178 /* Markers for the start and end of regions that represent polling and are
179  therefore uninteresting to architectural simulations 0x4376 and 0x4377 are
180  arbitrary numbers that should be unique in the space of SSC tags, but there
181  is no central issuing authority rather randomness is expected to work. */
182 #define SSC_MARK_SPIN_START() INSERT_SSC_MARK(0x4376)
183 #define SSC_MARK_SPIN_END() INSERT_SSC_MARK(0x4377)
184 
185 // Markers for architecture simulation.
186 // FORKING : Before the master thread forks.
187 // JOINING : At the start of the join.
188 // INVOKING : Before the threads invoke microtasks.
189 // DISPATCH_INIT: At the start of dynamically scheduled loop.
190 // DISPATCH_NEXT: After claming next iteration of dynamically scheduled loop.
191 #define SSC_MARK_FORKING() INSERT_SSC_MARK(0xd693)
192 #define SSC_MARK_JOINING() INSERT_SSC_MARK(0xd694)
193 #define SSC_MARK_INVOKING() INSERT_SSC_MARK(0xd695)
194 #define SSC_MARK_DISPATCH_INIT() INSERT_SSC_MARK(0xd696)
195 #define SSC_MARK_DISPATCH_NEXT() INSERT_SSC_MARK(0xd697)
196 
197 // The object is an address that associates a specific set of the prepare,
198 // acquire, release, and cancel operations.
199 
200 /* Sync prepare indicates a thread is going to start waiting for another thread
201  to send a release event. This operation should be done just before the
202  thread begins checking for the existence of the release event */
203 
204 /* Sync cancel indicates a thread is cancelling a wait on another thread and
205  continuing execution without waiting for the other thread to release it */
206 
207 /* Sync acquired indicates a thread has received a release event from another
208  thread and has stopped waiting. This operation must occur only after the
209  release event is received. */
210 
211 /* Sync release indicates a thread is going to send a release event to another
212  thread so it will stop waiting and continue execution. This operation must
213  just happen before the release event. */
214 
215 #define KMP_FSYNC_PREPARE(obj) __itt_fsync_prepare((void *)(obj))
216 #define KMP_FSYNC_CANCEL(obj) __itt_fsync_cancel((void *)(obj))
217 #define KMP_FSYNC_ACQUIRED(obj) __itt_fsync_acquired((void *)(obj))
218 #define KMP_FSYNC_RELEASING(obj) __itt_fsync_releasing((void *)(obj))
219 
220 /* In case of waiting in a spin loop, ITT wants KMP_FSYNC_PREPARE() to be called
221  with a delay (and not called at all if waiting time is small). So, in spin
222  loops, do not use KMP_FSYNC_PREPARE(), but use KMP_FSYNC_SPIN_INIT() (before
223  spin loop), KMP_FSYNC_SPIN_PREPARE() (whithin the spin loop), and
224  KMP_FSYNC_SPIN_ACQUIRED(). See KMP_WAIT_YIELD() for example. */
225 
226 #undef KMP_FSYNC_SPIN_INIT
227 #define KMP_FSYNC_SPIN_INIT(obj, spin) \
228  int sync_iters = 0; \
229  if (__itt_fsync_prepare_ptr) { \
230  if (obj == NULL) { \
231  obj = spin; \
232  } /* if */ \
233  } /* if */ \
234  SSC_MARK_SPIN_START()
235 
236 #undef KMP_FSYNC_SPIN_PREPARE
237 #define KMP_FSYNC_SPIN_PREPARE(obj) \
238  do { \
239  if (__itt_fsync_prepare_ptr && sync_iters < __kmp_itt_prepare_delay) { \
240  ++sync_iters; \
241  if (sync_iters >= __kmp_itt_prepare_delay) { \
242  KMP_FSYNC_PREPARE((void *)obj); \
243  } /* if */ \
244  } /* if */ \
245  } while (0)
246 #undef KMP_FSYNC_SPIN_ACQUIRED
247 #define KMP_FSYNC_SPIN_ACQUIRED(obj) \
248  do { \
249  SSC_MARK_SPIN_END(); \
250  if (sync_iters >= __kmp_itt_prepare_delay) { \
251  KMP_FSYNC_ACQUIRED((void *)obj); \
252  } /* if */ \
253  } while (0)
254 
255 /* ITT will not report objects created within KMP_ITT_IGNORE(), e. g.:
256  KMP_ITT_IGNORE(
257  ptr = malloc( size );
258  );
259 */
260 #define KMP_ITT_IGNORE(statement) \
261  do { \
262  __itt_state_t __itt_state_; \
263  if (__itt_state_get_ptr) { \
264  __itt_state_ = __itt_state_get(); \
265  __itt_obj_mode_set(__itt_obj_prop_ignore, __itt_obj_state_set); \
266  } /* if */ \
267  { statement } \
268  if (__itt_state_get_ptr) { \
269  __itt_state_set(__itt_state_); \
270  } /* if */ \
271  } while (0)
272 
273 const int KMP_MAX_FRAME_DOMAINS =
274  512; // Maximum number of frame domains to use (maps to
275 // different OpenMP regions in the user source code).
276 extern kmp_int32 __kmp_barrier_domain_count;
277 extern kmp_int32 __kmp_region_domain_count;
278 extern __itt_domain *__kmp_itt_barrier_domains[KMP_MAX_FRAME_DOMAINS];
279 extern __itt_domain *__kmp_itt_region_domains[KMP_MAX_FRAME_DOMAINS];
280 extern __itt_domain *__kmp_itt_imbalance_domains[KMP_MAX_FRAME_DOMAINS];
281 extern kmp_int32 __kmp_itt_region_team_size[KMP_MAX_FRAME_DOMAINS];
282 extern __itt_domain *metadata_domain;
283 extern __itt_string_handle *string_handle_imbl;
284 extern __itt_string_handle *string_handle_loop;
285 extern __itt_string_handle *string_handle_sngl;
286 
287 #else
288 
289 // Null definitions of the synchronization tracing functions.
290 #define KMP_FSYNC_PREPARE(obj) ((void)0)
291 #define KMP_FSYNC_CANCEL(obj) ((void)0)
292 #define KMP_FSYNC_ACQUIRED(obj) ((void)0)
293 #define KMP_FSYNC_RELEASING(obj) ((void)0)
294 
295 #define KMP_FSYNC_SPIN_INIT(obj, spin) ((void)0)
296 #define KMP_FSYNC_SPIN_PREPARE(obj) ((void)0)
297 #define KMP_FSYNC_SPIN_ACQUIRED(obj) ((void)0)
298 
299 #define KMP_ITT_IGNORE(stmt) \
300  do { \
301  stmt \
302  } while (0)
303 
304 #endif // USE_ITT_NOTIFY
305 
306 #if !KMP_DEBUG
307 // In release mode include definitions of inline functions.
308 #include "kmp_itt.inl"
309 #endif
310 
311 #endif // KMP_ITT_H
312 
313 #else /* USE_ITT_BUILD */
314 
315 // Null definitions of the synchronization tracing functions.
316 // If USE_ITT_BULID is not enabled, USE_ITT_NOTIFY cannot be either.
317 // By defining these we avoid unpleasant ifdef tests in many places.
318 #define KMP_FSYNC_PREPARE(obj) ((void)0)
319 #define KMP_FSYNC_CANCEL(obj) ((void)0)
320 #define KMP_FSYNC_ACQUIRED(obj) ((void)0)
321 #define KMP_FSYNC_RELEASING(obj) ((void)0)
322 
323 #define KMP_FSYNC_SPIN_INIT(obj, spin) ((void)0)
324 #define KMP_FSYNC_SPIN_PREPARE(obj) ((void)0)
325 #define KMP_FSYNC_SPIN_ACQUIRED(obj) ((void)0)
326 
327 #define KMP_ITT_IGNORE(stmt) \
328  do { \
329  stmt \
330  } while (0)
331 
332 #define USE_ITT_BUILD_ARG(x)
333 
334 #endif /* USE_ITT_BUILD */
Definition: kmp.h:208
sched_type
Definition: kmp.h:315