8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux
authordbuck
Tue, 18 Aug 2015 04:29:28 -0700
changeset 32417 6859107fc6c3
parent 32416 702b81d3cd39
child 32418 fe7885fbdad5
8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux Reviewed-by: sla, mgronlun
jdk/src/jdk.management/linux/native/libmanagement_ext/UnixOperatingSystem.c
--- a/jdk/src/jdk.management/linux/native/libmanagement_ext/UnixOperatingSystem.c	Mon Aug 17 12:45:16 2015 +0300
+++ b/jdk/src/jdk.management/linux/native/libmanagement_ext/UnixOperatingSystem.c	Tue Aug 18 04:29:28 2015 -0700
@@ -77,14 +77,17 @@
 static int get_totalticks(int which, ticks *pticks) {
     FILE         *fh;
     uint64_t        userTicks, niceTicks, systemTicks, idleTicks;
+    uint64_t        iowTicks = 0, irqTicks = 0, sirqTicks= 0;
     int             n;
 
     if((fh = fopen("/proc/stat", "r")) == NULL) {
         return -1;
     }
 
-    n = fscanf(fh, "cpu " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64,
-           &userTicks, &niceTicks, &systemTicks, &idleTicks);
+    n = fscanf(fh, "cpu " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " "
+                   DEC_64 " " DEC_64,
+           &userTicks, &niceTicks, &systemTicks, &idleTicks,
+           &iowTicks, &irqTicks, &sirqTicks);
 
     // Move to next line
     next_line(fh);
@@ -93,24 +96,30 @@
     if (which != -1) {
         int i;
         for (i = 0; i < which; i++) {
-            if (fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64, &userTicks, &niceTicks, &systemTicks, &idleTicks) != 4) {
+            if (fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " "
+                            DEC_64 " " DEC_64 " " DEC_64,
+                   &userTicks, &niceTicks, &systemTicks, &idleTicks,
+                   &iowTicks, &irqTicks, &sirqTicks) < 4) {
                 fclose(fh);
                 return -2;
             }
             next_line(fh);
         }
-        n = fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 "\n",
-           &userTicks, &niceTicks, &systemTicks, &idleTicks);
+        n = fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " "
+                       DEC_64 " " DEC_64 " " DEC_64 "\n",
+           &userTicks, &niceTicks, &systemTicks, &idleTicks,
+           &iowTicks, &irqTicks, &sirqTicks);
     }
 
     fclose(fh);
-    if (n != 4) {
+    if (n < 4) {
         return -2;
     }
 
     pticks->used       = userTicks + niceTicks;
-    pticks->usedKernel = systemTicks;
-    pticks->total      = userTicks + niceTicks + systemTicks + idleTicks;
+    pticks->usedKernel = systemTicks + irqTicks + sirqTicks;
+    pticks->total      = userTicks + niceTicks + systemTicks + idleTicks +
+                         iowTicks + irqTicks + sirqTicks;
 
     return 0;
 }