This ticket is created on behalf of Jaromir Hamala:
We can additionally optimize os::current_thread_cpu_time (used by ThreadMXBean.getCurrentThreadUserTime()) on Linux by using the kernel's fast-path for the calling thread.
The current code has 2 phases:
- Create a timer bound to the current Thread ID (TID) + massage the timer to switch from CPUCLOCK_SCHED timer to CPUCLOCK_VIRT
- Use the timer in clock_gettime()
Within the kernel, a routine, pid_for_clock, exists to extract the TID from the timer, followed by a radix lookup to find booking structures for the specified TID.
However, the kernel also has a fast-path: When TID is 0, then the kernel avoids the radix lookup and instead treats the timer as bound to 'the current thread' (or a process, depending on lower bits of the clock). The current thread/task has bookkeeping structures more readily available and the radix lookup is avoided. The result is around 13% faster getCurrentThreadUserTime().
We can additionally optimize os::current_thread_cpu_time (used by ThreadMXBean.getCurrentThreadUserTime()) on Linux by using the kernel's fast-path for the calling thread.
The current code has 2 phases:
- Create a timer bound to the current Thread ID (TID) + massage the timer to switch from CPUCLOCK_SCHED timer to CPUCLOCK_VIRT
- Use the timer in clock_gettime()
Within the kernel, a routine, pid_for_clock, exists to extract the TID from the timer, followed by a radix lookup to find booking structures for the specified TID.
However, the kernel also has a fast-path: When TID is 0, then the kernel avoids the radix lookup and instead treats the timer as bound to 'the current thread' (or a process, depending on lower bits of the clock). The current thread/task has bookkeeping structures more readily available and the radix lookup is avoided. The result is around 13% faster getCurrentThreadUserTime().
- relates to
-
JDK-8372584 [Linux]: Replace reading proc to get thread user CPU time with clock_gettime
-
- Resolved
-