[PATCH 6/11] QEMU/KVM: Introduce single vcpu pause/resume

Jan Kiszka
2008-05-26T22:10:14Z

Small helpers that allow to pause and resume only a single vcpu thread.

Signed-off-by: Jan Kiszka <jan.kiszka@web.de>
---
qemu/qemu-kvm.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)

Index: b/qemu/qemu-kvm.c
===================================================================
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -207,6 +207,17 @@ static int all_threads_paused(void)
return 1;
}

+static void pause_vcpu_thread(int index)
+{
+ assert(!cpu_single_env || cpu_single_env->cpu_index != index);
+
+ vcpu_info[index].stop = 1;
+ pthread_kill(vcpu_info[index].thread, SIG_IPI);
+
+ while (!vcpu_info[index].stopped)
+ qemu_cond_wait(&qemu_pause_cond);
+}
+
static void pause_all_threads(void)
{
int i;
@@ -221,17 +232,21 @@ static void pause_all_threads(void)
qemu_cond_wait(&qemu_pause_cond);
}

+static void resume_vcpu_thread(int index)
+{
+ assert(!cpu_single_env || cpu_single_env->cpu_index != index);
+
+ vcpu_info[index].stop = 0;
+ vcpu_info[index].stopped = 0;
+ pthread_kill(vcpu_info[index].thread, SIG_IPI);
+}
+
static void resume_all_threads(void)
{
int i;

- assert(!cpu_single_env);
-
- for (i = 0; i < smp_cpus; ++i) {
- vcpu_info[i].stop = 0;
- vcpu_info[i].stopped = 0;
- pthread_kill(vcpu_info[i].thread, SIG_IPI);
- }
+ for (i = 0; i < smp_cpus; ++i)
+ resume_vcpu_thread(i);
}

static void kvm_vm_state_change_handler(void *context, int running)