All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, aurelien@aurel32.net, blauwirbel@gmail.com,
	jan.kiszka@siemes.com, mtosatti@redhat.com,
	Jan Kiszka <jan.kiszka@siemens.com>
Subject: [PATCH v3 uq/master 04/22] Refactor thread retrieval and check
Date: Mon, 28 Feb 2011 10:10:06 +0100	[thread overview]
Message-ID: <1298884224-19734-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1298884224-19734-1-git-send-email-pbonzini@redhat.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

We have qemu_cpu_self and qemu_thread_self. The latter is retrieving the
current thread, the former is checking for equality (using CPUState). We
also have qemu_thread_equal which is only used like qemu_cpu_self.

This refactors the interfaces, creating qemu_cpu_is_self and
qemu_thread_is_self as well ass qemu_thread_get_self.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c              |   22 ++++++++--------------
 exec.c              |    2 +-
 qemu-common.h       |    2 +-
 qemu-thread.c       |    6 +++---
 qemu-thread.h       |    4 ++--
 target-i386/kvm.c   |    4 ++--
 ui/vnc-jobs-async.c |    2 +-
 7 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0f33945..09ce6fe 100644
--- a/cpus.c
+++ b/cpus.c
@@ -531,7 +531,7 @@ void qemu_init_vcpu(void *_env)
     }
 }
 
-int qemu_cpu_self(void *env)
+int qemu_cpu_is_self(void *env)
 {
     return 1;
 }
@@ -699,7 +699,7 @@ int qemu_init_main_loop(void)
     qemu_mutex_init(&qemu_global_mutex);
     qemu_mutex_lock(&qemu_global_mutex);
 
-    qemu_thread_self(&io_thread);
+    qemu_thread_get_self(&io_thread);
 
     return 0;
 }
@@ -714,7 +714,7 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data)
 {
     struct qemu_work_item wi;
 
-    if (qemu_cpu_self(env)) {
+    if (qemu_cpu_is_self(env)) {
         func(data);
         return;
     }
@@ -808,7 +808,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
     int r;
 
     qemu_mutex_lock(&qemu_global_mutex);
-    qemu_thread_self(env->thread);
+    qemu_thread_get_self(env->thread);
 
     r = kvm_init_vcpu(env);
     if (r < 0) {
@@ -845,7 +845,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
     CPUState *env = arg;
 
     qemu_tcg_init_cpu_signals();
-    qemu_thread_self(env->thread);
+    qemu_thread_get_self(env->thread);
 
     /* signal CPU creation */
     qemu_mutex_lock(&qemu_global_mutex);
@@ -888,14 +888,11 @@ void qemu_cpu_kick_self(void)
     }
 }
 
-int qemu_cpu_self(void *_env)
+int qemu_cpu_is_self(void *_env)
 {
     CPUState *env = _env;
-    QemuThread this;
 
-    qemu_thread_self(&this);
-
-    return qemu_thread_equal(&this, env->thread);
+    return qemu_thread_is_self(env->thread);
 }
 
 void qemu_mutex_lock_iothread(void)
@@ -1023,10 +1020,7 @@ void cpu_stop_current(void)
 
 void vm_stop(int reason)
 {
-    QemuThread me;
-    qemu_thread_self(&me);
-
-    if (!qemu_thread_equal(&me, &io_thread)) {
+    if (!qemu_thread_is_self(&io_thread)) {
         qemu_system_vmstop_request(reason);
         /*
          * FIXME: should not return to device code in case
diff --git a/exec.c b/exec.c
index d611100..439a6f6 100644
--- a/exec.c
+++ b/exec.c
@@ -1640,7 +1640,7 @@ void cpu_interrupt(CPUState *env, int mask)
      * If called from iothread context, wake the target cpu in
      * case its halted.
      */
-    if (!qemu_cpu_self(env)) {
+    if (!qemu_cpu_is_self(env)) {
         qemu_cpu_kick(env);
         return;
     }
diff --git a/qemu-common.h b/qemu-common.h
index 40dad52..958a002 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -289,7 +289,7 @@ void qemu_notify_event(void);
 /* Unblock cpu */
 void qemu_cpu_kick(void *env);
 void qemu_cpu_kick_self(void);
-int qemu_cpu_self(void *env);
+int qemu_cpu_is_self(void *env);
 
 /* work queue */
 struct qemu_work_item {
diff --git a/qemu-thread.c b/qemu-thread.c
index fbc78fe..e307773 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -176,14 +176,14 @@ void qemu_thread_signal(QemuThread *thread, int sig)
         error_exit(err, __func__);
 }
 
-void qemu_thread_self(QemuThread *thread)
+void qemu_thread_get_self(QemuThread *thread)
 {
     thread->thread = pthread_self();
 }
 
-int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
+int qemu_thread_is_self(QemuThread *thread)
 {
-   return pthread_equal(thread1->thread, thread2->thread);
+   return pthread_equal(pthread_self(), thread->thread);
 }
 
 void qemu_thread_exit(void *retval)
diff --git a/qemu-thread.h b/qemu-thread.h
index 19bb30c..add97bf 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -37,8 +37,8 @@ void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
                        void *arg);
 void qemu_thread_signal(QemuThread *thread, int sig);
-void qemu_thread_self(QemuThread *thread);
-int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2);
+void qemu_thread_get_self(QemuThread *thread);
+int qemu_thread_is_self(QemuThread *thread);
 void qemu_thread_exit(void *retval);
 
 #endif
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 0aa0a41..1f12cbf 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1355,7 +1355,7 @@ int kvm_arch_put_registers(CPUState *env, int level)
 {
     int ret;
 
-    assert(cpu_is_stopped(env) || qemu_cpu_self(env));
+    assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
 
     ret = kvm_getput_regs(env, 1);
     if (ret < 0) {
@@ -1403,7 +1403,7 @@ int kvm_arch_get_registers(CPUState *env)
 {
     int ret;
 
-    assert(cpu_is_stopped(env) || qemu_cpu_self(env));
+    assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
 
     ret = kvm_getput_regs(env, 0);
     if (ret < 0) {
diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c
index f596247..1dfa6c3 100644
--- a/ui/vnc-jobs-async.c
+++ b/ui/vnc-jobs-async.c
@@ -303,7 +303,7 @@ static void *vnc_worker_thread(void *arg)
 {
     VncJobQueue *queue = arg;
 
-    qemu_thread_self(&queue->thread);
+    qemu_thread_get_self(&queue->thread);
 
     while (!vnc_worker_thread_loop(queue)) ;
     vnc_queue_clear(queue);
-- 
1.7.4



WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, Jan Kiszka <jan.kiszka@siemens.com>,
	mtosatti@redhat.com, jan.kiszka@siemes.com, blauwirbel@gmail.com,
	aurelien@aurel32.net
Subject: [Qemu-devel] [PATCH v3 uq/master 04/22] Refactor thread retrieval and check
Date: Mon, 28 Feb 2011 10:10:06 +0100	[thread overview]
Message-ID: <1298884224-19734-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1298884224-19734-1-git-send-email-pbonzini@redhat.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

We have qemu_cpu_self and qemu_thread_self. The latter is retrieving the
current thread, the former is checking for equality (using CPUState). We
also have qemu_thread_equal which is only used like qemu_cpu_self.

This refactors the interfaces, creating qemu_cpu_is_self and
qemu_thread_is_self as well ass qemu_thread_get_self.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c              |   22 ++++++++--------------
 exec.c              |    2 +-
 qemu-common.h       |    2 +-
 qemu-thread.c       |    6 +++---
 qemu-thread.h       |    4 ++--
 target-i386/kvm.c   |    4 ++--
 ui/vnc-jobs-async.c |    2 +-
 7 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0f33945..09ce6fe 100644
--- a/cpus.c
+++ b/cpus.c
@@ -531,7 +531,7 @@ void qemu_init_vcpu(void *_env)
     }
 }
 
-int qemu_cpu_self(void *env)
+int qemu_cpu_is_self(void *env)
 {
     return 1;
 }
@@ -699,7 +699,7 @@ int qemu_init_main_loop(void)
     qemu_mutex_init(&qemu_global_mutex);
     qemu_mutex_lock(&qemu_global_mutex);
 
-    qemu_thread_self(&io_thread);
+    qemu_thread_get_self(&io_thread);
 
     return 0;
 }
@@ -714,7 +714,7 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data)
 {
     struct qemu_work_item wi;
 
-    if (qemu_cpu_self(env)) {
+    if (qemu_cpu_is_self(env)) {
         func(data);
         return;
     }
@@ -808,7 +808,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
     int r;
 
     qemu_mutex_lock(&qemu_global_mutex);
-    qemu_thread_self(env->thread);
+    qemu_thread_get_self(env->thread);
 
     r = kvm_init_vcpu(env);
     if (r < 0) {
@@ -845,7 +845,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
     CPUState *env = arg;
 
     qemu_tcg_init_cpu_signals();
-    qemu_thread_self(env->thread);
+    qemu_thread_get_self(env->thread);
 
     /* signal CPU creation */
     qemu_mutex_lock(&qemu_global_mutex);
@@ -888,14 +888,11 @@ void qemu_cpu_kick_self(void)
     }
 }
 
-int qemu_cpu_self(void *_env)
+int qemu_cpu_is_self(void *_env)
 {
     CPUState *env = _env;
-    QemuThread this;
 
-    qemu_thread_self(&this);
-
-    return qemu_thread_equal(&this, env->thread);
+    return qemu_thread_is_self(env->thread);
 }
 
 void qemu_mutex_lock_iothread(void)
@@ -1023,10 +1020,7 @@ void cpu_stop_current(void)
 
 void vm_stop(int reason)
 {
-    QemuThread me;
-    qemu_thread_self(&me);
-
-    if (!qemu_thread_equal(&me, &io_thread)) {
+    if (!qemu_thread_is_self(&io_thread)) {
         qemu_system_vmstop_request(reason);
         /*
          * FIXME: should not return to device code in case
diff --git a/exec.c b/exec.c
index d611100..439a6f6 100644
--- a/exec.c
+++ b/exec.c
@@ -1640,7 +1640,7 @@ void cpu_interrupt(CPUState *env, int mask)
      * If called from iothread context, wake the target cpu in
      * case its halted.
      */
-    if (!qemu_cpu_self(env)) {
+    if (!qemu_cpu_is_self(env)) {
         qemu_cpu_kick(env);
         return;
     }
diff --git a/qemu-common.h b/qemu-common.h
index 40dad52..958a002 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -289,7 +289,7 @@ void qemu_notify_event(void);
 /* Unblock cpu */
 void qemu_cpu_kick(void *env);
 void qemu_cpu_kick_self(void);
-int qemu_cpu_self(void *env);
+int qemu_cpu_is_self(void *env);
 
 /* work queue */
 struct qemu_work_item {
diff --git a/qemu-thread.c b/qemu-thread.c
index fbc78fe..e307773 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -176,14 +176,14 @@ void qemu_thread_signal(QemuThread *thread, int sig)
         error_exit(err, __func__);
 }
 
-void qemu_thread_self(QemuThread *thread)
+void qemu_thread_get_self(QemuThread *thread)
 {
     thread->thread = pthread_self();
 }
 
-int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
+int qemu_thread_is_self(QemuThread *thread)
 {
-   return pthread_equal(thread1->thread, thread2->thread);
+   return pthread_equal(pthread_self(), thread->thread);
 }
 
 void qemu_thread_exit(void *retval)
diff --git a/qemu-thread.h b/qemu-thread.h
index 19bb30c..add97bf 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -37,8 +37,8 @@ void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
                        void *arg);
 void qemu_thread_signal(QemuThread *thread, int sig);
-void qemu_thread_self(QemuThread *thread);
-int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2);
+void qemu_thread_get_self(QemuThread *thread);
+int qemu_thread_is_self(QemuThread *thread);
 void qemu_thread_exit(void *retval);
 
 #endif
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 0aa0a41..1f12cbf 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1355,7 +1355,7 @@ int kvm_arch_put_registers(CPUState *env, int level)
 {
     int ret;
 
-    assert(cpu_is_stopped(env) || qemu_cpu_self(env));
+    assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
 
     ret = kvm_getput_regs(env, 1);
     if (ret < 0) {
@@ -1403,7 +1403,7 @@ int kvm_arch_get_registers(CPUState *env)
 {
     int ret;
 
-    assert(cpu_is_stopped(env) || qemu_cpu_self(env));
+    assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
 
     ret = kvm_getput_regs(env, 0);
     if (ret < 0) {
diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c
index f596247..1dfa6c3 100644
--- a/ui/vnc-jobs-async.c
+++ b/ui/vnc-jobs-async.c
@@ -303,7 +303,7 @@ static void *vnc_worker_thread(void *arg)
 {
     VncJobQueue *queue = arg;
 
-    qemu_thread_self(&queue->thread);
+    qemu_thread_get_self(&queue->thread);
 
     while (!vnc_worker_thread_loop(queue)) ;
     vnc_queue_clear(queue);
-- 
1.7.4

  parent reply	other threads:[~2011-02-28  9:10 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-28  9:10 [PATCH v3 uq/master 00/22] Win32 iothread support Paolo Bonzini
2011-02-28  9:10 ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 01/22] unlock iothread during WaitForMultipleObjects Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 02/22] implement win32 dynticks timer Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 03/22] use win32 timer queues Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` Paolo Bonzini [this message]
2011-02-28  9:10   ` [Qemu-devel] [PATCH v3 uq/master 04/22] Refactor thread retrieval and check Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 05/22] add win32 qemu-thread implementation Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:33   ` Stefan Hajnoczi
2011-02-28  9:33     ` [Qemu-devel] " Stefan Hajnoczi
2011-02-28 10:14     ` [PATCH v4 uq/master] " Paolo Bonzini
2011-02-28 10:14       ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 06/22] include qemu-thread.h early Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 07/22] add assertions on the owner of a QemuMutex Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 08/22] remove CONFIG_THREAD Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 09/22] target-sh4: move intr_at_halt out of cpu_halted() Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 10/22] inline cpu_halted into sole caller Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 11/22] always qemu_cpu_kick after unhalting a cpu Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 12/22] exit round-robin vcpu loop if cpu->stopped is true Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 13/22] always signal pause_cond after stopping a VCPU Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 14/22] do not use timedwait on qemu_halt_cond Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 15/22] do not use timedwait on qemu_system_cond Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 16/22] do not use timedwait on qemu_pause_cond Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 17/22] do not use timedwait on qemu_cpu_cond Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 18/22] iothread stops the vcpu thread via IPI Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 19/22] merge all signal initialization with qemu_signalfd_init, rename Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 20/22] provide dummy signal init functions for win32 Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 21/22] protect qemu_cpu_kick_self for Win32 Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:10 ` [PATCH v3 uq/master 22/22] add Win32 IPI service Paolo Bonzini
2011-02-28  9:10   ` [Qemu-devel] " Paolo Bonzini
2011-02-28  9:16 ` [PATCH v3 uq/master 00/22] Win32 iothread support Avi Kivity
2011-02-28  9:16   ` [Qemu-devel] " Avi Kivity
2011-02-28 10:10   ` Paolo Bonzini
2011-02-28 10:10     ` [Qemu-devel] " Paolo Bonzini
2011-02-28 11:57     ` Jan Kiszka
2011-02-28 11:57       ` [Qemu-devel] " Jan Kiszka
2011-02-28 12:13       ` Avi Kivity
2011-02-28 12:13         ` [Qemu-devel] " Avi Kivity
2011-02-28 14:05         ` Paolo Bonzini
2011-02-28 14:05           ` [Qemu-devel] " Paolo Bonzini
2011-03-01 12:35           ` Avi Kivity
2011-03-01 12:35             ` [Qemu-devel] " Avi Kivity
2011-03-02 18:43             ` Marcelo Tosatti
2011-03-02 18:43               ` [Qemu-devel] " Marcelo Tosatti
2011-03-02 19:03               ` Jan Kiszka
2011-03-02 19:03                 ` [Qemu-devel] " Jan Kiszka
2011-03-02 19:36                 ` Marcelo Tosatti
2011-03-02 19:36                   ` [Qemu-devel] " Marcelo Tosatti
2011-03-02 19:42                   ` Marcelo Tosatti
2011-03-02 19:42                     ` [Qemu-devel] " Marcelo Tosatti
2011-03-03  8:48                     ` Avi Kivity
2011-03-03  8:48                       ` [Qemu-devel] " Avi Kivity
2011-03-03  9:07                       ` Jan Kiszka
2011-03-03  9:07                         ` [Qemu-devel] " Jan Kiszka
2011-03-03  9:12                         ` Avi Kivity
2011-03-03  9:12                           ` [Qemu-devel] " Avi Kivity
2011-03-03  9:13                         ` Paolo Bonzini
2011-03-03  9:13                           ` [Qemu-devel] " Paolo Bonzini
2011-03-03  9:28                           ` Avi Kivity
2011-03-03  9:28                             ` [Qemu-devel] " 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=1298884224-19734-5-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=blauwirbel@gmail.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jan.kiszka@siemes.com \
    --cc=kvm@vger.kernel.org \
    --cc=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 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.