[Bug 300333] java/openjdk25: getCurrentThreadCpuTime() does not return the actual time in nanoseconds

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 02 Nov 2026 18:51:08 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300333

--- Comment #4 from Saro <saro@saromedia.com> ---
(In reply to Harald Eilertsen from comment #2)

Hi Harald, I appreciate the quick follow-up!

I ran the test C++ code and am seeing identical results: the granularity of the
returned values is way too coarse. I have tested this on 2 separate physical
machines (no VMs or Jails) running FreeBSD 14.5-p2.

I understand that the `getCurrentThreadCpuTime()` does not guarantee nanosecond
accuracy, however running the same Java test on a test Debian 12 (physical)
machine returns a pristine 0 for `zero deltas`.

Is this a limitation with the FreeBSD kernel? From my understanding, it is
possible to return CPU thread time in nanoseconds using
`CLOCK_THREAD_CPUTIME_ID` when passing it to `clock_gettime()` based on
https://github.com/freebsd/freebsd-src/blob/releng/14.5/sys/kern/kern_time.c#L364

I noticed the Linux implementation is also using `CLOCK_THREAD_CPUTIME_ID` with
`clock_gettime` based on
https://github.com/freebsd/openjdk/blob/jdk25u-freebsd/src/hotspot/os/linux/os_linux.cpp#L5227
and
https://github.com/freebsd/openjdk/blob/jdk25u-freebsd/src/hotspot/os/linux/os_linux.cpp#L4443
(with a fallback to pthread somewhere, IIRC).

When I modified your test code to utilize `CLOCK_THREAD_CPUTIME_ID` alone, the
results were perfect: `zero deltas` was 0, with the lowest non-zero step being
~263 ns.

It's entirely possible I'm not fully understanding the code, kernel or the
implementation (I'm more of a Java guy...) so I apologize in advance for
wasting your time.

Thank you!

-- 
You are receiving this mail because:
You are on the CC list for the bug.