|
|
9ae3a8 |
From 1666ea1986c2fdce3bc27aa96ae6bf3a632dbc99 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Nigel Croxon <ncroxon@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 31 Jul 2013 15:12:17 +0200
|
|
|
9ae3a8 |
Subject: Introduce async_run_on_cpu
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Nigel Croxon <ncroxon@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1375283539-18714-2-git-send-email-ncroxon@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 52874
|
|
|
9ae3a8 |
O-Subject: [RHEL7 PATCH 1/3] Introduce async_run_on_cpu
|
|
|
9ae3a8 |
Bugzilla: 985958
|
|
|
9ae3a8 |
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Bugzilla: 985958 - Throttle-down guest to help with live migration convergence (backport to RHEL7.0)
|
|
|
9ae3a8 |
https://bugzilla.redhat.com/show_bug.cgi?id=985958
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Backported from the following upstream commit:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
commit 3c02270db980007424d797506301826310ce2db4
|
|
|
9ae3a8 |
Author: Chegu Vinod <chegu_vinod@hp.com>
|
|
|
9ae3a8 |
Date: Mon Jun 24 03:49:41 2013 -0600
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Introduce async_run_on_cpu()
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Introduce an asynchronous version of run_on_cpu() i.e. the caller
|
|
|
9ae3a8 |
doesn't have to block till the call back routine finishes execution
|
|
|
9ae3a8 |
on the target vcpu.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Chegu Vinod <chegu_vinod@hp.com>
|
|
|
9ae3a8 |
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Juan Quintela <quintela@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/cpus.c b/cpus.c
|
|
|
9ae3a8 |
index c232265..8cd4eab 100644
|
|
|
9ae3a8 |
--- a/cpus.c
|
|
|
9ae3a8 |
+++ b/cpus.c
|
|
|
9ae3a8 |
@@ -653,6 +653,7 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
wi.func = func;
|
|
|
9ae3a8 |
wi.data = data;
|
|
|
9ae3a8 |
+ wi.free = false;
|
|
|
9ae3a8 |
if (cpu->queued_work_first == NULL) {
|
|
|
9ae3a8 |
cpu->queued_work_first = &wi;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
@@ -671,6 +672,31 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ struct qemu_work_item *wi;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (qemu_cpu_is_self(cpu)) {
|
|
|
9ae3a8 |
+ func(data);
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ wi = g_malloc0(sizeof(struct qemu_work_item));
|
|
|
9ae3a8 |
+ wi->func = func;
|
|
|
9ae3a8 |
+ wi->data = data;
|
|
|
9ae3a8 |
+ wi->free = true;
|
|
|
9ae3a8 |
+ if (cpu->queued_work_first == NULL) {
|
|
|
9ae3a8 |
+ cpu->queued_work_first = wi;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ cpu->queued_work_last->next = wi;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ cpu->queued_work_last = wi;
|
|
|
9ae3a8 |
+ wi->next = NULL;
|
|
|
9ae3a8 |
+ wi->done = false;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ qemu_cpu_kick(cpu);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static void flush_queued_work(CPUState *cpu)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
struct qemu_work_item *wi;
|
|
|
9ae3a8 |
@@ -683,6 +709,9 @@ static void flush_queued_work(CPUState *cpu)
|
|
|
9ae3a8 |
cpu->queued_work_first = wi->next;
|
|
|
9ae3a8 |
wi->func(wi->data);
|
|
|
9ae3a8 |
wi->done = true;
|
|
|
9ae3a8 |
+ if (wi->free) {
|
|
|
9ae3a8 |
+ g_free(wi);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
cpu->queued_work_last = NULL;
|
|
|
9ae3a8 |
qemu_cond_broadcast(&qemu_work_cond);
|
|
|
9ae3a8 |
diff --git a/include/qemu-common.h b/include/qemu-common.h
|
|
|
9ae3a8 |
index 3b1ca8e..73c6419 100644
|
|
|
9ae3a8 |
--- a/include/qemu-common.h
|
|
|
9ae3a8 |
+++ b/include/qemu-common.h
|
|
|
9ae3a8 |
@@ -288,6 +288,7 @@ struct qemu_work_item {
|
|
|
9ae3a8 |
void (*func)(void *data);
|
|
|
9ae3a8 |
void *data;
|
|
|
9ae3a8 |
int done;
|
|
|
9ae3a8 |
+ bool free;
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#ifdef CONFIG_USER_ONLY
|
|
|
9ae3a8 |
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
|
|
|
9ae3a8 |
index 7cd9442..46465e9 100644
|
|
|
9ae3a8 |
--- a/include/qom/cpu.h
|
|
|
9ae3a8 |
+++ b/include/qom/cpu.h
|
|
|
9ae3a8 |
@@ -265,6 +265,16 @@ bool cpu_is_stopped(CPUState *cpu);
|
|
|
9ae3a8 |
void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/**
|
|
|
9ae3a8 |
+ * async_run_on_cpu:
|
|
|
9ae3a8 |
+ * @cpu: The vCPU to run on.
|
|
|
9ae3a8 |
+ * @func: The function to be executed.
|
|
|
9ae3a8 |
+ * @data: Data to pass to the function.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Schedules the function @func for execution on the vCPU @cpu asynchronously.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/**
|
|
|
9ae3a8 |
* qemu_for_each_cpu:
|
|
|
9ae3a8 |
* @func: The function to be executed.
|
|
|
9ae3a8 |
* @data: Data to pass to the function.
|