Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8326446

The User and System of jdk.CPULoad on Apple M1 are inaccurate

XMLWordPrintable

    • jfr
    • b14
    • aarch64
    • os_x

        Run the test code on OSX with Apple m1 for a few seconds and then check the User and System of jdk.CPULoad events

        java -XX:StartFlightRecording=name=test,settings=default,filename=test.jfr EatCpu 4

        top
        PID       COMMAND    %CPU (total 8 cores)
        42421   java              397.1

        jfr view jdk.CPULoad osx-m1.jfr
                                             CPU Load

        Time                         JVM User           JVM System           Machine Total
        ------------ --------------- -------------- -------------
        10:51:57                        0.64%                0.56%                  62.59%
        10:51:58                        0.64%                0.56%                  59.70%
        10:51:59                        0.64%                0.56%                  59.50%
        10:52:00                        0.63%                0.57%                  65.71%

        The User and System of jdk.CPULoad on Apple M1 are inaccurate.
        The system's CPU is mainly consumed by Java (see Machine Total), but both JVM User and JVM System are obviously low.

        The same code, if run on OSX with Intel x64 (12 Hyper-Threading cores), the result is accurate.

        jfr view jdk.CPULoad j17-x64.jfr

                                             CPU Load

        Time                         JVM User           JVM System           Machine Total
        ------------ --------------- --------------- -------------
        10:37:54                        8.39%               24.96%                  34.11%
        10:37:55                        8.45%               24.89%                  33.97%
        10:37:56                        8.44%               24.92%                  34.22%
        10:37:57                        8.42%               24.91%                   34.39%

        The reason is JFR used task_info() with flavor TASK_ABSOLUTETIME_INFO to read User and System time.

        https://github.com/openjdk/jdk/blob/f8a924a749a786f9e9172561135731c4948c9856/src/hotspot/os/bsd/os_perf_bsd.cpp#L158

        task_info(task, TASK_ABSOLUTETIME_INFO, (task_info_t)task_info_data, &task_info_count)

        but it is not reliable on Apple m1, see https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/tests/task_info.c#L344

        A possible solution is to use TASK_THREAD_TIMES_INFO and 
        TASK_BASIC_INFO_64, these two flavors are reliable, just like what UnixOperatingSystem.c does.
        https://github.com/openjdk/jdk/blob/2963c9e6778b95f5c0fc4298064a21d1e8f31b91/src/jdk.management/macosx/native/libmanagement_ext/UnixOperatingSystem.c#L87

         

          1. EatCpu.java
            0.6 kB
          2. j17-x64.jfr
            353 kB
          3. osx-m1.jfr
            434 kB

              lyang Long Yang
              lyang Long Yang
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: