Use spinlock_t for interrupt_lock
PATCH 1/1 Use spinlock_t for interrupt_lock
Hi,
The included patch changes cpu_interrupt()'s interrupt_lock variable to a spinlock_t instead of an int, and calls a function to reset the lock instead of directly setting it to zero. This is needed for HPPA host support, for which I will submit some preliminary patches, soon.
HPPA does not have a test-and-set instruction -- instead, it has a load-and-clear instruction (LDCW), so zero must be used for the locked state instead of the unlocked state. The LDCW instruction requires the lock variable to be aligned to a 16-byte boundary -- the simplest way to satisfy this requirement is to use an array of four four-byte words, and to handle the alignment in testandset() itself.
I would have preferred to use spin_trylock() and spin_unlock() in cpu_interrupt(), but it seems that spin_* are no-ops when building a softmmu target. I can submit patches to rename spin_* to spin_user_*, if that would be preferred.
Thanks,
Signature · 46 lines
Stuart Brady
diff -urpN qemu-orig/exec-all.h qemu-new/exec-all.h
--- qemu-orig/exec-all.h 2008-03-20 21:46:27.000000000 +0000
+++ qemu-new/exec-all.h 2008-03-20 19:56:03.000000000 +0000
@@ -432,6 +432,11 @@ typedef int spinlock_t;
#define SPIN_LOCK_UNLOCKED 0
+static inline void resetlock(spinlock_t *lock)
+{
+ *lock = SPIN_LOCK_UNLOCKED;
+}
+
#if defined(CONFIG_USER_ONLY)
static inline void spin_lock(spinlock_t *lock)
{
@@ -440,7 +445,7 @@ static inline void spin_lock(spinlock_t
static inline void spin_unlock(spinlock_t *lock)
{
- *lock = 0;
+ resetlock(lock);
}
static inline int spin_trylock(spinlock_t *lock)
diff -urpN qemu-orig/exec.c qemu-new/exec.c
--- qemu-orig/exec.c 2008-03-20 21:46:27.000000000 +0000
+++ qemu-new/exec.c 2008-03-20 21:47:24.000000000 +0000
@@ -1215,7 +1215,7 @@ void cpu_set_log_filename(const char *fi
void cpu_interrupt(CPUState *env, int mask)
{
TranslationBlock *tb;
- static int interrupt_lock;
+ static spinlock_t interrupt_lock = SPIN_LOCK_UNLOCKED;
env->interrupt_request |= mask;
/* if the cpu is currently executing code, we must unlink it and
@@ -1224,7 +1224,7 @@ void cpu_interrupt(CPUState *env, int ma
if (tb && !testandset(&interrupt_lock)) {
env->current_tb = NULL;
tb_reset_jump_recursive(tb);
- interrupt_lock = 0;
+ resetlock(&interrupt_lock);
}
}