Commit | Line | Data |
---|---|---|
efc403bb | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2012, 2014 Ericsson |
efc403bb AM |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
d85d2a6d | 5 | * |
efc403bb AM |
6 | * All rights reserved. This program and the accompanying materials are |
7 | * made available under the terms of the Eclipse Public License v1.0 which | |
8 | * accompanies this distribution, and is available at | |
9 | * http://www.eclipse.org/legal/epl-v10.html | |
d85d2a6d | 10 | * |
efc403bb AM |
11 | *******************************************************************************/ |
12 | ||
13 | package org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider; | |
14 | ||
79e0a1df AM |
15 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; |
16 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.LttngStrings; | |
17 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues; | |
e894a508 AM |
18 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
19 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
20 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; | |
21 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
22 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
23 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; | |
2bdf0193 AM |
24 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
25 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; | |
26 | import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; | |
27 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
efc403bb AM |
28 | |
29 | /** | |
30 | * This is the state change input plugin for TMF's state system which handles | |
31 | * the LTTng 2.0 kernel traces in CTF format. | |
d85d2a6d | 32 | * |
efc403bb | 33 | * It uses the reference handler defined in CTFKernelHandler.java. |
d85d2a6d | 34 | * |
efc403bb | 35 | * @author alexmont |
d85d2a6d | 36 | * |
efc403bb | 37 | */ |
d3ba47d4 | 38 | public class LttngKernelStateProvider extends AbstractTmfStateProvider { |
efc403bb | 39 | |
a96cc6be AM |
40 | /** |
41 | * Version number of this state provider. Please bump this if you modify the | |
42 | * contents of the generated state history in some way. | |
43 | */ | |
bc19bff3 | 44 | private static final int VERSION = 4; |
a96cc6be | 45 | |
6383e95d AM |
46 | // ------------------------------------------------------------------------ |
47 | // Constructor | |
48 | // ------------------------------------------------------------------------ | |
efc403bb AM |
49 | |
50 | /** | |
51 | * Instantiate a new state provider plugin. | |
d85d2a6d AM |
52 | * |
53 | * @param trace | |
efc403bb | 54 | * The LTTng 2.0 kernel trace directory |
efc403bb | 55 | */ |
1887c91b GB |
56 | public LttngKernelStateProvider(ITmfTrace trace) { |
57 | super(trace, ITmfEvent.class, "LTTng Kernel"); //$NON-NLS-1$ | |
2c2f900e | 58 | } |
efc403bb | 59 | |
6383e95d AM |
60 | // ------------------------------------------------------------------------ |
61 | // IStateChangeInput | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
a96cc6be AM |
64 | @Override |
65 | public int getVersion() { | |
66 | return VERSION; | |
67 | } | |
68 | ||
2c2f900e | 69 | @Override |
f1f86dfb | 70 | public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) { |
79e0a1df AM |
71 | /* We can only set up the locations once the state system is assigned */ |
72 | super.assignTargetStateSystem(ssb); | |
2c2f900e | 73 | } |
efc403bb | 74 | |
e96ab5c4 | 75 | @Override |
d3ba47d4 | 76 | public LttngKernelStateProvider getNewInstance() { |
1887c91b | 77 | return new LttngKernelStateProvider(this.getTrace()); |
e96ab5c4 AM |
78 | } |
79 | ||
efc403bb | 80 | @Override |
1887c91b | 81 | protected void eventHandle(ITmfEvent event) { |
79044a66 AM |
82 | /* |
83 | * AbstractStateChangeInput should have already checked for the correct | |
84 | * class type | |
85 | */ | |
79e0a1df | 86 | |
33803b9b | 87 | final String eventName = event.getType().getName(); |
79e0a1df AM |
88 | final long ts = event.getTimestamp().getValue(); |
89 | ||
2c2f900e | 90 | try { |
79e0a1df | 91 | /* Shortcut for the "current CPU" attribute node */ |
1887c91b | 92 | final Integer currentCPUNode = ss.getQuarkRelativeAndAdd(getNodeCPUs(), event.getSource()); |
79e0a1df AM |
93 | |
94 | /* | |
95 | * Shortcut for the "current thread" attribute node. It requires | |
96 | * querying the current CPU's current thread. | |
97 | */ | |
3ae73cfa AM |
98 | int quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD); |
99 | ITmfStateValue value = ss.queryOngoingState(quark); | |
359eeba0 | 100 | int thread = value.isNull() ? -1 : value.unboxInt(); |
6383e95d | 101 | final Integer currentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(thread)); |
79e0a1df AM |
102 | |
103 | /* | |
104 | * Feed event to the history system if it's known to cause a state | |
105 | * transition. | |
106 | */ | |
3ae73cfa | 107 | switch (eventName) { |
79e0a1df | 108 | |
3ae73cfa | 109 | case LttngStrings.EXIT_SYSCALL: |
79e0a1df AM |
110 | /* Fields: int64 ret */ |
111 | { | |
112 | /* Clear the current system call on the process */ | |
113 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
114 | value = TmfStateValue.nullValue(); | |
115 | ss.modifyAttribute(ts, value, quark); | |
116 | ||
117 | /* Put the process' status back to user mode */ | |
118 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
dfb27cee | 119 | value = StateValues.PROCESS_STATUS_RUN_USERMODE_VALUE; |
79e0a1df AM |
120 | ss.modifyAttribute(ts, value, quark); |
121 | ||
122 | /* Put the CPU's status back to user mode */ | |
123 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
dfb27cee | 124 | value = StateValues.CPU_STATUS_RUN_USERMODE_VALUE; |
79e0a1df AM |
125 | ss.modifyAttribute(ts, value, quark); |
126 | } | |
127 | break; | |
128 | ||
3ae73cfa | 129 | case LttngStrings.IRQ_HANDLER_ENTRY: |
79e0a1df AM |
130 | /* Fields: int32 irq, string name */ |
131 | { | |
7a2f04a6 | 132 | Integer irqId = ((Long) event.getContent().getField(LttngStrings.IRQ).getValue()).intValue(); |
79e0a1df AM |
133 | |
134 | /* Mark this IRQ as active in the resource tree. | |
135 | * The state value = the CPU on which this IRQ is sitting */ | |
6383e95d | 136 | quark = ss.getQuarkRelativeAndAdd(getNodeIRQs(), irqId.toString()); |
1887c91b | 137 | value = TmfStateValue.newValueInt(Integer.parseInt(event.getSource())); |
79e0a1df AM |
138 | ss.modifyAttribute(ts, value, quark); |
139 | ||
140 | /* Change the status of the running process to interrupted */ | |
141 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
dfb27cee | 142 | value = StateValues.PROCESS_STATUS_INTERRUPTED_VALUE; |
79e0a1df AM |
143 | ss.modifyAttribute(ts, value, quark); |
144 | ||
145 | /* Change the status of the CPU to interrupted */ | |
146 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
dfb27cee | 147 | value = StateValues.CPU_STATUS_IRQ_VALUE; |
79e0a1df AM |
148 | ss.modifyAttribute(ts, value, quark); |
149 | } | |
150 | break; | |
151 | ||
3ae73cfa | 152 | case LttngStrings.IRQ_HANDLER_EXIT: |
79e0a1df AM |
153 | /* Fields: int32 irq, int32 ret */ |
154 | { | |
7a2f04a6 | 155 | Integer irqId = ((Long) event.getContent().getField(LttngStrings.IRQ).getValue()).intValue(); |
79e0a1df AM |
156 | |
157 | /* Put this IRQ back to inactive in the resource tree */ | |
6383e95d | 158 | quark = ss.getQuarkRelativeAndAdd(getNodeIRQs(), irqId.toString()); |
79e0a1df AM |
159 | value = TmfStateValue.nullValue(); |
160 | ss.modifyAttribute(ts, value, quark); | |
161 | ||
162 | /* Set the previous process back to running */ | |
163 | setProcessToRunning(ts, currentThreadNode); | |
164 | ||
165 | /* Set the CPU status back to running or "idle" */ | |
166 | cpuExitInterrupt(ts, currentCPUNode, currentThreadNode); | |
167 | } | |
168 | break; | |
169 | ||
3ae73cfa | 170 | case LttngStrings.SOFTIRQ_ENTRY: |
79e0a1df AM |
171 | /* Fields: int32 vec */ |
172 | { | |
7a2f04a6 | 173 | Integer softIrqId = ((Long) event.getContent().getField(LttngStrings.VEC).getValue()).intValue(); |
79e0a1df AM |
174 | |
175 | /* Mark this SoftIRQ as active in the resource tree. | |
176 | * The state value = the CPU on which this SoftIRQ is processed */ | |
6383e95d | 177 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
1887c91b | 178 | value = TmfStateValue.newValueInt(Integer.parseInt(event.getSource())); |
79e0a1df AM |
179 | ss.modifyAttribute(ts, value, quark); |
180 | ||
181 | /* Change the status of the running process to interrupted */ | |
182 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
dfb27cee | 183 | value = StateValues.PROCESS_STATUS_INTERRUPTED_VALUE; |
79e0a1df AM |
184 | ss.modifyAttribute(ts, value, quark); |
185 | ||
186 | /* Change the status of the CPU to interrupted */ | |
187 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
dfb27cee | 188 | value = StateValues.CPU_STATUS_SOFTIRQ_VALUE; |
79e0a1df AM |
189 | ss.modifyAttribute(ts, value, quark); |
190 | } | |
191 | break; | |
192 | ||
3ae73cfa | 193 | case LttngStrings.SOFTIRQ_EXIT: |
79e0a1df AM |
194 | /* Fields: int32 vec */ |
195 | { | |
7a2f04a6 | 196 | Integer softIrqId = ((Long) event.getContent().getField(LttngStrings.VEC).getValue()).intValue(); |
79e0a1df AM |
197 | |
198 | /* Put this SoftIRQ back to inactive (= -1) in the resource tree */ | |
6383e95d | 199 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
79e0a1df AM |
200 | value = TmfStateValue.nullValue(); |
201 | ss.modifyAttribute(ts, value, quark); | |
202 | ||
203 | /* Set the previous process back to running */ | |
204 | setProcessToRunning(ts, currentThreadNode); | |
205 | ||
206 | /* Set the CPU status back to "busy" or "idle" */ | |
207 | cpuExitInterrupt(ts, currentCPUNode, currentThreadNode); | |
208 | } | |
209 | break; | |
210 | ||
3ae73cfa | 211 | case LttngStrings.SOFTIRQ_RAISE: |
79e0a1df AM |
212 | /* Fields: int32 vec */ |
213 | { | |
7a2f04a6 | 214 | Integer softIrqId = ((Long) event.getContent().getField(LttngStrings.VEC).getValue()).intValue(); |
79e0a1df AM |
215 | |
216 | /* Mark this SoftIRQ as *raised* in the resource tree. | |
217 | * State value = -2 */ | |
6383e95d | 218 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
dfb27cee | 219 | value = StateValues.SOFT_IRQ_RAISED_VALUE; |
79e0a1df AM |
220 | ss.modifyAttribute(ts, value, quark); |
221 | } | |
222 | break; | |
223 | ||
3ae73cfa | 224 | case LttngStrings.SCHED_SWITCH: |
79e0a1df AM |
225 | /* |
226 | * Fields: string prev_comm, int32 prev_tid, int32 prev_prio, int64 prev_state, | |
227 | * string next_comm, int32 next_tid, int32 next_prio | |
228 | */ | |
229 | { | |
7a2f04a6 | 230 | ITmfEventField content = event.getContent(); |
79e0a1df | 231 | Integer prevTid = ((Long) content.getField(LttngStrings.PREV_TID).getValue()).intValue(); |
f2338178 | 232 | Long prevState = (Long) content.getField(LttngStrings.PREV_STATE).getValue(); |
79e0a1df AM |
233 | String nextProcessName = (String) content.getField(LttngStrings.NEXT_COMM).getValue(); |
234 | Integer nextTid = ((Long) content.getField(LttngStrings.NEXT_TID).getValue()).intValue(); | |
235 | ||
6383e95d AM |
236 | Integer formerThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), prevTid.toString()); |
237 | Integer newCurrentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), nextTid.toString()); | |
79e0a1df AM |
238 | |
239 | /* Set the status of the process that got scheduled out. */ | |
240 | quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS); | |
f2338178 | 241 | if (prevState != 0) { |
dfb27cee | 242 | value = StateValues.PROCESS_STATUS_WAIT_BLOCKED_VALUE; |
f2338178 | 243 | } else { |
dfb27cee | 244 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; |
f2338178 | 245 | } |
79e0a1df AM |
246 | ss.modifyAttribute(ts, value, quark); |
247 | ||
248 | /* Set the status of the new scheduled process */ | |
249 | setProcessToRunning(ts, newCurrentThreadNode); | |
250 | ||
251 | /* Set the exec name of the new process */ | |
252 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.EXEC_NAME); | |
253 | value = TmfStateValue.newValueString(nextProcessName); | |
254 | ss.modifyAttribute(ts, value, quark); | |
255 | ||
25e43749 AM |
256 | /* Make sure the PPID and system_call sub-attributes exist */ |
257 | ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL); | |
258 | ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.PPID); | |
79e0a1df AM |
259 | |
260 | /* Set the current scheduled process on the relevant CPU */ | |
261 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD); | |
262 | value = TmfStateValue.newValueInt(nextTid); | |
263 | ss.modifyAttribute(ts, value, quark); | |
264 | ||
265 | /* Set the status of the CPU itself */ | |
266 | if (nextTid > 0) { | |
267 | /* Check if the entering process is in kernel or user mode */ | |
268 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL); | |
269 | if (ss.queryOngoingState(quark).isNull()) { | |
dfb27cee | 270 | value = StateValues.CPU_STATUS_RUN_USERMODE_VALUE; |
79e0a1df | 271 | } else { |
dfb27cee | 272 | value = StateValues.CPU_STATUS_RUN_SYSCALL_VALUE; |
79e0a1df AM |
273 | } |
274 | } else { | |
dfb27cee | 275 | value = StateValues.CPU_STATUS_IDLE_VALUE; |
79e0a1df AM |
276 | } |
277 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
278 | ss.modifyAttribute(ts, value, quark); | |
279 | } | |
280 | break; | |
281 | ||
3ae73cfa | 282 | case LttngStrings.SCHED_PROCESS_FORK: |
79e0a1df AM |
283 | /* Fields: string parent_comm, int32 parent_tid, |
284 | * string child_comm, int32 child_tid */ | |
285 | { | |
7a2f04a6 | 286 | ITmfEventField content = event.getContent(); |
79e0a1df AM |
287 | // String parentProcessName = (String) event.getFieldValue("parent_comm"); |
288 | String childProcessName = (String) content.getField(LttngStrings.CHILD_COMM).getValue(); | |
289 | // assert ( parentProcessName.equals(childProcessName) ); | |
290 | ||
291 | Integer parentTid = ((Long) content.getField(LttngStrings.PARENT_TID).getValue()).intValue(); | |
292 | Integer childTid = ((Long) content.getField(LttngStrings.CHILD_TID).getValue()).intValue(); | |
293 | ||
6383e95d AM |
294 | Integer parentTidNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), parentTid.toString()); |
295 | Integer childTidNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), childTid.toString()); | |
79e0a1df AM |
296 | |
297 | /* Assign the PPID to the new process */ | |
298 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.PPID); | |
299 | value = TmfStateValue.newValueInt(parentTid); | |
300 | ss.modifyAttribute(ts, value, quark); | |
301 | ||
302 | /* Set the new process' exec_name */ | |
303 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.EXEC_NAME); | |
304 | value = TmfStateValue.newValueString(childProcessName); | |
305 | ss.modifyAttribute(ts, value, quark); | |
306 | ||
307 | /* Set the new process' status */ | |
308 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.STATUS); | |
dfb27cee | 309 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; |
79e0a1df AM |
310 | ss.modifyAttribute(ts, value, quark); |
311 | ||
312 | /* Set the process' syscall name, to be the same as the parent's */ | |
313 | quark = ss.getQuarkRelativeAndAdd(parentTidNode, Attributes.SYSTEM_CALL); | |
314 | value = ss.queryOngoingState(quark); | |
b46ea93c AM |
315 | if (value.isNull()) { |
316 | /* | |
317 | * Maybe we were missing info about the parent? At least we | |
318 | * will set the child right. Let's suppose "sys_clone". | |
319 | */ | |
320 | value = TmfStateValue.newValueString(LttngStrings.SYS_CLONE); | |
321 | } | |
79e0a1df AM |
322 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL); |
323 | ss.modifyAttribute(ts, value, quark); | |
324 | } | |
325 | break; | |
326 | ||
3ae73cfa | 327 | case LttngStrings.SCHED_PROCESS_EXIT: |
79e0a1df AM |
328 | /* Fields: string comm, int32 tid, int32 prio */ |
329 | break; | |
330 | ||
3ae73cfa | 331 | case LttngStrings.SCHED_PROCESS_FREE: |
79e0a1df AM |
332 | /* Fields: string comm, int32 tid, int32 prio */ |
333 | /* | |
334 | * A sched_process_free will always happen after the sched_switch | |
335 | * that will remove the process from the cpu for the last time. So | |
336 | * this is when we should delete everything wrt to the process. | |
337 | */ | |
338 | { | |
7a2f04a6 | 339 | Integer tid = ((Long) event.getContent().getField(LttngStrings.TID).getValue()).intValue(); |
79e0a1df AM |
340 | /* |
341 | * Remove the process and all its sub-attributes from the | |
342 | * current state | |
343 | */ | |
6383e95d | 344 | quark = ss.getQuarkRelativeAndAdd(getNodeThreads(), tid.toString()); |
79e0a1df AM |
345 | ss.removeAttribute(ts, quark); |
346 | } | |
347 | break; | |
348 | ||
3ae73cfa | 349 | case LttngStrings.STATEDUMP_PROCESS_STATE: |
79e0a1df AM |
350 | /* Fields: |
351 | * int32 type, int32 mode, int32 pid, int32 submode, int32 vpid, | |
352 | * int32 ppid, int32 tid, string name, int32 status, int32 vtid */ | |
353 | { | |
7a2f04a6 | 354 | ITmfEventField content = event.getContent(); |
bc19bff3 AM |
355 | int tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue(); |
356 | int pid = ((Long) content.getField(LttngStrings.PID).getValue()).intValue(); | |
79e0a1df AM |
357 | int ppid = ((Long) content.getField(LttngStrings.PPID).getValue()).intValue(); |
358 | int status = ((Long) content.getField(LttngStrings.STATUS).getValue()).intValue(); | |
359 | String name = (String) content.getField(LttngStrings.NAME).getValue(); | |
360 | /* | |
361 | * "mode" could be interesting too, but it doesn't seem to be | |
362 | * populated with anything relevant for now. | |
363 | */ | |
364 | ||
bc19bff3 | 365 | int curThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(tid)); |
79e0a1df AM |
366 | |
367 | /* Set the process' name */ | |
368 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.EXEC_NAME); | |
369 | if (ss.queryOngoingState(quark).isNull()) { | |
370 | /* If the value didn't exist previously, set it */ | |
371 | value = TmfStateValue.newValueString(name); | |
372 | ss.modifyAttribute(ts, value, quark); | |
373 | } | |
374 | ||
375 | /* Set the process' PPID */ | |
376 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.PPID); | |
377 | if (ss.queryOngoingState(quark).isNull()) { | |
bc19bff3 AM |
378 | if (pid == tid) { |
379 | /* We have a process. Use the 'PPID' field. */ | |
380 | value = TmfStateValue.newValueInt(ppid); | |
381 | } else { | |
382 | /* We have a thread, use the 'PID' field for the parent. */ | |
383 | value = TmfStateValue.newValueInt(pid); | |
384 | } | |
79e0a1df AM |
385 | ss.modifyAttribute(ts, value, quark); |
386 | } | |
387 | ||
388 | /* Set the process' status */ | |
389 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.STATUS); | |
390 | if (ss.queryOngoingState(quark).isNull()) { | |
f2338178 MD |
391 | /* "2" here means "WAIT_FOR_CPU", and "5" "WAIT_BLOCKED" in the LTTng kernel. */ |
392 | if (status == 2) { | |
dfb27cee | 393 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; |
f2338178 | 394 | } else if (status == 5) { |
dfb27cee | 395 | value = StateValues.PROCESS_STATUS_WAIT_BLOCKED_VALUE; |
79e0a1df | 396 | } else { |
dfb27cee | 397 | value = StateValues.PROCESS_STATUS_UNKNOWN_VALUE; |
79e0a1df AM |
398 | } |
399 | ss.modifyAttribute(ts, value, quark); | |
400 | } | |
401 | } | |
402 | break; | |
403 | ||
3ae73cfa AM |
404 | case LttngStrings.SCHED_WAKEUP: |
405 | case LttngStrings.SCHED_WAKEUP_NEW: | |
d1b933e7 AM |
406 | /* Fields (same fields for both types): |
407 | * string comm, int32 pid, int32 prio, int32 success, | |
408 | * int32 target_cpu */ | |
409 | { | |
7a2f04a6 | 410 | final int tid = ((Long) event.getContent().getField(LttngStrings.TID).getValue()).intValue(); |
d1b933e7 AM |
411 | final int threadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(tid)); |
412 | ||
413 | /* | |
414 | * The process indicated in the event's payload is now ready to | |
3d6e6112 FR |
415 | * run. Assign it to the "wait for cpu" state, but only if it |
416 | * was not already running. | |
d1b933e7 AM |
417 | */ |
418 | quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.STATUS); | |
3d6e6112 FR |
419 | int status = ss.queryOngoingState(quark).unboxInt(); |
420 | ||
421 | if (status != StateValues.PROCESS_STATUS_RUN_SYSCALL && | |
422 | status != StateValues.PROCESS_STATUS_RUN_USERMODE) { | |
423 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; | |
424 | ss.modifyAttribute(ts, value, quark); | |
425 | } | |
d1b933e7 AM |
426 | } |
427 | break; | |
428 | ||
79e0a1df AM |
429 | default: |
430 | /* Other event types not covered by the main switch */ | |
431 | { | |
432 | if (eventName.startsWith(LttngStrings.SYSCALL_PREFIX) | |
433 | || eventName.startsWith(LttngStrings.COMPAT_SYSCALL_PREFIX)) { | |
434 | /* | |
435 | * This is a replacement for the old sys_enter event. Now | |
436 | * syscall names are listed into the event type | |
437 | */ | |
438 | ||
439 | /* Assign the new system call to the process */ | |
440 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
441 | value = TmfStateValue.newValueString(eventName); | |
442 | ss.modifyAttribute(ts, value, quark); | |
443 | ||
444 | /* Put the process in system call mode */ | |
445 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
dfb27cee | 446 | value = StateValues.PROCESS_STATUS_RUN_SYSCALL_VALUE; |
79e0a1df AM |
447 | ss.modifyAttribute(ts, value, quark); |
448 | ||
449 | /* Put the CPU in system call (kernel) mode */ | |
450 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
dfb27cee | 451 | value = StateValues.CPU_STATUS_RUN_SYSCALL_VALUE; |
79e0a1df AM |
452 | ss.modifyAttribute(ts, value, quark); |
453 | } | |
454 | } | |
455 | break; | |
456 | } // End of big switch | |
457 | ||
79e0a1df AM |
458 | } catch (AttributeNotFoundException ae) { |
459 | /* | |
460 | * This would indicate a problem with the logic of the manager here, | |
461 | * so it shouldn't happen. | |
462 | */ | |
463 | ae.printStackTrace(); | |
464 | ||
465 | } catch (TimeRangeException tre) { | |
466 | /* | |
467 | * This would happen if the events in the trace aren't ordered | |
468 | * chronologically, which should never be the case ... | |
469 | */ | |
470 | System.err.println("TimeRangeExcpetion caught in the state system's event manager."); //$NON-NLS-1$ | |
471 | System.err.println("Are the events in the trace correctly ordered?"); //$NON-NLS-1$ | |
472 | tre.printStackTrace(); | |
473 | ||
474 | } catch (StateValueTypeException sve) { | |
475 | /* | |
476 | * This would happen if we were trying to push/pop attributes not of | |
477 | * type integer. Which, once again, should never happen. | |
478 | */ | |
479 | sve.printStackTrace(); | |
2c2f900e AM |
480 | } |
481 | } | |
482 | ||
6383e95d AM |
483 | // ------------------------------------------------------------------------ |
484 | // Convenience methods for commonly-used attribute tree locations | |
485 | // ------------------------------------------------------------------------ | |
486 | ||
487 | private int getNodeCPUs() { | |
488 | return ss.getQuarkAbsoluteAndAdd(Attributes.CPUS); | |
79e0a1df AM |
489 | } |
490 | ||
6383e95d AM |
491 | private int getNodeThreads() { |
492 | return ss.getQuarkAbsoluteAndAdd(Attributes.THREADS); | |
493 | } | |
494 | ||
495 | private int getNodeIRQs() { | |
496 | return ss.getQuarkAbsoluteAndAdd(Attributes.RESOURCES, Attributes.IRQS); | |
497 | } | |
498 | ||
499 | private int getNodeSoftIRQs() { | |
500 | return ss.getQuarkAbsoluteAndAdd(Attributes.RESOURCES, Attributes.SOFT_IRQS); | |
501 | } | |
502 | ||
6383e95d AM |
503 | // ------------------------------------------------------------------------ |
504 | // Advanced state-setting methods | |
505 | // ------------------------------------------------------------------------ | |
506 | ||
79e0a1df AM |
507 | /** |
508 | * When we want to set a process back to a "running" state, first check | |
509 | * its current System_call attribute. If there is a system call active, we | |
510 | * put the process back in the syscall state. If not, we put it back in | |
511 | * user mode state. | |
512 | */ | |
513 | private void setProcessToRunning(long ts, int currentThreadNode) | |
514 | throws AttributeNotFoundException, TimeRangeException, | |
515 | StateValueTypeException { | |
516 | int quark; | |
517 | ITmfStateValue value; | |
518 | ||
519 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
520 | if (ss.queryOngoingState(quark).isNull()) { | |
521 | /* We were in user mode before the interruption */ | |
dfb27cee | 522 | value = StateValues.PROCESS_STATUS_RUN_USERMODE_VALUE; |
79e0a1df AM |
523 | } else { |
524 | /* We were previously in kernel mode */ | |
dfb27cee | 525 | value = StateValues.PROCESS_STATUS_RUN_SYSCALL_VALUE; |
79e0a1df AM |
526 | } |
527 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
528 | ss.modifyAttribute(ts, value, quark); | |
529 | } | |
530 | ||
531 | /** | |
532 | * Similar logic as above, but to set the CPU's status when it's coming out | |
533 | * of an interruption. | |
534 | */ | |
535 | private void cpuExitInterrupt(long ts, int currentCpuNode, int currentThreadNode) | |
536 | throws StateValueTypeException, AttributeNotFoundException, | |
537 | TimeRangeException { | |
538 | int quark; | |
539 | ITmfStateValue value; | |
540 | ||
541 | quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.CURRENT_THREAD); | |
542 | if (ss.queryOngoingState(quark).unboxInt() > 0) { | |
543 | /* There was a process on the CPU */ | |
544 | quark = ss.getQuarkRelative(currentThreadNode, Attributes.SYSTEM_CALL); | |
545 | if (ss.queryOngoingState(quark).isNull()) { | |
546 | /* That process was in user mode */ | |
dfb27cee | 547 | value = StateValues.CPU_STATUS_RUN_USERMODE_VALUE; |
79e0a1df AM |
548 | } else { |
549 | /* That process was in a system call */ | |
dfb27cee | 550 | value = StateValues.CPU_STATUS_RUN_SYSCALL_VALUE; |
79e0a1df AM |
551 | } |
552 | } else { | |
553 | /* There was no real process scheduled, CPU was idle */ | |
dfb27cee | 554 | value = StateValues.CPU_STATUS_IDLE_VALUE; |
2c2f900e | 555 | } |
79e0a1df AM |
556 | quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.STATUS); |
557 | ss.modifyAttribute(ts, value, quark); | |
efc403bb AM |
558 | } |
559 | } |