qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Use spinlock_t for interrupt_lock
@ 2008-03-20 22:44 Stuart Brady
  0 siblings, 0 replies; only message in thread
From: Stuart Brady @ 2008-03-20 22:44 UTC (permalink / raw)
  To: qemu-devel

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,
-- 
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);
     }
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-20 22:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-20 22:44 [Qemu-devel] [PATCH] Use spinlock_t for interrupt_lock Stuart Brady

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).