1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
;
12 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
13 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.Attributes
;
14 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.StateValues
;
15 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.ILttngKernelEventLayout
;
17 import ca
.polymtl
.dorsal
.libdelorean
.ITmfStateSystemBuilder
;
18 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.AttributeNotFoundException
;
19 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.ITmfStateValue
;
20 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.TmfStateValue
;
23 * Handler for task migration events. Normally moves a (non-running) process
24 * from one run queue to another.
26 * @author Alexandre Montplaisir
28 public class SchedMigrateTaskHandler
extends KernelEventHandler
{
34 * The event layout to use
36 public SchedMigrateTaskHandler(ILttngKernelEventLayout layout
) {
41 public void handleEvent(ITmfStateSystemBuilder ss
, ITmfEvent event
) throws AttributeNotFoundException
{
42 Long tid
= event
.getContent().getFieldValue(Long
.class, getLayout().fieldTid());
43 Long destCpu
= event
.getContent().getFieldValue(Long
.class, getLayout().fieldDestCpu());
45 if (tid
== null || destCpu
== null) {
49 long t
= event
.getTimestamp().toNanos();
51 String threadAttributeName
= Attributes
.buildThreadAttributeName(tid
.intValue(), null);
52 if (threadAttributeName
== null) {
53 /* Swapper threads do not get migrated */
56 int threadNode
= ss
.getQuarkRelativeAndAdd(KernelEventHandlerUtils
.getNodeThreads(ss
), threadAttributeName
);
59 * Put the thread in the "wait for cpu" state. Some older versions of
60 * the kernel/tracers may not have the corresponding sched_waking events
61 * that also does so, so we can set it at the migrate, if applicable.
63 ITmfStateValue value
= StateValues
.PROCESS_STATUS_WAIT_FOR_CPU_VALUE
;
64 ss
.modifyAttribute(t
, value
, threadNode
);
66 /* Update the thread's running queue to the new one indicated by the event */
67 int quark
= ss
.getQuarkRelativeAndAdd(threadNode
, Attributes
.CURRENT_CPU_RQ
);
68 value
= TmfStateValue
.newValueInt(destCpu
.intValue());
69 ss
.modifyAttribute(t
, value
, quark
);