[Linux] Avoid radix lookup in kernel pid_for_clock to speedup getCurrentThreadUserTime

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: None
    • Component/s: hotspot

      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().

            Assignee:
            Unassigned
            Reporter:
            Evgeny Astigeevich
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: