All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Paul Brook <paul@codesourcery.com>,
	Paulo Bonzini <pbonzini@redhat.com>,
	Arun Bharadwaj <arun@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 5/7] threads: get rid of QemuCond and teach callers about GCond
Date: Mon, 24 Jan 2011 15:00:43 -0600	[thread overview]
Message-ID: <1295902845-29807-6-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1295902845-29807-1-git-send-email-aliguori@us.ibm.com>

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/cpu-defs.h b/cpu-defs.h
index 8d4bf86..9343824 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -204,7 +204,7 @@ typedef struct CPUWatchpoint {
     uint32_t stop;   /* Stop request */                                 \
     uint32_t stopped; /* Artificially stopped */                        \
     struct QemuThread *thread;                                          \
-    struct QemuCond *halt_cond;                                         \
+    struct _GCond *halt_cond;                                           \
     struct qemu_work_item *queued_work_first, *queued_work_last;        \
     const char *cpu_model_str;                                          \
     struct KVMState *kvm_state;                                         \
diff --git a/cpus.c b/cpus.c
index 0f8e33b..bc7363f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -327,15 +327,15 @@ static GStaticMutex qemu_fair_mutex;
 static QemuThread io_thread;
 
 static QemuThread *tcg_cpu_thread;
-static QemuCond *tcg_halt_cond;
+static GCond *tcg_halt_cond;
 
 static int qemu_system_ready;
 /* cpu creation */
-static QemuCond qemu_cpu_cond;
+static GCond *qemu_cpu_cond;
 /* system init */
-static QemuCond qemu_system_cond;
-static QemuCond qemu_pause_cond;
-static QemuCond qemu_work_cond;
+static GCond *qemu_system_cond;
+static GCond *qemu_pause_cond;
+static GCond *qemu_work_cond;
 
 static void tcg_init_ipi(void);
 static void kvm_init_ipi(CPUState *env);
@@ -412,10 +412,10 @@ int qemu_init_main_loop(void)
     if (ret)
         return ret;
 
-    qemu_cond_init(&qemu_cpu_cond);
-    qemu_cond_init(&qemu_system_cond);
-    qemu_cond_init(&qemu_pause_cond);
-    qemu_cond_init(&qemu_work_cond);
+    qemu_cpu_cond = g_cond_new();
+    qemu_system_cond = g_cond_new();
+    qemu_pause_cond = g_cond_new();
+    qemu_work_cond = g_cond_new();
     g_static_mutex_init(&qemu_fair_mutex);
     g_static_mutex_init(&qemu_global_mutex);
     g_static_mutex_lock(&qemu_global_mutex);
@@ -428,7 +428,7 @@ int qemu_init_main_loop(void)
 void qemu_main_loop_start(void)
 {
     qemu_system_ready = 1;
-    qemu_cond_broadcast(&qemu_system_cond);
+    g_cond_broadcast(qemu_system_cond);
 }
 
 void run_on_cpu(CPUState *env, void (*func)(void *data), void *data)
@@ -454,8 +454,8 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data)
     while (!wi.done) {
         CPUState *self_env = cpu_single_env;
 
-        qemu_cond_wait(&qemu_work_cond,
-                       g_static_mutex_get_mutex(&qemu_global_mutex));
+        g_cond_wait(qemu_work_cond,
+                    g_static_mutex_get_mutex(&qemu_global_mutex));
         cpu_single_env = self_env;
     }
 }
@@ -473,7 +473,7 @@ static void flush_queued_work(CPUState *env)
         wi->done = true;
     }
     env->queued_work_last = NULL;
-    qemu_cond_broadcast(&qemu_work_cond);
+    g_cond_broadcast(qemu_work_cond);
 }
 
 static void qemu_wait_io_event_common(CPUState *env)
@@ -481,7 +481,7 @@ static void qemu_wait_io_event_common(CPUState *env)
     if (env->stop) {
         env->stop = 0;
         env->stopped = 1;
-        qemu_cond_signal(&qemu_pause_cond);
+        g_cond_signal(qemu_pause_cond);
     }
     flush_queued_work(env);
 }
@@ -490,9 +490,13 @@ static void qemu_tcg_wait_io_event(void)
 {
     CPUState *env;
 
-    while (!any_cpu_has_work())
-        qemu_cond_timedwait(tcg_halt_cond,
-                            g_static_mutex_get_mutex(&qemu_global_mutex), 1000);
+    while (!any_cpu_has_work()) {
+        GTimeVal t;
+        g_get_current_time(&t);
+        g_time_val_add(&t, 1000000);
+        g_cond_timed_wait(tcg_halt_cond,
+                          g_static_mutex_get_mutex(&qemu_global_mutex), &t);
+    }
 
     g_static_mutex_unlock(&qemu_global_mutex);
 
@@ -586,9 +590,13 @@ static void qemu_kvm_eat_signal(CPUState *env, int timeout)
 
 static void qemu_kvm_wait_io_event(CPUState *env)
 {
-    while (!cpu_has_work(env))
-        qemu_cond_timedwait(env->halt_cond,
-                            g_static_mutex_get_mutex(&qemu_global_mutex), 1000);
+    while (!cpu_has_work(env)) {
+        GTimeVal t;
+        g_get_current_time(&t);
+        g_time_val_add(&t, 1000000);
+        g_cond_timed_wait(env->halt_cond,
+                          g_static_mutex_get_mutex(&qemu_global_mutex), &t);
+    }
 
     qemu_kvm_eat_signal(env, 0);
     qemu_wait_io_event_common(env);
@@ -609,12 +617,16 @@ static void *kvm_cpu_thread_fn(void *arg)
 
     /* signal CPU creation */
     env->created = 1;
-    qemu_cond_signal(&qemu_cpu_cond);
+    g_cond_signal(qemu_cpu_cond);
 
     /* and wait for machine initialization */
-    while (!qemu_system_ready)
-        qemu_cond_timedwait(&qemu_system_cond,
-                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
+    while (!qemu_system_ready) {
+        GTimeVal t;
+        g_get_current_time(&t);
+        g_time_val_add(&t, 100000);
+        g_cond_timed_wait(qemu_system_cond,
+                          g_static_mutex_get_mutex(&qemu_global_mutex), &t);
+    }
 
     while (1) {
         if (cpu_can_run(env))
@@ -636,12 +648,16 @@ static void *tcg_cpu_thread_fn(void *arg)
     g_static_mutex_lock(&qemu_global_mutex);
     for (env = first_cpu; env != NULL; env = env->next_cpu)
         env->created = 1;
-    qemu_cond_signal(&qemu_cpu_cond);
+    g_cond_signal(qemu_cpu_cond);
 
     /* and wait for machine initialization */
-    while (!qemu_system_ready)
-        qemu_cond_timedwait(&qemu_system_cond,
-                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
+    while (!qemu_system_ready) {
+        GTimeVal t;
+        g_get_current_time(&t);
+        g_time_val_add(&t, 100000);
+        g_cond_timed_wait(qemu_system_cond,
+                          g_static_mutex_get_mutex(&qemu_global_mutex), &t);
+    }
 
     while (1) {
         cpu_exec_all();
@@ -654,7 +670,7 @@ static void *tcg_cpu_thread_fn(void *arg)
 void qemu_cpu_kick(void *_env)
 {
     CPUState *env = _env;
-    qemu_cond_broadcast(env->halt_cond);
+    g_cond_broadcast(env->halt_cond);
     qemu_thread_signal(env->thread, SIG_IPI);
 }
 
@@ -784,8 +800,11 @@ void pause_all_vcpus(void)
     }
 
     while (!all_vcpus_paused()) {
-        qemu_cond_timedwait(&qemu_pause_cond,
-                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
+        GTimeVal t;
+        g_get_current_time(&t);
+        g_time_val_add(&t, 10000);
+        g_cond_timed_wait(qemu_pause_cond,
+                          g_static_mutex_get_mutex(&qemu_global_mutex), &t);
         penv = first_cpu;
         while (penv) {
             qemu_cpu_kick(penv);
@@ -812,13 +831,15 @@ static void tcg_init_vcpu(void *_env)
     /* share a single thread for all cpus with TCG */
     if (!tcg_cpu_thread) {
         env->thread = qemu_mallocz(sizeof(QemuThread));
-        env->halt_cond = qemu_mallocz(sizeof(QemuCond));
-        qemu_cond_init(env->halt_cond);
+        env->halt_cond = g_cond_new();
         qemu_thread_create(env->thread, tcg_cpu_thread_fn, env);
-        while (env->created == 0)
-            qemu_cond_timedwait(&qemu_cpu_cond,
-                                g_static_mutex_get_mutex(&qemu_global_mutex),
-                                100);
+        while (env->created == 0) {
+            GTimeVal t;
+            g_get_current_time(&t);
+            g_time_val_add(&t, 10000);
+            g_cond_timed_wait(qemu_cpu_cond,
+                              g_static_mutex_get_mutex(&qemu_global_mutex), &t);
+        }
         tcg_cpu_thread = env->thread;
         tcg_halt_cond = env->halt_cond;
     } else {
@@ -830,12 +851,15 @@ static void tcg_init_vcpu(void *_env)
 static void kvm_start_vcpu(CPUState *env)
 {
     env->thread = qemu_mallocz(sizeof(QemuThread));
-    env->halt_cond = qemu_mallocz(sizeof(QemuCond));
-    qemu_cond_init(env->halt_cond);
+    env->halt_cond = g_cond_new();
     qemu_thread_create(env->thread, kvm_cpu_thread_fn, env);
-    while (env->created == 0)
-        qemu_cond_timedwait(&qemu_cpu_cond,
-                            g_static_mutex_get_mutex(&qemu_global_mutex), 100);
+    while (env->created == 0) {
+        GTimeVal t;
+        g_get_current_time(&t);
+        g_time_val_add(&t, 100000);
+        g_cond_timed_wait(qemu_cpu_cond,
+                          g_static_mutex_get_mutex(&qemu_global_mutex), &t);
+    }
 }
 
 void qemu_init_vcpu(void *_env)
diff --git a/qemu-thread.c b/qemu-thread.c
index df17eb4..748da5e 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -14,43 +14,6 @@
 #include "qemu-common.h"
 #include "qemu-thread.h"
 
-void qemu_cond_init(QemuCond *cond)
-{
-    cond->cond = g_cond_new();
-}
-
-void qemu_cond_destroy(QemuCond *cond)
-{
-    g_cond_free(cond->cond);
-}
-
-void qemu_cond_signal(QemuCond *cond)
-{
-    g_cond_signal(cond->cond);
-}
-
-void qemu_cond_broadcast(QemuCond *cond)
-{
-    g_cond_broadcast(cond->cond);
-}
-
-void qemu_cond_wait(QemuCond *cond, GMutex *mutex)
-{
-    g_cond_wait(cond->cond, mutex);
-}
-
-int qemu_cond_timedwait(QemuCond *cond, GMutex *mutex, uint64_t msecs)
-{
-    GTimeVal abs_time;
-
-    assert(cond->cond != NULL);
-
-    g_get_current_time(&abs_time);
-    g_time_val_add(&abs_time, msecs * 1000); /* MSEC to USEC */
-
-    return g_cond_timed_wait(cond->cond, mutex, &abs_time);
-}
-
 struct trampoline_data
 {
     QemuThread *thread;
diff --git a/qemu-thread.h b/qemu-thread.h
index dec6848..2c99c94 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -3,25 +3,13 @@
 #include <glib.h>
 #include <pthread.h>
 
-struct QemuCond {
-    GCond *cond;
-};
-
 struct QemuThread {
     GThread *thread;
     pthread_t tid;
 };
 
-typedef struct QemuCond QemuCond;
 typedef struct QemuThread QemuThread;
 
-void qemu_cond_init(QemuCond *cond);
-void qemu_cond_destroy(QemuCond *cond);
-void qemu_cond_signal(QemuCond *cond);
-void qemu_cond_broadcast(QemuCond *cond);
-void qemu_cond_wait(QemuCond *cond, GMutex *mutex);
-int qemu_cond_timedwait(QemuCond *cond, GMutex *mutex, uint64_t msecs);
-
 void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
                        void *arg);
diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c
index 48f567e..0c2b1a0 100644
--- a/ui/vnc-jobs-async.c
+++ b/ui/vnc-jobs-async.c
@@ -49,7 +49,7 @@
 */
 
 struct VncJobQueue {
-    QemuCond cond;
+    GCond *cond;
     GStaticMutex mutex;
     QemuThread thread;
     Buffer buffer;
@@ -108,7 +108,7 @@ void vnc_job_push(VncJob *job)
         qemu_free(job);
     } else {
         QTAILQ_INSERT_TAIL(&queue->jobs, job, next);
-        qemu_cond_broadcast(&queue->cond);
+        g_cond_broadcast(queue->cond);
     }
     vnc_unlock_queue(queue);
 }
@@ -152,7 +152,7 @@ void vnc_jobs_join(VncState *vs)
 {
     vnc_lock_queue(queue);
     while (vnc_has_job_locked(vs)) {
-        qemu_cond_wait(&queue->cond, g_static_mutex_get_mutex(&queue->mutex));
+        g_cond_wait(queue->cond, g_static_mutex_get_mutex(&queue->mutex));
     }
     vnc_unlock_queue(queue);
 }
@@ -195,7 +195,7 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
     vnc_lock_queue(queue);
     while (QTAILQ_EMPTY(&queue->jobs) && !queue->exit) {
-        qemu_cond_wait(&queue->cond, g_static_mutex_get_mutex(&queue->mutex));
+        g_cond_wait(queue->cond, g_static_mutex_get_mutex(&queue->mutex));
     }
     /* Here job can only be NULL if queue->exit is true */
     job = QTAILQ_FIRST(&queue->jobs);
@@ -265,7 +265,7 @@ disconnected:
     vnc_lock_queue(queue);
     QTAILQ_REMOVE(&queue->jobs, job, next);
     vnc_unlock_queue(queue);
-    qemu_cond_broadcast(&queue->cond);
+    g_cond_broadcast(queue->cond);
     qemu_free(job);
     return 0;
 }
@@ -274,7 +274,7 @@ static VncJobQueue *vnc_queue_init(void)
 {
     VncJobQueue *queue = qemu_mallocz(sizeof(VncJobQueue));
 
-    qemu_cond_init(&queue->cond);
+    queue->cond = g_cond_new();
     g_static_mutex_init(&queue->mutex);
     QTAILQ_INIT(&queue->jobs);
     return queue;
@@ -282,7 +282,7 @@ static VncJobQueue *vnc_queue_init(void)
 
 static void vnc_queue_clear(VncJobQueue *q)
 {
-    qemu_cond_destroy(&queue->cond);
+    g_cond_free(queue->cond);
     g_static_mutex_free(&queue->mutex);
     buffer_free(&queue->buffer);
     qemu_free(q);
@@ -327,5 +327,5 @@ void vnc_stop_worker_thread(void)
     queue->exit = true;
     vnc_unlock_queue(queue);
     vnc_jobs_clear(NULL);
-    qemu_cond_broadcast(&queue->cond);
+    g_cond_broadcast(queue->cond);
 }
-- 
1.7.0.4

  parent reply	other threads:[~2011-01-24 21:01 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-24 21:00 [Qemu-devel] [RFC 0/7] Introduce hard dependency on glib Anthony Liguori
2011-01-24 21:00 ` [Qemu-devel] [PATCH 1/7] io-thread: make sure to initialize qemu_work_cond and qemu_cpu_cond Anthony Liguori
2011-02-08  8:53   ` [Qemu-devel] " Jan Kiszka
2011-02-08  9:01     ` Anthony Liguori
2011-01-24 21:00 ` [Qemu-devel] [PATCH 2/7] Enable I/O thread and VNC threads by default Anthony Liguori
2011-01-24 22:28   ` [Qemu-devel] " Anthony Liguori
2011-01-25  9:17     ` Edgar E. Iglesias
2011-01-25 13:34       ` Marcelo Tosatti
2011-02-07 10:12         ` Marcelo Tosatti
2011-02-07 16:03           ` Marcelo Tosatti
2011-02-07 16:23             ` Paolo Bonzini
2011-02-07 17:10               ` Jan Kiszka
2011-02-07 21:02                 ` Anthony Liguori
2011-02-07 21:45                   ` Aurelien Jarno
2011-02-08  2:09                     ` Anthony Liguori
2011-02-08  7:26                       ` Aurelien Jarno
2011-02-08  8:08                         ` Paolo Bonzini
2011-02-08  8:50                           ` Jan Kiszka
2011-02-08  9:05                             ` Aurelien Jarno
2011-02-08  9:12                               ` Anthony Liguori
2011-02-08  9:49                                 ` Paolo Bonzini
2011-02-08  9:51                               ` Jan Kiszka
2011-02-08  9:58                                 ` Aurelien Jarno
2011-02-08 10:03                                   ` Jan Kiszka
2011-02-08 10:06                                     ` Aurelien Jarno
2011-02-08 10:16                                       ` Alexander Graf
2011-02-08 10:17                                       ` Stefan Hajnoczi
2011-02-08 10:27                                         ` Aurelien Jarno
2011-02-08 10:31                                           ` Paolo Bonzini
2011-02-08 10:40                                           ` Jan Kiszka
2011-02-08 18:05                                           ` Anthony Liguori
2011-02-08 11:29                                             ` Aurelien Jarno
2011-02-08 12:38                                             ` Riku Voipio
2011-02-08 10:21                                       ` Jan Kiszka
2011-02-08 10:26                                         ` Aurelien Jarno
2011-02-08 10:30                                           ` Jan Kiszka
2011-02-08 17:58                                       ` Anthony Liguori
2011-02-08 11:07                                         ` Tristan Gingold
2011-02-08 11:46                                           ` Aurelien Jarno
2011-02-08 12:07                                             ` Paolo Bonzini
2011-02-08 19:21                                             ` Anthony Liguori
2011-02-08 11:15                                         ` Aurelien Jarno
2011-02-08 12:10                                           ` Paolo Bonzini
2011-02-08 13:31                                             ` Aurelien Jarno
2011-02-08 15:08                                               ` Aurelien Jarno
2011-02-09 17:35                                                 ` Aurelien Jarno
2011-02-09 20:07                                                   ` Anthony Liguori
2011-02-11  0:03                                                     ` Marcelo Tosatti
2011-02-08 19:17                                           ` Anthony Liguori
2011-02-08 13:30                                             ` Aurelien Jarno
2011-02-08 20:54                                               ` Anthony Liguori
2011-02-08 15:09                                                 ` Aurelien Jarno
2011-02-09 17:13                                                   ` Blue Swirl
2011-02-09 22:16                                                     ` [Qemu-devel] " Stefan Weil
2011-02-10  7:34                                                       ` Paolo Bonzini
2011-02-10  9:54                                                       ` Paolo Bonzini
2011-02-10 19:46                                                         ` Stefan Weil
2011-02-08 10:06                                   ` [Qemu-devel] " Paolo Bonzini
2011-02-07 18:35             ` Edgar E. Iglesias
2011-02-07 20:44             ` Aurelien Jarno
2011-02-07 21:30             ` Scott Wood
2011-02-07 20:47           ` Edgar E. Iglesias
2011-01-25  8:33   ` [Qemu-devel] [PATCH 0/2] vnc: the lost parts Corentin Chary
2011-01-25  8:33   ` [Qemu-devel] [PATCH 1/2] vl.c: set NULL upon deleting handlers in qemu_set_fd_handler2() Corentin Chary
2011-01-25 10:03     ` Stefan Hajnoczi
2011-01-25 10:13       ` Corentin Chary
2011-01-25 10:26         ` Stefan Hajnoczi
2011-01-25 12:05           ` Yoshiaki Tamura
2011-01-25  8:33   ` [Qemu-devel] [PATCH 2/2] vnc: qemu can die if the client is disconnected while updating screen Corentin Chary
2011-01-24 21:00 ` [Qemu-devel] [PATCH 3/7] Add support for glib based threading and convert qemu thread to use it Anthony Liguori
2011-01-25 14:24   ` Aurelien Jarno
2011-01-25 15:34     ` Anthony Liguori
2011-02-02 17:32   ` [Qemu-devel] " Paolo Bonzini
2011-02-02 17:35     ` Anthony Liguori
2011-01-24 21:00 ` [Qemu-devel] [PATCH 4/7] Get rid of QemuMutex and teach its callers about GStaticMutex Anthony Liguori
2011-01-24 22:24   ` [Qemu-devel] " Jan Kiszka
2011-01-25  0:02     ` Anthony Liguori
2011-01-25  7:39       ` Jan Kiszka
2011-01-24 21:00 ` Anthony Liguori [this message]
2011-01-24 21:00 ` [Qemu-devel] [PATCH 6/7] Teach vnc server to use GThread directly Anthony Liguori
2011-01-26 10:39   ` Stefan Hajnoczi
2011-01-24 21:00 ` [Qemu-devel] [PATCH 7/7] Rename QemuThread to QemuSThread to indicate that it is not a generic thread Anthony Liguori
2011-01-24 21:28 ` [Qemu-devel] Re: [RFC 0/7] Introduce hard dependency on glib Paolo Bonzini
2011-01-24 22:01   ` Anthony Liguori
2011-01-25 10:41     ` Paolo Bonzini
2011-01-25 11:14       ` Daniel P. Berrange
2011-01-25 11:21         ` Paolo Bonzini
2011-01-25  0:24 ` [Qemu-devel] " Anthony Liguori
2011-01-25  6:51   ` Edgar E. Iglesias
2011-01-25 10:24 ` Stefan Hajnoczi
2011-01-25 11:51 ` Gerd Hoffmann
2011-01-25 12:04   ` Daniel P. Berrange
2011-01-25 14:48   ` Stefano Stabellini
2011-01-25 17:48     ` Anthony Liguori
2011-01-25 18:12       ` Stefano Stabellini
2011-01-25 14:23 ` Aurelien Jarno
2011-01-25 15:35   ` Anthony Liguori
     [not found] ` <20110126044710.GU9566@redhat.com>
2011-01-26 15:53   ` Anthony Liguori
2011-01-26 21:23     ` Stefan Hajnoczi
2011-01-26 22:12       ` Anthony Liguori
2011-01-26 17:48 ` Johannes Stezenbach

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=1295902845-29807-6-git-send-email-aliguori@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=arun@linux.vnet.ibm.com \
    --cc=mtosatti@redhat.com \
    --cc=paul@codesourcery.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.