Fine tune OpenMP some more

This commit is contained in:
Justine Tunney 2024-01-30 04:38:11 -08:00
parent 369aebfc48
commit 616717fa82
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 45 additions and 48 deletions

View file

@ -22,6 +22,9 @@
#include "kmp_wrapper_getpid.h"
#if KMP_USE_FUTEX
#ifdef __COSMOPOLITAN__
#include "third_party/nsync/futex.internal.h"
#else
#include <sys/syscall.h>
#include <unistd.h>
// We should really include <futex.h>, but that causes compatibility problems on
@ -36,6 +39,7 @@
#define FUTEX_WAKE 1
#endif
#endif
#endif
/* Implement spin locks for internal library use. */
/* The algorithm implemented is Lamport's bakery lock [1974]. */
@ -375,8 +379,12 @@ __kmp_acquire_futex_lock_timed_template(kmp_futex_lock_t *lck, kmp_int32 gtid) {
lck, gtid, poll_val));
long rc;
#ifdef __COSMOPOLITAN__
if ((rc = nsync_futex_wait_(&(lck->lk.poll), poll_val, false, NULL)) != 0) {
#else
if ((rc = syscall(__NR_futex, &(lck->lk.poll), FUTEX_WAIT, poll_val, NULL,
NULL, 0)) != 0) {
#endif
KA_TRACE(1000, ("__kmp_acquire_futex_lock: lck:%p, T#%d futex_wait(0x%x) "
"failed (rc=%ld errno=%d)\n",
lck, gtid, poll_val, rc, errno));
@ -453,8 +461,12 @@ int __kmp_release_futex_lock(kmp_futex_lock_t *lck, kmp_int32 gtid) {
KA_TRACE(1000,
("__kmp_release_futex_lock: lck:%p, T#%d futex_wake 1 thread\n",
lck, gtid));
#ifdef __COSMOPOLITAN__
nsync_futex_wake_(&(lck->lk.poll), 1, false);
#else
syscall(__NR_futex, &(lck->lk.poll), FUTEX_WAKE, KMP_LOCK_BUSY(1, futex),
NULL, NULL, 0);
#endif
}
KMP_MB(); /* Flush all pending memory write invalidates. */