6 #ifndef ABTI_H_INCLUDED
7 #define ABTI_H_INCLUDED
19 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
20 #define ABTI_IS_ERROR_CHECK_ENABLED 1
22 #define ABTI_IS_ERROR_CHECK_ENABLED 0
25 #ifdef ABT_CONFIG_DISABLE_EXT_THREAD
26 #define ABTI_IS_EXT_THREAD_ENABLED 0
28 #define ABTI_IS_EXT_THREAD_ENABLED 1
31 #ifdef ABT_CONFIG_DISABLE_UB_ASSERT
32 #define ABTI_IS_UB_ASSERT_ENABLED 0
34 #define ABTI_IS_UB_ASSERT_ENABLED 1
42 #define ABTI_SCHED_NUM_PRIO 3
44 #define ABTI_SCHED_REQ_FINISH (1 << 0)
45 #define ABTI_SCHED_REQ_EXIT (1 << 1)
46 #define ABTI_SCHED_REQ_REPLACE (1 << 2)
48 #define ABTI_THREAD_REQ_JOIN (1 << 0)
49 #define ABTI_THREAD_REQ_CANCEL (1 << 1)
50 #define ABTI_THREAD_REQ_MIGRATE (1 << 2)
52 #define ABTI_THREAD_INIT_ID 0xFFFFFFFFFFFFFFFF
53 #define ABTI_TASK_INIT_ID 0xFFFFFFFFFFFFFFFF
57 #define ABTI_UNIT_HASH_TABLE_SIZE_EXP 8
58 #define ABTI_UNIT_HASH_TABLE_SIZE ((size_t)(1 << ABTI_UNIT_HASH_TABLE_SIZE_EXP))
60 #define ABTI_STACK_CHECK_TYPE_NONE 0
61 #define ABTI_STACK_CHECK_TYPE_CANARY 1
62 #define ABTI_STACK_CHECK_TYPE_MPROTECT 2
63 #define ABTI_STACK_CHECK_TYPE_MPROTECT_STRICT 3
65 enum ABTI_xstream_type {
66 ABTI_XSTREAM_TYPE_PRIMARY,
67 ABTI_XSTREAM_TYPE_SECONDARY
70 enum ABTI_sched_used {
76 enum ABTI_stack_guard {
77 ABTI_STACK_GUARD_NONE = 0,
78 ABTI_STACK_GUARD_MPROTECT,
79 ABTI_STACK_GUARD_MPROTECT_STRICT,
82 #define ABTI_THREAD_TYPE_EXT ((ABTI_thread_type)0)
83 #define ABTI_THREAD_TYPE_THREAD ((ABTI_thread_type)(0x1 << 0))
84 #define ABTI_THREAD_TYPE_ROOT ((ABTI_thread_type)(0x1 << 1))
85 #define ABTI_THREAD_TYPE_PRIMARY ((ABTI_thread_type)(0x1 << 2))
86 #define ABTI_THREAD_TYPE_MAIN_SCHED ((ABTI_thread_type)(0x1 << 3))
87 #define ABTI_THREAD_TYPE_YIELDABLE ((ABTI_thread_type)(0x1 << 4))
88 #define ABTI_THREAD_TYPE_NAMED ((ABTI_thread_type)(0x1 << 5))
89 #define ABTI_THREAD_TYPE_MIGRATABLE ((ABTI_thread_type)(0x1 << 6))
94 #define ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC ((ABTI_thread_type)(0x1 << 7))
97 #define ABTI_THREAD_TYPE_MEM_MALLOC_DESC ((ABTI_thread_type)(0x1 << 8))
100 #define ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK ((ABTI_thread_type)(0x1 << 9))
103 #define ABTI_THREAD_TYPE_MEM_MALLOC_DESC_STACK ((ABTI_thread_type)(0x1 << 10))
107 #define ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_MEMPOOL_LAZY_STACK \
108 ((ABTI_thread_type)(0x1 << 11))
112 #define ABTI_THREAD_TYPE_MEM_MALLOC_DESC_MEMPOOL_LAZY_STACK \
113 ((ABTI_thread_type)(0x1 << 12))
115 #define ABTI_THREAD_TYPES_MEM \
116 (ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC | ABTI_THREAD_TYPE_MEM_MALLOC_DESC | \
117 ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK | \
118 ABTI_THREAD_TYPE_MEM_MALLOC_DESC_STACK | \
119 ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_MEMPOOL_LAZY_STACK | \
120 ABTI_THREAD_TYPE_MEM_MALLOC_DESC_MEMPOOL_LAZY_STACK)
123 #define ABTI_MUTEX_ATTR_NONE 0
125 #define ABTI_MUTEX_ATTR_RECURSIVE 1
128 #define ABTI_UNUSED(a) (void)(a)
131 typedef struct ABTI_global ABTI_global;
132 typedef struct ABTI_local ABTI_local;
133 typedef struct ABTI_local_func ABTI_local_func;
134 typedef struct ABTI_xstream ABTI_xstream;
135 typedef enum ABTI_xstream_type ABTI_xstream_type;
136 typedef struct ABTI_sched ABTI_sched;
137 typedef struct ABTI_sched_config ABTI_sched_config;
138 typedef enum ABTI_sched_used ABTI_sched_used;
139 typedef void *ABTI_sched_id;
140 typedef uintptr_t ABTI_sched_kind;
141 typedef struct ABTI_pool ABTI_pool;
142 typedef struct ABTI_pool_required_def ABTI_pool_required_def;
143 typedef struct ABTI_pool_optional_def ABTI_pool_optional_def;
144 typedef struct ABTI_pool_deprecated_def ABTI_pool_deprecated_def;
145 typedef struct ABTI_pool_old_def ABTI_pool_old_def;
146 typedef struct ABTI_pool_user_def ABTI_pool_user_def;
147 typedef struct ABTI_pool_config ABTI_pool_config;
148 typedef struct ABTI_thread ABTI_thread;
149 typedef struct ABTI_thread_attr ABTI_thread_attr;
150 typedef struct ABTI_ythread ABTI_ythread;
151 typedef struct ABTI_thread_mig_data ABTI_thread_mig_data;
152 typedef uint32_t ABTI_thread_type;
153 typedef struct ABTI_key ABTI_key;
154 typedef struct ABTI_ktelem ABTI_ktelem;
155 typedef struct ABTI_ktable ABTI_ktable;
156 typedef struct ABTI_waitlist ABTI_waitlist;
157 typedef struct ABTI_mutex_attr ABTI_mutex_attr;
158 typedef struct ABTI_mutex ABTI_mutex;
159 typedef struct ABTI_cond ABTI_cond;
160 typedef struct ABTI_rwlock ABTI_rwlock;
161 typedef struct ABTI_eventual ABTI_eventual;
162 typedef struct ABTI_future ABTI_future;
163 typedef struct ABTI_barrier ABTI_barrier;
164 typedef struct ABTI_xstream_barrier ABTI_xstream_barrier;
165 typedef struct ABTI_timer ABTI_timer;
166 #ifndef ABT_CONFIG_DISABLE_TOOL_INTERFACE
167 typedef struct ABTI_tool_context ABTI_tool_context;
171 struct ABTI_native_thread_id_opaque;
172 typedef struct ABTI_native_thread_id_opaque *ABTI_native_thread_id;
174 struct ABTI_thread_id_opaque;
175 typedef struct ABTI_thread_id_opaque *ABTI_thread_id;
177 typedef struct ABTI_atomic_unit_to_thread ABTI_atomic_unit_to_thread;
178 typedef struct ABTI_unit_to_thread_entry ABTI_unit_to_thread_entry;
179 typedef enum ABTI_stack_guard ABTI_stack_guard;
189 struct ABTI_waitlist {
190 #ifndef ABT_CONFIG_ACTIVE_WAIT_POLICY
191 ABTD_futex_multiple futex;
197 struct ABTI_mutex_attr {
207 ABTI_thread_id owner_id;
208 #ifndef ABT_CONFIG_USE_SIMPLE_MUTEX
209 ABTD_spinlock waiter_lock;
210 ABTI_waitlist waitlist;
214 struct ABTI_atomic_unit_to_thread {
218 struct ABTI_unit_to_thread_entry {
219 ABTI_atomic_unit_to_thread list;
226 ABTI_xstream *p_xstream_head;
236 uint32_t key_table_size;
237 size_t thread_stacksize;
238 size_t sched_stacksize;
239 uint32_t sched_event_freq;
240 uint64_t sched_sleep_nsec;
241 ABTI_ythread *p_primary_ythread;
245 uint32_t mutex_max_wakeups;
246 size_t sys_page_size;
247 size_t huge_page_size;
248 #ifdef ABT_CONFIG_USE_MEM_POOL
249 size_t mem_page_size;
251 uint32_t mem_max_stacks;
252 uint32_t mem_max_descs;
255 ABTI_mem_pool_global_pool mem_pool_stack;
256 ABTI_mem_pool_global_pool mem_pool_desc;
258 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
260 ABTD_spinlock mem_pool_stack_lock;
261 ABTI_mem_pool_local_pool mem_pool_stack_ext;
262 ABTD_spinlock mem_pool_desc_lock;
263 ABTI_mem_pool_local_pool mem_pool_desc_ext;
266 ABTI_stack_guard stack_guard_kind;
270 #ifndef ABT_CONFIG_DISABLE_TOOL_INTERFACE
271 ABTD_spinlock tool_writer_lock;
274 void *tool_thread_user_arg;
275 ABTD_atomic_uint64 tool_thread_event_mask_tagged;
278 ABTI_unit_to_thread_entry
279 unit_to_thread_entires[ABTI_UNIT_HASH_TABLE_SIZE];
286 struct ABTI_local_func {
288 ABTI_local *(*get_local_f)(void);
289 void (*set_local_xstream_f)(ABTI_xstream *);
290 void *(*get_local_ptr_f)(void);
294 struct ABTI_xstream {
296 ABTI_xstream *p_prev;
297 ABTI_xstream *p_next;
300 ABTI_xstream_type type;
301 ABTD_atomic_int state;
302 ABTI_sched *p_main_sched;
304 ABTD_xstream_context ctx;
308 ABTI_pool *p_root_pool;
311 ABTI_thread *p_thread;
313 #ifdef ABT_CONFIG_USE_MEM_POOL
314 ABTI_mem_pool_local_pool mem_pool_stack;
315 ABTI_mem_pool_local_pool mem_pool_desc;
320 ABTI_sched_used used;
322 ABTI_sched_kind kind;
324 ABTI_sched *p_replace_sched;
326 ABTI_ythread *p_replace_waiter;
327 ABTD_atomic_uint32 request;
330 ABTI_ythread *p_ythread;
339 #ifdef ABT_CONFIG_USE_DEBUG_LOG
344 struct ABTI_sched_config {
348 struct ABTI_pool_required_def {
357 struct ABTI_pool_optional_def {
368 struct ABTI_pool_deprecated_def {
376 struct ABTI_pool_old_def {
394 ABTD_atomic_int32 num_scheds;
395 ABTD_atomic_int32 num_blocked;
399 ABTI_pool_required_def required_def;
400 ABTI_pool_optional_def optional_def;
401 ABTI_pool_deprecated_def deprecated_def;
402 ABTI_pool_old_def old_def;
405 struct ABTI_pool_user_def {
414 ABTI_pool_required_def required_def;
415 ABTI_pool_optional_def optional_def;
418 struct ABTI_pool_config {
425 ABTD_atomic_int is_in_pool;
426 ABTI_thread_type type;
428 ABTI_xstream *p_last_xstream;
429 ABTI_thread *p_parent;
430 void (*f_thread)(
void *);
432 ABTD_atomic_int state;
433 ABTD_atomic_uint32 request;
435 ABTD_atomic_ptr p_keytable;
439 struct ABTI_thread_attr {
442 #ifndef ABT_CONFIG_DISABLE_MIGRATION
449 struct ABTI_thread_mig_data {
451 void *p_migration_cb_arg;
456 struct ABTI_ythread {
458 ABTD_ythread_context ctx;
462 void (*f_destructor)(
void *value);
468 void (*f_destructor)(
void *value);
471 ABTD_atomic_ptr p_next;
479 size_t extra_mem_size;
480 ABTD_atomic_ptr p_elems[1];
485 ABTI_mutex *p_waiter_mutex;
486 ABTI_waitlist waitlist;
496 struct ABTI_eventual {
501 ABTI_waitlist waitlist;
506 ABTD_atomic_size counter;
507 size_t num_compartments;
509 void (*p_callback)(
void **arg);
510 ABTI_waitlist waitlist;
513 struct ABTI_barrier {
515 volatile size_t counter;
517 ABTI_waitlist waitlist;
520 struct ABTI_xstream_barrier {
521 uint32_t num_waiters;
522 #ifdef HAVE_PTHREAD_BARRIER_INIT
523 ABTD_xstream_barrier bar;
527 ABTD_atomic_uint64 tag;
536 #ifndef ABT_CONFIG_DISABLE_TOOL_INTERFACE
537 struct ABTI_tool_context {
538 ABTI_thread *p_caller;
558 ABTU_ret_err int ABTI_xstream_create_primary(ABTI_global *p_global,
559 ABTI_xstream **pp_xstream);
560 void ABTI_xstream_start_primary(ABTI_global *p_global,
561 ABTI_xstream **pp_local_xstream,
562 ABTI_xstream *p_xstream,
563 ABTI_ythread *p_ythread);
564 void ABTI_xstream_free(ABTI_global *p_global, ABTI_local *p_local,
565 ABTI_xstream *p_xstream,
ABT_bool force_free);
566 void ABTI_xstream_schedule(
void *p_arg);
567 void ABTI_xstream_check_events(ABTI_xstream *p_xstream, ABTI_sched *p_sched);
568 void ABTI_xstream_print(ABTI_xstream *p_xstream, FILE *p_os,
int indent,
576 void ABTI_sched_finish(ABTI_sched *p_sched);
577 void ABTI_sched_exit(ABTI_sched *p_sched);
580 ABTI_sched_config *p_config,
581 ABTI_sched **pp_newsched);
582 void ABTI_sched_free(ABTI_global *p_global, ABTI_local *p_local,
583 ABTI_sched *p_sched,
ABT_bool force_free);
584 ABTU_ret_err int ABTI_sched_get_migration_pool(ABTI_sched *, ABTI_pool *,
586 ABT_bool ABTI_sched_has_to_stop(ABTI_sched *p_sched);
587 ABT_bool ABTI_sched_has_unit(ABTI_sched *p_sched);
588 void ABTI_sched_print(ABTI_sched *p_sched, FILE *p_os,
int indent,
590 void ABTI_sched_reset_id(
void);
593 ABTU_ret_err int ABTI_sched_config_read(
const ABTI_sched_config *p_config,
594 int idx,
void *p_val);
600 ABTI_pool **pp_newpool);
601 void ABTI_pool_free(ABTI_pool *p_pool);
604 ABTI_pool_required_def *p_required_def,
605 ABTI_pool_optional_def *p_optional_def,
606 ABTI_pool_deprecated_def *p_deprecated_def);
609 ABTI_pool_required_def *p_required_def,
610 ABTI_pool_optional_def *p_optional_def,
611 ABTI_pool_deprecated_def *p_deprecated_def);
614 ABTI_pool_required_def *p_required_def,
615 ABTI_pool_optional_def *p_optional_def,
616 ABTI_pool_deprecated_def *p_deprecated_def);
617 void ABTI_pool_print(ABTI_pool *p_pool, FILE *p_os,
int indent);
618 void ABTI_pool_reset_id(
void);
621 ABTU_ret_err int ABTI_pool_config_read(
const ABTI_pool_config *p_config,
622 int key,
void *p_val);
628 void ABTI_unit_init_hash_table(ABTI_global *p_global);
629 void ABTI_unit_finalize_hash_table(ABTI_global *p_global);
631 ABTI_thread *p_thread);
632 void ABTI_unit_unmap_thread(ABTI_global *p_global,
ABT_unit unit);
633 ABTI_thread *ABTI_unit_get_thread_from_user_defined_unit(ABTI_global *p_global,
636 ABTU_ret_err int ABTI_thread_get_mig_data(ABTI_global *p_global,
638 ABTI_thread *p_thread,
639 ABTI_thread_mig_data **pp_mig_data);
640 ABTU_ret_err int ABTI_thread_revive(ABTI_global *p_global, ABTI_local *p_local,
642 void (*thread_func)(
void *),
void *arg,
643 ABTI_thread *p_thread);
644 void ABTI_thread_join(ABTI_local **pp_local, ABTI_thread *p_thread);
645 void ABTI_thread_free(ABTI_global *p_global, ABTI_local *p_local,
646 ABTI_thread *p_thread);
647 void ABTI_thread_handle_request_cancel(ABTI_global *p_global,
648 ABTI_xstream *p_local_xstream,
649 ABTI_thread *p_thread);
650 ABTU_ret_err int ABTI_thread_handle_request_migrate(ABTI_global *p_global,
652 ABTI_thread *p_thread);
653 void ABTI_thread_print(ABTI_thread *p_thread, FILE *p_os,
int indent);
654 void ABTI_thread_reset_id(
void);
655 ABT_unit_id ABTI_thread_get_id(ABTI_thread *p_thread);
658 ABTU_ret_err int ABTI_ythread_create_root(ABTI_global *p_global,
660 ABTI_xstream *p_xstream,
661 ABTI_ythread **pp_root_ythread);
662 ABTU_ret_err int ABTI_ythread_create_primary(ABTI_global *p_global,
664 ABTI_xstream *p_xstream,
665 ABTI_ythread **p_ythread);
666 ABTU_ret_err int ABTI_ythread_create_main_sched(ABTI_global *p_global,
668 ABTI_xstream *p_xstream,
669 ABTI_sched *p_sched);
670 ABTU_ret_err int ABTI_ythread_create_sched(ABTI_global *p_global,
673 ABTI_sched *p_sched);
674 void ABTI_ythread_free_primary(ABTI_global *p_global, ABTI_local *p_local,
675 ABTI_ythread *p_ythread);
676 void ABTI_ythread_free_root(ABTI_global *p_global, ABTI_local *p_local,
677 ABTI_ythread *p_ythread);
678 void ABTI_ythread_print_stack(ABTI_global *p_global, ABTI_ythread *p_ythread,
682 void ABTI_thread_attr_print(ABTI_thread_attr *p_attr, FILE *p_os,
int indent);
684 ABTI_thread_attr_dup(
const ABTI_thread_attr *p_attr,
688 void ABTI_ktable_free(ABTI_global *p_global, ABTI_local *p_local,
689 ABTI_ktable *p_ktable);
692 void ABTI_info_print_config(ABTI_global *p_global, FILE *fp);
693 void ABTI_info_check_print_all_thread_stacks(
void);