#include <xen/xenoprof.h>
#include <xen/event.h>
#include <xen/guest_access.h>
+#include <xen/cpu.h>
#include <asm/regs.h>
#include <asm/types.h>
#include <asm/msr.h>
* We will test it again in vpmu_clear_last() with interrupts
* disabled to make sure we don't clear someone else.
*/
- if ( per_cpu(last_vcpu, vpmu->last_pcpu) == v )
+ if ( cpu_online(vpmu->last_pcpu) &&
+ per_cpu(last_vcpu, vpmu->last_pcpu) == v )
on_selected_cpus(cpumask_of(vpmu->last_pcpu),
vpmu_clear_last, v, 1);
if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_destroy )
{
- /* Unload VPMU first. This will stop counters */
- on_selected_cpus(cpumask_of(vcpu_vpmu(v)->last_pcpu),
- vpmu_save_force, v, 1);
+ /*
+ * Unload VPMU first if VPMU_CONTEXT_LOADED being set.
+ * This will stop counters.
+ */
+ if ( vpmu_is_set(vpmu, VPMU_CONTEXT_LOADED) )
+ on_selected_cpus(cpumask_of(vcpu_vpmu(v)->last_pcpu),
+ vpmu_save_force, v, 1);
+
vpmu->arch_vpmu_ops->arch_vpmu_destroy(v);
}
}
return ret;
}
+static int cpu_callback(
+ struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+ unsigned int cpu = (unsigned long)hcpu;
+ struct vcpu *vcpu = per_cpu(last_vcpu, cpu);
+ struct vpmu_struct *vpmu;
+
+ if ( !vcpu )
+ return NOTIFY_DONE;
+
+ vpmu = vcpu_vpmu(vcpu);
+ if ( !vpmu_is_set(vpmu, VPMU_CONTEXT_ALLOCATED) )
+ return NOTIFY_DONE;
+
+ if ( action == CPU_DYING )
+ {
+ vpmu_save_force(vcpu);
+ vpmu_reset(vpmu, VPMU_CONTEXT_LOADED);
+ }
+
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block cpu_nfb = {
+ .notifier_call = cpu_callback
+};
+
static int __init vpmu_init(void)
{
int vendor = current_cpu_data.x86_vendor;
}
if ( vpmu_mode != XENPMU_MODE_OFF )
+ {
+ register_cpu_notifier(&cpu_nfb);
printk(XENLOG_INFO "VPMU: version " __stringify(XENPMU_VER_MAJ) "."
__stringify(XENPMU_VER_MIN) "\n");
+ }
else
opt_vpmu_enabled = 0;