feat(arch timer): migrate vCPU with pending timer to another CPU

This patch adds necessary support to migrate the vCPU from old CPU
to a new CPU whenever the vCPU has a pending timer. During this
migration, SPMC removes the vCPU timer entry from list maintained on
the old host and adds it to the list on the new host.

Change-Id: Ic1448ca8d1b83f7ede0479db9769f51a85b821a3
Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
diff --git a/src/timer_mgmt.c b/src/timer_mgmt.c
index 43d1c30..df26a8a 100644
--- a/src/timer_mgmt.c
+++ b/src/timer_mgmt.c
@@ -136,3 +136,33 @@
 
 	return target_vcpu;
 }
+
+void timer_migrate_to_other_cpu(struct cpu *to_cpu,
+				struct vcpu_locked migrate_vcpu_locked)
+{
+	struct cpu *from_cpu;
+	struct vcpu *migrate_vcpu;
+
+	assert(to_cpu != NULL);
+
+	migrate_vcpu = migrate_vcpu_locked.vcpu;
+	from_cpu = migrate_vcpu->cpu;
+
+	if (from_cpu != NULL && (to_cpu != from_cpu)) {
+		if (!list_empty(&migrate_vcpu->timer_node)) {
+			assert(arch_timer_enabled(&migrate_vcpu->regs));
+
+			/*
+			 * Remove vcpu from timer list maintained by SPMC for
+			 * old CPU.
+			 */
+			timer_list_remove_vcpu(from_cpu, migrate_vcpu);
+
+			/*
+			 * Add vcpu to timer list maintained by SPMC for new
+			 * CPU.
+			 */
+			timer_list_add_vcpu(to_cpu, migrate_vcpu);
+		}
+	}
+}