Repository navigation
Description
What happened?
Hi all, I came across this while reading host execution profiles from local-task on an Apple M5, and it looks like a small platform detail more than a bug.
iree_platform_time_now in runtime/src/iree/base/internal/time.c reads clock_gettime(CLOCK_MONOTONIC) on every POSIX platform. On macOS that clock has a resolution of 1 µs, and none of 1,000 consecutive reads had a sub-microsecond part. CLOCK_MONOTONIC_RAW and CLOCK_UPTIME_RAW on the same machine resolve to 42 ns:
CLOCK_MONOTONIC res=1000 ns sub-us reads=0/1000 min step=1000 ns
CLOCK_MONOTONIC_RAW res=42 ns sub-us reads=960/1000 min step=41 ns
CLOCK_UPTIME_RAW res=42 ns sub-us reads=958/1000 min step=41 ns
Host execution events stamp each dispatch with iree_time_now around iree_hal_local_executable_issue_dispatch_inline, so a dispatch that finishes within a microsecond is recorded with a duration of 0 ns, and the surrounding execute shows one or two ticks. The order and structure of the events are exact, but their durations are not usable below a microsecond on this platform. The same applies to anything else that measures short intervals with iree_time_now on Apple.
The comment above the clock read explains that CLOCK_MONOTONIC_RAW is avoided because pthread_cond_timedwait cannot take it, and that holds on Linux. On Apple the wait paths do not depend on the clock domain. notification.c and wait_address.c use pthread_cond_timedwait_relative_np there, since Apple has no pthread_condattr_setclock. iree_wait_until_impl in base/time.c falls back to relative nanosleep, and the posix proactor waits with a relative timeout. Each of them turns an iree_time_now deadline into a duration, so the Apple branch could read a finer clock without affecting waits.
A possible change is a separate Apple branch that returns clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW). Like CLOCK_MONOTONIC on macOS it keeps counting during sleep, so deadlines and timestamps keep their current meaning, and it avoids the timespec round trip. The comment in time.c and the clock table in base/time.h would then name the Apple clock. IREE_TIME_NOW_FN already lets an embedder override the clock, but a finer default on Apple seems worth having since the profiling tools rely on it. I am happy to send a PR along these lines.
Steps to reproduce your issue
clock.c:
#include <stdio.h>
#include <time.h>
static void probe(const char* name, clockid_t id) {
struct timespec res;
clock_getres(id, &res);
int sub_us = 0;
for (int i = 0; i < 1000; ++i) {
struct timespec t;
clock_gettime(id, &t);
if (t.tv_nsec % 1000) ++sub_us;
}
printf("%-22s res=%ld ns sub-us reads=%d/1000\n", name, res.tv_nsec, sub_us);
}
int main(void) {
probe("CLOCK_MONOTONIC", CLOCK_MONOTONIC);
probe("CLOCK_MONOTONIC_RAW", CLOCK_MONOTONIC_RAW);
probe("CLOCK_UPTIME_RAW", CLOCK_UPTIME_RAW);
return 0;
}cc -O2 clock.c -o clock && ./clockIn IREE itself, a local-task run of a small dispatch with --device_profiling_mode=host-execution records host execution events whose start and end times are whole microseconds and whose durations are 0 ns.
Expected: iree_time_now on macOS resolves below a microsecond, as it does on Linux and Windows.
What component(s) does this issue relate to?
Runtime
Version information
Reproduced with a build of v3.13.0 (89ece87) on macOS 26.6.2, arm64 (Apple M5). The Apple branch of iree_platform_time_now is unchanged on main at 5332c68.
Additional context
#23325 moved iree_time_now from CLOCK_REALTIME to CLOCK_MONOTONIC, which made it monotonic everywhere. On macOS both clocks tick in microseconds, so the resolution was the same before that change.
Thanks for taking a look!
Activity
github-actions commentedon Nov 15, 2026
Hello @hamidelmaazouz 👋
Thank you for submitting an issue to IREE! It looks like it's your first one.
The volume of issues is huge, and triage times may vary. If you need quicker assistance on the issue, consider posting it on IREE Discord and providing short context there.
Feel free to identify the most frequent contributors to the corresponding part of the codebase via Git history/CODEOWNERS and (gently!) tag them below.
Action required: acknowledge IREE project policies
IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.
Please note that all contributions to IREE, including GitHub issues, must follow our IREE AI Tool Use Policy. This means:
For bug reports, specifics of the use-case, workflow and/or crash scenario usually suffice.
For improvement suggestions, this usually implies deeper understanding of suboptimal code, IR design choices, assumed performance tradeoffs, etc.
Before the issue can be triaged, we kindly ask you to reply to this message and confirm that you understand and accept the proposed policy. As required, please adjust your initial issue description.
If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.
Thank you,
The IREE Community
devtbi commentedon Nov 17, 2026
might want to consider using CLOCK_MONOTONIC_RAW for profiling. NTP frequency-adjustment is irrelevant for profiling IMO.