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