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
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
;
15 import java
.util
.List
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.StateValues
;
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
;
27 * Soft Irq exit handler
29 public class SoftIrqExitHandler
extends KernelEventHandler
{
37 public SoftIrqExitHandler(IKernelAnalysisEventLayout layout
) {
42 public void handleEvent(ITmfStateSystemBuilder ss
, ITmfEvent event
) throws AttributeNotFoundException
{
43 Integer cpu
= KernelEventHandlerUtils
.getCpu(event
);
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 */
51 int quark
= ss
.getQuarkRelativeAndAdd(KernelEventHandlerUtils
.getNodeSoftIRQs(cpu
, ss
), softIrqId
.toString());
52 long timestamp
= KernelEventHandlerUtils
.getTimestamp(event
);
53 if (isSoftIrqRaised(ss
.queryOngoingState(quark
))) {
54 ss
.modifyAttribute(timestamp
, StateValues
.SOFT_IRQ_RAISED_VALUE
, quark
);
56 ss
.modifyAttribute(timestamp
, TmfStateValue
.nullValue(), quark
);
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()) {
65 /* Set the previous process back to running */
66 KernelEventHandlerUtils
.setProcessToRunning(timestamp
, currentThreadNode
, ss
);
68 /* Set the CPU status back to "busy" or "idle" */
69 KernelEventHandlerUtils
.cpuExitInterrupt(timestamp
, cpu
, ss
);
73 * This checks if the running <stong>bit</strong> is set
77 * @return true if in a softirq. The softirq may be pre-empted by an irq
79 private static boolean isSoftIrqRaised(@Nullable ITmfStateValue state
) {
80 return (state
!= null &&
82 (state
.unboxInt() & StateValues
.CPU_STATUS_SOFT_IRQ_RAISED
) == StateValues
.CPU_STATUS_SOFT_IRQ_RAISED
);