On Tue Feb 4 18:43:10 2025 +0000, Brendan Shanks wrote:
Wouldn't it be essentially the same to call `gettimeofday()` instead of `__commpage_gettimeofday()`? This line could change to `#if defined(HAVE_CLOCK_GETTIME) && !defined(__APPLE__)`.
Indeed, but this commit essentially inlines the call to `__commpage_gettimeofday()` inside `gettimeofday()`, wheres the latter still incurs of overhead of 23 CPU cycles before calling into `__commpage_gettimeofday()`, if I counted correctly.
It actually does more than inlining though, `gettimeofday()`, will do a syscall if `__commpage_gettimeofday()` fails, and use that value instead.
This can happen rarely (about 1 in a million in my testing), probably when page time values that are updated asynchronously from the kernel are read simultaneously.
As the commit is right now, it effectively tries to read from the commpage *twice*, making that chance of doing a syscall astronomically low.
Also it is still measurably faster to use `__commpage_gettimeofday()` directly (benchmarked at 10000000 iterations through Rosetta):
``` clock_gettime() Duration: 0.290506 seconds gettimeofday() Duration: 0.233024 seconds __commpage_gettimeofday() Duration: 0.217468 seconds ```