14#include "kmp_affinity.h"
21#include "kmp_wait_release.h"
22#include "kmp_wrapper_getpid.h"
24#if !KMP_OS_DRAGONFLY && !KMP_OS_FREEBSD && !KMP_OS_NETBSD && !KMP_OS_OPENBSD
31#include <sys/resource.h>
32#include <sys/syscall.h>
38#include <sys/sysinfo.h>
54#include <sys/sysctl.h>
55#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD
57#include <sys/sysctl.h>
59#include <pthread_np.h>
60#elif KMP_OS_NETBSD || KMP_OS_OPENBSD
62#include <sys/sysctl.h>
70 struct timespec start;
74#define TS2NS(timespec) \
75 (((timespec).tv_sec * (long int)1e9) + (timespec).tv_nsec)
77static struct kmp_sys_timer __kmp_sys_timer_data;
80typedef void (*sig_func_t)(int);
81STATIC_EFI2_WORKAROUND
struct sigaction __kmp_sighldrs[NSIG];
82static sigset_t __kmp_sigset;
85static int __kmp_init_runtime = FALSE;
87static int __kmp_fork_count = 0;
89static pthread_condattr_t __kmp_suspend_cond_attr;
90static pthread_mutexattr_t __kmp_suspend_mutex_attr;
92static kmp_cond_align_t __kmp_wait_cv;
93static kmp_mutex_align_t __kmp_wait_mx;
95kmp_uint64 __kmp_ticks_per_msec = 1000000;
98static void __kmp_print_cond(
char *buffer, kmp_cond_align_t *cond) {
99 KMP_SNPRINTF(buffer, 128,
"(cond (lock (%ld, %d)), (descr (%p)))",
100 cond->c_cond.__c_lock.__status, cond->c_cond.__c_lock.__spinlock,
101 cond->c_cond.__c_waiting);
105#if ((KMP_OS_LINUX || KMP_OS_FREEBSD) && KMP_AFFINITY_SUPPORTED)
109void __kmp_affinity_bind_thread(
int which) {
110 KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
111 "Illegal set affinity operation when not capable");
113 kmp_affin_mask_t *mask;
114 KMP_CPU_ALLOC_ON_STACK(mask);
116 KMP_CPU_SET(which, mask);
117 __kmp_set_system_affinity(mask, TRUE);
118 KMP_CPU_FREE_FROM_STACK(mask);
124void __kmp_affinity_determine_capable(
const char *env_var) {
128#define KMP_CPU_SET_SIZE_LIMIT (1024 * 1024)
129#define KMP_CPU_SET_TRY_SIZE CACHE_LINE
131#define KMP_CPU_SET_SIZE_LIMIT (sizeof(cpuset_t))
137 buf = (
unsigned char *)KMP_INTERNAL_MALLOC(KMP_CPU_SET_SIZE_LIMIT);
141 gCode = syscall(__NR_sched_getaffinity, 0, KMP_CPU_SET_TRY_SIZE, buf);
142 KA_TRACE(30, (
"__kmp_affinity_determine_capable: "
143 "initial getaffinity call returned %ld errno = %d\n",
146 if (gCode < 0 && errno != EINVAL) {
148 if (__kmp_affinity_verbose ||
149 (__kmp_affinity_warnings && (__kmp_affinity_type != affinity_none) &&
150 (__kmp_affinity_type != affinity_default) &&
151 (__kmp_affinity_type != affinity_disabled))) {
153 kmp_msg_t err_code = KMP_ERR(error);
154 __kmp_msg(kmp_ms_warning, KMP_MSG(GetAffSysCallNotSupported, env_var),
155 err_code, __kmp_msg_null);
156 if (__kmp_generate_warnings == kmp_warnings_off) {
157 __kmp_str_free(&err_code.str);
160 KMP_AFFINITY_DISABLE();
161 KMP_INTERNAL_FREE(buf);
163 }
else if (gCode > 0) {
165 KMP_AFFINITY_ENABLE(gCode);
166 KA_TRACE(10, (
"__kmp_affinity_determine_capable: "
167 "affinity supported (mask size %d)\n",
168 (
int)__kmp_affin_mask_size));
169 KMP_INTERNAL_FREE(buf);
175 KA_TRACE(30, (
"__kmp_affinity_determine_capable: "
176 "searching for proper set size\n"));
178 for (size = 1; size <= KMP_CPU_SET_SIZE_LIMIT; size *= 2) {
179 gCode = syscall(__NR_sched_getaffinity, 0, size, buf);
180 KA_TRACE(30, (
"__kmp_affinity_determine_capable: "
181 "getaffinity for mask size %ld returned %ld errno = %d\n",
182 size, gCode, errno));
185 if (errno == ENOSYS) {
187 KA_TRACE(30, (
"__kmp_affinity_determine_capable: "
188 "inconsistent OS call behavior: errno == ENOSYS for mask "
191 if (__kmp_affinity_verbose ||
192 (__kmp_affinity_warnings &&
193 (__kmp_affinity_type != affinity_none) &&
194 (__kmp_affinity_type != affinity_default) &&
195 (__kmp_affinity_type != affinity_disabled))) {
197 kmp_msg_t err_code = KMP_ERR(error);
198 __kmp_msg(kmp_ms_warning, KMP_MSG(GetAffSysCallNotSupported, env_var),
199 err_code, __kmp_msg_null);
200 if (__kmp_generate_warnings == kmp_warnings_off) {
201 __kmp_str_free(&err_code.str);
204 KMP_AFFINITY_DISABLE();
205 KMP_INTERNAL_FREE(buf);
211 KMP_AFFINITY_ENABLE(gCode);
212 KA_TRACE(10, (
"__kmp_affinity_determine_capable: "
213 "affinity supported (mask size %d)\n",
214 (
int)__kmp_affin_mask_size));
215 KMP_INTERNAL_FREE(buf);
221 buf = (
unsigned char *)KMP_INTERNAL_MALLOC(KMP_CPU_SET_SIZE_LIMIT);
222 gCode = pthread_getaffinity_np(pthread_self(), KMP_CPU_SET_SIZE_LIMIT,
223 reinterpret_cast<cpuset_t *
>(buf));
224 KA_TRACE(30, (
"__kmp_affinity_determine_capable: "
225 "initial getaffinity call returned %d errno = %d\n",
228 KMP_AFFINITY_ENABLE(KMP_CPU_SET_SIZE_LIMIT);
229 KA_TRACE(10, (
"__kmp_affinity_determine_capable: "
230 "affinity supported (mask size %d)\n",
231 (
int)__kmp_affin_mask_size));
232 KMP_INTERNAL_FREE(buf);
236 KMP_INTERNAL_FREE(buf);
239 KMP_AFFINITY_DISABLE();
240 KA_TRACE(10, (
"__kmp_affinity_determine_capable: "
241 "cannot determine mask size - affinity not supported\n"));
242 if (__kmp_affinity_verbose ||
243 (__kmp_affinity_warnings && (__kmp_affinity_type != affinity_none) &&
244 (__kmp_affinity_type != affinity_default) &&
245 (__kmp_affinity_type != affinity_disabled))) {
246 KMP_WARNING(AffCantGetMaskSize, env_var);
254int __kmp_futex_determine_capable() {
256 long rc = syscall(__NR_futex, &loc, FUTEX_WAKE, 1, NULL, NULL, 0);
257 int retval = (rc == 0) || (errno != ENOSYS);
260 (
"__kmp_futex_determine_capable: rc = %d errno = %d\n", rc, errno));
261 KA_TRACE(10, (
"__kmp_futex_determine_capable: futex syscall%s supported\n",
262 retval ?
"" :
" not"));
269#if (KMP_ARCH_X86 || KMP_ARCH_X86_64) && (!KMP_ASM_INTRINS)
273kmp_int8 __kmp_test_then_or8(
volatile kmp_int8 *p, kmp_int8 d) {
274 kmp_int8 old_value, new_value;
276 old_value = TCR_1(*p);
277 new_value = old_value | d;
279 while (!KMP_COMPARE_AND_STORE_REL8(p, old_value, new_value)) {
281 old_value = TCR_1(*p);
282 new_value = old_value | d;
287kmp_int8 __kmp_test_then_and8(
volatile kmp_int8 *p, kmp_int8 d) {
288 kmp_int8 old_value, new_value;
290 old_value = TCR_1(*p);
291 new_value = old_value & d;
293 while (!KMP_COMPARE_AND_STORE_REL8(p, old_value, new_value)) {
295 old_value = TCR_1(*p);
296 new_value = old_value & d;
301kmp_uint32 __kmp_test_then_or32(
volatile kmp_uint32 *p, kmp_uint32 d) {
302 kmp_uint32 old_value, new_value;
304 old_value = TCR_4(*p);
305 new_value = old_value | d;
307 while (!KMP_COMPARE_AND_STORE_REL32(p, old_value, new_value)) {
309 old_value = TCR_4(*p);
310 new_value = old_value | d;
315kmp_uint32 __kmp_test_then_and32(
volatile kmp_uint32 *p, kmp_uint32 d) {
316 kmp_uint32 old_value, new_value;
318 old_value = TCR_4(*p);
319 new_value = old_value & d;
321 while (!KMP_COMPARE_AND_STORE_REL32(p, old_value, new_value)) {
323 old_value = TCR_4(*p);
324 new_value = old_value & d;
330kmp_int8 __kmp_test_then_add8(
volatile kmp_int8 *p, kmp_int8 d) {
331 kmp_int8 old_value, new_value;
333 old_value = TCR_1(*p);
334 new_value = old_value + d;
336 while (!KMP_COMPARE_AND_STORE_REL8(p, old_value, new_value)) {
338 old_value = TCR_1(*p);
339 new_value = old_value + d;
344kmp_int64 __kmp_test_then_add64(
volatile kmp_int64 *p, kmp_int64 d) {
345 kmp_int64 old_value, new_value;
347 old_value = TCR_8(*p);
348 new_value = old_value + d;
350 while (!KMP_COMPARE_AND_STORE_REL64(p, old_value, new_value)) {
352 old_value = TCR_8(*p);
353 new_value = old_value + d;
359kmp_uint64 __kmp_test_then_or64(
volatile kmp_uint64 *p, kmp_uint64 d) {
360 kmp_uint64 old_value, new_value;
362 old_value = TCR_8(*p);
363 new_value = old_value | d;
364 while (!KMP_COMPARE_AND_STORE_REL64(p, old_value, new_value)) {
366 old_value = TCR_8(*p);
367 new_value = old_value | d;
372kmp_uint64 __kmp_test_then_and64(
volatile kmp_uint64 *p, kmp_uint64 d) {
373 kmp_uint64 old_value, new_value;
375 old_value = TCR_8(*p);
376 new_value = old_value & d;
377 while (!KMP_COMPARE_AND_STORE_REL64(p, old_value, new_value)) {
379 old_value = TCR_8(*p);
380 new_value = old_value & d;
387void __kmp_terminate_thread(
int gtid) {
389 kmp_info_t *th = __kmp_threads[gtid];
394#ifdef KMP_CANCEL_THREADS
395 KA_TRACE(10, (
"__kmp_terminate_thread: kill (%d)\n", gtid));
396 status = pthread_cancel(th->th.th_info.ds.ds_thread);
397 if (status != 0 && status != ESRCH) {
398 __kmp_fatal(KMP_MSG(CantTerminateWorkerThread), KMP_ERR(status),
409static kmp_int32 __kmp_set_stack_info(
int gtid, kmp_info_t *th) {
411#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
421 if (!KMP_UBER_GTID(gtid)) {
424 status = pthread_attr_init(&attr);
425 KMP_CHECK_SYSFAIL(
"pthread_attr_init", status);
426#if KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD
427 status = pthread_attr_get_np(pthread_self(), &attr);
428 KMP_CHECK_SYSFAIL(
"pthread_attr_get_np", status);
430 status = pthread_getattr_np(pthread_self(), &attr);
431 KMP_CHECK_SYSFAIL(
"pthread_getattr_np", status);
433 status = pthread_attr_getstack(&attr, &addr, &size);
434 KMP_CHECK_SYSFAIL(
"pthread_attr_getstack", status);
436 (
"__kmp_set_stack_info: T#%d pthread_attr_getstack returned size:"
437 " %lu, low addr: %p\n",
439 status = pthread_attr_destroy(&attr);
440 KMP_CHECK_SYSFAIL(
"pthread_attr_destroy", status);
443 if (size != 0 && addr != 0) {
445 TCW_PTR(th->th.th_info.ds.ds_stackbase, (((
char *)addr) + size));
446 TCW_PTR(th->th.th_info.ds.ds_stacksize, size);
447 TCW_4(th->th.th_info.ds.ds_stackgrow, FALSE);
453 TCW_PTR(th->th.th_info.ds.ds_stacksize, 0);
454 TCW_PTR(th->th.th_info.ds.ds_stackbase, &stack_data);
455 TCW_4(th->th.th_info.ds.ds_stackgrow, TRUE);
459static void *__kmp_launch_worker(
void *thr) {
460 int status, old_type, old_state;
461#ifdef KMP_BLOCK_SIGNALS
462 sigset_t new_set, old_set;
465#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
466 KMP_OS_OPENBSD || KMP_OS_HURD
467 void *
volatile padding = 0;
471 gtid = ((kmp_info_t *)thr)->th.th_info.ds.ds_gtid;
472 __kmp_gtid_set_specific(gtid);
478 __kmp_stats_thread_ptr = ((kmp_info_t *)thr)->th.th_stats;
479 __kmp_stats_thread_ptr->startLife();
480 KMP_SET_THREAD_STATE(IDLE);
485 __kmp_itt_thread_name(gtid);
488#if KMP_AFFINITY_SUPPORTED
489 __kmp_affinity_set_init_mask(gtid, FALSE);
492#ifdef KMP_CANCEL_THREADS
493 status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_type);
494 KMP_CHECK_SYSFAIL(
"pthread_setcanceltype", status);
496 status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_state);
497 KMP_CHECK_SYSFAIL(
"pthread_setcancelstate", status);
500#if KMP_ARCH_X86 || KMP_ARCH_X86_64
502 __kmp_clear_x87_fpu_status_word();
503 __kmp_load_x87_fpu_control_word(&__kmp_init_x87_fpu_control_word);
504 __kmp_load_mxcsr(&__kmp_init_mxcsr);
507#ifdef KMP_BLOCK_SIGNALS
508 status = sigfillset(&new_set);
509 KMP_CHECK_SYSFAIL_ERRNO(
"sigfillset", status);
510 status = pthread_sigmask(SIG_BLOCK, &new_set, &old_set);
511 KMP_CHECK_SYSFAIL(
"pthread_sigmask", status);
514#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
516 if (__kmp_stkoffset > 0 && gtid > 0) {
517 padding = KMP_ALLOCA(gtid * __kmp_stkoffset);
523 __kmp_set_stack_info(gtid, (kmp_info_t *)thr);
525 __kmp_check_stack_overlap((kmp_info_t *)thr);
527 exit_val = __kmp_launch_thread((kmp_info_t *)thr);
529#ifdef KMP_BLOCK_SIGNALS
530 status = pthread_sigmask(SIG_SETMASK, &old_set, NULL);
531 KMP_CHECK_SYSFAIL(
"pthread_sigmask", status);
540static void *__kmp_launch_monitor(
void *thr) {
541 int status, old_type, old_state;
542#ifdef KMP_BLOCK_SIGNALS
545 struct timespec interval;
549 KA_TRACE(10, (
"__kmp_launch_monitor: #1 launched\n"));
552 __kmp_gtid_set_specific(KMP_GTID_MONITOR);
554 __kmp_gtid = KMP_GTID_MONITOR;
561 __kmp_itt_thread_ignore();
564 __kmp_set_stack_info(((kmp_info_t *)thr)->th.th_info.ds.ds_gtid,
567 __kmp_check_stack_overlap((kmp_info_t *)thr);
569#ifdef KMP_CANCEL_THREADS
570 status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_type);
571 KMP_CHECK_SYSFAIL(
"pthread_setcanceltype", status);
573 status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_state);
574 KMP_CHECK_SYSFAIL(
"pthread_setcancelstate", status);
582 int sched = sched_getscheduler(0);
583 if (sched == SCHED_FIFO || sched == SCHED_RR) {
586 struct sched_param param;
587 int max_priority = sched_get_priority_max(sched);
589 KMP_WARNING(RealTimeSchedNotSupported);
590 sched_getparam(0, ¶m);
591 if (param.sched_priority < max_priority) {
592 param.sched_priority += 1;
593 rc = sched_setscheduler(0, sched, ¶m);
596 kmp_msg_t err_code = KMP_ERR(error);
597 __kmp_msg(kmp_ms_warning, KMP_MSG(CantChangeMonitorPriority),
598 err_code, KMP_MSG(MonitorWillStarve), __kmp_msg_null);
599 if (__kmp_generate_warnings == kmp_warnings_off) {
600 __kmp_str_free(&err_code.str);
607 __kmp_msg(kmp_ms_warning, KMP_MSG(RunningAtMaxPriority),
608 KMP_MSG(MonitorWillStarve), KMP_HNT(RunningAtMaxPriority),
613 TCW_4(__kmp_global.g.g_time.dt.t_value, 0);
619 if (__kmp_monitor_wakeups == 1) {
621 interval.tv_nsec = 0;
624 interval.tv_nsec = (KMP_NSEC_PER_SEC / __kmp_monitor_wakeups);
627 KA_TRACE(10, (
"__kmp_launch_monitor: #2 monitor\n"));
629 while (!TCR_4(__kmp_global.g.g_done)) {
635 KA_TRACE(15, (
"__kmp_launch_monitor: update\n"));
637 status = gettimeofday(&tval, NULL);
638 KMP_CHECK_SYSFAIL_ERRNO(
"gettimeofday", status);
639 TIMEVAL_TO_TIMESPEC(&tval, &now);
641 now.tv_sec += interval.tv_sec;
642 now.tv_nsec += interval.tv_nsec;
644 if (now.tv_nsec >= KMP_NSEC_PER_SEC) {
646 now.tv_nsec -= KMP_NSEC_PER_SEC;
649 status = pthread_mutex_lock(&__kmp_wait_mx.m_mutex);
650 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
652 if (!TCR_4(__kmp_global.g.g_done)) {
653 status = pthread_cond_timedwait(&__kmp_wait_cv.c_cond,
654 &__kmp_wait_mx.m_mutex, &now);
656 if (status != ETIMEDOUT && status != EINTR) {
657 KMP_SYSFAIL(
"pthread_cond_timedwait", status);
661 status = pthread_mutex_unlock(&__kmp_wait_mx.m_mutex);
662 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
664 TCW_4(__kmp_global.g.g_time.dt.t_value,
665 TCR_4(__kmp_global.g.g_time.dt.t_value) + 1);
670 KA_TRACE(10, (
"__kmp_launch_monitor: #3 cleanup\n"));
672#ifdef KMP_BLOCK_SIGNALS
673 status = sigfillset(&new_set);
674 KMP_CHECK_SYSFAIL_ERRNO(
"sigfillset", status);
675 status = pthread_sigmask(SIG_UNBLOCK, &new_set, NULL);
676 KMP_CHECK_SYSFAIL(
"pthread_sigmask", status);
679 KA_TRACE(10, (
"__kmp_launch_monitor: #4 finished\n"));
681 if (__kmp_global.g.g_abort != 0) {
687 KA_TRACE(10, (
"__kmp_launch_monitor: #5 terminate sig=%d\n",
688 __kmp_global.g.g_abort));
693 for (gtid = 1; gtid < __kmp_threads_capacity; ++gtid)
694 __kmp_terminate_thread(gtid);
698 KA_TRACE(10, (
"__kmp_launch_monitor: #6 raise sig=%d\n",
699 __kmp_global.g.g_abort));
701 if (__kmp_global.g.g_abort > 0)
702 raise(__kmp_global.g.g_abort);
705 KA_TRACE(10, (
"__kmp_launch_monitor: #7 exit\n"));
711void __kmp_create_worker(
int gtid, kmp_info_t *th,
size_t stack_size) {
713 pthread_attr_t thread_attr;
716 th->th.th_info.ds.ds_gtid = gtid;
720 __kmp_acquire_tas_lock(&__kmp_stats_lock, gtid);
726 if (!KMP_UBER_GTID(gtid)) {
727 th->th.th_stats = __kmp_stats_list->push_back(gtid);
731 th->th.th_stats = __kmp_stats_thread_ptr;
733 __kmp_release_tas_lock(&__kmp_stats_lock, gtid);
737 if (KMP_UBER_GTID(gtid)) {
738 KA_TRACE(10, (
"__kmp_create_worker: uber thread (%d)\n", gtid));
739 th->th.th_info.ds.ds_thread = pthread_self();
740 __kmp_set_stack_info(gtid, th);
741 __kmp_check_stack_overlap(th);
745 KA_TRACE(10, (
"__kmp_create_worker: try to create thread (%d)\n", gtid));
749#ifdef KMP_THREAD_ATTR
750 status = pthread_attr_init(&thread_attr);
752 __kmp_fatal(KMP_MSG(CantInitThreadAttrs), KMP_ERR(status), __kmp_msg_null);
754 status = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
756 __kmp_fatal(KMP_MSG(CantSetWorkerState), KMP_ERR(status), __kmp_msg_null);
766 stack_size += gtid * __kmp_stkoffset * 2;
768#if defined(__ANDROID__) && __ANDROID_API__ < 19
772 stack_size = (stack_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
775 KA_TRACE(10, (
"__kmp_create_worker: T#%d, default stacksize = %lu bytes, "
776 "__kmp_stksize = %lu bytes, final stacksize = %lu bytes\n",
777 gtid, KMP_DEFAULT_STKSIZE, __kmp_stksize, stack_size));
779#ifdef _POSIX_THREAD_ATTR_STACKSIZE
780 status = pthread_attr_setstacksize(&thread_attr, stack_size);
781#ifdef KMP_BACKUP_STKSIZE
783 if (!__kmp_env_stksize) {
784 stack_size = KMP_BACKUP_STKSIZE + gtid * __kmp_stkoffset;
785 __kmp_stksize = KMP_BACKUP_STKSIZE;
786 KA_TRACE(10, (
"__kmp_create_worker: T#%d, default stacksize = %lu bytes, "
787 "__kmp_stksize = %lu bytes, (backup) final stacksize = %lu "
789 gtid, KMP_DEFAULT_STKSIZE, __kmp_stksize, stack_size));
790 status = pthread_attr_setstacksize(&thread_attr, stack_size);
795 __kmp_fatal(KMP_MSG(CantSetWorkerStackSize, stack_size), KMP_ERR(status),
796 KMP_HNT(ChangeWorkerStackSize), __kmp_msg_null);
803 pthread_create(&handle, &thread_attr, __kmp_launch_worker, (
void *)th);
804 if (status != 0 || !handle) {
805#ifdef _POSIX_THREAD_ATTR_STACKSIZE
806 if (status == EINVAL) {
807 __kmp_fatal(KMP_MSG(CantSetWorkerStackSize, stack_size), KMP_ERR(status),
808 KMP_HNT(IncreaseWorkerStackSize), __kmp_msg_null);
810 if (status == ENOMEM) {
811 __kmp_fatal(KMP_MSG(CantSetWorkerStackSize, stack_size), KMP_ERR(status),
812 KMP_HNT(DecreaseWorkerStackSize), __kmp_msg_null);
815 if (status == EAGAIN) {
816 __kmp_fatal(KMP_MSG(NoResourcesForWorkerThread), KMP_ERR(status),
817 KMP_HNT(Decrease_NUM_THREADS), __kmp_msg_null);
819 KMP_SYSFAIL(
"pthread_create", status);
822 th->th.th_info.ds.ds_thread = handle;
824#ifdef KMP_THREAD_ATTR
825 status = pthread_attr_destroy(&thread_attr);
827 kmp_msg_t err_code = KMP_ERR(status);
828 __kmp_msg(kmp_ms_warning, KMP_MSG(CantDestroyThreadAttrs), err_code,
830 if (__kmp_generate_warnings == kmp_warnings_off) {
831 __kmp_str_free(&err_code.str);
838 KA_TRACE(10, (
"__kmp_create_worker: done creating thread (%d)\n", gtid));
843void __kmp_create_monitor(kmp_info_t *th) {
845 pthread_attr_t thread_attr;
848 int auto_adj_size = FALSE;
850 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME) {
852 KA_TRACE(10, (
"__kmp_create_monitor: skipping monitor thread because of "
854 th->th.th_info.ds.ds_tid = 0;
855 th->th.th_info.ds.ds_gtid = 0;
858 KA_TRACE(10, (
"__kmp_create_monitor: try to create monitor\n"));
862 th->th.th_info.ds.ds_tid = KMP_GTID_MONITOR;
863 th->th.th_info.ds.ds_gtid = KMP_GTID_MONITOR;
865 TCW_4(__kmp_global.g.g_time.dt.t_value,
868 TCW_4(__kmp_global.g.g_time.dt.t_value, 0);
871#ifdef KMP_THREAD_ATTR
872 if (__kmp_monitor_stksize == 0) {
873 __kmp_monitor_stksize = KMP_DEFAULT_MONITOR_STKSIZE;
874 auto_adj_size = TRUE;
876 status = pthread_attr_init(&thread_attr);
878 __kmp_fatal(KMP_MSG(CantInitThreadAttrs), KMP_ERR(status), __kmp_msg_null);
880 status = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
882 __kmp_fatal(KMP_MSG(CantSetMonitorState), KMP_ERR(status), __kmp_msg_null);
885#ifdef _POSIX_THREAD_ATTR_STACKSIZE
886 status = pthread_attr_getstacksize(&thread_attr, &size);
887 KMP_CHECK_SYSFAIL(
"pthread_attr_getstacksize", status);
889 size = __kmp_sys_min_stksize;
893 if (__kmp_monitor_stksize == 0) {
894 __kmp_monitor_stksize = KMP_DEFAULT_MONITOR_STKSIZE;
896 if (__kmp_monitor_stksize < __kmp_sys_min_stksize) {
897 __kmp_monitor_stksize = __kmp_sys_min_stksize;
900 KA_TRACE(10, (
"__kmp_create_monitor: default stacksize = %lu bytes,"
901 "requested stacksize = %lu bytes\n",
902 size, __kmp_monitor_stksize));
907#ifdef _POSIX_THREAD_ATTR_STACKSIZE
908 KA_TRACE(10, (
"__kmp_create_monitor: setting stacksize = %lu bytes,",
909 __kmp_monitor_stksize));
910 status = pthread_attr_setstacksize(&thread_attr, __kmp_monitor_stksize);
913 __kmp_monitor_stksize *= 2;
916 kmp_msg_t err_code = KMP_ERR(status);
917 __kmp_msg(kmp_ms_warning,
918 KMP_MSG(CantSetMonitorStackSize, (
long int)__kmp_monitor_stksize),
919 err_code, KMP_HNT(ChangeMonitorStackSize), __kmp_msg_null);
920 if (__kmp_generate_warnings == kmp_warnings_off) {
921 __kmp_str_free(&err_code.str);
927 pthread_create(&handle, &thread_attr, __kmp_launch_monitor, (
void *)th);
930#ifdef _POSIX_THREAD_ATTR_STACKSIZE
931 if (status == EINVAL) {
932 if (auto_adj_size && (__kmp_monitor_stksize < (
size_t)0x40000000)) {
933 __kmp_monitor_stksize *= 2;
936 __kmp_fatal(KMP_MSG(CantSetMonitorStackSize, __kmp_monitor_stksize),
937 KMP_ERR(status), KMP_HNT(IncreaseMonitorStackSize),
940 if (status == ENOMEM) {
941 __kmp_fatal(KMP_MSG(CantSetMonitorStackSize, __kmp_monitor_stksize),
942 KMP_ERR(status), KMP_HNT(DecreaseMonitorStackSize),
946 if (status == EAGAIN) {
947 __kmp_fatal(KMP_MSG(NoResourcesForMonitorThread), KMP_ERR(status),
948 KMP_HNT(DecreaseNumberOfThreadsInUse), __kmp_msg_null);
950 KMP_SYSFAIL(
"pthread_create", status);
953 th->th.th_info.ds.ds_thread = handle;
957 KMP_DEBUG_ASSERT(
sizeof(kmp_uint32) ==
958 sizeof(__kmp_global.g.g_time.dt.t_value));
959 __kmp_wait_4((kmp_uint32
volatile *)&__kmp_global.g.g_time.dt.t_value, -1,
963#ifdef KMP_THREAD_ATTR
964 status = pthread_attr_destroy(&thread_attr);
966 kmp_msg_t err_code = KMP_ERR(status);
967 __kmp_msg(kmp_ms_warning, KMP_MSG(CantDestroyThreadAttrs), err_code,
969 if (__kmp_generate_warnings == kmp_warnings_off) {
970 __kmp_str_free(&err_code.str);
977 KA_TRACE(10, (
"__kmp_create_monitor: monitor created %#.8lx\n",
978 th->th.th_info.ds.ds_thread));
983void __kmp_exit_thread(
int exit_status) {
984 pthread_exit((
void *)(intptr_t)exit_status);
988void __kmp_resume_monitor();
990void __kmp_reap_monitor(kmp_info_t *th) {
994 KA_TRACE(10, (
"__kmp_reap_monitor: try to reap monitor thread with handle"
996 th->th.th_info.ds.ds_thread));
1001 KMP_DEBUG_ASSERT(th->th.th_info.ds.ds_tid == th->th.th_info.ds.ds_gtid);
1002 if (th->th.th_info.ds.ds_gtid != KMP_GTID_MONITOR) {
1003 KA_TRACE(10, (
"__kmp_reap_monitor: monitor did not start, returning\n"));
1013 status = pthread_kill(th->th.th_info.ds.ds_thread, 0);
1014 if (status != ESRCH) {
1015 __kmp_resume_monitor();
1017 KA_TRACE(10, (
"__kmp_reap_monitor: try to join with monitor\n"));
1018 status = pthread_join(th->th.th_info.ds.ds_thread, &exit_val);
1019 if (exit_val != th) {
1020 __kmp_fatal(KMP_MSG(ReapMonitorError), KMP_ERR(status), __kmp_msg_null);
1023 th->th.th_info.ds.ds_tid = KMP_GTID_DNE;
1024 th->th.th_info.ds.ds_gtid = KMP_GTID_DNE;
1026 KA_TRACE(10, (
"__kmp_reap_monitor: done reaping monitor thread with handle"
1028 th->th.th_info.ds.ds_thread));
1034void __kmp_reap_worker(kmp_info_t *th) {
1041 10, (
"__kmp_reap_worker: try to reap T#%d\n", th->th.th_info.ds.ds_gtid));
1043 status = pthread_join(th->th.th_info.ds.ds_thread, &exit_val);
1047 __kmp_fatal(KMP_MSG(ReapWorkerError), KMP_ERR(status), __kmp_msg_null);
1049 if (exit_val != th) {
1050 KA_TRACE(10, (
"__kmp_reap_worker: worker T#%d did not reap properly, "
1052 th->th.th_info.ds.ds_gtid, exit_val));
1058 KA_TRACE(10, (
"__kmp_reap_worker: done reaping T#%d\n",
1059 th->th.th_info.ds.ds_gtid));
1064#if KMP_HANDLE_SIGNALS
1066static void __kmp_null_handler(
int signo) {
1070static void __kmp_team_handler(
int signo) {
1071 if (__kmp_global.g.g_abort == 0) {
1074 __kmp_debug_printf(
"__kmp_team_handler: caught signal = %d\n", signo);
1089 if (__kmp_debug_buf) {
1090 __kmp_dump_debug_buffer();
1092 __kmp_unregister_library();
1094 TCW_4(__kmp_global.g.g_abort, signo);
1096 TCW_4(__kmp_global.g.g_done, TRUE);
1101 __kmp_debug_printf(
"__kmp_team_handler: unknown signal type");
1108static void __kmp_sigaction(
int signum,
const struct sigaction *act,
1109 struct sigaction *oldact) {
1110 int rc = sigaction(signum, act, oldact);
1111 KMP_CHECK_SYSFAIL_ERRNO(
"sigaction", rc);
1114static void __kmp_install_one_handler(
int sig, sig_func_t handler_func,
1115 int parallel_init) {
1118 (
"__kmp_install_one_handler( %d, ..., %d )\n", sig, parallel_init));
1119 if (parallel_init) {
1120 struct sigaction new_action;
1121 struct sigaction old_action;
1122 new_action.sa_handler = handler_func;
1123 new_action.sa_flags = 0;
1124 sigfillset(&new_action.sa_mask);
1125 __kmp_sigaction(sig, &new_action, &old_action);
1126 if (old_action.sa_handler == __kmp_sighldrs[sig].sa_handler) {
1127 sigaddset(&__kmp_sigset, sig);
1130 __kmp_sigaction(sig, &old_action, NULL);
1134 __kmp_sigaction(sig, NULL, &__kmp_sighldrs[sig]);
1139static void __kmp_remove_one_handler(
int sig) {
1140 KB_TRACE(60, (
"__kmp_remove_one_handler( %d )\n", sig));
1141 if (sigismember(&__kmp_sigset, sig)) {
1142 struct sigaction old;
1144 __kmp_sigaction(sig, &__kmp_sighldrs[sig], &old);
1145 if ((old.sa_handler != __kmp_team_handler) &&
1146 (old.sa_handler != __kmp_null_handler)) {
1148 KB_TRACE(10, (
"__kmp_remove_one_handler: oops, not our handler, "
1149 "restoring: sig=%d\n",
1151 __kmp_sigaction(sig, &old, NULL);
1153 sigdelset(&__kmp_sigset, sig);
1158void __kmp_install_signals(
int parallel_init) {
1159 KB_TRACE(10, (
"__kmp_install_signals( %d )\n", parallel_init));
1160 if (__kmp_handle_signals || !parallel_init) {
1163 sigemptyset(&__kmp_sigset);
1164 __kmp_install_one_handler(SIGHUP, __kmp_team_handler, parallel_init);
1165 __kmp_install_one_handler(SIGINT, __kmp_team_handler, parallel_init);
1166 __kmp_install_one_handler(SIGQUIT, __kmp_team_handler, parallel_init);
1167 __kmp_install_one_handler(SIGILL, __kmp_team_handler, parallel_init);
1168 __kmp_install_one_handler(SIGABRT, __kmp_team_handler, parallel_init);
1169 __kmp_install_one_handler(SIGFPE, __kmp_team_handler, parallel_init);
1170 __kmp_install_one_handler(SIGBUS, __kmp_team_handler, parallel_init);
1171 __kmp_install_one_handler(SIGSEGV, __kmp_team_handler, parallel_init);
1173 __kmp_install_one_handler(SIGSYS, __kmp_team_handler, parallel_init);
1175 __kmp_install_one_handler(SIGTERM, __kmp_team_handler, parallel_init);
1177 __kmp_install_one_handler(SIGPIPE, __kmp_team_handler, parallel_init);
1182void __kmp_remove_signals(
void) {
1184 KB_TRACE(10, (
"__kmp_remove_signals()\n"));
1185 for (sig = 1; sig < NSIG; ++sig) {
1186 __kmp_remove_one_handler(sig);
1192void __kmp_enable(
int new_state) {
1193#ifdef KMP_CANCEL_THREADS
1194 int status, old_state;
1195 status = pthread_setcancelstate(new_state, &old_state);
1196 KMP_CHECK_SYSFAIL(
"pthread_setcancelstate", status);
1197 KMP_DEBUG_ASSERT(old_state == PTHREAD_CANCEL_DISABLE);
1201void __kmp_disable(
int *old_state) {
1202#ifdef KMP_CANCEL_THREADS
1204 status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, old_state);
1205 KMP_CHECK_SYSFAIL(
"pthread_setcancelstate", status);
1209static void __kmp_atfork_prepare(
void) {
1210 __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
1211 __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
1214static void __kmp_atfork_parent(
void) {
1215 __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
1216 __kmp_release_bootstrap_lock(&__kmp_initz_lock);
1222static void __kmp_atfork_child(
void) {
1223 __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
1224 __kmp_release_bootstrap_lock(&__kmp_initz_lock);
1231#if KMP_AFFINITY_SUPPORTED
1232#if KMP_OS_LINUX || KMP_OS_FREEBSD
1235 kmp_set_thread_affinity_mask_initial();
1240 __kmp_affinity_type = affinity_none;
1241 if (__kmp_nested_proc_bind.bind_types != NULL) {
1242 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1244 __kmp_affinity_masks = NULL;
1245 __kmp_affinity_num_masks = 0;
1249 __kmp_init_monitor = 0;
1251 __kmp_init_parallel = FALSE;
1252 __kmp_init_middle = FALSE;
1253 __kmp_init_serial = FALSE;
1254 TCW_4(__kmp_init_gtid, FALSE);
1255 __kmp_init_common = FALSE;
1257 TCW_4(__kmp_init_user_locks, FALSE);
1258#if !KMP_USE_DYNAMIC_LOCK
1259 __kmp_user_lock_table.used = 1;
1260 __kmp_user_lock_table.allocated = 0;
1261 __kmp_user_lock_table.table = NULL;
1262 __kmp_lock_blocks = NULL;
1266 TCW_4(__kmp_nth, 0);
1268 __kmp_thread_pool = NULL;
1269 __kmp_thread_pool_insert_pt = NULL;
1270 __kmp_team_pool = NULL;
1274 KA_TRACE(10, (
"__kmp_atfork_child: checking cache address list %p\n",
1275 __kmp_threadpriv_cache_list));
1277 while (__kmp_threadpriv_cache_list != NULL) {
1279 if (*__kmp_threadpriv_cache_list->addr != NULL) {
1280 KC_TRACE(50, (
"__kmp_atfork_child: zeroing cache at address %p\n",
1281 &(*__kmp_threadpriv_cache_list->addr)));
1283 *__kmp_threadpriv_cache_list->addr = NULL;
1285 __kmp_threadpriv_cache_list = __kmp_threadpriv_cache_list->next;
1288 __kmp_init_runtime = FALSE;
1291 __kmp_init_bootstrap_lock(&__kmp_initz_lock);
1292 __kmp_init_bootstrap_lock(&__kmp_stdio_lock);
1293 __kmp_init_bootstrap_lock(&__kmp_console_lock);
1294 __kmp_init_bootstrap_lock(&__kmp_task_team_lock);
1304 __kmp_need_register_serial = FALSE;
1305 __kmp_serial_initialize();
1319void __kmp_register_atfork(
void) {
1320 if (__kmp_need_register_atfork) {
1321 int status = pthread_atfork(__kmp_atfork_prepare, __kmp_atfork_parent,
1322 __kmp_atfork_child);
1323 KMP_CHECK_SYSFAIL(
"pthread_atfork", status);
1324 __kmp_need_register_atfork = FALSE;
1328void __kmp_suspend_initialize(
void) {
1330 status = pthread_mutexattr_init(&__kmp_suspend_mutex_attr);
1331 KMP_CHECK_SYSFAIL(
"pthread_mutexattr_init", status);
1332 status = pthread_condattr_init(&__kmp_suspend_cond_attr);
1333 KMP_CHECK_SYSFAIL(
"pthread_condattr_init", status);
1336void __kmp_suspend_initialize_thread(kmp_info_t *th) {
1337 int old_value = KMP_ATOMIC_LD_RLX(&th->th.th_suspend_init_count);
1338 int new_value = __kmp_fork_count + 1;
1340 if (old_value == new_value)
1343 if (old_value == -1 || !__kmp_atomic_compare_store(
1344 &th->th.th_suspend_init_count, old_value, -1)) {
1345 while (KMP_ATOMIC_LD_ACQ(&th->th.th_suspend_init_count) != new_value) {
1351 status = pthread_cond_init(&th->th.th_suspend_cv.c_cond,
1352 &__kmp_suspend_cond_attr);
1353 KMP_CHECK_SYSFAIL(
"pthread_cond_init", status);
1354 status = pthread_mutex_init(&th->th.th_suspend_mx.m_mutex,
1355 &__kmp_suspend_mutex_attr);
1356 KMP_CHECK_SYSFAIL(
"pthread_mutex_init", status);
1357 KMP_ATOMIC_ST_REL(&th->th.th_suspend_init_count, new_value);
1361void __kmp_suspend_uninitialize_thread(kmp_info_t *th) {
1362 if (KMP_ATOMIC_LD_ACQ(&th->th.th_suspend_init_count) > __kmp_fork_count) {
1367 status = pthread_cond_destroy(&th->th.th_suspend_cv.c_cond);
1368 if (status != 0 && status != EBUSY) {
1369 KMP_SYSFAIL(
"pthread_cond_destroy", status);
1371 status = pthread_mutex_destroy(&th->th.th_suspend_mx.m_mutex);
1372 if (status != 0 && status != EBUSY) {
1373 KMP_SYSFAIL(
"pthread_mutex_destroy", status);
1375 --th->th.th_suspend_init_count;
1376 KMP_DEBUG_ASSERT(KMP_ATOMIC_LD_RLX(&th->th.th_suspend_init_count) ==
1382int __kmp_try_suspend_mx(kmp_info_t *th) {
1383 return (pthread_mutex_trylock(&th->th.th_suspend_mx.m_mutex) == 0);
1386void __kmp_lock_suspend_mx(kmp_info_t *th) {
1387 int status = pthread_mutex_lock(&th->th.th_suspend_mx.m_mutex);
1388 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
1391void __kmp_unlock_suspend_mx(kmp_info_t *th) {
1392 int status = pthread_mutex_unlock(&th->th.th_suspend_mx.m_mutex);
1393 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
1399static inline void __kmp_suspend_template(
int th_gtid, C *flag) {
1400 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_suspend);
1401 kmp_info_t *th = __kmp_threads[th_gtid];
1403 typename C::flag_t old_spin;
1405 KF_TRACE(30, (
"__kmp_suspend_template: T#%d enter for flag = %p\n", th_gtid,
1408 __kmp_suspend_initialize_thread(th);
1410 __kmp_lock_suspend_mx(th);
1412 KF_TRACE(10, (
"__kmp_suspend_template: T#%d setting sleep bit for spin(%p)\n",
1413 th_gtid, flag->get()));
1417 old_spin = flag->set_sleeping();
1418 TCW_PTR(th->th.th_sleep_loc, (
void *)flag);
1419 th->th.th_sleep_loc_type = flag->get_type();
1420 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1421 __kmp_pause_status != kmp_soft_paused) {
1422 flag->unset_sleeping();
1423 TCW_PTR(th->th.th_sleep_loc, NULL);
1424 th->th.th_sleep_loc_type = flag_unset;
1425 __kmp_unlock_suspend_mx(th);
1428 KF_TRACE(5, (
"__kmp_suspend_template: T#%d set sleep bit for spin(%p)==%x,"
1430 th_gtid, flag->get(), flag->load(), old_spin));
1432 if (flag->done_check_val(old_spin) || flag->done_check()) {
1433 flag->unset_sleeping();
1434 TCW_PTR(th->th.th_sleep_loc, NULL);
1435 th->th.th_sleep_loc_type = flag_unset;
1436 KF_TRACE(5, (
"__kmp_suspend_template: T#%d false alarm, reset sleep bit "
1438 th_gtid, flag->get()));
1443 int deactivated = FALSE;
1445 while (flag->is_sleeping()) {
1448 __kmp_suspend_count++;
1449 __kmp_print_cond(buffer, &th->th.th_suspend_cv);
1450 __kmp_printf(
"__kmp_suspend_template: suspending T#%d: %s\n", th_gtid,
1456 th->th.th_active = FALSE;
1457 if (th->th.th_active_in_pool) {
1458 th->th.th_active_in_pool = FALSE;
1459 KMP_ATOMIC_DEC(&__kmp_thread_pool_active_nth);
1460 KMP_DEBUG_ASSERT(TCR_4(__kmp_thread_pool_active_nth) >= 0);
1465 KMP_DEBUG_ASSERT(th->th.th_sleep_loc);
1466 KMP_DEBUG_ASSERT(flag->get_type() == th->th.th_sleep_loc_type);
1468#if USE_SUSPEND_TIMEOUT
1469 struct timespec now;
1470 struct timeval tval;
1473 status = gettimeofday(&tval, NULL);
1474 KMP_CHECK_SYSFAIL_ERRNO(
"gettimeofday", status);
1475 TIMEVAL_TO_TIMESPEC(&tval, &now);
1477 msecs = (4 * __kmp_dflt_blocktime) + 200;
1478 now.tv_sec += msecs / 1000;
1479 now.tv_nsec += (msecs % 1000) * 1000;
1481 KF_TRACE(15, (
"__kmp_suspend_template: T#%d about to perform "
1482 "pthread_cond_timedwait\n",
1484 status = pthread_cond_timedwait(&th->th.th_suspend_cv.c_cond,
1485 &th->th.th_suspend_mx.m_mutex, &now);
1487 KF_TRACE(15, (
"__kmp_suspend_template: T#%d about to perform"
1488 " pthread_cond_wait\n",
1490 status = pthread_cond_wait(&th->th.th_suspend_cv.c_cond,
1491 &th->th.th_suspend_mx.m_mutex);
1494 if ((status != 0) && (status != EINTR) && (status != ETIMEDOUT)) {
1495 KMP_SYSFAIL(
"pthread_cond_wait", status);
1498 KMP_DEBUG_ASSERT(flag->get_type() == flag->get_ptr_type());
1500 if (!flag->is_sleeping() &&
1501 ((status == EINTR) || (status == ETIMEDOUT))) {
1505 flag->unset_sleeping();
1506 TCW_PTR(th->th.th_sleep_loc, NULL);
1507 th->th.th_sleep_loc_type = flag_unset;
1510 if (status == ETIMEDOUT) {
1511 if (flag->is_sleeping()) {
1513 (
"__kmp_suspend_template: T#%d timeout wakeup\n", th_gtid));
1515 KF_TRACE(2, (
"__kmp_suspend_template: T#%d timeout wakeup, sleep bit "
1518 TCW_PTR(th->th.th_sleep_loc, NULL);
1519 th->th.th_sleep_loc_type = flag_unset;
1521 }
else if (flag->is_sleeping()) {
1523 (
"__kmp_suspend_template: T#%d spurious wakeup\n", th_gtid));
1530 th->th.th_active = TRUE;
1531 if (TCR_4(th->th.th_in_pool)) {
1532 KMP_ATOMIC_INC(&__kmp_thread_pool_active_nth);
1533 th->th.th_active_in_pool = TRUE;
1539 TCW_PTR(th->th.th_sleep_loc, NULL);
1540 th->th.th_sleep_loc_type = flag_unset;
1542 KMP_DEBUG_ASSERT(!flag->is_sleeping());
1543 KMP_DEBUG_ASSERT(!th->th.th_sleep_loc);
1547 __kmp_print_cond(buffer, &th->th.th_suspend_cv);
1548 __kmp_printf(
"__kmp_suspend_template: T#%d has awakened: %s\n", th_gtid,
1553 __kmp_unlock_suspend_mx(th);
1554 KF_TRACE(30, (
"__kmp_suspend_template: T#%d exit\n", th_gtid));
1557template <
bool C,
bool S>
1558void __kmp_suspend_32(
int th_gtid, kmp_flag_32<C, S> *flag) {
1559 __kmp_suspend_template(th_gtid, flag);
1561template <
bool C,
bool S>
1562void __kmp_suspend_64(
int th_gtid, kmp_flag_64<C, S> *flag) {
1563 __kmp_suspend_template(th_gtid, flag);
1565template <
bool C,
bool S>
1566void __kmp_atomic_suspend_64(
int th_gtid, kmp_atomic_flag_64<C, S> *flag) {
1567 __kmp_suspend_template(th_gtid, flag);
1569void __kmp_suspend_oncore(
int th_gtid, kmp_flag_oncore *flag) {
1570 __kmp_suspend_template(th_gtid, flag);
1573template void __kmp_suspend_32<false, false>(
int, kmp_flag_32<false, false> *);
1574template void __kmp_suspend_64<false, true>(
int, kmp_flag_64<false, true> *);
1575template void __kmp_suspend_64<true, false>(
int, kmp_flag_64<true, false> *);
1577__kmp_atomic_suspend_64<false, true>(
int, kmp_atomic_flag_64<false, true> *);
1579__kmp_atomic_suspend_64<true, false>(
int, kmp_atomic_flag_64<true, false> *);
1585static inline void __kmp_resume_template(
int target_gtid, C *flag) {
1586 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_resume);
1587 kmp_info_t *th = __kmp_threads[target_gtid];
1591 int gtid = TCR_4(__kmp_init_gtid) ? __kmp_get_gtid() : -1;
1594 KF_TRACE(30, (
"__kmp_resume_template: T#%d wants to wakeup T#%d enter\n",
1595 gtid, target_gtid));
1596 KMP_DEBUG_ASSERT(gtid != target_gtid);
1598 __kmp_suspend_initialize_thread(th);
1600 __kmp_lock_suspend_mx(th);
1602 if (!flag || flag != th->th.th_sleep_loc) {
1605 flag = (C *)CCAST(
void *, th->th.th_sleep_loc);
1611 KF_TRACE(5, (
"__kmp_resume_template: T#%d exiting, thread T#%d already "
1612 "awake: flag(%p)\n",
1613 gtid, target_gtid, (
void *)NULL));
1614 __kmp_unlock_suspend_mx(th);
1616 }
else if (flag->get_type() != th->th.th_sleep_loc_type) {
1621 (
"__kmp_resume_template: T#%d retrying, thread T#%d Mismatch flag(%p), "
1622 "spin(%p) type=%d ptr_type=%d\n",
1623 gtid, target_gtid, flag, flag->get(), flag->get_type(),
1624 th->th.th_sleep_loc_type));
1625 __kmp_unlock_suspend_mx(th);
1626 __kmp_null_resume_wrapper(th);
1630 if (!flag->is_sleeping()) {
1631 KF_TRACE(5, (
"__kmp_resume_template: T#%d exiting, thread T#%d already "
1632 "awake: flag(%p): %u\n",
1633 gtid, target_gtid, flag->get(), (
unsigned int)flag->load()));
1634 __kmp_unlock_suspend_mx(th);
1638 KMP_DEBUG_ASSERT(flag);
1639 flag->unset_sleeping();
1640 TCW_PTR(th->th.th_sleep_loc, NULL);
1641 th->th.th_sleep_loc_type = flag_unset;
1643 KF_TRACE(5, (
"__kmp_resume_template: T#%d about to wakeup T#%d, reset "
1644 "sleep bit for flag's loc(%p): %u\n",
1645 gtid, target_gtid, flag->get(), (
unsigned int)flag->load()));
1650 __kmp_print_cond(buffer, &th->th.th_suspend_cv);
1651 __kmp_printf(
"__kmp_resume_template: T#%d resuming T#%d: %s\n", gtid,
1652 target_gtid, buffer);
1655 status = pthread_cond_signal(&th->th.th_suspend_cv.c_cond);
1656 KMP_CHECK_SYSFAIL(
"pthread_cond_signal", status);
1657 __kmp_unlock_suspend_mx(th);
1658 KF_TRACE(30, (
"__kmp_resume_template: T#%d exiting after signaling wake up"
1660 gtid, target_gtid));
1663template <
bool C,
bool S>
1664void __kmp_resume_32(
int target_gtid, kmp_flag_32<C, S> *flag) {
1665 __kmp_resume_template(target_gtid, flag);
1667template <
bool C,
bool S>
1668void __kmp_resume_64(
int target_gtid, kmp_flag_64<C, S> *flag) {
1669 __kmp_resume_template(target_gtid, flag);
1671template <
bool C,
bool S>
1672void __kmp_atomic_resume_64(
int target_gtid, kmp_atomic_flag_64<C, S> *flag) {
1673 __kmp_resume_template(target_gtid, flag);
1675void __kmp_resume_oncore(
int target_gtid, kmp_flag_oncore *flag) {
1676 __kmp_resume_template(target_gtid, flag);
1679template void __kmp_resume_32<false, true>(
int, kmp_flag_32<false, true> *);
1680template void __kmp_resume_32<false, false>(
int, kmp_flag_32<false, false> *);
1681template void __kmp_resume_64<false, true>(
int, kmp_flag_64<false, true> *);
1683__kmp_atomic_resume_64<false, true>(
int, kmp_atomic_flag_64<false, true> *);
1686void __kmp_resume_monitor() {
1687 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_resume);
1690 int gtid = TCR_4(__kmp_init_gtid) ? __kmp_get_gtid() : -1;
1691 KF_TRACE(30, (
"__kmp_resume_monitor: T#%d wants to wakeup T#%d enter\n", gtid,
1693 KMP_DEBUG_ASSERT(gtid != KMP_GTID_MONITOR);
1695 status = pthread_mutex_lock(&__kmp_wait_mx.m_mutex);
1696 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
1700 __kmp_print_cond(buffer, &__kmp_wait_cv.c_cond);
1701 __kmp_printf(
"__kmp_resume_monitor: T#%d resuming T#%d: %s\n", gtid,
1702 KMP_GTID_MONITOR, buffer);
1705 status = pthread_cond_signal(&__kmp_wait_cv.c_cond);
1706 KMP_CHECK_SYSFAIL(
"pthread_cond_signal", status);
1707 status = pthread_mutex_unlock(&__kmp_wait_mx.m_mutex);
1708 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
1709 KF_TRACE(30, (
"__kmp_resume_monitor: T#%d exiting after signaling wake up"
1711 gtid, KMP_GTID_MONITOR));
1715void __kmp_yield() { sched_yield(); }
1717void __kmp_gtid_set_specific(
int gtid) {
1718 if (__kmp_init_gtid) {
1720 status = pthread_setspecific(__kmp_gtid_threadprivate_key,
1721 (
void *)(intptr_t)(gtid + 1));
1722 KMP_CHECK_SYSFAIL(
"pthread_setspecific", status);
1724 KA_TRACE(50, (
"__kmp_gtid_set_specific: runtime shutdown, returning\n"));
1728int __kmp_gtid_get_specific() {
1730 if (!__kmp_init_gtid) {
1731 KA_TRACE(50, (
"__kmp_gtid_get_specific: runtime shutdown, returning "
1732 "KMP_GTID_SHUTDOWN\n"));
1733 return KMP_GTID_SHUTDOWN;
1735 gtid = (int)(
size_t)pthread_getspecific(__kmp_gtid_threadprivate_key);
1737 gtid = KMP_GTID_DNE;
1741 KA_TRACE(50, (
"__kmp_gtid_get_specific: key:%d gtid:%d\n",
1742 __kmp_gtid_threadprivate_key, gtid));
1746double __kmp_read_cpu_time(
void) {
1752 return (
double)(buffer.tms_utime + buffer.tms_cutime) /
1753 (
double)CLOCKS_PER_SEC;
1756int __kmp_read_system_info(
struct kmp_sys_info *info) {
1758 struct rusage r_usage;
1760 memset(info, 0,
sizeof(*info));
1762 status = getrusage(RUSAGE_SELF, &r_usage);
1763 KMP_CHECK_SYSFAIL_ERRNO(
"getrusage", status);
1766 info->maxrss = r_usage.ru_maxrss;
1768 info->minflt = r_usage.ru_minflt;
1770 info->majflt = r_usage.ru_majflt;
1772 info->nswap = r_usage.ru_nswap;
1774 info->inblock = r_usage.ru_inblock;
1776 info->oublock = r_usage.ru_oublock;
1778 info->nvcsw = r_usage.ru_nvcsw;
1780 info->nivcsw = r_usage.ru_nivcsw;
1782 return (status != 0);
1785void __kmp_read_system_time(
double *delta) {
1787 struct timeval tval;
1788 struct timespec stop;
1791 status = gettimeofday(&tval, NULL);
1792 KMP_CHECK_SYSFAIL_ERRNO(
"gettimeofday", status);
1793 TIMEVAL_TO_TIMESPEC(&tval, &stop);
1794 t_ns = (double)(TS2NS(stop) - TS2NS(__kmp_sys_timer_data.start));
1795 *delta = (t_ns * 1e-9);
1798void __kmp_clear_system_time(
void) {
1799 struct timeval tval;
1801 status = gettimeofday(&tval, NULL);
1802 KMP_CHECK_SYSFAIL_ERRNO(
"gettimeofday", status);
1803 TIMEVAL_TO_TIMESPEC(&tval, &__kmp_sys_timer_data.start);
1806static int __kmp_get_xproc(
void) {
1812 __kmp_type_convert(sysconf(_SC_NPROCESSORS_CONF), &(r));
1814#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_OPENBSD || \
1817 __kmp_type_convert(sysconf(_SC_NPROCESSORS_ONLN), &(r));
1825 host_basic_info_data_t info;
1826 mach_msg_type_number_t num = HOST_BASIC_INFO_COUNT;
1827 rc = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&info, &num);
1828 if (rc == 0 && num == HOST_BASIC_INFO_COUNT) {
1831 r = info.avail_cpus;
1833 KMP_WARNING(CantGetNumAvailCPU);
1834 KMP_INFORM(AssumedNumCPU);
1839#error "Unknown or unsupported OS."
1843 return r > 0 ? r : 2;
1847int __kmp_read_from_file(
char const *path,
char const *format, ...) {
1851 va_start(args, format);
1852 FILE *f = fopen(path,
"rb");
1855 result = vfscanf(f, format, args);
1861void __kmp_runtime_initialize(
void) {
1863 pthread_mutexattr_t mutex_attr;
1864 pthread_condattr_t cond_attr;
1866 if (__kmp_init_runtime) {
1870#if (KMP_ARCH_X86 || KMP_ARCH_X86_64)
1871 if (!__kmp_cpuinfo.initialized) {
1872 __kmp_query_cpuid(&__kmp_cpuinfo);
1876 __kmp_xproc = __kmp_get_xproc();
1882 status = getrlimit(RLIMIT_STACK, &rlim);
1884 __kmp_stksize = rlim.rlim_cur;
1885 __kmp_check_stksize(&__kmp_stksize);
1889 if (sysconf(_SC_THREADS)) {
1892 __kmp_type_convert(sysconf(_SC_THREAD_THREADS_MAX), &(__kmp_sys_max_nth));
1893 if (__kmp_sys_max_nth == -1) {
1895 __kmp_sys_max_nth = INT_MAX;
1896 }
else if (__kmp_sys_max_nth <= 1) {
1898 __kmp_sys_max_nth = KMP_MAX_NTH;
1902 __kmp_sys_min_stksize = sysconf(_SC_THREAD_STACK_MIN);
1903 if (__kmp_sys_min_stksize <= 1) {
1904 __kmp_sys_min_stksize = KMP_MIN_STKSIZE;
1909 __kmp_tls_gtid_min = KMP_TLS_GTID_MIN;
1911 status = pthread_key_create(&__kmp_gtid_threadprivate_key,
1912 __kmp_internal_end_dest);
1913 KMP_CHECK_SYSFAIL(
"pthread_key_create", status);
1914 status = pthread_mutexattr_init(&mutex_attr);
1915 KMP_CHECK_SYSFAIL(
"pthread_mutexattr_init", status);
1916 status = pthread_mutex_init(&__kmp_wait_mx.m_mutex, &mutex_attr);
1917 KMP_CHECK_SYSFAIL(
"pthread_mutex_init", status);
1918 status = pthread_mutexattr_destroy(&mutex_attr);
1919 KMP_CHECK_SYSFAIL(
"pthread_mutexattr_destroy", status);
1920 status = pthread_condattr_init(&cond_attr);
1921 KMP_CHECK_SYSFAIL(
"pthread_condattr_init", status);
1922 status = pthread_cond_init(&__kmp_wait_cv.c_cond, &cond_attr);
1923 KMP_CHECK_SYSFAIL(
"pthread_cond_init", status);
1924 status = pthread_condattr_destroy(&cond_attr);
1925 KMP_CHECK_SYSFAIL(
"pthread_condattr_destroy", status);
1927 __kmp_itt_initialize();
1930 __kmp_init_runtime = TRUE;
1933void __kmp_runtime_destroy(
void) {
1936 if (!__kmp_init_runtime) {
1941 __kmp_itt_destroy();
1944 status = pthread_key_delete(__kmp_gtid_threadprivate_key);
1945 KMP_CHECK_SYSFAIL(
"pthread_key_delete", status);
1947 status = pthread_mutex_destroy(&__kmp_wait_mx.m_mutex);
1948 if (status != 0 && status != EBUSY) {
1949 KMP_SYSFAIL(
"pthread_mutex_destroy", status);
1951 status = pthread_cond_destroy(&__kmp_wait_cv.c_cond);
1952 if (status != 0 && status != EBUSY) {
1953 KMP_SYSFAIL(
"pthread_cond_destroy", status);
1955#if KMP_AFFINITY_SUPPORTED
1956 __kmp_affinity_uninitialize();
1959 __kmp_init_runtime = FALSE;
1964void __kmp_thread_sleep(
int millis) { sleep((millis + 500) / 1000); }
1967void __kmp_elapsed(
double *t) {
1972 status = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
1973 KMP_CHECK_SYSFAIL_ERRNO(
"clock_gettime", status);
1975 (double)ts.tv_nsec * (1.0 / (
double)KMP_NSEC_PER_SEC) + (
double)ts.tv_sec;
1979 status = gettimeofday(&tv, NULL);
1980 KMP_CHECK_SYSFAIL_ERRNO(
"gettimeofday", status);
1982 (double)tv.tv_usec * (1.0 / (
double)KMP_USEC_PER_SEC) + (
double)tv.tv_sec;
1987void __kmp_elapsed_tick(
double *t) { *t = 1 / (double)CLOCKS_PER_SEC; }
1990kmp_uint64 __kmp_now_nsec() {
1992 gettimeofday(&t, NULL);
1993 kmp_uint64 nsec = (kmp_uint64)KMP_NSEC_PER_SEC * (kmp_uint64)t.tv_sec +
1994 (kmp_uint64)1000 * (kmp_uint64)t.tv_usec;
1998#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2000void __kmp_initialize_system_tick() {
2001 kmp_uint64 now, nsec2, diff;
2002 kmp_uint64 delay = 100000;
2003 kmp_uint64 nsec = __kmp_now_nsec();
2004 kmp_uint64 goal = __kmp_hardware_timestamp() + delay;
2005 while ((now = __kmp_hardware_timestamp()) < goal)
2007 nsec2 = __kmp_now_nsec();
2008 diff = nsec2 - nsec;
2010 kmp_uint64 tpms = ((kmp_uint64)1e6 * (delay + (now - goal)) / diff);
2012 __kmp_ticks_per_msec = tpms;
2020int __kmp_is_address_mapped(
void *addr) {
2025#if KMP_OS_LINUX || KMP_OS_HURD
2030 char *name = __kmp_str_format(
"/proc/%d/maps", getpid());
2033 file = fopen(name,
"r");
2034 KMP_ASSERT(file != NULL);
2038 void *beginning = NULL;
2039 void *ending = NULL;
2042 rc = fscanf(file,
"%p-%p %4s %*[^\n]\n", &beginning, &ending, perms);
2046 KMP_ASSERT(rc == 3 &&
2047 KMP_STRLEN(perms) == 4);
2050 if ((addr >= beginning) && (addr < ending)) {
2052 if (strcmp(perms,
"rw") == 0) {
2062 KMP_INTERNAL_FREE(name);
2066 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid()};
2067 rc = sysctl(mib, 4, NULL, &lstsz, NULL, 0);
2072 lstsz = lstsz * 4 / 3;
2073 buf =
reinterpret_cast<char *
>(kmpc_malloc(lstsz));
2074 rc = sysctl(mib, 4, buf, &lstsz, NULL, 0);
2081 char *up = buf + lstsz;
2084 struct kinfo_vmentry *cur =
reinterpret_cast<struct kinfo_vmentry *
>(lw);
2085 size_t cursz = cur->kve_structsize;
2088 void *start =
reinterpret_cast<void *
>(cur->kve_start);
2089 void *end =
reinterpret_cast<void *
>(cur->kve_end);
2091 if ((addr >= start) && (addr < end)) {
2092 if ((cur->kve_protection & KVME_PROT_READ) != 0 &&
2093 (cur->kve_protection & KVME_PROT_WRITE) != 0) {
2109 rc = vm_read_overwrite(
2111 (vm_address_t)(addr),
2113 (vm_address_t)(&buffer),
2126 mib[2] = VM_PROC_MAP;
2128 mib[4] =
sizeof(
struct kinfo_vmentry);
2131 rc = sysctl(mib, __arraycount(mib), NULL, &size, NULL, 0);
2135 size = size * 4 / 3;
2136 struct kinfo_vmentry *kiv = (
struct kinfo_vmentry *)KMP_INTERNAL_MALLOC(size);
2139 rc = sysctl(mib, __arraycount(mib), kiv, &size, NULL, 0);
2143 for (
size_t i = 0; i < size; i++) {
2144 if (kiv[i].kve_start >= (uint64_t)addr &&
2145 kiv[i].kve_end <= (uint64_t)addr) {
2150 KMP_INTERNAL_FREE(kiv);
2155 mib[1] = KERN_PROC_VMMAP;
2160 rc = sysctl(mib, 3, NULL, &size, NULL, 0);
2165 struct kinfo_vmentry kiv = {.kve_start = 0};
2167 while ((rc = sysctl(mib, 3, &kiv, &size, NULL, 0)) == 0) {
2169 if (kiv.kve_end == end)
2172 if (kiv.kve_start >= (uint64_t)addr && kiv.kve_end <= (uint64_t)addr) {
2178#elif KMP_OS_DRAGONFLY
2185#error "Unknown or unsupported OS"
2193#ifdef USE_LOAD_BALANCE
2195#if KMP_OS_DARWIN || KMP_OS_NETBSD
2202int __kmp_get_load_balance(
int max) {
2206 int res = getloadavg(averages, 3);
2211 if (__kmp_load_balance_interval < 180 && (res >= 1)) {
2212 ret_avg = (int)averages[0];
2213 }
else if ((__kmp_load_balance_interval >= 180 &&
2214 __kmp_load_balance_interval < 600) &&
2216 ret_avg = (int)averages[1];
2217 }
else if ((__kmp_load_balance_interval >= 600) && (res == 3)) {
2218 ret_avg = (int)averages[2];
2232int __kmp_get_load_balance(
int max) {
2233 static int permanent_error = 0;
2234 static int glb_running_threads = 0;
2236 static double glb_call_time = 0;
2238 int running_threads = 0;
2240 DIR *proc_dir = NULL;
2241 struct dirent *proc_entry = NULL;
2243 kmp_str_buf_t task_path;
2244 DIR *task_dir = NULL;
2245 struct dirent *task_entry = NULL;
2246 int task_path_fixed_len;
2248 kmp_str_buf_t stat_path;
2250 int stat_path_fixed_len;
2252 int total_processes = 0;
2253 int total_threads = 0;
2255 double call_time = 0.0;
2257 __kmp_str_buf_init(&task_path);
2258 __kmp_str_buf_init(&stat_path);
2260 __kmp_elapsed(&call_time);
2262 if (glb_call_time &&
2263 (call_time - glb_call_time < __kmp_load_balance_interval)) {
2264 running_threads = glb_running_threads;
2268 glb_call_time = call_time;
2271 if (permanent_error) {
2272 running_threads = -1;
2281 proc_dir = opendir(
"/proc");
2282 if (proc_dir == NULL) {
2285 running_threads = -1;
2286 permanent_error = 1;
2291 __kmp_str_buf_cat(&task_path,
"/proc/", 6);
2292 task_path_fixed_len = task_path.used;
2294 proc_entry = readdir(proc_dir);
2295 while (proc_entry != NULL) {
2298 if (proc_entry->d_type == DT_DIR && isdigit(proc_entry->d_name[0])) {
2306 KMP_DEBUG_ASSERT(total_processes != 1 ||
2307 strcmp(proc_entry->d_name,
"1") == 0);
2310 task_path.used = task_path_fixed_len;
2311 __kmp_str_buf_cat(&task_path, proc_entry->d_name,
2312 KMP_STRLEN(proc_entry->d_name));
2313 __kmp_str_buf_cat(&task_path,
"/task", 5);
2315 task_dir = opendir(task_path.str);
2316 if (task_dir == NULL) {
2325 if (strcmp(proc_entry->d_name,
"1") == 0) {
2326 running_threads = -1;
2327 permanent_error = 1;
2332 __kmp_str_buf_clear(&stat_path);
2333 __kmp_str_buf_cat(&stat_path, task_path.str, task_path.used);
2334 __kmp_str_buf_cat(&stat_path,
"/", 1);
2335 stat_path_fixed_len = stat_path.used;
2337 task_entry = readdir(task_dir);
2338 while (task_entry != NULL) {
2340 if (proc_entry->d_type == DT_DIR && isdigit(task_entry->d_name[0])) {
2348 stat_path_fixed_len;
2349 __kmp_str_buf_cat(&stat_path, task_entry->d_name,
2350 KMP_STRLEN(task_entry->d_name));
2351 __kmp_str_buf_cat(&stat_path,
"/stat", 5);
2355 stat_file = open(stat_path.str, O_RDONLY);
2356 if (stat_file == -1) {
2386 len = read(stat_file, buffer,
sizeof(buffer) - 1);
2393 char *close_parent = strstr(buffer,
") ");
2394 if (close_parent != NULL) {
2395 char state = *(close_parent + 2);
2398 if (running_threads >= max) {
2408 task_entry = readdir(task_dir);
2414 proc_entry = readdir(proc_dir);
2420 KMP_DEBUG_ASSERT(running_threads > 0);
2421 if (running_threads <= 0) {
2422 running_threads = 1;
2426 if (proc_dir != NULL) {
2429 __kmp_str_buf_free(&task_path);
2430 if (task_dir != NULL) {
2433 __kmp_str_buf_free(&stat_path);
2434 if (stat_file != -1) {
2438 glb_running_threads = running_threads;
2440 return running_threads;
2448#if !(KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_MIC || \
2449 ((KMP_OS_LINUX || KMP_OS_DARWIN) && KMP_ARCH_AARCH64) || \
2450 KMP_ARCH_PPC64 || KMP_ARCH_RISCV64)
2454int __kmp_invoke_microtask(microtask_t pkfn,
int gtid,
int tid,
int argc,
2458 void **exit_frame_ptr
2462 *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
2467 fprintf(stderr,
"Too many args to microtask: %d!\n", argc);
2471 (*pkfn)(>id, &tid);
2474 (*pkfn)(>id, &tid, p_argv[0]);
2477 (*pkfn)(>id, &tid, p_argv[0], p_argv[1]);
2480 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2]);
2483 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3]);
2486 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4]);
2489 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2493 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2494 p_argv[5], p_argv[6]);
2497 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2498 p_argv[5], p_argv[6], p_argv[7]);
2501 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2502 p_argv[5], p_argv[6], p_argv[7], p_argv[8]);
2505 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2506 p_argv[5], p_argv[6], p_argv[7], p_argv[8], p_argv[9]);
2509 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2510 p_argv[5], p_argv[6], p_argv[7], p_argv[8], p_argv[9], p_argv[10]);
2513 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2514 p_argv[5], p_argv[6], p_argv[7], p_argv[8], p_argv[9], p_argv[10],
2518 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2519 p_argv[5], p_argv[6], p_argv[7], p_argv[8], p_argv[9], p_argv[10],
2520 p_argv[11], p_argv[12]);
2523 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2524 p_argv[5], p_argv[6], p_argv[7], p_argv[8], p_argv[9], p_argv[10],
2525 p_argv[11], p_argv[12], p_argv[13]);
2528 (*pkfn)(>id, &tid, p_argv[0], p_argv[1], p_argv[2], p_argv[3], p_argv[4],
2529 p_argv[5], p_argv[6], p_argv[7], p_argv[8], p_argv[9], p_argv[10],
2530 p_argv[11], p_argv[12], p_argv[13], p_argv[14]);
2543pthread_cond_t hidden_helper_threads_initz_cond_var;
2544pthread_mutex_t hidden_helper_threads_initz_lock;
2545volatile int hidden_helper_initz_signaled = FALSE;
2548pthread_cond_t hidden_helper_threads_deinitz_cond_var;
2549pthread_mutex_t hidden_helper_threads_deinitz_lock;
2550volatile int hidden_helper_deinitz_signaled = FALSE;
2553pthread_cond_t hidden_helper_main_thread_cond_var;
2554pthread_mutex_t hidden_helper_main_thread_lock;
2555volatile int hidden_helper_main_thread_signaled = FALSE;
2560sem_t hidden_helper_task_sem;
2563void __kmp_hidden_helper_worker_thread_wait() {
2564 int status = sem_wait(&hidden_helper_task_sem);
2565 KMP_CHECK_SYSFAIL(
"sem_wait", status);
2568void __kmp_do_initialize_hidden_helper_threads() {
2571 pthread_cond_init(&hidden_helper_threads_initz_cond_var,
nullptr);
2572 KMP_CHECK_SYSFAIL(
"pthread_cond_init", status);
2574 status = pthread_cond_init(&hidden_helper_threads_deinitz_cond_var,
nullptr);
2575 KMP_CHECK_SYSFAIL(
"pthread_cond_init", status);
2577 status = pthread_cond_init(&hidden_helper_main_thread_cond_var,
nullptr);
2578 KMP_CHECK_SYSFAIL(
"pthread_cond_init", status);
2580 status = pthread_mutex_init(&hidden_helper_threads_initz_lock,
nullptr);
2581 KMP_CHECK_SYSFAIL(
"pthread_mutex_init", status);
2583 status = pthread_mutex_init(&hidden_helper_threads_deinitz_lock,
nullptr);
2584 KMP_CHECK_SYSFAIL(
"pthread_mutex_init", status);
2586 status = pthread_mutex_init(&hidden_helper_main_thread_lock,
nullptr);
2587 KMP_CHECK_SYSFAIL(
"pthread_mutex_init", status);
2590 status = sem_init(&hidden_helper_task_sem, 0, 0);
2591 KMP_CHECK_SYSFAIL(
"sem_init", status);
2595 status = pthread_create(
2597 [](
void *) ->
void * {
2598 __kmp_hidden_helper_threads_initz_routine();
2602 KMP_CHECK_SYSFAIL(
"pthread_create", status);
2605void __kmp_hidden_helper_threads_initz_wait() {
2608 int status = pthread_mutex_lock(&hidden_helper_threads_initz_lock);
2609 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
2611 if (!TCR_4(hidden_helper_initz_signaled)) {
2612 status = pthread_cond_wait(&hidden_helper_threads_initz_cond_var,
2613 &hidden_helper_threads_initz_lock);
2614 KMP_CHECK_SYSFAIL(
"pthread_cond_wait", status);
2617 status = pthread_mutex_unlock(&hidden_helper_threads_initz_lock);
2618 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
2621void __kmp_hidden_helper_initz_release() {
2623 int status = pthread_mutex_lock(&hidden_helper_threads_initz_lock);
2624 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
2626 status = pthread_cond_signal(&hidden_helper_threads_initz_cond_var);
2627 KMP_CHECK_SYSFAIL(
"pthread_cond_wait", status);
2629 TCW_SYNC_4(hidden_helper_initz_signaled, TRUE);
2631 status = pthread_mutex_unlock(&hidden_helper_threads_initz_lock);
2632 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
2635void __kmp_hidden_helper_main_thread_wait() {
2638 int status = pthread_mutex_lock(&hidden_helper_main_thread_lock);
2639 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
2641 if (!TCR_4(hidden_helper_main_thread_signaled)) {
2642 status = pthread_cond_wait(&hidden_helper_main_thread_cond_var,
2643 &hidden_helper_main_thread_lock);
2644 KMP_CHECK_SYSFAIL(
"pthread_cond_wait", status);
2647 status = pthread_mutex_unlock(&hidden_helper_main_thread_lock);
2648 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
2651void __kmp_hidden_helper_main_thread_release() {
2654 int status = pthread_mutex_lock(&hidden_helper_main_thread_lock);
2655 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
2657 status = pthread_cond_signal(&hidden_helper_main_thread_cond_var);
2658 KMP_CHECK_SYSFAIL(
"pthread_cond_signal", status);
2661 TCW_SYNC_4(hidden_helper_main_thread_signaled, TRUE);
2663 status = pthread_mutex_unlock(&hidden_helper_main_thread_lock);
2664 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
2667void __kmp_hidden_helper_worker_thread_signal() {
2668 int status = sem_post(&hidden_helper_task_sem);
2669 KMP_CHECK_SYSFAIL(
"sem_post", status);
2672void __kmp_hidden_helper_threads_deinitz_wait() {
2675 int status = pthread_mutex_lock(&hidden_helper_threads_deinitz_lock);
2676 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
2678 if (!TCR_4(hidden_helper_deinitz_signaled)) {
2679 status = pthread_cond_wait(&hidden_helper_threads_deinitz_cond_var,
2680 &hidden_helper_threads_deinitz_lock);
2681 KMP_CHECK_SYSFAIL(
"pthread_cond_wait", status);
2684 status = pthread_mutex_unlock(&hidden_helper_threads_deinitz_lock);
2685 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
2688void __kmp_hidden_helper_threads_deinitz_release() {
2689 int status = pthread_mutex_lock(&hidden_helper_threads_deinitz_lock);
2690 KMP_CHECK_SYSFAIL(
"pthread_mutex_lock", status);
2692 status = pthread_cond_signal(&hidden_helper_threads_deinitz_cond_var);
2693 KMP_CHECK_SYSFAIL(
"pthread_cond_wait", status);
2695 TCW_SYNC_4(hidden_helper_deinitz_signaled, TRUE);
2697 status = pthread_mutex_unlock(&hidden_helper_threads_deinitz_lock);
2698 KMP_CHECK_SYSFAIL(
"pthread_mutex_unlock", status);
2701void __kmp_hidden_helper_worker_thread_wait() {
2702 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2705void __kmp_do_initialize_hidden_helper_threads() {
2706 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2709void __kmp_hidden_helper_threads_initz_wait() {
2710 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2713void __kmp_hidden_helper_initz_release() {
2714 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2717void __kmp_hidden_helper_main_thread_wait() {
2718 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2721void __kmp_hidden_helper_main_thread_release() {
2722 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2725void __kmp_hidden_helper_worker_thread_signal() {
2726 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2729void __kmp_hidden_helper_threads_deinitz_wait() {
2730 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
2733void __kmp_hidden_helper_threads_deinitz_release() {
2734 KMP_ASSERT(0 &&
"Hidden helper task is not supported on this OS");
#define KMP_INIT_PARTITIONED_TIMERS(name)
Initializes the partitioned timers to begin with name.