[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions
From: |
Emilio G. Cota |
Subject: |
[Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions |
Date: |
Sun, 23 Aug 2015 20:23:34 -0400 |
On some parallel workloads this gives up to a 15% speed improvement.
Signed-off-by: Emilio G. Cota <address@hidden>
---
include/qemu/thread-posix.h | 47 ++++++++++++++++++++++++++++++++++++++++++
include/qemu/thread.h | 6 ------
util/qemu-thread-posix.c | 50 +++++----------------------------------------
3 files changed, 52 insertions(+), 51 deletions(-)
diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h
index 8ce8f01..7d3a9f1 100644
--- a/include/qemu/thread-posix.h
+++ b/include/qemu/thread-posix.h
@@ -37,4 +37,51 @@ struct QemuThread {
pthread_t thread;
};
+void qemu_spin_error_exit(int err, const char *msg);
+
+static inline void qemu_spin_init(QemuSpin *spin)
+{
+ int err;
+
+ err = pthread_spin_init(&spin->lock, 0);
+ if (err) {
+ qemu_spin_error_exit(err, __func__);
+ }
+}
+
+static inline void qemu_spin_destroy(QemuSpin *spin)
+{
+ int err;
+
+ err = pthread_spin_destroy(&spin->lock);
+ if (err) {
+ qemu_spin_error_exit(err, __func__);
+ }
+}
+
+static inline void qemu_spin_lock(QemuSpin *spin)
+{
+ int err;
+
+ err = pthread_spin_lock(&spin->lock);
+ if (err) {
+ qemu_spin_error_exit(err, __func__);
+ }
+}
+
+static inline int qemu_spin_trylock(QemuSpin *spin)
+{
+ return pthread_spin_trylock(&spin->lock);
+}
+
+static inline void qemu_spin_unlock(QemuSpin *spin)
+{
+ int err;
+
+ err = pthread_spin_unlock(&spin->lock);
+ if (err) {
+ qemu_spin_error_exit(err, __func__);
+ }
+}
+
#endif
diff --git a/include/qemu/thread.h b/include/qemu/thread.h
index f5d1259..003daab 100644
--- a/include/qemu/thread.h
+++ b/include/qemu/thread.h
@@ -26,12 +26,6 @@ void qemu_mutex_lock(QemuMutex *mutex);
int qemu_mutex_trylock(QemuMutex *mutex);
void qemu_mutex_unlock(QemuMutex *mutex);
-void qemu_spin_init(QemuSpin *spin);
-void qemu_spin_destroy(QemuSpin *spin);
-void qemu_spin_lock(QemuSpin *spin);
-int qemu_spin_trylock(QemuSpin *spin);
-void qemu_spin_unlock(QemuSpin *spin);
-
void qemu_cond_init(QemuCond *cond);
void qemu_cond_destroy(QemuCond *cond);
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index 224bacc..04dae0f 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -48,6 +48,11 @@ static void error_exit(int err, const char *msg)
abort();
}
+void qemu_spin_error_exit(int err, const char *msg)
+{
+ error_exit(err, msg);
+}
+
void qemu_mutex_init(QemuMutex *mutex)
{
int err;
@@ -89,51 +94,6 @@ void qemu_mutex_unlock(QemuMutex *mutex)
error_exit(err, __func__);
}
-void qemu_spin_init(QemuSpin *spin)
-{
- int err;
-
- err = pthread_spin_init(&spin->lock, 0);
- if (err) {
- error_exit(err, __func__);
- }
-}
-
-void qemu_spin_destroy(QemuSpin *spin)
-{
- int err;
-
- err = pthread_spin_destroy(&spin->lock);
- if (err) {
- error_exit(err, __func__);
- }
-}
-
-void qemu_spin_lock(QemuSpin *spin)
-{
- int err;
-
- err = pthread_spin_lock(&spin->lock);
- if (err) {
- error_exit(err, __func__);
- }
-}
-
-int qemu_spin_trylock(QemuSpin *spin)
-{
- return pthread_spin_trylock(&spin->lock);
-}
-
-void qemu_spin_unlock(QemuSpin *spin)
-{
- int err;
-
- err = pthread_spin_unlock(&spin->lock);
- if (err) {
- error_exit(err, __func__);
- }
-}
-
void qemu_cond_init(QemuCond *cond)
{
int err;
--
1.9.1
- [Qemu-devel] [PATCH 3/4] linux-user: call rcu_(un)register_thread on thread creation/deletion, (continued)
- [Qemu-devel] [RFC 04/38] translate-all: remove volatile from have_tb_lock, Emilio G. Cota, 2015/08/23
- [Qemu-devel] [RFC 06/38] seqlock: add missing 'inline' to seqlock_read_retry, Emilio G. Cota, 2015/08/23
- [Qemu-devel] [RFC 02/38] hw/i386/kvmvapic: add missing include of tcg.h, Emilio G. Cota, 2015/08/23
- [Qemu-devel] [RFC 01/38] cpu-exec: add missing mmap_lock in tb_find_slow, Emilio G. Cota, 2015/08/23
- [Qemu-devel] [RFC 10/38] translate-all: remove obsolete comment about l1_map, Emilio G. Cota, 2015/08/23
- [Qemu-devel] [RFC 18/38] tcg: add fences, Emilio G. Cota, 2015/08/23
- [Qemu-devel] [RFC 12/38] linux-user: call rcu_(un)register_thread on pthread_(exit|create), Emilio G. Cota, 2015/08/23
- [Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions,
Emilio G. Cota <=
[Qemu-devel] [RFC 11/38] qemu-thread: handle spurious futex_wait wakeups, Emilio G. Cota, 2015/08/23
[Qemu-devel] [RFC 13/38] cputlb: add physical address to CPUTLBEntry, Emilio G. Cota, 2015/08/23
[Qemu-devel] [RFC 14/38] softmmu: add helpers to get ld/st physical addresses, Emilio G. Cota, 2015/08/23
[Qemu-devel] [RFC 17/38] aie: add target helpers, Emilio G. Cota, 2015/08/23