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; | |
2c2f900e | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
79e0a1df AM |
19 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
20 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; | |
21 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; | |
22 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
0fe46f2a | 23 | import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider; |
f1f86dfb | 24 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystemBuilder; |
79e0a1df AM |
25 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
26 | import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; | |
91e7f946 AM |
27 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent; |
28 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; | |
efc403bb AM |
29 | |
30 | /** | |
31 | * This is the state change input plugin for TMF's state system which handles | |
32 | * the LTTng 2.0 kernel traces in CTF format. | |
d85d2a6d | 33 | * |
efc403bb | 34 | * It uses the reference handler defined in CTFKernelHandler.java. |
d85d2a6d | 35 | * |
efc403bb | 36 | * @author alexmont |
d85d2a6d | 37 | * |
efc403bb | 38 | */ |
d3ba47d4 | 39 | public class LttngKernelStateProvider extends AbstractTmfStateProvider { |
efc403bb | 40 | |
a96cc6be AM |
41 | /** |
42 | * Version number of this state provider. Please bump this if you modify the | |
43 | * contents of the generated state history in some way. | |
44 | */ | |
bc19bff3 | 45 | private static final int VERSION = 4; |
a96cc6be | 46 | |
6383e95d AM |
47 | // ------------------------------------------------------------------------ |
48 | // Constructor | |
49 | // ------------------------------------------------------------------------ | |
efc403bb AM |
50 | |
51 | /** | |
52 | * Instantiate a new state provider plugin. | |
d85d2a6d AM |
53 | * |
54 | * @param trace | |
efc403bb | 55 | * The LTTng 2.0 kernel trace directory |
efc403bb | 56 | */ |
d3ba47d4 | 57 | public LttngKernelStateProvider(CtfTmfTrace trace) { |
71f2da63 | 58 | super(trace, CtfTmfEvent.class, "LTTng Kernel"); //$NON-NLS-1$ |
2c2f900e | 59 | } |
efc403bb | 60 | |
6383e95d AM |
61 | // ------------------------------------------------------------------------ |
62 | // IStateChangeInput | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
a96cc6be AM |
65 | @Override |
66 | public int getVersion() { | |
67 | return VERSION; | |
68 | } | |
69 | ||
2c2f900e | 70 | @Override |
f1f86dfb | 71 | public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) { |
79e0a1df AM |
72 | /* We can only set up the locations once the state system is assigned */ |
73 | super.assignTargetStateSystem(ssb); | |
2c2f900e | 74 | } |
efc403bb | 75 | |
e96ab5c4 | 76 | @Override |
d3ba47d4 AM |
77 | public LttngKernelStateProvider getNewInstance() { |
78 | return new LttngKernelStateProvider((CtfTmfTrace) this.getTrace()); | |
e96ab5c4 AM |
79 | } |
80 | ||
efc403bb | 81 | @Override |
79e0a1df | 82 | protected void eventHandle(ITmfEvent ev) { |
79044a66 AM |
83 | /* |
84 | * AbstractStateChangeInput should have already checked for the correct | |
85 | * class type | |
86 | */ | |
3ae73cfa | 87 | final CtfTmfEvent event = (CtfTmfEvent) ev; |
79e0a1df AM |
88 | |
89 | final ITmfEventField content = event.getContent(); | |
33803b9b | 90 | final String eventName = event.getType().getName(); |
79e0a1df AM |
91 | final long ts = event.getTimestamp().getValue(); |
92 | ||
2c2f900e | 93 | try { |
79e0a1df | 94 | /* Shortcut for the "current CPU" attribute node */ |
6383e95d | 95 | final Integer currentCPUNode = ss.getQuarkRelativeAndAdd(getNodeCPUs(), String.valueOf(event.getCPU())); |
79e0a1df AM |
96 | |
97 | /* | |
98 | * Shortcut for the "current thread" attribute node. It requires | |
99 | * querying the current CPU's current thread. | |
100 | */ | |
3ae73cfa AM |
101 | int quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD); |
102 | ITmfStateValue value = ss.queryOngoingState(quark); | |
359eeba0 | 103 | int thread = value.isNull() ? -1 : value.unboxInt(); |
6383e95d | 104 | final Integer currentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(thread)); |
79e0a1df AM |
105 | |
106 | /* | |
107 | * Feed event to the history system if it's known to cause a state | |
108 | * transition. | |
109 | */ | |
3ae73cfa | 110 | switch (eventName) { |
79e0a1df | 111 | |
3ae73cfa | 112 | case LttngStrings.EXIT_SYSCALL: |
79e0a1df AM |
113 | /* Fields: int64 ret */ |
114 | { | |
115 | /* Clear the current system call on the process */ | |
116 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
117 | value = TmfStateValue.nullValue(); | |
118 | ss.modifyAttribute(ts, value, quark); | |
119 | ||
120 | /* Put the process' status back to user mode */ | |
121 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
dfb27cee | 122 | value = StateValues.PROCESS_STATUS_RUN_USERMODE_VALUE; |
79e0a1df AM |
123 | ss.modifyAttribute(ts, value, quark); |
124 | ||
125 | /* Put the CPU's status back to user mode */ | |
126 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
dfb27cee | 127 | value = StateValues.CPU_STATUS_RUN_USERMODE_VALUE; |
79e0a1df AM |
128 | ss.modifyAttribute(ts, value, quark); |
129 | } | |
130 | break; | |
131 | ||
3ae73cfa | 132 | case LttngStrings.IRQ_HANDLER_ENTRY: |
79e0a1df AM |
133 | /* Fields: int32 irq, string name */ |
134 | { | |
135 | Integer irqId = ((Long) content.getField(LttngStrings.IRQ).getValue()).intValue(); | |
136 | ||
137 | /* Mark this IRQ as active in the resource tree. | |
138 | * The state value = the CPU on which this IRQ is sitting */ | |
6383e95d | 139 | quark = ss.getQuarkRelativeAndAdd(getNodeIRQs(), irqId.toString()); |
79e0a1df AM |
140 | value = TmfStateValue.newValueInt(event.getCPU()); |
141 | ss.modifyAttribute(ts, value, quark); | |
142 | ||
143 | /* Change the status of the running process to interrupted */ | |
144 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
dfb27cee | 145 | value = StateValues.PROCESS_STATUS_INTERRUPTED_VALUE; |
79e0a1df AM |
146 | ss.modifyAttribute(ts, value, quark); |
147 | ||
148 | /* Change the status of the CPU to interrupted */ | |
149 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
dfb27cee | 150 | value = StateValues.CPU_STATUS_IRQ_VALUE; |
79e0a1df AM |
151 | ss.modifyAttribute(ts, value, quark); |
152 | } | |
153 | break; | |
154 | ||
3ae73cfa | 155 | case LttngStrings.IRQ_HANDLER_EXIT: |
79e0a1df AM |
156 | /* Fields: int32 irq, int32 ret */ |
157 | { | |
158 | Integer irqId = ((Long) content.getField(LttngStrings.IRQ).getValue()).intValue(); | |
159 | ||
160 | /* Put this IRQ back to inactive in the resource tree */ | |
6383e95d | 161 | quark = ss.getQuarkRelativeAndAdd(getNodeIRQs(), irqId.toString()); |
79e0a1df AM |
162 | value = TmfStateValue.nullValue(); |
163 | ss.modifyAttribute(ts, value, quark); | |
164 | ||
165 | /* Set the previous process back to running */ | |
166 | setProcessToRunning(ts, currentThreadNode); | |
167 | ||
168 | /* Set the CPU status back to running or "idle" */ | |
169 | cpuExitInterrupt(ts, currentCPUNode, currentThreadNode); | |
170 | } | |
171 | break; | |
172 | ||
3ae73cfa | 173 | case LttngStrings.SOFTIRQ_ENTRY: |
79e0a1df AM |
174 | /* Fields: int32 vec */ |
175 | { | |
176 | Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue(); | |
177 | ||
178 | /* Mark this SoftIRQ as active in the resource tree. | |
179 | * The state value = the CPU on which this SoftIRQ is processed */ | |
6383e95d | 180 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
79e0a1df AM |
181 | value = TmfStateValue.newValueInt(event.getCPU()); |
182 | ss.modifyAttribute(ts, value, quark); | |
183 | ||
184 | /* Change the status of the running process to interrupted */ | |
185 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
dfb27cee | 186 | value = StateValues.PROCESS_STATUS_INTERRUPTED_VALUE; |
79e0a1df AM |
187 | ss.modifyAttribute(ts, value, quark); |
188 | ||
189 | /* Change the status of the CPU to interrupted */ | |
190 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
dfb27cee | 191 | value = StateValues.CPU_STATUS_SOFTIRQ_VALUE; |
79e0a1df AM |
192 | ss.modifyAttribute(ts, value, quark); |
193 | } | |
194 | break; | |
195 | ||
3ae73cfa | 196 | case LttngStrings.SOFTIRQ_EXIT: |
79e0a1df AM |
197 | /* Fields: int32 vec */ |
198 | { | |
199 | Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue(); | |
200 | ||
201 | /* Put this SoftIRQ back to inactive (= -1) in the resource tree */ | |
6383e95d | 202 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
79e0a1df AM |
203 | value = TmfStateValue.nullValue(); |
204 | ss.modifyAttribute(ts, value, quark); | |
205 | ||
206 | /* Set the previous process back to running */ | |
207 | setProcessToRunning(ts, currentThreadNode); | |
208 | ||
209 | /* Set the CPU status back to "busy" or "idle" */ | |
210 | cpuExitInterrupt(ts, currentCPUNode, currentThreadNode); | |
211 | } | |
212 | break; | |
213 | ||
3ae73cfa | 214 | case LttngStrings.SOFTIRQ_RAISE: |
79e0a1df AM |
215 | /* Fields: int32 vec */ |
216 | { | |
217 | Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue(); | |
218 | ||
219 | /* Mark this SoftIRQ as *raised* in the resource tree. | |
220 | * State value = -2 */ | |
6383e95d | 221 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
dfb27cee | 222 | value = StateValues.SOFT_IRQ_RAISED_VALUE; |
79e0a1df AM |
223 | ss.modifyAttribute(ts, value, quark); |
224 | } | |
225 | break; | |
226 | ||
3ae73cfa | 227 | case LttngStrings.SCHED_SWITCH: |
79e0a1df AM |
228 | /* |
229 | * Fields: string prev_comm, int32 prev_tid, int32 prev_prio, int64 prev_state, | |
230 | * string next_comm, int32 next_tid, int32 next_prio | |
231 | */ | |
232 | { | |
233 | Integer prevTid = ((Long) content.getField(LttngStrings.PREV_TID).getValue()).intValue(); | |
f2338178 | 234 | Long prevState = (Long) content.getField(LttngStrings.PREV_STATE).getValue(); |
79e0a1df AM |
235 | String nextProcessName = (String) content.getField(LttngStrings.NEXT_COMM).getValue(); |
236 | Integer nextTid = ((Long) content.getField(LttngStrings.NEXT_TID).getValue()).intValue(); | |
237 | ||
6383e95d AM |
238 | Integer formerThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), prevTid.toString()); |
239 | Integer newCurrentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), nextTid.toString()); | |
79e0a1df AM |
240 | |
241 | /* Set the status of the process that got scheduled out. */ | |
242 | quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS); | |
f2338178 | 243 | if (prevState != 0) { |
dfb27cee | 244 | value = StateValues.PROCESS_STATUS_WAIT_BLOCKED_VALUE; |
f2338178 | 245 | } else { |
dfb27cee | 246 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; |
f2338178 | 247 | } |
79e0a1df AM |
248 | ss.modifyAttribute(ts, value, quark); |
249 | ||
250 | /* Set the status of the new scheduled process */ | |
251 | setProcessToRunning(ts, newCurrentThreadNode); | |
252 | ||
253 | /* Set the exec name of the new process */ | |
254 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.EXEC_NAME); | |
255 | value = TmfStateValue.newValueString(nextProcessName); | |
256 | ss.modifyAttribute(ts, value, quark); | |
257 | ||
25e43749 AM |
258 | /* Make sure the PPID and system_call sub-attributes exist */ |
259 | ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL); | |
260 | ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.PPID); | |
79e0a1df AM |
261 | |
262 | /* Set the current scheduled process on the relevant CPU */ | |
263 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD); | |
264 | value = TmfStateValue.newValueInt(nextTid); | |
265 | ss.modifyAttribute(ts, value, quark); | |
266 | ||
267 | /* Set the status of the CPU itself */ | |
268 | if (nextTid > 0) { | |
269 | /* Check if the entering process is in kernel or user mode */ | |
270 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL); | |
271 | if (ss.queryOngoingState(quark).isNull()) { | |
dfb27cee | 272 | value = StateValues.CPU_STATUS_RUN_USERMODE_VALUE; |
79e0a1df | 273 | } else { |
dfb27cee | 274 | value = StateValues.CPU_STATUS_RUN_SYSCALL_VALUE; |
79e0a1df AM |
275 | } |
276 | } else { | |
dfb27cee | 277 | value = StateValues.CPU_STATUS_IDLE_VALUE; |
79e0a1df AM |
278 | } |
279 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
280 | ss.modifyAttribute(ts, value, quark); | |
281 | } | |
282 | break; | |
283 | ||
3ae73cfa | 284 | case LttngStrings.SCHED_PROCESS_FORK: |
79e0a1df AM |
285 | /* Fields: string parent_comm, int32 parent_tid, |
286 | * string child_comm, int32 child_tid */ | |
287 | { | |
288 | // String parentProcessName = (String) event.getFieldValue("parent_comm"); | |
289 | String childProcessName = (String) content.getField(LttngStrings.CHILD_COMM).getValue(); | |
290 | // assert ( parentProcessName.equals(childProcessName) ); | |
291 | ||
292 | Integer parentTid = ((Long) content.getField(LttngStrings.PARENT_TID).getValue()).intValue(); | |
293 | Integer childTid = ((Long) content.getField(LttngStrings.CHILD_TID).getValue()).intValue(); | |
294 | ||
6383e95d AM |
295 | Integer parentTidNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), parentTid.toString()); |
296 | Integer childTidNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), childTid.toString()); | |
79e0a1df AM |
297 | |
298 | /* Assign the PPID to the new process */ | |
299 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.PPID); | |
300 | value = TmfStateValue.newValueInt(parentTid); | |
301 | ss.modifyAttribute(ts, value, quark); | |
302 | ||
303 | /* Set the new process' exec_name */ | |
304 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.EXEC_NAME); | |
305 | value = TmfStateValue.newValueString(childProcessName); | |
306 | ss.modifyAttribute(ts, value, quark); | |
307 | ||
308 | /* Set the new process' status */ | |
309 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.STATUS); | |
dfb27cee | 310 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; |
79e0a1df AM |
311 | ss.modifyAttribute(ts, value, quark); |
312 | ||
313 | /* Set the process' syscall name, to be the same as the parent's */ | |
314 | quark = ss.getQuarkRelativeAndAdd(parentTidNode, Attributes.SYSTEM_CALL); | |
315 | value = ss.queryOngoingState(quark); | |
b46ea93c AM |
316 | if (value.isNull()) { |
317 | /* | |
318 | * Maybe we were missing info about the parent? At least we | |
319 | * will set the child right. Let's suppose "sys_clone". | |
320 | */ | |
321 | value = TmfStateValue.newValueString(LttngStrings.SYS_CLONE); | |
322 | } | |
79e0a1df AM |
323 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL); |
324 | ss.modifyAttribute(ts, value, quark); | |
325 | } | |
326 | break; | |
327 | ||
3ae73cfa | 328 | case LttngStrings.SCHED_PROCESS_EXIT: |
79e0a1df AM |
329 | /* Fields: string comm, int32 tid, int32 prio */ |
330 | break; | |
331 | ||
3ae73cfa | 332 | case LttngStrings.SCHED_PROCESS_FREE: |
79e0a1df AM |
333 | /* Fields: string comm, int32 tid, int32 prio */ |
334 | /* | |
335 | * A sched_process_free will always happen after the sched_switch | |
336 | * that will remove the process from the cpu for the last time. So | |
337 | * this is when we should delete everything wrt to the process. | |
338 | */ | |
339 | { | |
340 | Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue(); | |
341 | /* | |
342 | * Remove the process and all its sub-attributes from the | |
343 | * current state | |
344 | */ | |
6383e95d | 345 | quark = ss.getQuarkRelativeAndAdd(getNodeThreads(), tid.toString()); |
79e0a1df AM |
346 | ss.removeAttribute(ts, quark); |
347 | } | |
348 | break; | |
349 | ||
3ae73cfa | 350 | case LttngStrings.STATEDUMP_PROCESS_STATE: |
79e0a1df AM |
351 | /* Fields: |
352 | * int32 type, int32 mode, int32 pid, int32 submode, int32 vpid, | |
353 | * int32 ppid, int32 tid, string name, int32 status, int32 vtid */ | |
354 | { | |
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 | { | |
410 | final int tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue(); | |
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 | } |