ARGOBOTS  dce6e727ffc4ca5b3ffc04cb9517c6689be51ec5
tool.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
8 #ifndef ABT_CONFIG_DISABLE_TOOL_INTERFACE
9 ABTU_ret_err static inline int tool_query(ABTI_tool_context *p_tctx,
10  ABT_tool_query_kind query_kind,
11  void *val);
12 #endif
13 
84  uint64_t event_mask, void *user_arg)
85 {
86  ABTI_UB_ASSERT(ABTI_initialized());
87 
88 #ifdef ABT_CONFIG_DISABLE_TOOL_INTERFACE
89  ABTI_HANDLE_ERROR(ABT_ERR_FEATURE_NA);
90 #else
91  ABTI_global *p_global;
92  ABTI_SETUP_GLOBAL(&p_global);
93 
94  if (cb_func == NULL)
95  event_mask = ABT_TOOL_EVENT_THREAD_NONE;
96  ABTI_tool_event_thread_update_callback(p_global, cb_func,
97  event_mask &
99  user_arg);
100  return ABT_SUCCESS;
101 #endif
102 }
103 
235 int ABT_tool_query_thread(ABT_tool_context context, uint64_t event,
236  ABT_tool_query_kind query_kind, void *val)
237 {
238  ABTI_UB_ASSERT(ABTI_initialized());
239  ABTI_UB_ASSERT(val);
240 
241 #ifdef ABT_CONFIG_DISABLE_TOOL_INTERFACE
242  ABTI_HANDLE_ERROR(ABT_ERR_FEATURE_NA);
243 #else
244  ABTI_tool_context *p_tctx = ABTI_tool_context_get_ptr(context);
245  ABTI_CHECK_NULL_TOOL_CONTEXT_PTR(p_tctx);
246 
247  int abt_errno = tool_query(p_tctx, query_kind, val);
248  ABTI_CHECK_ERROR(abt_errno);
249  return ABT_SUCCESS;
250 #endif
251 }
252 
253 /*****************************************************************************/
254 /* Internal static functions */
255 /*****************************************************************************/
256 
257 #ifndef ABT_CONFIG_DISABLE_TOOL_INTERFACE
258 ABTU_ret_err static inline int
259 tool_query(ABTI_tool_context *p_tctx, ABT_tool_query_kind query_kind, void *val)
260 {
261  switch (query_kind) {
263  *(ABT_pool *)val = ABTI_pool_get_handle(p_tctx->p_pool);
264  break;
266  if (!p_tctx->p_parent) {
267  *(int *)val = 0;
268  } else {
269  int depth = 0;
270  ABTI_thread *p_cur = p_tctx->p_parent;
271  while (p_cur) {
272  depth++;
273  p_cur = p_cur->p_parent;
274  }
275  /* We do not count the root thread, so -1. */
276  *(int *)val = depth - 1;
277  }
278  break;
280  if (!p_tctx->p_caller) {
282  } else {
284  }
285  break;
287  if (!p_tctx->p_caller) {
288  *(void **)val = NULL;
289  } else {
290  *(ABT_thread *)val = ABTI_thread_get_handle(p_tctx->p_caller);
291  }
292  break;
294  *(ABT_sync_event_type *)val = p_tctx->sync_event_type;
295  break;
297  switch (p_tctx->sync_event_type) {
299  *(ABT_xstream *)val = ABTI_xstream_get_handle(
300  (ABTI_xstream *)p_tctx->p_sync_object);
301  break;
303  *(ABT_thread *)val = ABTI_thread_get_handle(
304  (ABTI_thread *)p_tctx->p_sync_object);
305  break;
307  *(ABT_mutex *)val = ABTI_mutex_get_handle(
308  (ABTI_mutex *)p_tctx->p_sync_object);
309  break;
311  *(ABT_cond *)val = ABTI_cond_get_handle(
312  (ABTI_cond *)p_tctx->p_sync_object);
313  break;
315  *(ABT_rwlock *)val = ABTI_rwlock_get_handle(
316  (ABTI_rwlock *)p_tctx->p_sync_object);
317  break;
319  *(ABT_eventual *)val = ABTI_eventual_get_handle(
320  (ABTI_eventual *)p_tctx->p_sync_object);
321  break;
323  *(ABT_future *)val = ABTI_future_get_handle(
324  (ABTI_future *)p_tctx->p_sync_object);
325  break;
327  *(ABT_barrier *)val = ABTI_barrier_get_handle(
328  (ABTI_barrier *)p_tctx->p_sync_object);
329  break;
330  default:
331  *(void **)val = NULL;
332  }
333  break;
334  default:
335  ABTI_HANDLE_ERROR(ABT_ERR_OTHER);
336  }
337  return ABT_SUCCESS;
338 }
339 #endif
ABT_tool_query_kind
ABT_tool_query_kind
Tool query kind for ABT_tool_query_thread().
Definition: abt.h:666
ABT_TOOL_QUERY_KIND_STACK_DEPTH
@ ABT_TOOL_QUERY_KIND_STACK_DEPTH
Definition: abt.h:670
ABT_EXEC_ENTITY_TYPE_EXT
@ ABT_EXEC_ENTITY_TYPE_EXT
Definition: abt.h:687
ABT_TOOL_QUERY_KIND_CALLER_HANDLE
@ ABT_TOOL_QUERY_KIND_CALLER_HANDLE
Definition: abt.h:674
ABT_thread
struct ABT_thread_opaque * ABT_thread
Work unit handle type.
Definition: abt.h:932
ABT_TOOL_QUERY_KIND_SYNC_OBJECT_TYPE
@ ABT_TOOL_QUERY_KIND_SYNC_OBJECT_TYPE
Definition: abt.h:676
ABT_exec_entity_type
ABT_exec_entity_type
Type of execution entity.
Definition: abt.h:685
ABT_tool_register_thread_callback
int ABT_tool_register_thread_callback(ABT_tool_thread_callback_fn cb_func, uint64_t event_mask, void *user_arg)
Register a callback function for work-unit events.
Definition: tool.c:83
ABT_SYNC_EVENT_TYPE_XSTREAM_JOIN
@ ABT_SYNC_EVENT_TYPE_XSTREAM_JOIN
Definition: abt.h:704
ABT_mutex
struct ABT_mutex_opaque * ABT_mutex
Mutex handle type.
Definition: abt.h:987
ABT_SYNC_EVENT_TYPE_MUTEX
@ ABT_SYNC_EVENT_TYPE_MUTEX
Definition: abt.h:708
ABT_SYNC_EVENT_TYPE_FUTURE
@ ABT_SYNC_EVENT_TYPE_FUTURE
Definition: abt.h:716
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:878
ABT_TOOL_QUERY_KIND_CALLER_TYPE
@ ABT_TOOL_QUERY_KIND_CALLER_TYPE
Definition: abt.h:672
ABT_sync_event_type
ABT_sync_event_type
Type of synchronization event.
Definition: abt.h:696
abti.h
ABT_tool_context
struct ABT_tool_context_opaque * ABT_tool_context
Tool context handle type.
Definition: abt.h:1055
ABT_xstream
struct ABT_xstream_opaque * ABT_xstream
Execution stream handle type.
Definition: abt.h:826
ABT_barrier
struct ABT_barrier_opaque * ABT_barrier
Barrier handle type.
Definition: abt.h:1029
ABT_future
struct ABT_future_opaque * ABT_future
Future handle type.
Definition: abt.h:1022
ABT_TOOL_EVENT_THREAD_ALL
#define ABT_TOOL_EVENT_THREAD_ALL
Work-unit-event mask: all events.
Definition: abt.h:780
ABT_SYNC_EVENT_TYPE_COND
@ ABT_SYNC_EVENT_TYPE_COND
Definition: abt.h:710
ABT_eventual
struct ABT_eventual_opaque * ABT_eventual
Eventual handle type.
Definition: abt.h:1015
ABT_SUCCESS
#define ABT_SUCCESS
Error code: the routine returns successfully.
Definition: abt.h:92
ABT_TOOL_QUERY_KIND_POOL
@ ABT_TOOL_QUERY_KIND_POOL
Definition: abt.h:668
ABT_SYNC_EVENT_TYPE_BARRIER
@ ABT_SYNC_EVENT_TYPE_BARRIER
Definition: abt.h:718
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:155
ABT_SYNC_EVENT_TYPE_EVENTUAL
@ ABT_SYNC_EVENT_TYPE_EVENTUAL
Definition: abt.h:714
ABT_SYNC_EVENT_TYPE_RWLOCK
@ ABT_SYNC_EVENT_TYPE_RWLOCK
Definition: abt.h:712
ABT_SYNC_EVENT_TYPE_THREAD_JOIN
@ ABT_SYNC_EVENT_TYPE_THREAD_JOIN
Definition: abt.h:706
ABT_TOOL_EVENT_THREAD_NONE
#define ABT_TOOL_EVENT_THREAD_NONE
Work-unit-event mask: none.
Definition: abt.h:725
tool_query
static ABTU_ret_err int tool_query(ABTI_tool_context *p_tctx, ABT_tool_query_kind query_kind, void *val)
Definition: tool.c:259
ABT_tool_query_thread
int ABT_tool_query_thread(ABT_tool_context context, uint64_t event, ABT_tool_query_kind query_kind, void *val)
Query information associated with a work-unit event.
Definition: tool.c:235
ABT_ERR_OTHER
#define ABT_ERR_OTHER
Error code: other error.
Definition: abt.h:109
ABT_cond
struct ABT_cond_opaque * ABT_cond
Condition variable handle type.
Definition: abt.h:1001
ABT_TOOL_QUERY_KIND_SYNC_OBJECT_HANDLE
@ ABT_TOOL_QUERY_KIND_SYNC_OBJECT_HANDLE
Definition: abt.h:678
ABT_ERR_FEATURE_NA
#define ABT_ERR_FEATURE_NA
Error code: unsupported feature.
Definition: abt.h:391
ABT_EXEC_ENTITY_TYPE_THREAD
@ ABT_EXEC_ENTITY_TYPE_THREAD
Definition: abt.h:689
ABT_tool_thread_callback_fn
void(* ABT_tool_thread_callback_fn)(ABT_thread, ABT_xstream, uint64_t event, ABT_tool_context context, void *user_arg)
Definition: abt.h:2307
ABT_rwlock
struct ABT_rwlock_opaque * ABT_rwlock
Readers-writer lock handle type.
Definition: abt.h:1008