lttng: Track the CPU statuses in the event handler
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 25 May 2012 13:59:11 +0000 (09:59 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 25 May 2012 14:29:05 +0000 (10:29 -0400)
A new "CPUs/<n>/Status" attribute will allow us to track if a
CPU is currently idle, busy (running a process) or interrupted
(processing an interrupt). This will match more closely what
we want to show in the Resource view.

org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelHandler.java
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/Attributes.java

index b91d05825d3b96a8dc3fc88bdfd11b0925a06bca..f3f5d4ef6f6346801a37f84831f90ed7e7303bc9 100644 (file)
@@ -175,6 +175,11 @@ class CtfKernelHandler implements Runnable {
                 quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
                 value = TmfStateValue.newValueInt(Attributes.STATUS_INTERRUPTED);
                 ss.modifyAttribute(ts, value, quark);
+\r
+                /* Change the status of the CPU to interrupted */\r
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);\r
+                value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_INTERRUPTED);\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -190,6 +195,9 @@ class CtfKernelHandler implements Runnable {
 
                 /* Set the previous process back to running */
                 setProcessToRunning(ts, currentThreadNode);
+\r
+                /* Set the CPU status back to "busy" or "idle" */\r
+                cpuExitInterrupt(ts, currentCPUNode);\r
             }
                 break;
 
@@ -208,6 +216,11 @@ class CtfKernelHandler implements Runnable {
                 quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
                 value = TmfStateValue.newValueInt(Attributes.STATUS_INTERRUPTED);
                 ss.modifyAttribute(ts, value, quark);
+\r
+                /* Change the status of the CPU to interrupted */\r
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);\r
+                value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_INTERRUPTED);\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -223,6 +236,9 @@ class CtfKernelHandler implements Runnable {
 
                 /* Set the previous process back to running */
                 setProcessToRunning(ts, currentThreadNode);
+\r
+                /* Set the CPU status back to "busy" or "idle" */\r
+                cpuExitInterrupt(ts, currentCPUNode);\r
             }
                 break;
 
@@ -295,6 +311,15 @@ class CtfKernelHandler implements Runnable {
                 quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD);
                 value = TmfStateValue.newValueInt(nextTid);
                 ss.modifyAttribute(ts, value, quark);
+\r
+                /* Set the status of the CPU itself */\r
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);\r
+                if (nextTid > 0) {\r
+                    value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_BUSY);\r
+                } else {\r
+                    value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_IDLE);\r
+                }\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -493,4 +518,29 @@ class CtfKernelHandler implements Runnable {
         quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
         ss.modifyAttribute(ts, value, quark);
     }
+\r
+    /**\r
+     * Similar logic as above, but to set the CPU's status when it's coming out\r
+     * of an interruption.\r
+     * @throws AttributeNotFoundException \r
+     * @throws StateValueTypeException \r
+     * @throws TimeRangeException \r
+     */\r
+    private void cpuExitInterrupt(long ts, int currentCpuNode)\r
+            throws StateValueTypeException, AttributeNotFoundException,\r
+            TimeRangeException {\r
+        int quark;\r
+        ITmfStateValue value;\r
+\r
+        quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.CURRENT_THREAD);\r
+        if (ss.queryOngoingState(quark).unboxInt() > 0) {\r
+            /* There was a process on the CPU */\r
+            value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_BUSY);\r
+        } else {\r
+            /* There was no real process scheduled, CPU was idle */\r
+            value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_IDLE);\r
+        }\r
+        quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.STATUS);\r
+        ss.modifyAttribute(ts, value, quark);\r
+    }\r
 }
index dd5a324cb91f09cafd0a10a0e5e7cc40bd79ebd4..bd8f18399a0edb9a5c1e79b98c873973d7da30fb 100644 (file)
@@ -34,10 +34,11 @@ public abstract class Attributes {
 
     /* Sub-attributes of the CPU nodes */
     public static final String CURRENT_THREAD = "Current_thread";
+    public static final String STATUS = "Status";\r
 
     /* Sub-attributes of the Thread nodes */
     public static final String PPID = "PPID";
-    public static final String STATUS = "Status";
+    //public static final String STATUS = "Status"\r
     public static final String EXEC_NAME = "Exec_name";
     public static final String SYSTEM_CALL = "System_call";
 
@@ -52,7 +53,12 @@ public abstract class Attributes {
     public static final String STATISTICS = "Stats";
     public static final String EVENT_TYPES = "Event_types";
 
-    /* Process status (note these are *values*, not attribute names) */
+    /* CPU Status (note these are *values*, not attribute names) */\r
+    public static final int CPU_STATUS_IDLE = 0;\r
+    public static final int CPU_STATUS_BUSY = 1;\r
+    public static final int CPU_STATUS_INTERRUPTED = 2;\r
+\r
+    /* Process status */\r
     public static final int STATUS_WAIT = 1;
     public static final int STATUS_RUN_USERMODE = 2;
     public static final int STATUS_RUN_SYSCALL = 3;
This page took 0.030745 seconds and 5 git commands to generate.