+static void nmi_cpu_switch(void *dummy)
+{
+ int cpu = smp_processor_id();
+ int si = per_cpu(switch_index, cpu);
+ struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
+
+ nmi_cpu_stop(NULL);
+ nmi_cpu_save_mpx_registers(msrs);
+
+ /* move to next set */
+ si += model->num_hardware_counters;
+ if ((si > model->num_counters) || (counter_config[si].count == 0))
+ per_cpu(switch_index, smp_processor_id()) = 0;
+ else
+ per_cpu(switch_index, smp_processor_id()) = si;
+
+ nmi_cpu_restore_mpx_registers(msrs);
+ model->setup_ctrs(msrs);
+ nmi_cpu_start(NULL);
+}
+
+/*
+ * Quick check to see if multiplexing is necessary.
+ * The check should be sufficient since counters are used
+ * in ordre.
+ */
+static int nmi_multiplex_on(void)
+{
+ return counter_config[model->num_hardware_counters].count ? 0 : -EINVAL;
+}
+
+static int nmi_switch_event(void)
+{
+ if (nmi_multiplex_on() < 0)
+ return -EINVAL;
+
+ on_each_cpu(nmi_cpu_switch, NULL, 0, 1);
+
+ return 0;
+}
+