[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions |
Date: |
Sun, 23 Aug 2015 18:04:46 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 |
On 23/08/2015 17:23, Emilio G. Cota wrote:
> 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;
>
Applied, but in the end the spinlock will probably simply use a simple
test-and-test-and-set lock, or an MCS lock. There is no need to use
pthreads for this.
Paolo
- [Qemu-devel] [PATCH 2/4] linux-user: add helper to set current_cpu before cpu_loop(), (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, 2015/08/23
- Re: [Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions,
Paolo Bonzini <=
[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
[Qemu-devel] [RFC 15/38] radix-tree: add generic lockless radix tree module, Emilio G. Cota, 2015/08/23