[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v1 09/12] translate-all: introduces tb_flush_safe.
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [RFC v1 09/12] translate-all: introduces tb_flush_safe. |
Date: |
Fri, 15 Apr 2016 15:23:48 +0100 |
From: KONRAD Frederic <address@hidden>
tb_flush is not thread safe we definitely need to exit VCPUs to do that.
This introduces tb_flush_safe which just creates an async safe work which will
do a tb_flush later. This is called when we run out of space.
Signed-off-by: KONRAD Frederic <address@hidden>
[AJB: merge the various tb_flush commits]
Signed-off-by: Alex Bennée <address@hidden>
---
v1:
- add more comments
- fix build for linux-user
- add log warning on linux-user
---
include/exec/exec-all.h | 1 +
translate-all.c | 34 +++++++++++++++++++++++++++-------
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index f695577..858055b 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -307,6 +307,7 @@ struct TBContext {
void tb_free(TranslationBlock *tb);
void tb_flush(CPUState *cpu);
+void tb_flush_safe(CPUState *cpu);
void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);
#if defined(USE_DIRECT_JUMP)
diff --git a/translate-all.c b/translate-all.c
index 8e70583..874dc56 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -825,9 +825,30 @@ static void page_flush_tb(void)
}
}
-/* flush all the translation blocks */
-/* XXX: tb_flush is currently not thread safe. System emulation calls it only
- * with tb_lock taken or from safe_work, so no need to take tb_lock here.
+#ifdef CONFIG_SOFTMMU
+static void tb_flush_work(CPUState *cpu, void *opaque)
+{
+ tb_flush(cpu);
+}
+#endif
+
+void tb_flush_safe(CPUState *cpu)
+{
+#ifdef CONFIG_SOFTMMU
+ async_safe_run_on_cpu(cpu, tb_flush_work, NULL);
+#else
+ qemu_log("Safe flushing of TBs not implemented for linux-user\n");
+ tb_flush(cpu);
+#endif
+}
+
+/* Flush *all* translations
+ *
+ * This invalidates all translations, lookups and caches.
+ *
+ * This is not thread save for linux-user. For softmmu targets the
+ * flushing is done when all vCPUs are quiescent via the
+ * async_safe_work mechanism
*/
void tb_flush(CPUState *cpu)
{
@@ -1183,10 +1204,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
if (unlikely(!tb)) {
buffer_overflow:
/* flush must be done */
- tb_flush(cpu);
- /* cannot fail at this point */
- tb = tb_alloc(pc);
- assert(tb != NULL);
+ tb_flush_safe(cpu);
+ tb_unlock();
+ cpu_loop_exit(cpu);
}
gen_code_buf = tcg_ctx.code_gen_ptr;
--
2.7.4
- [Qemu-devel] [RFC v1 04/12] atomic: introduce atomic_dec_fetch., (continued)
- [Qemu-devel] [RFC v1 04/12] atomic: introduce atomic_dec_fetch., Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 07/12] cpus: introduce async_safe_run_on_cpu., Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 11/12] arm: atomically check the exclusive value in a STREX, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 10/12] arm: use tlb_flush_page_all for tlbimva[a], Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 06/12] cpus: pass CPUState to run_on_cpu helpers, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 09/12] translate-all: introduces tb_flush_safe.,
Alex Bennée <=
- [Qemu-devel] [RFC v1 08/12] cputlb: introduce tlb_flush_* async work., Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 12/12] cpus: default MTTCG to on for 32 bit ARM on x86, Alex Bennée, 2016/04/15
- Re: [Qemu-devel] [RFC v1 00/12] Enable MTTCG for 32 bit arm on x86, Alex Bennée, 2016/04/15