os.linux: Correctly model each CPU's run queue
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / kernel / handlers / 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.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers;
14
15 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues;
16 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
17 import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
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 {
39 Integer cpu = KernelEventHandlerUtils.getCpu(event);
40 final int tid = ((Long) event.getContent().getField(getLayout().fieldTid()).getValue()).intValue();
41 final int prio = ((Long) event.getContent().getField(getLayout().fieldPrio()).getValue()).intValue();
42 Long targetCpu = event.getContent().getFieldValue(Long.class, getLayout().fieldTargetCpu());
43
44 String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
45
46 if (cpu == null || targetCpu == null || threadAttributeName == null) {
47 return;
48 }
49
50 final int threadNode = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeThreads(ss), threadAttributeName);
51
52 /*
53 * The process indicated in the event's payload is now ready to run.
54 * Assign it to the "wait for cpu" state, but only if it was not already
55 * running.
56 */
57 int status = ss.queryOngoingState(threadNode).unboxInt();
58 ITmfStateValue value = null;
59 long timestamp = KernelEventHandlerUtils.getTimestamp(event);
60 if (status != StateValues.PROCESS_STATUS_RUN_SYSCALL &&
61 status != StateValues.PROCESS_STATUS_RUN_USERMODE) {
62 value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE;
63 ss.modifyAttribute(timestamp, value, threadNode);
64 }
65
66 /* Set the thread's target run queue */
67 int quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.CURRENT_CPU_RQ);
68 value = TmfStateValue.newValueInt(targetCpu.intValue());
69 ss.modifyAttribute(timestamp, value, quark);
70
71 /*
72 * When a user changes a threads prio (e.g. with pthread_setschedparam),
73 * it shows in ftrace with a sched_wakeup.
74 */
75 quark = ss.getQuarkRelativeAndAdd(threadNode, Attributes.PRIO);
76 value = TmfStateValue.newValueInt(prio);
77 ss.modifyAttribute(timestamp, value, quark);
78 }
79 }
This page took 0.046433 seconds and 5 git commands to generate.