RFR: 8326446: The User and System of jdk.CPULoad on Apple M1 are inaccurate [v2]
Long Yang
duke at openjdk.org
Thu Mar 7 01:59:57 UTC 2024
On Fri, 23 Feb 2024 08:21:11 GMT, Long Yang <duke at openjdk.org> wrote:
>> hi
>>
>> I would like to fix this.
>>
>> As the description in [JDK-8326446](https://bugs.openjdk.org/browse/JDK-8326446).
>> JFR uses task_info() with flavor TASK_ABSOLUTETIME_INFO to read User and System time. it is not reliable on Apple m1.
>>
>> Libc provides the [times](https://man7.org/linux/man-pages/man2/times.2.html) function, which uses TASK_BASIC_INFO_COUNT and TASK_THREAD_TIMES_INFO_COUNT. It will also return the real time of the process, and the time unit is the same, which is suitable for solving this problem.
>>
>> I ran test/jdk/jdk/jfr/event/os/TestCPULoad.java and passed.
>>
>> I would appreciate it if you could review this.
>
> Long Yang has updated the pull request incrementally with one additional commit since the last revision:
>
> update copyright header
Because the [times](https://man7.org/linux/man-pages/man2/times.2.html) libc api returns the real time of the process. So we don't need to calculate the `total_cpu_nanos`, just use the return value of `times`.
struct tms buf;
clock_t jvm_real = times(&buf);
if (jvm_real == (clock_t) (-1)) {
return OS_ERR;
}
...
uint64_t delta = active_processor_count * (jvm_real - _jvm_real);
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17976#issuecomment-1982198946
More information about the hotspot-jfr-dev
mailing list