Commit | Line | Data |
---|---|---|
c8f45ad2 MK |
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.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers; | |
14 | ||
0f7a12d3 | 15 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues; |
c8f45ad2 | 16 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout; |
f69045e2 | 17 | import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes; |
c8f45ad2 MK |
18 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
19 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
20 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
21 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; | |
22 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
23 | ||
24 | /** | |
25 | * Wakeup handler | |
26 | */ | |
27 | public class SchedWakeupHandler extends KernelEventHandler { | |
28 | ||
29 | /** | |
30 | * Constructor | |
31 | * @param layout event layout | |
32 | */ | |
33 | public SchedWakeupHandler(IKernelAnalysisEventLayout layout) { | |
34 | super(layout); | |
35 | } | |
36 | ||
37 | @Override | |
38 | public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException { | |
8a0bbebf | 39 | Integer cpu = KernelEventHandlerUtils.getCpu(event); |
c8f45ad2 MK |
40 | final int tid = ((Long) event.getContent().getField(getLayout().fieldTid()).getValue()).intValue(); |
41 | final int prio = ((Long) event.getContent().getField(getLayout().fieldPrio()).getValue()).intValue(); | |
8a0bbebf | 42 | |
642b4947 | 43 | String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu); |
8a0bbebf MJ |
44 | if (threadAttributeName == null) { |
45 | return; | |
46 | } | |
47 | ||
48 | final int threadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), threadAttributeName); | |
c8f45ad2 MK |
49 | |
50 | /* | |
51 | * The process indicated in the event's payload is now ready to run. | |
52 | * Assign it to the "wait for cpu" state, but only if it was not already | |
53 | * running. | |
54 | */ | |
55 | int quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.STATUS); | |
56 | int status = ss.queryOngoingState(quark).unboxInt(); | |
57 | ITmfStateValue value = null; | |
58 | long timestamp = KernelEventHandlerUtils.getTimestamp(event); | |
59 | if (status != StateValues.PROCESS_STATUS_RUN_SYSCALL && | |
60 | status != StateValues.PROCESS_STATUS_RUN_USERMODE) { | |
61 | value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE; | |
62 | ss.modifyAttribute(timestamp, value, quark); | |
63 | } | |
64 | ||
65 | /* | |
66 | * When a user changes a threads prio (e.g. with pthread_setschedparam), | |
67 | * it shows in ftrace with a sched_wakeup. | |
68 | */ | |
69 | quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.PRIO); | |
70 | value = TmfStateValue.newValueInt(prio); | |
71 | ss.modifyAttribute(timestamp, value, quark); | |
72 | } | |
73 | } |