RFR: 8372584: [Linux]: Replace reading proc to get thread user CPU time with clock_gettime [v3]
David Holmes
dholmes at openjdk.org
Tue Dec 2 09:18:10 UTC 2025
On Mon, 1 Dec 2025 11:42:45 GMT, Jonas Norlinder <jnorlinder at openjdk.org> wrote:
>> src/hotspot/os/linux/os_linux.cpp line 4968:
>>
>>> 4966: // POSIX.1-2024/IEEE Std 1003.1-2024 §3.90.
>>> 4967: static clockid_t get_thread_clockid(Thread* thread, bool total, bool* success) {
>>> 4968: constexpr clockid_t CLOCK_TYPE_MASK = 3;
>>
>> Shouldn't the mask be covering 3-bits?
>
> No we should not touch bit 3 which encodes if the clock is for a thread of process. See here https://elixir.bootlin.com/linux/v6.17.9/source/include/linux/posix-timers_types.h#L9-L19.
Okay so
> encoding the clock types in the last three bits
needs a bit more explanation.
>> src/hotspot/os/linux/os_linux.cpp line 4979:
>>
>>> 4977: // to detach itself from the VM - which should result in ESRCH.
>>> 4978: assert_status(rc == ESRCH, rc, "pthread_getcpuclockid failed");
>>> 4979: *success = false;
>>
>> The normal way I've seen this pattern used is to set it to true rather than assuming it was true to begin with.
>
> Using a positive outcome like success to encode the outcome make it possible to return like so `return success ? os::Linux::thread_cpu_time(clockid) : -1;`. I prefer having the `-1` at the end as I find this reads easier. If we encode a failure we would need to write `return !failure ? os::Linux::thread_cpu_time(clockid) : -1;`. Hence, I would prefer keeping this as is as double-negatives may be harder to parse.
Okay but you are setting up a usage requirement without documenting anywhere that that requirement exists.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28556#discussion_r2580306175
PR Review Comment: https://git.openjdk.org/jdk/pull/28556#discussion_r2580309226
More information about the hotspot-runtime-dev
mailing list