Patchwork [1/3] enable tb unlinking when compiled with NPTL

login
register
mail settings
Submitter riku.voipio@nokia.com
Date Dec. 4, 2009, 1:16 p.m.
Message ID <bad7a35a02220befc46812ee095255ed2355632e.1259931926.git.riku.voipio@nokia.com>
Download mbox | patch
Permalink /patch/40372/
State New
Headers show

Comments

riku.voipio@nokia.com - Dec. 4, 2009, 1:16 p.m.
From: Riku Voipio <riku.voipio@nokia.com>

Fixes recieving signals when guest code is being executed in a tight
loop. For an example, try interrupting the following code with ctrl-c.

http://nchipin.kos.to/test-loop.c

The tight loop is ofcourse brainless, but it is also exactly how the waitpid* testcases
are implemented.

Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
---
 exec.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

Patch

diff --git a/exec.c b/exec.c
index eb1ee51..3f7e4eb 100644
--- a/exec.c
+++ b/exec.c
@@ -1526,24 +1526,22 @@  void cpu_set_log_filename(const char *filename)
 
 static void cpu_unlink_tb(CPUState *env)
 {
-#if defined(CONFIG_USE_NPTL)
     /* FIXME: TB unchaining isn't SMP safe.  For now just ignore the
        problem and hope the cpu will stop of its own accord.  For userspace
        emulation this often isn't actually as bad as it sounds.  Often
        signals are used primarily to interrupt blocking syscalls.  */
-#else
     TranslationBlock *tb;
     static spinlock_t interrupt_lock = SPIN_LOCK_UNLOCKED;
 
     tb = env->current_tb;
     /* if the cpu is currently executing code, we must unlink it and
        all the potentially executing TB */
-    if (tb && !testandset(&interrupt_lock)) {
+    if (tb) {
+        spin_lock(&interrupt_lock);
         env->current_tb = NULL;
         tb_reset_jump_recursive(tb);
-        resetlock(&interrupt_lock);
+        spin_unlock(&interrupt_lock);
     }
-#endif
 }
 
 /* mask must never be zero, except for A20 change call */