[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v10 72/73] cpu: add async_run_on_cpu_no_bql
From: |
Robert Foley |
Subject: |
[PATCH v10 72/73] cpu: add async_run_on_cpu_no_bql |
Date: |
Wed, 17 Jun 2020 17:02:30 -0400 |
From: "Emilio G. Cota" <cota@braap.org>
Some async jobs do not need the BQL.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: Robert Foley <robert.foley@linaro.org>
---
cpus-common.c | 39 ++++++++++++++++++++++++++++++++++-----
include/hw/core/cpu.h | 14 ++++++++++++++
2 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/cpus-common.c b/cpus-common.c
index eecd63029a..923371a997 100644
--- a/cpus-common.c
+++ b/cpus-common.c
@@ -99,6 +99,7 @@ struct qemu_work_item {
run_on_cpu_func func;
run_on_cpu_data data;
bool free, exclusive, done;
+ bool bql;
};
/* Called with the CPU's lock held */
@@ -145,6 +146,7 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func,
run_on_cpu_data data)
wi.done = false;
wi.free = false;
wi.exclusive = false;
+ wi.bql = true;
cpu_mutex_lock(cpu);
queue_work_on_cpu_locked(cpu, &wi);
@@ -169,6 +171,21 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func,
run_on_cpu_data data)
wi->func = func;
wi->data = data;
wi->free = true;
+ wi->bql = true;
+
+ queue_work_on_cpu(cpu, wi);
+}
+
+void async_run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func,
+ run_on_cpu_data data)
+{
+ struct qemu_work_item *wi;
+
+ wi = g_malloc0(sizeof(struct qemu_work_item));
+ wi->func = func;
+ wi->data = data;
+ wi->free = true;
+ /* wi->bql initialized to false */
queue_work_on_cpu(cpu, wi);
}
@@ -315,6 +332,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func
func,
wi->data = data;
wi->free = true;
wi->exclusive = true;
+ /* wi->bql initialized to false */
queue_work_on_cpu(cpu, wi);
}
@@ -339,6 +357,7 @@ static void process_queued_cpu_work_locked(CPUState *cpu)
* BQL, so it goes to sleep; start_exclusive() is sleeping too, so
* neither CPU can proceed.
*/
+ g_assert(!wi->bql);
if (has_bql) {
qemu_mutex_unlock_iothread();
}
@@ -349,12 +368,22 @@ static void process_queued_cpu_work_locked(CPUState *cpu)
qemu_mutex_lock_iothread();
}
} else {
- if (has_bql) {
- wi->func(cpu, wi->data);
+ if (wi->bql) {
+ if (has_bql) {
+ wi->func(cpu, wi->data);
+ } else {
+ qemu_mutex_lock_iothread();
+ wi->func(cpu, wi->data);
+ qemu_mutex_unlock_iothread();
+ }
} else {
- qemu_mutex_lock_iothread();
- wi->func(cpu, wi->data);
- qemu_mutex_unlock_iothread();
+ if (has_bql) {
+ qemu_mutex_unlock_iothread();
+ wi->func(cpu, wi->data);
+ qemu_mutex_lock_iothread();
+ } else {
+ wi->func(cpu, wi->data);
+ }
}
}
cpu_mutex_lock(cpu);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index d5e4c339e1..e37f64b57a 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -894,9 +894,23 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func,
run_on_cpu_data data);
* @data: Data to pass to the function.
*
* Schedules the function @func for execution on the vCPU @cpu asynchronously.
+ * See also: async_run_on_cpu_no_bql()
*/
void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data
data);
+/**
+ * async_run_on_cpu_no_bql:
+ * @cpu: The vCPU to run on.
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ *
+ * Schedules the function @func for execution on the vCPU @cpu asynchronously.
+ * This function is run outside the BQL.
+ * See also: async_run_on_cpu()
+ */
+void async_run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func,
+ run_on_cpu_data data);
+
/**
* async_safe_run_on_cpu:
* @cpu: The vCPU to run on.
--
2.17.1
- [PATCH v10 62/73] cpu: introduce cpu_has_work_with_iothread_lock, (continued)
- [PATCH v10 62/73] cpu: introduce cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 63/73] ppc: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 61/73] cpu: call .cpu_has_work with the CPU lock held, Robert Foley, 2020/06/17
- [PATCH v10 64/73] mips: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 66/73] riscv: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 68/73] xtensa: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 65/73] s390x: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 69/73] cpu: rename all_cpu_threads_idle to qemu_tcg_rr_all_cpu_threads_idle, Robert Foley, 2020/06/17
- [PATCH v10 70/73] cpu: protect CPU state with cpu->lock instead of the BQL, Robert Foley, 2020/06/17
- [PATCH v10 73/73] cputlb: queue async flush jobs without the BQL, Robert Foley, 2020/06/17
- [PATCH v10 72/73] cpu: add async_run_on_cpu_no_bql,
Robert Foley <=
- [PATCH v10 67/73] sparc: convert to cpu_has_work_with_iothread_lock, Robert Foley, 2020/06/17
- [PATCH v10 71/73] cpus-common: release BQL earlier in run_on_cpu, Robert Foley, 2020/06/17
- Re: [PATCH v10 00/73] per-CPU locks, no-reply, 2020/06/17