public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>, Anthony Liguori <aliguori@us.ibm.com>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>
Subject: [patch 13/13] QEMU/KVM: get rid of global lock
Date: Thu, 17 Apr 2008 17:10:34 -0300	[thread overview]
Message-ID: <20080417203027.089193735@localhost.localdomain> (raw)
In-Reply-To: 20080417201021.515148882@localhost.localdomain

[-- Attachment #1: remove-global-lock --]
[-- Type: text/plain, Size: 3611 bytes --]

Now that QEMU does all necessary locking itself, get rid of the global mutex lock.

Allows more than one thread inside QEMU simultaneously.

Index: kvm-userspace.io/qemu/qemu-kvm.c
===================================================================
--- kvm-userspace.io.orig/qemu/qemu-kvm.c
+++ kvm-userspace.io/qemu/qemu-kvm.c
@@ -145,7 +145,6 @@ static int try_push_interrupts(void *opa
 static void post_kvm_run(void *opaque, int vcpu)
 {
 
-    pthread_mutex_lock(&qemu_mutex);
     kvm_arch_post_kvm_run(opaque, vcpu);
 }
 
@@ -157,7 +156,6 @@ static int pre_kvm_run(void *opaque, int
 
     if (env->interrupt_request & CPU_INTERRUPT_EXIT)
 	return 1;
-    pthread_mutex_unlock(&qemu_mutex);
     return 0;
 }
 
@@ -228,7 +226,6 @@ static int kvm_eat_signal(struct qemu_kv
     if (r == -1 && (errno == EAGAIN || errno == EINTR) && !timeout)
 	return 0;
     e = errno;
-    pthread_mutex_lock(&qemu_mutex);
     if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
 	printf("sigtimedwait: %s\n", strerror(e));
 	exit(1);
@@ -241,7 +238,6 @@ static int kvm_eat_signal(struct qemu_kv
 	vcpu_info[env->cpu_index].stopped = 1;
 	pthread_kill(io_thread, SIGUSR1);
     }
-    pthread_mutex_unlock(&qemu_mutex);
 
     return ret;
 }
@@ -264,9 +260,7 @@ static void kvm_eat_signals(CPUState *en
 
 static void kvm_main_loop_wait(CPUState *env, int timeout)
 {
-    pthread_mutex_unlock(&qemu_mutex);
     kvm_eat_signals(env, timeout);
-    pthread_mutex_lock(&qemu_mutex);
     vcpu_info[env->cpu_index].signalled = 0;
 }
 
@@ -339,7 +333,6 @@ static int kvm_main_loop_cpu(CPUState *e
     struct vcpu_info *info = &vcpu_info[env->cpu_index];
 
     setup_kernel_sigmask(env);
-    pthread_mutex_lock(&qemu_mutex);
 
     kvm_qemu_init_env(env);
     env->ready_for_interrupt_injection = 1;
@@ -367,7 +360,6 @@ static int kvm_main_loop_cpu(CPUState *e
 	    kvm_arch_load_regs(env);
 	}
     }
-    pthread_mutex_unlock(&qemu_mutex);
     return 0;
 }
 
@@ -456,12 +448,10 @@ void qemu_kvm_notify_work(void)
 int kvm_main_loop(void)
 {
     io_thread = pthread_self();
-    pthread_mutex_unlock(&qemu_mutex);
     while (1) {
         if (get_cpu_env())
             hw_error("io thread has valid env\n");
         kvm_eat_signal(&io_signal_table, NULL, 1000);
-        pthread_mutex_lock(&qemu_mutex);
         main_loop_wait(0);
         if (qemu_shutdown_requested())
             break;
@@ -471,10 +461,8 @@ int kvm_main_loop(void)
             pthread_kill(vcpu_info[0].thread, SIG_IPI);
             qemu_kvm_reset_requested = 1;
         }
-        pthread_mutex_unlock(&qemu_mutex);
     }
 
-    pthread_mutex_unlock(&qemu_mutex);
     return 0;
 }
 
@@ -614,7 +602,6 @@ int kvm_qemu_init()
     if (!kvm_context) {
       	return -1;
     }
-    pthread_mutex_lock(&qemu_mutex);
 
     return 0;
 }
@@ -833,12 +820,13 @@ void qemu_kvm_aio_wait(void)
 
     /* io thread */
     if (!env) {
-        pthread_mutex_unlock(&qemu_mutex);
         kvm_eat_signal(&io_signal_table, NULL, 1000);
-        pthread_mutex_lock(&qemu_mutex);
     /* vcpu thread */
-    } else
+    } else {
+        pthread_mutex_lock(&qemu_mutex);
         pthread_cond_wait(&qemu_aio_cond, &qemu_mutex);
+        pthread_mutex_unlock(&qemu_mutex);
+    }
 }
 
 void qemu_kvm_aio_wait_end(void)

-- 


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

  parent reply	other threads:[~2008-04-17 20:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-17 20:10 [patch 00/13] RFC: split the global mutex Marcelo Tosatti
2008-04-17 20:10 ` [patch 01/13] QEMU: get rid of global cpu_single_env Marcelo Tosatti
2008-04-17 20:10 ` [patch 02/13] QEMU: introduce QEMUDevice Marcelo Tosatti
2008-04-17 20:10 ` [patch 03/13] QEMU: make esp.c build conditional to SPARC target Marcelo Tosatti
2008-04-17 20:10 ` [patch 04/13] QEMU: plug QEMUDevice pt1 / ioport awareness Marcelo Tosatti
2008-04-17 20:10 ` [patch 05/13] QEMU: add a mutex to protect IRQ chip data structures Marcelo Tosatti
2008-04-17 20:10 ` [patch 06/13] QEMU: plug QEMUDevice pt2 / iomem awareness Marcelo Tosatti
2008-04-17 20:10 ` [patch 07/13] QEMU: grab device lock for ioport/iomem processing Marcelo Tosatti
2008-04-17 20:10 ` [patch 08/13] QEMU: character device locking Marcelo Tosatti
2008-04-17 20:10 ` [patch 09/13] QEMU: network " Marcelo Tosatti
2008-04-17 20:10 ` [patch 10/13] QEMU: get rid of aiocb cache Marcelo Tosatti
2008-04-17 20:10 ` [patch 11/13] QEMU: block device locking Marcelo Tosatti
2008-04-17 20:10 ` [patch 12/13] QEMU: scsi-disk reentrancy fix Marcelo Tosatti
2008-04-17 20:10 ` Marcelo Tosatti [this message]
2008-04-20 11:16 ` [patch 00/13] RFC: split the global mutex Avi Kivity
2008-04-21  0:00   ` Marcelo Tosatti
2008-04-21  6:10     ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080417203027.089193735@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox