[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v3 06/56] cpu: introduce process_queued_cpu_work_locke
From: |
Emilio G. Cota |
Subject: |
[Qemu-devel] [RFC v3 06/56] cpu: introduce process_queued_cpu_work_locked |
Date: |
Thu, 18 Oct 2018 21:05:35 -0400 |
It will gain a user once we protect more of CPUState under cpu->lock.
This completes the conversion to cpu_mutex_lock/unlock in the file.
Signed-off-by: Emilio G. Cota <address@hidden>
---
include/qom/cpu.h | 9 +++++++++
cpus-common.c | 17 +++++++++++------
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 90fd685899..30d1c260dc 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -986,6 +986,15 @@ void cpu_remove_sync(CPUState *cpu);
*/
void process_queued_cpu_work(CPUState *cpu);
+/**
+ * process_queued_cpu_work_locked - process all items on CPU work queue
+ * @cpu: The CPU which work queue to process.
+ *
+ * Call with @cpu->lock held.
+ * See also: process_queued_cpu_work()
+ */
+void process_queued_cpu_work_locked(CPUState *cpu);
+
/**
* cpu_exec_start:
* @cpu: The CPU for the current thread.
diff --git a/cpus-common.c b/cpus-common.c
index 20096ec3c6..d559f94ef1 100644
--- a/cpus-common.c
+++ b/cpus-common.c
@@ -315,20 +315,19 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func
func,
queue_work_on_cpu(cpu, wi);
}
-void process_queued_cpu_work(CPUState *cpu)
+/* Called with the CPU's lock held */
+void process_queued_cpu_work_locked(CPUState *cpu)
{
struct qemu_work_item *wi;
bool has_bql = qemu_mutex_iothread_locked();
- qemu_mutex_lock(&cpu->lock);
if (QSIMPLEQ_EMPTY(&cpu->work_list)) {
- qemu_mutex_unlock(&cpu->lock);
return;
}
while (!QSIMPLEQ_EMPTY(&cpu->work_list)) {
wi = QSIMPLEQ_FIRST(&cpu->work_list);
QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node);
- qemu_mutex_unlock(&cpu->lock);
+ cpu_mutex_unlock(cpu);
if (wi->exclusive) {
/* Running work items outside the BQL avoids the following
deadlock:
* 1) start_exclusive() is called with the BQL taken while another
@@ -354,13 +353,19 @@ void process_queued_cpu_work(CPUState *cpu)
qemu_mutex_unlock_iothread();
}
}
- qemu_mutex_lock(&cpu->lock);
+ cpu_mutex_lock(cpu);
if (wi->free) {
g_free(wi);
} else {
atomic_mb_set(&wi->done, true);
}
}
- qemu_mutex_unlock(&cpu->lock);
qemu_cond_broadcast(&cpu->cond);
}
+
+void process_queued_cpu_work(CPUState *cpu)
+{
+ cpu_mutex_lock(cpu);
+ process_queued_cpu_work_locked(cpu);
+ cpu_mutex_unlock(cpu);
+}
--
2.17.1
- [Qemu-devel] [RFC v3 0/56] per-CPU locks, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 11/56] sh4: convert to cpu_halted, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 05/56] cpu: move run_on_cpu to cpus-common, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 03/56] cpu: introduce cpu_mutex_lock/unlock, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 04/56] cpu: make qemu_work_cond per-cpu, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 06/56] cpu: introduce process_queued_cpu_work_locked,
Emilio G. Cota <=
- [Qemu-devel] [RFC v3 02/56] cpu: rename cpu->work_mutex to cpu->lock, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 10/56] ppc: convert to cpu_halted, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 13/56] lm32: convert to cpu_halted, Emilio G. Cota, 2018/10/18
- [Qemu-devel] [RFC v3 01/56] cpu: convert queued work to a QSIMPLEQ, Emilio G. Cota, 2018/10/18