From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JcTVJ-0001P8-Df for qemu-devel@nongnu.org; Thu, 20 Mar 2008 18:44:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JcTVH-0001Nb-S7 for qemu-devel@nongnu.org; Thu, 20 Mar 2008 18:44:57 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JcTVH-0001NU-Oe for qemu-devel@nongnu.org; Thu, 20 Mar 2008 18:44:55 -0400 Received: from mx20.gnu.org ([199.232.41.8]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JcTVH-0005PQ-FK for qemu-devel@nongnu.org; Thu, 20 Mar 2008 18:44:55 -0400 Received: from mtaout01-winn.ispmail.ntl.com ([81.103.221.47]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JcTV1-00028N-DU for qemu-devel@nongnu.org; Thu, 20 Mar 2008 18:44:42 -0400 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com with ESMTP id <20080320224653.DUBQ22033.mtaout01-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Thu, 20 Mar 2008 22:46:53 +0000 Received: from miranda.arrow ([213.107.26.151]) by aamtaout01-winn.ispmail.ntl.com with ESMTP id <20080320224743.SKCV219.aamtaout01-winn.ispmail.ntl.com@miranda.arrow> for ; Thu, 20 Mar 2008 22:47:43 +0000 Received: from sdb by miranda.arrow with local (Exim 4.63) (envelope-from ) id 1JcTUh-0005sk-C9 for qemu-devel@nongnu.org; Thu, 20 Mar 2008 22:44:19 +0000 Date: Thu, 20 Mar 2008 22:44:19 +0000 From: Stuart Brady Message-ID: <20080320224419.GA22571@miranda.arrow> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] Use spinlock_t for interrupt_lock Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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); } }