qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: mtosatti@redhat.com
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [patch 3/7] qemu: main thread does io and cpu thread is spawned
Date: Thu, 19 Mar 2009 11:57:08 -0300	[thread overview]
Message-ID: <20090319150538.014041718@localhost.localdomain> (raw)
In-Reply-To: 20090319145705.988576615@localhost.localdomain

[-- Attachment #1: vcpus-on-thread --]
[-- Type: text/plain, Size: 2647 bytes --]


Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c
+++ qemu/vl.c
@@ -3623,12 +3623,13 @@ static int wait_signal(int timeout)
 
 static int has_work(CPUState *env)
 {
-    int r = 0;
+    if (!vm_running)
+        return 0;
     if (!env->halted)
-        r = 1;
+        return 1;
     if (env->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI))
-        r = 1;
-    return r;
+        return 1;
+    return 0;
 }
 
 static void qemu_wait_io_event(CPUState *env, int timeout)
@@ -3737,14 +3738,6 @@ void main_loop_break(void)
     qemu_thread_signal(&io_thread, SIG_IPI);
 }
 
-static void *io_thread_fn(void *arg)
-{
-    unblock_io_signals();
-    qemu_mutex_lock(&qemu_global_mutex);
-    while (1)
-        main_loop_wait(1000);
-}
-
 static void qemu_signal_lock(unsigned int msecs)
 {
     qemu_mutex_lock(&qemu_fair_mutex);
@@ -3842,9 +3835,11 @@ void main_loop_wait(int timeout)
 #endif
 
     /* vm time timers */
-    if (vm_running && likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
-        qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
-                        qemu_get_clock(vm_clock));
+    if (vm_running) {
+        if (cur_cpu && likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
+            qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
+                             qemu_get_clock(vm_clock));
+    }
 
     /* real time timers */
     qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
@@ -3856,7 +3851,7 @@ void main_loop_wait(int timeout)
 
 }
 
-static int main_loop(void)
+static void *cpu_main_loop(void *arg)
 {
     int ret, timeout;
 #ifdef CONFIG_PROFILER
@@ -3864,15 +3859,11 @@ static int main_loop(void)
 #endif
     CPUState *env;
 
-    qemu_mutex_init(&qemu_fair_mutex);
-    qemu_mutex_init(&qemu_global_mutex);
-    qemu_mutex_lock(&qemu_global_mutex);
-
-    qemu_thread_create(&io_thread, io_thread_fn, NULL);
     block_io_signals();
-
     qemu_thread_self(&cpus_thread);
 
+    qemu_mutex_lock(&qemu_global_mutex);
+
     cur_cpu = first_cpu;
     next_cpu = cur_cpu->next_cpu ?: first_cpu;
     for(;;) {
@@ -4011,7 +4002,23 @@ static int main_loop(void)
 #endif
     }
     cpu_disable_ticks();
-    return ret;
+    return NULL;
+}
+
+static void main_loop(void)
+{
+    qemu_mutex_init(&qemu_fair_mutex);
+    qemu_mutex_init(&qemu_global_mutex);
+    qemu_mutex_lock(&qemu_global_mutex);
+
+    qemu_thread_self(&io_thread);
+
+    unblock_io_signals();
+
+    qemu_thread_create(&cpus_thread, cpu_main_loop, NULL);
+
+    while (1)
+        main_loop_wait(1000);
 }
 
 static void help(int exitcode)

-- 

  parent reply	other threads:[~2009-03-19 15:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19 14:57 [Qemu-devel] [patch 0/7] separate thread for io v2 mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 1/7] qemu: mutex/thread/cond wrappers mtosatti
2009-03-19 15:59   ` Avi Kivity
2009-03-19 18:49     ` Jamie Lokier
2009-03-23 23:17     ` Marcelo Tosatti
2009-03-24  7:43       ` Avi Kivity
2009-03-19 14:57 ` [Qemu-devel] [patch 2/7] qemu: separate thread for io mtosatti
2009-03-20 17:43   ` [Qemu-devel] " Anthony Liguori
2009-03-21  0:06     ` Marcelo Tosatti
2009-03-21  1:04       ` Anthony Liguori
2009-03-21  1:44         ` Marcelo Tosatti
2009-03-21  1:50           ` Anthony Liguori
2009-03-22  8:48             ` Avi Kivity
2009-03-22 11:17               ` Anthony Liguori
2009-03-19 14:57 ` mtosatti [this message]
2009-03-19 14:57 ` [Qemu-devel] [patch 4/7] qemu: handle reset/poweroff/shutdown in iothread mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 5/7] qemu: pause and resume cpu thread(s) mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 6/7] qemu: handle vmstop from cpu context mtosatti
2009-03-19 14:57 ` [Qemu-devel] [patch 7/7] qemu: use pipe to wakeup io thread mtosatti

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=20090319150538.014041718@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).