From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTgBz-0007g0-O1 for qemu-devel@nongnu.org; Sun, 23 Aug 2015 21:04:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTgBv-0006TS-OY for qemu-devel@nongnu.org; Sun, 23 Aug 2015 21:04:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54972) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTgBv-0006TH-HU for qemu-devel@nongnu.org; Sun, 23 Aug 2015 21:04:51 -0400 References: <1440375847-17603-1-git-send-email-cota@braap.org> <1440375847-17603-6-git-send-email-cota@braap.org> From: Paolo Bonzini Message-ID: <55DA6DAE.9070105@redhat.com> Date: Sun, 23 Aug 2015 18:04:46 -0700 MIME-Version: 1.0 In-Reply-To: <1440375847-17603-6-git-send-email-cota@braap.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , qemu-devel@nongnu.org, mttcg@greensocs.com Cc: guillaume.delbergue@greensocs.com, alex.bennee@linaro.org, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, Frederic Konrad 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 > --- > 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