10 #define ABTD_KEY_TABLE_DEFAULT_SIZE 4
11 #define ABTD_SCHED_DEFAULT_STACKSIZE (4 * 1024 * 1024)
12 #define ABTD_SCHED_EVENT_FREQ 50
13 #define ABTD_SCHED_SLEEP_NSEC 100
15 #define ABTD_SYS_PAGE_SIZE 4096
16 #define ABTD_HUGE_PAGE_SIZE (2 * 1024 * 1024)
17 #define ABTD_MEM_PAGE_SIZE (2 * 1024 * 1024)
18 #define ABTD_MEM_STACK_PAGE_SIZE (8 * 1024 * 1024)
19 #define ABTD_MEM_MAX_NUM_STACKS 1024
20 #define ABTD_MEM_MAX_TOTAL_STACK_SIZE (64 * 1024 * 1024)
21 #define ABTD_MEM_MAX_NUM_DESCS 4096
25 #define ABTD_ENV_INT_MAX ((int)(INT_MAX / 2))
26 #define ABTD_ENV_UINT32_MAX ((uint32_t)(UINT32_MAX / 2))
27 #define ABTD_ENV_UINT64_MAX ((uint64_t)(UINT64_MAX / 2))
28 #define ABTD_ENV_SIZE_MAX ((size_t)(SIZE_MAX / 2))
32 static const char *
get_abt_env(
const char *env_suffix);
36 static int load_env_int(
const char *env_suffix,
int default_val,
int min_val,
38 static uint32_t
load_env_uint32(
const char *env_suffix, uint32_t default_val,
39 uint32_t min_val, uint32_t max_val);
40 static uint64_t
load_env_uint64(
const char *env_suffix, uint64_t default_val,
41 uint64_t min_val, uint64_t max_val);
42 static size_t load_env_size(
const char *env_suffix,
size_t default_val,
43 size_t min_val,
size_t max_val);
45 void ABTD_env_init(ABTI_global *p_global)
50 p_global->num_cores = sysconf(_SC_NPROCESSORS_ONLN);
59 ABTD_affinity_init(p_global, env);
63 p_global->use_logging = ABTD_env_get_use_logging();
65 p_global->use_debug = ABTD_env_get_use_debug();
67 p_global->max_xstreams = ABTD_env_get_max_xstreams();
69 p_global->key_table_size = ABTD_env_key_table_size();
72 if (ABTD_env_get_stack_guard_mprotect(&is_strict)) {
74 p_global->stack_guard_kind = ABTI_STACK_GUARD_MPROTECT_STRICT;
76 p_global->stack_guard_kind = ABTI_STACK_GUARD_MPROTECT;
80 p_global->stack_guard_kind = ABTI_STACK_GUARD_NONE;
83 p_global->sys_page_size = ABTD_env_get_sys_pagesize();
85 p_global->thread_stacksize = ABTD_env_get_thread_stacksize();
87 p_global->sched_stacksize = ABTD_env_get_sched_stacksize();
89 p_global->sched_event_freq = ABTD_env_get_sched_event_freq();
91 p_global->sched_sleep_nsec = ABTD_env_get_sched_sleep_nsec();
95 p_global->mutex_max_handovers =
100 p_global->mutex_max_wakeups =
105 #ifdef ABT_CONFIG_DISABLE_STACK_UNWIND_DUMP_RAW_STACK
108 p_global->print_raw_stack =
114 : ABTD_HUGE_PAGE_SIZE;
115 p_global->huge_page_size =
116 load_env_size(
"HUGE_PAGE_SIZE", default_huge_page_size, 4096,
119 #ifdef ABT_CONFIG_USE_MEM_POOL
124 4096, ABTD_ENV_SIZE_MAX),
129 p_global->mem_sp_size =
131 ABTD_MEM_STACK_PAGE_SIZE,
132 p_global->thread_stacksize * 4,
140 const uint32_t default_mem_max_stacks =
142 p_global->thread_stacksize,
143 ABTD_MEM_MAX_NUM_STACKS);
145 p_global->mem_max_stacks =
147 default_mem_max_stacks,
149 ABTD_ENV_UINT32_MAX),
155 p_global->mem_max_descs =
157 ABTD_MEM_MAX_NUM_DESCS,
159 ABTD_ENV_UINT32_MAX),
167 #if defined(HAVE_MAP_ANONYMOUS) || defined(HAVE_MAP_ANON)
176 lp_alloc = ABTI_MEM_LP_MMAP_HP_RP;
182 #ifdef ABT_CONFIG_USE_HUGE_PAGE_DEFAULT
185 lp_alloc = ABTI_MEM_LP_MMAP_HP_RP;
187 lp_alloc = ABTI_MEM_LP_MMAP_RP;
191 lp_alloc = ABTI_MEM_LP_MMAP_RP;
196 lp_alloc = ABTI_MEM_LP_MALLOC;
200 if (strcasecmp(env,
"malloc") == 0) {
201 lp_alloc = ABTI_MEM_LP_MALLOC;
202 #if defined(HAVE_MAP_ANONYMOUS) || defined(HAVE_MAP_ANON)
203 }
else if (strcasecmp(env,
"mmap_rp") == 0) {
204 lp_alloc = ABTI_MEM_LP_MMAP_RP;
205 }
else if (strcasecmp(env,
"mmap_hp_rp") == 0) {
206 lp_alloc = ABTI_MEM_LP_MMAP_HP_RP;
207 }
else if (strcasecmp(env,
"mmap_hp_thp") == 0) {
208 lp_alloc = ABTI_MEM_LP_MMAP_HP_THP;
210 }
else if (strcasecmp(env,
"thp") == 0) {
211 lp_alloc = ABTI_MEM_LP_THP;
216 if (lp_alloc != ABTI_MEM_LP_MALLOC) {
217 p_global->mem_lp_alloc = ABTI_mem_check_lp_alloc(p_global, lp_alloc);
219 p_global->mem_lp_alloc = lp_alloc;
224 p_global->print_config = ABTD_env_get_print_config();
230 ABT_bool ABTD_env_get_use_debug(
void)
232 #ifdef ABT_CONFIG_USE_DEBUG_LOG_PRINT
241 ABT_bool ABTD_env_get_use_logging(
void)
243 #ifdef ABT_CONFIG_USE_DEBUG_LOG_PRINT
255 ABT_bool ABTD_env_get_print_config(
void)
261 int ABTD_env_get_max_xstreams(
void)
263 const int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
265 return load_env_int(
"MAX_NUM_XSTREAMS", num_cores, 1, ABTD_ENV_INT_MAX);
268 uint32_t ABTD_env_key_table_size(
void)
272 ABTD_KEY_TABLE_DEFAULT_SIZE, 1,
273 ABTD_ENV_UINT32_MAX));
276 size_t ABTD_env_get_sys_pagesize(
void)
280 size_t sys_page_size = ABTD_SYS_PAGE_SIZE;
282 sys_page_size = getpagesize();
285 load_env_size(
"SYS_PAGE_SIZE", sys_page_size, 64, ABTD_ENV_SIZE_MAX));
288 size_t ABTD_env_get_thread_stacksize(
void)
291 if (ABTD_env_get_stack_guard_mprotect(NULL)) {
294 const size_t sys_page_size = ABTD_env_get_sys_pagesize();
295 default_thread_stacksize += sys_page_size * 2;
299 default_thread_stacksize, 512,
304 size_t ABTD_env_get_sched_stacksize(
void)
306 size_t default_sched_stacksize = ABTD_SCHED_DEFAULT_STACKSIZE;
307 if (ABTD_env_get_stack_guard_mprotect(NULL)) {
310 const size_t sys_page_size = ABTD_env_get_sys_pagesize();
311 default_sched_stacksize += sys_page_size * 2;
315 default_sched_stacksize, 512,
320 uint32_t ABTD_env_get_sched_event_freq(
void)
324 ABTD_ENV_UINT32_MAX);
327 uint64_t ABTD_env_get_sched_sleep_nsec(
void)
331 ABTD_ENV_UINT64_MAX);
337 const char *env =
get_abt_env(
"STACK_OVERFLOW_CHECK");
340 if (strcasecmp(env,
"mprotect_strict") == 0) {
343 }
else if (strcasecmp(env,
"mprotect") == 0) {
353 #if ABT_CONFIG_STACK_CHECK_TYPE == ABTI_STACK_CHECK_TYPE_MPROTECT
356 #elif ABT_CONFIG_STACK_CHECK_TYPE == ABTI_STACK_CHECK_TYPE_MPROTECT_STRICT
365 *is_strict = strict_val;
381 for (i = 0; i <
sizeof(uint32_t) * 8 - 1; i++) {
382 if ((val - 1) >> i == 0)
385 return ((uint32_t)1) << i;
393 for (i = 0; i <
sizeof(size_t) * 8 - 1; i++) {
394 if ((val - 1) >> i == 0)
397 return ((
size_t)1) << i;
404 const char *prefixes[] = {
"ABT_",
"ABT_ENV_" };
406 for (i = 0; i <
sizeof(prefixes) /
sizeof(prefixes[0]); i++) {
407 int prefix_size = strlen(prefixes[i]);
408 int env_suffix_size = strlen(env_suffix);
409 if (prefix_size + env_suffix_size + 1 <= (
int)
sizeof(buffer)) {
410 memcpy(buffer, prefixes[i], prefix_size);
411 memcpy(buffer + prefix_size, env_suffix, env_suffix_size);
412 buffer[prefix_size + env_suffix_size] =
'\0';
413 const char *env = getenv(buffer);
423 if (include0 && strcmp(str,
"0") == 0) {
425 }
else if (strcasecmp(str,
"n") == 0 || strcasecmp(str,
"no") == 0 ||
426 strcasecmp(str,
"false") == 0 || strcasecmp(str,
"off") == 0) {
434 if (include1 && strcmp(str,
"1") == 0) {
436 }
else if (strcasecmp(str,
"y") == 0 || strcasecmp(str,
"yes") == 0 ||
437 strcasecmp(str,
"true") == 0 || strcasecmp(str,
"on") == 0) {
459 static int load_env_int(
const char *env_suffix,
int default_val,
int min_val,
467 int abt_errno =
ABTU_atoi(env, &val, NULL);
477 uint32_t min_val, uint32_t max_val)
495 uint64_t min_val, uint64_t max_val)
513 size_t min_val,
size_t max_val)