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 | ||
8140841e MK |
15 | import java.util.List; |
16 | ||
17 | import org.eclipse.jdt.annotation.Nullable; | |
0f7a12d3 | 18 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues; |
c8f45ad2 MK |
19 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout; |
20 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; | |
21 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
22 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
23 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; | |
24 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
25 | ||
26 | /** | |
27 | * Soft Irq exit handler | |
28 | */ | |
29 | public class SoftIrqExitHandler extends KernelEventHandler { | |
30 | ||
31 | /** | |
32 | * Constructor | |
33 | * | |
34 | * @param layout | |
35 | * event layout | |
36 | */ | |
37 | public SoftIrqExitHandler(IKernelAnalysisEventLayout layout) { | |
38 | super(layout); | |
39 | } | |
40 | ||
41 | @Override | |
42 | public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException { | |
43 | Integer cpu = KernelEventHandlerUtils.getCpu(event); | |
44 | if (cpu == null) { | |
45 | return; | |
46 | } | |
47 | ||
48 | Integer softIrqId = ((Long) event.getContent().getField(getLayout().fieldVec()).getValue()).intValue(); | |
49 | int currentThreadNode = KernelEventHandlerUtils.getCurrentThreadNode(cpu, ss); | |
50 | /* Put this SoftIRQ back to inactive (= -1) in the resource tree */ | |
19ed6598 | 51 | int quark = ss.getQuarkRelativeAndAdd(KernelEventHandlerUtils.getNodeSoftIRQs(cpu, ss), softIrqId.toString()); |
c8f45ad2 | 52 | long timestamp = KernelEventHandlerUtils.getTimestamp(event); |
8140841e MK |
53 | if (isSoftIrqRaised(ss.queryOngoingState(quark))) { |
54 | ss.modifyAttribute(timestamp, StateValues.SOFT_IRQ_RAISED_VALUE, quark); | |
55 | } else { | |
56 | ss.modifyAttribute(timestamp, TmfStateValue.nullValue(), quark); | |
57 | } | |
58 | List<Integer> softIrqs = ss.getSubAttributes(ss.getParentAttributeQuark(quark), false); | |
59 | /* Only set status to running and no exit if ALL softirqs are exited. */ | |
60 | for (Integer softIrq : softIrqs) { | |
61 | if (!ss.queryOngoingState(softIrq).isNull()) { | |
62 | return; | |
63 | } | |
64 | } | |
c8f45ad2 MK |
65 | /* Set the previous process back to running */ |
66 | KernelEventHandlerUtils.setProcessToRunning(timestamp, currentThreadNode, ss); | |
67 | ||
68 | /* Set the CPU status back to "busy" or "idle" */ | |
69 | KernelEventHandlerUtils.cpuExitInterrupt(timestamp, cpu, ss); | |
70 | } | |
71 | ||
8140841e MK |
72 | /** |
73 | * This checks if the running <stong>bit</strong> is set | |
74 | * | |
75 | * @param state | |
76 | * the state to check | |
77 | * @return true if in a softirq. The softirq may be pre-empted by an irq | |
78 | */ | |
79 | private static boolean isSoftIrqRaised(@Nullable ITmfStateValue state) { | |
80 | return (state != null && | |
81 | !state.isNull() && | |
82 | (state.unboxInt() & StateValues.CPU_STATUS_SOFT_IRQ_RAISED) == StateValues.CPU_STATUS_SOFT_IRQ_RAISED); | |
83 | } | |
84 | ||
c8f45ad2 | 85 | } |