Commit | Line | Data |
---|---|---|
af3275f8 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir | |
3 | * | |
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 | *******************************************************************************/ | |
9 | ||
10 | package org.lttng.scope.lttng.kernel.core.analysis.os.handlers.internal; | |
11 | ||
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; | |
16 | ||
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; | |
21 | ||
22 | /** | |
23 | * Handler for task migration events. Normally moves a (non-running) process | |
24 | * from one run queue to another. | |
25 | * | |
26 | * @author Alexandre Montplaisir | |
27 | */ | |
28 | public class SchedMigrateTaskHandler extends KernelEventHandler { | |
29 | ||
30 | /** | |
31 | * Constructor | |
32 | * | |
33 | * @param layout | |
34 | * The event layout to use | |
35 | */ | |
36 | public SchedMigrateTaskHandler(ILttngKernelEventLayout layout) { | |
37 | super(layout); | |
38 | } | |
39 | ||
40 | @Override | |
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()); | |
44 | ||
45 | if (tid == null || destCpu == null) { | |
46 | return; | |
47 | } | |
48 | ||
49 | long t = event.getTimestamp().toNanos(); | |
50 | ||
51 | String threadAttributeName = Attributes.buildThreadAttributeName(tid.intValue(), null); | |
52 | if (threadAttributeName == null) { | |
53 | /* Swapper threads do not get migrated */ | |
54 | return; | |
55 | } | |
56 | int threadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), threadAttributeName); | |
57 | ||
58 | /* | |
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. | |
62 | */ | |
63 | ITmfStateValue value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; | |
64 | ss.modifyAttribute(t, value, threadNode); | |
65 | ||
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); | |
70 | } | |
71 | ||
72 | } |