cosmopolitan/libc/log
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
..
addr2linepath.c Make improvements 2023-09-18 21:04:47 -07:00
appendresourcereport.c Make improvements 2023-09-18 21:04:47 -07:00
appendresourcereport.internal.h Pay off more technical debt 2022-09-12 23:36:56 -07:00
attachdebugger.c Fix warnings 2023-09-01 20:50:18 -07:00
backtrace.internal.h Optimize memory layout 2022-09-12 04:26:52 -07:00
backtrace2.c Fix warnings 2023-09-01 20:50:18 -07:00
backtrace3.c Make improvements 2023-09-18 21:04:47 -07:00
bsd.h Add script.com and whois.com courtesy of FreeBSD 2022-09-13 20:26:13 -07:00
check.h Fix bugs in cosmocc toolchain 2023-06-08 23:44:03 -07:00
checkaligned.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
checkfail.c Make improvements 2023-09-21 07:30:39 -07:00
checkfail_ndebug.c Make improvements for Actually Portable Emacs 2023-08-19 06:44:58 -07:00
color.internal.h Make exciting improvements 2022-03-18 03:02:00 -07:00
commandvenv.c Make improvements 2023-09-06 12:34:59 -07:00
countbranch.h Introduce native support for MacOS ARM64 2023-05-20 04:17:03 -07:00
countbranch_data.S Make progress towards aarch64 build 2023-05-10 04:20:46 -07:00
countbranch_report.c Get llama.com building as an aarch64 native binary 2023-05-10 04:20:47 -07:00
countexpr.h Introduce native support for MacOS ARM64 2023-05-20 04:17:03 -07:00
countexpr_data.S Make progress towards aarch64 build 2023-05-10 04:20:46 -07:00
countexpr_report.c Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
cxaprintexits.c Pay off more technical debt 2022-09-12 23:36:56 -07:00
die.c Make improvements 2023-10-03 06:17:16 -07:00
err.c Disable linker map generation and improve tinyness 2023-06-09 03:29:26 -07:00
flogf.c Change license 2020-12-27 17:18:44 -08:00
gdb.h Make improvements 2023-09-18 21:04:47 -07:00
gdbexec.c Fix warnings 2023-09-01 20:50:18 -07:00
gdbpath.c Change license 2020-12-27 17:18:44 -08:00
gdbsync.c Remove _Hide keyword 2023-07-24 08:34:58 -07:00
getcallername.c Fix warnings 2023-09-01 20:50:18 -07:00
getcallername.internal.h Pay off more technical debt 2022-09-12 23:36:56 -07:00
internal.h Make improvements 2023-09-18 21:04:47 -07:00
leaks.c Make improvements 2023-09-18 21:04:47 -07:00
libfatal.internal.h Overhaul process spawning 2023-09-10 08:17:44 -07:00
log.h Improve performance and remove fd leaks 2023-09-10 11:52:03 -07:00
log.mk Make improvements 2023-09-18 21:04:47 -07:00
log_exit.c Make improvements for Actually Portable Emacs 2023-08-19 06:44:58 -07:00
log_get_errno.c Get GCC to mostly build with Cosmo 2023-06-09 06:41:34 -07:00
log_retrace.c Get GCC to mostly build with Cosmo 2023-06-09 06:41:34 -07:00
log_set_errno.c Get GCC to mostly build with Cosmo 2023-06-09 06:41:34 -07:00
log_untrace.c Get GCC to mostly build with Cosmo 2023-06-09 06:41:34 -07:00
logerrno.c Remove printf() linking hack 2023-06-17 10:13:50 -07:00
logfile.c Make progress towards aarch64 build 2023-05-10 04:20:46 -07:00
loglevel.c Get LIBC_TESTLIB building on AARCH64 2023-05-11 19:57:09 -07:00
meminfo.c Remove printf() linking hack 2023-06-17 10:13:50 -07:00
memlog.c Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
memsummary.c Fix warnings 2023-09-01 20:50:18 -07:00
minicrash.c Make improvements 2023-10-03 06:17:16 -07:00
oncrash_amd64.c Make improvements 2023-09-18 21:04:47 -07:00
oncrash_arm64.c Make futexes 100x better on x86 MacOS 2023-10-03 15:15:43 -07:00
printwindowsmemory.c Fix warnings 2023-09-01 20:50:18 -07:00
rop.internal.h Introduce #include <cosmo.h> to toolchain users 2023-06-09 18:03:05 -07:00
showcrashreports.c Make improvements 2023-09-18 21:04:47 -07:00
showcrashreportsearly.S Mint APE Loader v1.5 2023-07-26 13:54:49 -07:00
startfatal.c Further improve fatcosmocc 2023-08-13 01:51:39 -07:00
traceme.c Undiamond Python headers 2021-08-12 14:07:40 -07:00
traceme.h Undiamond Python headers 2021-08-12 14:07:40 -07:00
vflogf.c Make improvements 2023-10-03 06:17:16 -07:00
watch-hook.S Make improvements 2022-08-15 15:20:36 -07:00
watch.c Fix warnings 2023-09-01 20:50:18 -07:00