qemu-devel
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]