6 #ifndef ABTI_H_INCLUDED 7 #define ABTI_H_INCLUDED 23 #define ABTI_SCHED_NUM_PRIO 3 25 #define ABTI_XSTREAM_REQ_JOIN (1 << 0) 26 #define ABTI_XSTREAM_REQ_EXIT (1 << 1) 27 #define ABTI_XSTREAM_REQ_CANCEL (1 << 2) 28 #define ABTI_XSTREAM_REQ_STOP (1 << 3) 30 #define ABTI_SCHED_REQ_FINISH (1 << 0) 31 #define ABTI_SCHED_REQ_EXIT (1 << 1) 33 #define ABTI_THREAD_REQ_JOIN (1 << 0) 34 #define ABTI_THREAD_REQ_EXIT (1 << 1) 35 #define ABTI_THREAD_REQ_CANCEL (1 << 2) 36 #define ABTI_THREAD_REQ_MIGRATE (1 << 3) 37 #define ABTI_THREAD_REQ_TERMINATE (1 << 4) 38 #define ABTI_THREAD_REQ_BLOCK (1 << 5) 39 #define ABTI_THREAD_REQ_ORPHAN (1 << 6) 40 #define ABTI_THREAD_REQ_NOPUSH (1 << 7) 41 #define ABTI_THREAD_REQ_STOP (ABTI_THREAD_REQ_EXIT | ABTI_THREAD_REQ_TERMINATE) 42 #define ABTI_THREAD_REQ_NON_YIELD \ 43 (ABTI_THREAD_REQ_EXIT | ABTI_THREAD_REQ_CANCEL | ABTI_THREAD_REQ_MIGRATE | \ 44 ABTI_THREAD_REQ_TERMINATE | ABTI_THREAD_REQ_BLOCK | \ 45 ABTI_THREAD_REQ_ORPHAN | ABTI_THREAD_REQ_NOPUSH) 47 #define ABTI_TASK_REQ_CANCEL (1 << 0) 49 #define ABTI_THREAD_INIT_ID 0xFFFFFFFFFFFFFFFF 50 #define ABTI_TASK_INIT_ID 0xFFFFFFFFFFFFFFFF 54 #define ABT_THREAD_TYPE_FULLY_FLEDGED 0 55 #define ABT_THREAD_TYPE_DYNAMIC_PROMOTION 1 57 enum ABTI_xstream_type {
58 ABTI_XSTREAM_TYPE_PRIMARY,
59 ABTI_XSTREAM_TYPE_SECONDARY
62 enum ABTI_sched_used {
68 enum ABTI_thread_type {
69 ABTI_THREAD_TYPE_MAIN,
70 ABTI_THREAD_TYPE_MAIN_SCHED,
74 enum ABTI_mutex_attr_val {
75 ABTI_MUTEX_ATTR_NONE = 0,
76 ABTI_MUTEX_ATTR_RECURSIVE = 1 << 0
79 enum ABTI_stack_type {
80 ABTI_STACK_TYPE_MEMPOOL = 0,
81 ABTI_STACK_TYPE_MALLOC,
87 #define ABTI_UNUSED(a) (void)(a) 90 typedef struct ABTI_global ABTI_global;
91 typedef struct ABTI_local ABTI_local;
92 typedef struct ABTI_local_func ABTI_local_func;
93 typedef struct ABTI_xstream ABTI_xstream;
94 typedef enum ABTI_xstream_type ABTI_xstream_type;
95 typedef struct ABTI_sched ABTI_sched;
96 typedef char *ABTI_sched_config;
97 typedef enum ABTI_sched_used ABTI_sched_used;
98 typedef void *ABTI_sched_id;
99 typedef uintptr_t ABTI_sched_kind;
100 typedef struct ABTI_pool ABTI_pool;
101 typedef struct ABTI_unit ABTI_unit;
102 typedef struct ABTI_thread_attr ABTI_thread_attr;
103 typedef struct ABTI_thread ABTI_thread;
104 typedef enum ABTI_thread_type ABTI_thread_type;
105 typedef enum ABTI_stack_type ABTI_stack_type;
106 typedef struct ABTI_thread_req_arg ABTI_thread_req_arg;
107 typedef struct ABTI_thread_list ABTI_thread_list;
108 typedef struct ABTI_thread_entry ABTI_thread_entry;
109 typedef struct ABTI_thread_htable ABTI_thread_htable;
110 typedef struct ABTI_thread_queue ABTI_thread_queue;
111 typedef struct ABTI_task ABTI_task;
112 typedef struct ABTI_key ABTI_key;
113 typedef struct ABTI_ktelem ABTI_ktelem;
114 typedef struct ABTI_ktable ABTI_ktable;
115 typedef struct ABTI_mutex_attr ABTI_mutex_attr;
116 typedef struct ABTI_mutex ABTI_mutex;
117 typedef struct ABTI_cond ABTI_cond;
118 typedef struct ABTI_rwlock ABTI_rwlock;
119 typedef struct ABTI_eventual ABTI_eventual;
120 typedef struct ABTI_future ABTI_future;
121 typedef struct ABTI_barrier ABTI_barrier;
122 typedef struct ABTI_timer ABTI_timer;
123 #ifdef ABT_CONFIG_USE_MEM_POOL 124 typedef struct ABTI_stack_header ABTI_stack_header;
125 typedef struct ABTI_page_header ABTI_page_header;
126 typedef struct ABTI_sp_header ABTI_sp_header;
130 struct ABTI_native_thread_id_opaque;
131 typedef struct ABTI_native_thread_id_opaque *ABTI_native_thread_id;
133 struct ABTI_unit_id_opaque;
134 typedef struct ABTI_unit_id_opaque *ABTI_unit_id;
140 typedef struct ABTI_spinlock ABTI_spinlock;
144 struct ABTI_mutex_attr {
146 uint32_t nesting_cnt;
147 ABTI_unit_id owner_id;
148 uint32_t max_handovers;
149 uint32_t max_wakeups;
153 ABTD_atomic_uint32 val;
154 ABTI_mutex_attr attr;
155 ABTI_thread_htable *p_htable;
156 ABTI_thread *p_handover;
157 ABTI_thread *p_giver;
163 ABTI_xstream **p_xstreams;
164 ABTI_spinlock xstreams_lock;
173 size_t thread_stacksize;
174 size_t sched_stacksize;
175 uint32_t sched_event_freq;
176 long sched_sleep_nsec;
177 ABTI_thread *p_thread_main;
179 uint32_t mutex_max_handovers;
180 uint32_t mutex_max_wakeups;
181 uint32_t os_page_size;
182 uint32_t huge_page_size;
183 #ifdef ABT_CONFIG_USE_MEM_POOL 184 ABTI_spinlock mem_task_lock;
185 uint32_t mem_page_size;
186 uint32_t mem_sp_size;
187 uint32_t mem_max_stacks;
189 ABTI_stack_header *p_mem_stack;
190 ABTI_page_header *p_mem_task;
191 ABTI_sp_header *p_mem_sph;
197 struct ABTI_local_func {
199 ABTI_local *(*get_local_f)(void);
200 void (*set_local_f)(ABTI_local *);
201 void *(*get_local_ptr_f)(void);
206 ABTI_xstream *p_xstream;
207 ABTI_thread *p_thread;
210 #ifdef ABT_CONFIG_USE_MEM_POOL 212 ABTI_stack_header *p_mem_stack;
213 ABTI_page_header *p_mem_task_head;
214 ABTI_page_header *p_mem_task_tail;
218 struct ABTI_xstream {
220 ABTI_xstream_type type;
221 ABTD_atomic_int state;
225 ABTI_spinlock sched_lock;
227 ABTD_atomic_uint32 request;
229 ABTI_sched *p_main_sched;
231 ABTD_xstream_context ctx;
235 ABTI_sched_used used;
237 ABTI_sched_kind kind;
240 ABTD_atomic_uint32 request;
243 ABTI_thread *p_thread;
245 ABTD_thread_context *p_ctx;
254 #ifdef ABT_CONFIG_USE_DEBUG_LOG 262 #ifndef ABT_CONFIG_DISABLE_POOL_CONSUMER_CHECK 263 ABTI_native_thread_id consumer_id;
265 #ifndef ABT_CONFIG_DISABLE_POOL_PRODUCER_CHECK 266 ABTI_native_thread_id producer_id;
269 ABTD_atomic_int32 num_scheds;
270 ABTD_atomic_int32 num_blocked;
271 ABTD_atomic_int32 num_migrations;
302 ABTD_atomic_int is_in_pool;
306 struct ABTI_thread_attr {
309 ABTI_stack_type stacktype;
310 #ifndef ABT_CONFIG_DISABLE_MIGRATION 318 ABTD_thread_context ctx;
320 ABTD_atomic_int state;
321 ABTD_atomic_uint32 request;
322 ABTI_xstream *p_last_xstream;
323 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 324 ABTI_sched *is_sched;
329 ABTI_thread_type type;
330 #ifndef ABT_CONFIG_DISABLE_MIGRATION 331 ABTI_thread_req_arg *p_req_arg;
334 ABTI_ktable *p_keytable;
335 ABTI_thread_attr attr;
339 #ifndef ABT_CONFIG_DISABLE_MIGRATION 340 struct ABTI_thread_req_arg {
343 ABTI_thread_req_arg *next;
347 struct ABTI_thread_list {
348 ABTI_thread_entry *head;
349 ABTI_thread_entry *tail;
352 struct ABTI_thread_entry {
353 ABTI_thread *current;
354 struct ABTI_thread_entry *next;
359 ABTI_xstream *p_xstream;
360 ABTD_atomic_int state;
361 ABTD_atomic_uint32 request;
362 void (*f_task)(
void *);
364 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 365 ABTI_sched *is_sched;
371 ABTI_ktable *p_keytable;
372 #ifndef ABT_CONFIG_DISABLE_MIGRATION 379 void (*f_destructor)(
void *value);
381 ABTD_atomic_uint32 refcount;
388 struct ABTI_ktelem *p_next;
394 ABTI_ktelem **p_elems;
399 ABTI_mutex *p_waiter_mutex;
412 struct ABTI_eventual {
423 ABTD_atomic_uint32 counter;
424 uint32_t compartments;
426 void (*p_callback)(
void **arg);
431 struct ABTI_barrier {
432 uint32_t num_waiters;
433 volatile uint32_t counter;
434 ABTI_thread **waiters;
452 void ABTI_global_update_max_xstreams(
int new_size);
455 int ABTI_local_init(ABTI_local **pp_local);
456 int ABTI_local_finalize(ABTI_local **pp_local);
459 int ABTI_xstream_create(ABTI_local **pp_local, ABTI_sched *p_sched,
460 ABTI_xstream **pp_xstream);
461 int ABTI_xstream_create_primary(ABTI_local **pp_local,
462 ABTI_xstream **pp_xstream);
463 int ABTI_xstream_start(ABTI_local *p_local, ABTI_xstream *p_xstream);
464 int ABTI_xstream_start_primary(ABTI_local **pp_local, ABTI_xstream *p_xstream,
465 ABTI_thread *p_thread);
466 int ABTI_xstream_free(ABTI_local *p_local, ABTI_xstream *p_xstream);
467 int ABTI_xstream_join(ABTI_local **pp_local, ABTI_xstream *p_xstream);
468 void ABTI_xstream_schedule(
void *p_arg);
469 int ABTI_xstream_run_unit(ABTI_local **pp_local, ABTI_xstream *p_xstream,
471 int ABTI_xstream_schedule_thread(ABTI_local **pp_local, ABTI_xstream *p_xstream,
472 ABTI_thread *p_thread);
473 void ABTI_xstream_schedule_task(ABTI_local *p_local, ABTI_xstream *p_xstream,
475 int ABTI_xstream_migrate_thread(ABTI_local *p_local, ABTI_thread *p_thread);
476 int ABTI_xstream_set_main_sched(ABTI_local **pp_local, ABTI_xstream *p_xstream,
477 ABTI_sched *p_sched);
478 int ABTI_xstream_check_events(ABTI_xstream *p_xstream,
ABT_sched sched);
479 void *ABTI_xstream_launch_main_sched(
void *p_arg);
480 void ABTI_xstream_print(ABTI_xstream *p_xstream, FILE *p_os,
int indent,
488 void ABTI_sched_finish(ABTI_sched *p_sched);
489 void ABTI_sched_exit(ABTI_sched *p_sched);
492 ABTI_sched **pp_newsched);
495 ABTI_sched **pp_newsched);
496 int ABTI_sched_free(ABTI_local *p_local, ABTI_sched *p_sched);
497 int ABTI_sched_get_migration_pool(ABTI_sched *, ABTI_pool *, ABTI_pool **);
499 ABT_bool ABTI_sched_has_to_stop(ABTI_local **pp_local, ABTI_sched *p_sched,
500 ABTI_xstream *p_xstream);
501 size_t ABTI_sched_get_size(ABTI_sched *p_sched);
502 size_t ABTI_sched_get_total_size(ABTI_sched *p_sched);
503 size_t ABTI_sched_get_effective_size(ABTI_local *p_local, ABTI_sched *p_sched);
504 void ABTI_sched_print(ABTI_sched *p_sched, FILE *p_os,
int indent,
506 void ABTI_sched_reset_id(
void);
517 ABT_bool automatic, ABTI_pool **pp_newpool);
519 ABT_bool automatic, ABTI_pool **pp_newpool);
520 void ABTI_pool_free(ABTI_pool *p_pool);
523 #ifndef ABT_CONFIG_DISABLE_POOL_CONSUMER_CHECK 524 int ABTI_pool_set_consumer(ABTI_pool *p_pool,
525 ABTI_native_thread_id consumer_id);
527 #ifndef ABT_CONFIG_DISABLE_POOL_PRODUCER_CHECK 528 int ABTI_pool_set_producer(ABTI_pool *p_pool,
529 ABTI_native_thread_id producer_id);
531 int ABTI_pool_accept_migration(ABTI_pool *p_pool, ABTI_pool *source);
532 void ABTI_pool_print(ABTI_pool *p_pool, FILE *p_os,
int indent);
533 void ABTI_pool_reset_id(
void);
536 void ABTI_unit_set_associated_pool(
ABT_unit unit, ABTI_pool *p_pool);
539 int ABTI_thread_migrate_to_pool(ABTI_local **pp_local, ABTI_thread *p_thread,
541 int ABTI_thread_create(ABTI_local *p_local, ABTI_pool *p_pool,
542 void (*thread_func)(
void *),
void *arg,
543 ABTI_thread_attr *p_attr, ABTI_thread **pp_newthread);
544 int ABTI_thread_create_main(ABTI_local *p_local, ABTI_xstream *p_xstream,
545 ABTI_thread **p_thread);
546 int ABTI_thread_create_main_sched(ABTI_local *p_local, ABTI_xstream *p_xstream,
547 ABTI_sched *p_sched);
548 int ABTI_thread_create_sched(ABTI_local *p_local, ABTI_pool *p_pool,
549 ABTI_sched *p_sched);
550 void ABTI_thread_free(ABTI_local *p_local, ABTI_thread *p_thread);
551 void ABTI_thread_free_main(ABTI_local *p_local, ABTI_thread *p_thread);
552 void ABTI_thread_free_main_sched(ABTI_local *p_local, ABTI_thread *p_thread);
553 int ABTI_thread_set_blocked(ABTI_thread *p_thread);
554 void ABTI_thread_suspend(ABTI_local **pp_local, ABTI_thread *p_thread);
555 int ABTI_thread_set_ready(ABTI_local *p_local, ABTI_thread *p_thread);
556 void ABTI_thread_print(ABTI_thread *p_thread, FILE *p_os,
int indent);
557 int ABTI_thread_print_stack(ABTI_thread *p_thread, FILE *p_os);
558 #ifndef ABT_CONFIG_DISABLE_MIGRATION 559 void ABTI_thread_add_req_arg(ABTI_thread *p_thread, uint32_t req,
void *arg);
560 void *ABTI_thread_extract_req_arg(ABTI_thread *p_thread, uint32_t req);
562 void ABTI_thread_reset_id(
void);
565 int ABTI_thread_get_xstream_rank(ABTI_thread *p_thread);
566 int ABTI_thread_self_xstream_rank(ABTI_local *p_local);
569 void ABTI_thread_attr_print(ABTI_thread_attr *p_attr, FILE *p_os,
int indent);
570 void ABTI_thread_attr_get_str(ABTI_thread_attr *p_attr,
char *p_buf);
571 ABTI_thread_attr *ABTI_thread_attr_dup(ABTI_thread_attr *p_attr);
574 ABTI_thread_htable *ABTI_thread_htable_create(uint32_t num_rows);
575 void ABTI_thread_htable_free(ABTI_thread_htable *p_htable);
576 void ABTI_thread_htable_push(ABTI_thread_htable *p_htable,
int idx,
577 ABTI_thread *p_thread);
578 ABT_bool ABTI_thread_htable_add(ABTI_thread_htable *p_htable,
int idx,
579 ABTI_thread *p_thread);
580 void ABTI_thread_htable_push_low(ABTI_thread_htable *p_htable,
int idx,
581 ABTI_thread *p_thread);
582 ABT_bool ABTI_thread_htable_add_low(ABTI_thread_htable *p_htable,
int idx,
583 ABTI_thread *p_thread);
584 ABTI_thread *ABTI_thread_htable_pop(ABTI_thread_htable *p_htable,
585 ABTI_thread_queue *p_queue);
586 ABTI_thread *ABTI_thread_htable_pop_low(ABTI_thread_htable *p_htable,
587 ABTI_thread_queue *p_queue);
588 ABT_bool ABTI_thread_htable_switch_low(ABTI_local **pp_local,
589 ABTI_thread_queue *p_queue,
590 ABTI_thread *p_thread,
591 ABTI_thread_htable *p_htable);
594 int ABTI_task_create_sched(ABTI_local *p_local, ABTI_pool *p_pool,
595 ABTI_sched *p_sched);
596 void ABTI_task_free(ABTI_local *p_local, ABTI_task *p_task);
597 void ABTI_task_print(ABTI_task *p_task, FILE *p_os,
int indent);
598 void ABTI_task_reset_id(
void);
599 uint64_t ABTI_task_get_id(ABTI_task *p_task);
602 ABTI_ktable *ABTI_ktable_alloc(
int size);
603 void ABTI_ktable_free(ABTI_ktable *p_ktable);
606 void ABTI_mutex_wait(ABTI_local **pp_local, ABTI_mutex *p_mutex,
int val);
607 void ABTI_mutex_wait_low(ABTI_local **pp_local, ABTI_mutex *p_mutex,
int val);
608 void ABTI_mutex_wake_se(ABTI_mutex *p_mutex,
int num);
609 void ABTI_mutex_wake_de(ABTI_local *p_local, ABTI_mutex *p_mutex);
612 void ABTI_mutex_attr_print(ABTI_mutex_attr *p_attr, FILE *p_os,
int indent);
613 void ABTI_mutex_attr_get_str(ABTI_mutex_attr *p_attr,
char *p_buf);
616 int ABTI_info_print_config(FILE *fp);
617 void ABTI_info_check_print_all_thread_stacks(
void);
struct ABT_unit_opaque * ABT_unit
struct ABT_sched_opaque * ABT_sched
ABT_unit(* ABT_unit_create_from_task_fn)(ABT_task)
ABT_unit(* ABT_pool_pop_fn)(ABT_pool)
struct ABT_task_opaque * ABT_task
size_t(* ABT_pool_get_size_fn)(ABT_pool)
#define ABT_CONFIG_STATIC_CACHELINE_SIZE
void(* ABT_pool_push_fn)(ABT_pool, ABT_unit)
struct ABT_pool_opaque * ABT_pool
ABT_task(* ABT_unit_get_task_fn)(ABT_unit)
struct ABT_thread_opaque * ABT_thread
ABT_pool(* ABT_sched_get_migr_pool_fn)(ABT_sched)
int(* ABT_sched_free_fn)(ABT_sched)
int(* ABT_sched_init_fn)(ABT_sched, ABT_sched_config)
ABTI_global * gp_ABTI_global
ABT_bool(* ABT_unit_is_in_pool_fn)(ABT_unit)
ABT_unit_type(* ABT_unit_get_type_fn)(ABT_unit)
void(* ABT_unit_free_fn)(ABT_unit *)
ABTI_local_func gp_ABTI_local_func
ABTD_XSTREAM_LOCAL ABTI_local * lp_ABTI_local
ABT_thread(* ABT_unit_get_thread_fn)(ABT_unit)
void(* ABT_sched_run_fn)(ABT_sched)
int(* ABT_pool_remove_fn)(ABT_pool, ABT_unit)
struct ABT_sched_config_opaque * ABT_sched_config
struct ABT_pool_config_opaque * ABT_pool_config
int(* ABT_pool_free_fn)(ABT_pool)
int(* ABT_pool_print_all_fn)(ABT_pool, void *arg, void(*)(void *, ABT_unit))
ABT_unit(* ABT_unit_create_from_thread_fn)(ABT_thread)
ABT_unit(* ABT_pool_pop_timedwait_fn)(ABT_pool, double)
int(* ABT_pool_init_fn)(ABT_pool, ABT_pool_config)