1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
;
15 import java
.util
.List
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
19 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.StateValues
;
20 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.ILttngKernelEventLayout
;
22 import ca
.polymtl
.dorsal
.libdelorean
.ITmfStateSystemBuilder
;
23 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.AttributeNotFoundException
;
24 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.ITmfStateValue
;
25 import ca
.polymtl
.dorsal
.libdelorean
.statevalue
.TmfStateValue
;
28 * Soft Irq exit handler
30 public class SoftIrqExitHandler
extends KernelEventHandler
{
38 public SoftIrqExitHandler(ILttngKernelEventLayout layout
) {
43 public void handleEvent(ITmfStateSystemBuilder ss
, ITmfEvent event
) throws AttributeNotFoundException
{
44 Integer cpu
= KernelEventHandlerUtils
.getCpu(event
);
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
);
57 ss
.modifyAttribute(timestamp
, TmfStateValue
.nullValue(), quark
);
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()) {
66 /* Set the previous process back to running */
67 KernelEventHandlerUtils
.setProcessToRunning(timestamp
, currentThreadNode
, ss
);
69 /* Set the CPU status back to "busy" or "idle" */
70 KernelEventHandlerUtils
.cpuExitInterrupt(timestamp
, cpu
, ss
);
74 * This checks if the running <stong>bit</strong> is set
78 * @return true if in a softirq. The softirq may be pre-empted by an irq
80 private static boolean isSoftIrqRaised(@Nullable ITmfStateValue state
) {
81 return (state
!= null &&
83 (state
.unboxInt() & StateValues
.CPU_STATUS_SOFT_IRQ_RAISED
) == StateValues
.CPU_STATUS_SOFT_IRQ_RAISED
);