blob: 573983abe4db23f2e1185b4824c5291a3821bbba [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.fused.handlers;
import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.fused.FusedAttributes;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.model.VirtualCPU;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.model.VirtualMachine;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
/**
* @author Cédric Biancheri
*/
public class KvmNestedVmExitInjectHandler extends VMKernelEventHandler {
/**
* Constructor
*
* @param layout
* the layout
* @param sp
* the state provider
*/
public KvmNestedVmExitInjectHandler(IKernelAnalysisEventLayout layout, FusedVirtualMachineStateProvider sp) {
super(layout, sp);
}
@Override
public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) {
Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), TmfCpuAspect.class, event);
if (cpu == null) {
return;
}
FusedVirtualMachineStateProvider sp = getStateProvider();
VirtualMachine host = sp.getCurrentMachine(event);
if (host == null) {
return;
}
/* We expect to handle this event only for the host. */
if (host.isGuest()) {
return;
}
int currentCPUNode = FusedVMEventHandlerUtils.getCurrentCPUNode(cpu, ss);
/*
* Shortcut for the "current thread" attribute node. It requires
* querying the current CPU's current thread.
*/
int quark = ss.getQuarkRelativeAndAdd(currentCPUNode, FusedAttributes.CURRENT_THREAD);
Object value = ss.queryOngoing(quark);
int thread = (value instanceof Integer) ? (int) value : -1;
thread = VirtualCPU.getVirtualCPU(host, cpu.longValue()).getCurrentThread();
if (thread == -1) {
return;
}
HostThread ht = new HostThread(event.getTrace().getHostId(), thread);
/*
* This event means that this thread will not go to a higher layer
* during the next entry. So we remove it from the list of ready
* threads.
*/
host.removeThreadFromReadyForNextLayerSet(ht);
}
}