1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
;
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
;
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
;
26 * Waking/wakeup handler.
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
32 public class SchedWakeupHandler
extends KernelEventHandler
{
36 * @param layout event layout
38 public SchedWakeupHandler(ILttngKernelEventLayout layout
) {
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());
49 String threadAttributeName
= Attributes
.buildThreadAttributeName(tid
, cpu
);
50 if (cpu
== null || targetCpu
== null || threadAttributeName
== null) {
54 final int threadNode
= ss
.getQuarkRelativeAndAdd(KernelEventHandlerUtils
.getNodeThreads(ss
), threadAttributeName
);
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
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
);
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
);
76 * When a user changes a threads prio (e.g. with pthread_setschedparam),
77 * it shows in ftrace with a sched_wakeup.
79 quark
= ss
.getQuarkRelativeAndAdd(threadNode
, Attributes
.PRIO
);
80 value
= TmfStateValue
.newValueInt(prio
);
81 ss
.modifyAttribute(timestamp
, value
, quark
);