[Linux]: Replace reading proc to get thread user CPU time with clock_gettime

XMLWordPrintable

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

      To get user CPU time on Linux for a thread we read /proc. Reading proc is slow (hence why this procedure is put under the method slow_thread_cpu_time(...)) and may lead noticeable spikes in case of contention for kernel resources.

      Linux internally accounts for system and user time separately for threads/processes. Each clock id supports two modes: retrieve total CPU time (sys+user) or just user time. That way we can to two calls to clock_gettime and get total and user. From that we can get system (total - user).

      I did some benchmarking and it is clear that the cost is minimal with two calls to clock_gettime vs reading proc (see attached plot). Moreover, and more importantly, the code will be substantially simplified.

      Note: This is a feature that is only specific to Linux and not part of the POSIX standard, but used by glibc/musl (both of which OpenJDK supports) and is a Linux ABI. Additionally, the current implementation of slow_thread_cpu_time already have a Linux specific implementation it fits well to replace the call to read proc.

            Assignee:
            Jonas Norlinder
            Reporter:
            Jonas Norlinder
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: