[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 03/33] translate-all: add DEBUG_LOCKING asserts
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [PATCH v5 03/33] translate-all: add DEBUG_LOCKING asserts |
Date: |
Thu, 27 Oct 2016 16:10:00 +0100 |
This adds asserts to check the locking on the various translation
engines structures. There are two sets of structures that are protected
by locks.
The first the l1map and PageDesc structures used to track which
translation blocks are associated with which physical addresses. In
user-mode this is covered by the mmap_lock.
The second case are TB context related structures which are protected by
tb_lock which is also user-mode only.
Currently the asserts do nothing in SoftMMU mode but this will change
for MTTCG.
Signed-off-by: Alex Bennée <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
---
bsd-user/mmap.c | 5 +++++
include/exec/exec-all.h | 1 +
linux-user/mmap.c | 5 +++++
translate-all.c | 41 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 52 insertions(+)
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 610f91b..ee59073 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -42,6 +42,11 @@ void mmap_unlock(void)
}
}
+bool have_mmap_lock(void)
+{
+ return mmap_lock_count > 0 ? true : false;
+}
+
/* Grab lock to make sure things are in a consistent state after fork(). */
void mmap_fork_start(void)
{
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 13633a2..84fecc8 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -370,6 +370,7 @@ void tlb_fill(CPUState *cpu, target_ulong addr,
MMUAccessType access_type,
#if defined(CONFIG_USER_ONLY)
void mmap_lock(void);
void mmap_unlock(void);
+bool have_mmap_lock(void);
static inline tb_page_addr_t get_page_addr_code(CPUArchState *env1,
target_ulong addr)
{
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index c4371d9..19aeec5 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -43,6 +43,11 @@ void mmap_unlock(void)
}
}
+bool have_mmap_lock(void)
+{
+ return mmap_lock_count > 0 ? true : false;
+}
+
/* Grab lock to make sure things are in a consistent state after fork(). */
void mmap_fork_start(void)
{
diff --git a/translate-all.c b/translate-all.c
index 8907302..758f654 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -31,6 +31,7 @@
#include "tcg.h"
#if defined(CONFIG_USER_ONLY)
#include "qemu.h"
+#include "exec/exec-all.h"
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <sys/param.h>
#if __FreeBSD_version >= 700104
@@ -58,6 +59,7 @@
/* #define DEBUG_TB_INVALIDATE */
/* #define DEBUG_TB_FLUSH */
+/* #define DEBUG_LOCKING */
/* make various TB consistency checks */
/* #define DEBUG_TB_CHECK */
@@ -66,6 +68,28 @@
#undef DEBUG_TB_CHECK
#endif
+/* Access to the various translations structures need to be serialised via
locks
+ * for consistency. This is automatic for SoftMMU based system
+ * emulation due to its single threaded nature. In user-mode emulation
+ * access to the memory related structures are protected with the
+ * mmap_lock.
+ */
+#ifdef DEBUG_LOCKING
+#define DEBUG_MEM_LOCKS 1
+#else
+#define DEBUG_MEM_LOCKS 0
+#endif
+
+#ifdef CONFIG_SOFTMMU
+#define assert_memory_lock() do { /* nothing */ } while (0)
+#else
+#define assert_memory_lock() do { \
+ if (DEBUG_MEM_LOCKS) { \
+ g_assert(have_mmap_lock()); \
+ } \
+ } while (0)
+#endif
+
#define SMC_BITMAP_USE_THRESHOLD 10
typedef struct PageDesc {
@@ -154,6 +178,23 @@ void tb_lock_reset(void)
#endif
}
+#ifdef DEBUG_LOCKING
+#define DEBUG_TB_LOCKS 1
+#else
+#define DEBUG_TB_LOCKS 0
+#endif
+
+#ifdef CONFIG_SOFTMMU
+#define assert_tb_lock() do { /* nothing */ } while (0)
+#else
+#define assert_tb_lock() do { \
+ if (DEBUG_TB_LOCKS) { \
+ g_assert(have_tb_lock); \
+ } \
+ } while (0)
+#endif
+
+
static TranslationBlock *tb_find_pc(uintptr_t tc_ptr);
void cpu_gen_init(void)
--
2.10.1
- [Qemu-devel] [PATCH v5 00/33] MTTCG Base Enabling patches with ARM on x86 defaults, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 02/33] translate_all: DEBUG_FLUSH -> DEBUG_TB_FLUSH, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 01/33] cpus: make all_vcpus_paused() return bool, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 04/33] cpu-exec: include cpu_index in CPU_LOG_EXEC messages, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 05/33] docs: new design document multi-thread-tcg.txt (DRAFTING), Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 07/33] linux-user/elfload: ensure mmap_lock() held while setting up, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 08/33] translate-all: Add assert_(memory|tb)_lock annotations, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 10/33] target-arm/arm-powerctl: wake up sleeping CPUs, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 03/33] translate-all: add DEBUG_LOCKING asserts,
Alex Bennée <=
- [Qemu-devel] [PATCH v5 09/33] tcg: protect translation related stuff with tb_lock., Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 12/33] tcg: cpus rm tcg_exec_all(), Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 14/33] tcg: add kick timer for single-threaded vCPU emulation, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 13/33] tcg: add options for enabling MTTCG, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 17/33] cpus: re-factor out handle_icount_deadline, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 22/33] atomic: introduce cmpxchg_bool, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 16/33] tcg: drop global lock during TCG code execution, Alex Bennée, 2016/10/27
- [Qemu-devel] [PATCH v5 18/33] tcg: remove global exit_request, Alex Bennée, 2016/10/27