cosmopolitan/third_party
Justine Tunney 85f64f3851
Make futexes 100x better on x86 MacOS
Thanks to @autumnjolitz (in #876) the Cosmopolitan codebase is now
acquainted with Apple's outstanding ulock system calls which offer
something much closer to futexes than Grand Central Dispatch which
wasn't quite as good, since its wait function can't be interrupted
by signals (therefore necessitating a busy loop) and it also needs
semaphore objects to be created and freed. Even though ulock is an
internal Apple API, strictly speaking, the benefits of futexes are
so great that it's worth the risk for now especially since we have
the GCD implementation still as a quick escape hatch if it changes

Here's why this change is important for x86 XNU users. Cosmo has a
suboptimal polyfill when the operating system doesn't offer an API
that let's us implement futexes properly. Sadly we had to use that
on X86 XNU until now. The polyfill works using clock_nanosleep, to
poll the futex in a busy loop with exponential backoff. On XNU x86
clock_nanosleep suffers from us not being able to use a fast clock
gettime implementation, which had a compounding effect that's made
the polyfill function even more poorly. On X86 XNU we also need to
polyfill sched_yield() using select(), which made things even more
troublesome. Now that we have futexes we don't have any busy loops
anymore for both condition variables and thread joining so optimal
performance is attained. To demonstrate, consider these benchmarks

Before:

    $ ./lockscale_test.com -b
    consumed 38.8377   seconds real time and
              0.087131 seconds cpu time

After:

    $ ./lockscale_test.com -b
    consumed 0.007955 seconds real time and
             0.011515 seconds cpu time

Fixes #876
2023-10-03 15:15:43 -07:00
..
aarch64 Upgrade to Cosmopolitan GCC 11.2.0 for aarch64 2023-06-05 02:07:28 -07:00
argon2 Make the Windows Console work better 2023-09-07 18:27:22 -07:00
awk Make improvements 2023-09-18 21:04:47 -07:00
bzip2 Fix warnings 2023-09-01 20:50:18 -07:00
chibicc Make improvements 2023-10-03 06:17:16 -07:00
compiler_rt Make improvements 2023-09-06 12:34:59 -07:00
ctags Make improvements 2023-09-18 21:04:47 -07:00
dlmalloc Make improvements 2023-09-18 21:04:47 -07:00
double-conversion Fix warnings 2023-09-01 20:50:18 -07:00
finger Get rid of kmalloc() 2023-09-11 21:56:00 -07:00
gcc Make cosmocc capable of cross compilation 2023-08-13 14:40:22 -07:00
gdtoa Fix strtod NaN handling / fix SIGSEGV in testlib/showerror (#901) 2023-09-27 00:16:36 -07:00
getopt Fix getopt again 2023-08-15 20:06:19 -07:00
ggml Make improvements 2023-09-18 21:04:47 -07:00
hiredis Make improvements 2023-09-06 12:34:59 -07:00
intel Fix some build errors 2023-06-05 15:53:44 -07:00
libcxx Include missing symbols in <cstdint> for C++ 2023-10-03 08:19:09 -07:00
linenoise Make improvements 2023-09-18 21:04:47 -07:00
lua Remove Windows executable path guessing logic 2023-09-21 08:13:50 -07:00
lz4cli Make progress towards aarch64 build 2023-05-10 04:20:46 -07:00
make Make improvements 2023-09-18 21:04:47 -07:00
maxmind Brush up some more code 2023-07-10 10:17:26 -07:00
mbedtls Temporarily disable test_suite_x509parse.com 2023-10-02 13:49:16 -07:00
musl Make improvements 2023-10-03 06:17:16 -07:00
nsync Make futexes 100x better on x86 MacOS 2023-10-03 15:15:43 -07:00
puff Make improvements 2023-09-18 21:04:47 -07:00
python Make improvements 2023-10-03 06:17:16 -07:00
qemu Fix MODE=aarch64 build 2023-06-08 05:17:37 -07:00
quickjs Make improvements 2023-09-18 21:04:47 -07:00
radpajama Fix warnings 2023-09-01 20:50:18 -07:00
regex Make the Windows Console work better 2023-09-07 18:27:22 -07:00
sed Remove IMAGE_BASE_VIRTUAL 2023-09-12 01:21:36 -07:00
smallz4 Clean up more code 2023-06-18 01:00:05 -07:00
sqlite3 Make improvements 2023-10-03 06:17:16 -07:00
stb Fix warnings 2023-09-01 20:50:18 -07:00
tidy Remove VM variable 2023-09-12 01:27:30 -07:00
tr Remove old stack code and improve dirstream 2023-08-16 07:54:40 -07:00
unzip Fix warnings 2023-09-01 20:50:18 -07:00
vqsort Overhaul process spawning 2023-09-10 08:17:44 -07:00
xed Make improvements 2023-09-18 21:04:47 -07:00
xxhash Make improvements 2023-09-06 12:34:59 -07:00
zip Make improvements 2023-10-03 06:17:16 -07:00
zlib Remove IMAGE_BASE_VIRTUAL 2023-09-12 01:21:36 -07:00
zstd Make improvements 2023-10-03 06:17:16 -07:00
third_party.mk Move demangling utility to stdio 2023-07-07 10:47:50 -07:00