Skip to content

Commit

Permalink
translate-all: add DEBUG_LOCKING asserts
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
stsquad authored and bonzini committed Oct 31, 2016
1 parent 955939a commit 301e40e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bsd-user/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions include/exec/exec-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,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)
{
Expand Down
5 changes: 5 additions & 0 deletions linux-user/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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)
{
Expand Down
41 changes: 41 additions & 0 deletions translate-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,6 +59,7 @@

/* #define DEBUG_TB_INVALIDATE */
/* #define DEBUG_TB_FLUSH */
/* #define DEBUG_LOCKING */
/* make various TB consistency checks */
/* #define DEBUG_TB_CHECK */

Expand All @@ -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 {
Expand Down Expand Up @@ -173,6 +197,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)
Expand Down

0 comments on commit 301e40e

Please sign in to comment.