Import lttng.kernel.core plugins from Scope
[deliverable/tracecompass.git] / lttng / org.lttng.scope.lttng.kernel.core / src / org / lttng / scope / lttng / kernel / core / analysis / os / handlers / internal / SchedWakeupHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.lttng.scope.lttng.kernel.core.analysis.os.handlers.internal;
14
15 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
16 import org.lttng.scope.lttng.kernel.core.analysis.os.Attributes;
17 import org.lttng.scope.lttng.kernel.core.analysis.os.StateValues;
18 import org.lttng.scope.lttng.kernel.core.trace.layout.ILttngKernelEventLayout;
19
20 import ca.polymtl.dorsal.libdelorean.ITmfStateSystemBuilder;
21 import ca.polymtl.dorsal.libdelorean.exceptions.AttributeNotFoundException;
22 import ca.polymtl.dorsal.libdelorean.statevalue.ITmfStateValue;
23 import ca.polymtl.dorsal.libdelorean.statevalue.TmfStateValue;
24
25 /**
26 * Waking/wakeup handler.
27 *
28 * "sched_waking" and "sched_wakeup" tracepoints contain the same fields, and
29 * apply the same state transitions in our model, so they can both use this
30 * handler.
31 */
32 public class SchedWakeupHandler extends KernelEventHandler {
33
34 /**
35 * Constructor
36 * @param layout event layout
37 */
38 public SchedWakeupHandler(ILttngKernelEventLayout layout) {
39 super(layout);
40 }
41
42 @Override
43 public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException {
44 Integer cpu = KernelEventHandlerUtils.getCpu(event);
45 final int tid = ((Long) event.getContent().getField(getLayout().fieldTid()).getValue()).intValue();
46 final int prio = ((Long) event.getContent().getField(getLayout().fieldPrio()).getValue()).intValue();
47 Long targetCpu = event.getContent().getFieldValue(Long.class, getLayout().fieldTargetCpu());
48
49 String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
50 if (cpu == null || targetCpu == null || threadAttributeName == null) {
51 return;
52 }
53
54 final int threadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), threadAttributeName);
55
56 /*
57 * The process indicated in the event's payload is now ready to run.
58 * Assign it to the "wait for cpu" state, but only if it was not already
59 * running.
60 */
61 int status = ss.queryOngoingState(threadNode).unboxInt();
62 ITmfStateValue value = null;
63 long timestamp = KernelEventHandlerUtils.getTimestamp(event);
64 if (status != StateValues.PROCESS_STATUS_RUN_SYSCALL &&
65 status != StateValues.PROCESS_STATUS_RUN_USERMODE) {
66 value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE;
67 ss.modifyAttribute(timestamp, value, threadNode);
68 }
69
70 /* Set the thread's target run queue */
71 int quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.CURRENT_CPU_RQ);
72 value = TmfStateValue.newValueInt(targetCpu.intValue());
73 ss.modifyAttribute(timestamp, value, quark);
74
75 /*
76 * When a user changes a threads prio (e.g. with pthread_setschedparam),
77 * it shows in ftrace with a sched_wakeup.
78 */
79 quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.PRIO);
80 value = TmfStateValue.newValueInt(prio);
81 ss.modifyAttribute(timestamp, value, quark);
82 }
83 }
This page took 0.032374 seconds and 5 git commands to generate.