[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Use spinlock_t for interrupt_lock

From: Stuart Brady
Subject: [Qemu-devel] [PATCH] Use spinlock_t for interrupt_lock
Date: Thu, 20 Mar 2008 22:44:19 +0000
User-agent: Mutt/1.5.13 (2006-08-11)


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.

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;
+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;
-        interrupt_lock = 0;
+        resetlock(&interrupt_lock);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]