From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8VbF-0007xj-6F for qemu-devel@nongnu.org; Fri, 26 Jun 2015 11:31:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8VbA-0008De-3n for qemu-devel@nongnu.org; Fri, 26 Jun 2015 11:31:29 -0400 Received: from greensocs.com ([193.104.36.180]:51347) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8Vb9-0008DT-Rp for qemu-devel@nongnu.org; Fri, 26 Jun 2015 11:31:24 -0400 Message-ID: <558D7047.8070307@greensocs.com> Date: Fri, 26 Jun 2015 17:31:19 +0200 From: Frederic Konrad MIME-Version: 1.0 References: <1435330053-18733-1-git-send-email-fred.konrad@greensocs.com> <1435330053-18733-5-git-send-email-fred.konrad@greensocs.com> <558D67DA.90302@redhat.com> In-Reply-To: <558D67DA.90302@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH V6 04/18] add support for spin lock on POSIX systems exclusively List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org, mttcg@greensocs.com Cc: peter.maydell@linaro.org, a.spyridakis@virtualopensystems.com, mark.burton@greensocs.com, agraf@suse.de, alistair.francis@xilinx.com, guillaume.delbergue@greensocs.com, alex.bennee@linaro.org On 26/06/2015 16:55, Paolo Bonzini wrote: > > On 26/06/2015 16:47, fred.konrad@greensocs.com wrote: >> From: Guillaume Delbergue >> >> WARNING: spin lock is currently not implemented on WIN32 > The Windows KSPIN_LOCK is a kernel data structure. You can implement a > simple, portable test-and-test-and-set spinlock using atomics, and use > it on both POSIX and Win32. > > Paolo ok we will take a look at atomic instruction. Fred > >> Signed-off-by: Guillaume Delbergue >> --- >> include/qemu/thread-posix.h | 4 ++++ >> include/qemu/thread-win32.h | 4 ++++ >> include/qemu/thread.h | 7 +++++++ >> util/qemu-thread-posix.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ >> util/qemu-thread-win32.c | 30 ++++++++++++++++++++++++++++++ >> 5 files changed, 90 insertions(+) >> >> diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h >> index eb5c7a1..8ce8f01 100644 >> --- a/include/qemu/thread-posix.h >> +++ b/include/qemu/thread-posix.h >> @@ -7,6 +7,10 @@ struct QemuMutex { >> pthread_mutex_t lock; >> }; >> >> +struct QemuSpin { >> + pthread_spinlock_t lock; >> +}; >> + >> struct QemuCond { >> pthread_cond_t cond; >> }; >> diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h >> index 3d58081..310c8bd 100644 >> --- a/include/qemu/thread-win32.h >> +++ b/include/qemu/thread-win32.h >> @@ -7,6 +7,10 @@ struct QemuMutex { >> LONG owner; >> }; >> >> +struct QemuSpin { >> + PKSPIN_LOCK lock; >> +}; >> + >> struct QemuCond { >> LONG waiters, target; >> HANDLE sema; >> diff --git a/include/qemu/thread.h b/include/qemu/thread.h >> index 5114ec8..f5d1259 100644 >> --- a/include/qemu/thread.h >> +++ b/include/qemu/thread.h >> @@ -5,6 +5,7 @@ >> #include >> >> typedef struct QemuMutex QemuMutex; >> +typedef struct QemuSpin QemuSpin; >> typedef struct QemuCond QemuCond; >> typedef struct QemuSemaphore QemuSemaphore; >> typedef struct QemuEvent QemuEvent; >> @@ -25,6 +26,12 @@ 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 ba67cec..224bacc 100644 >> --- a/util/qemu-thread-posix.c >> +++ b/util/qemu-thread-posix.c >> @@ -89,6 +89,51 @@ 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; >> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c >> index 406b52f..6fbe6a8 100644 >> --- a/util/qemu-thread-win32.c >> +++ b/util/qemu-thread-win32.c >> @@ -80,6 +80,36 @@ void qemu_mutex_unlock(QemuMutex *mutex) >> LeaveCriticalSection(&mutex->lock); >> } >> >> +void qemu_spin_init(QemuSpin *spin) >> +{ >> + printf("spinlock not implemented"); >> + abort(); >> +} >> + >> +void qemu_spin_destroy(QemuSpin *spin) >> +{ >> + printf("spinlock not implemented"); >> + abort(); >> +} >> + >> +void qemu_spin_lock(QemuSpin *spin) >> +{ >> + printf("spinlock not implemented"); >> + abort(); >> +} >> + >> +int qemu_spin_trylock(QemuSpin *spin) >> +{ >> + printf("spinlock not implemented"); >> + abort(); >> +} >> + >> +void qemu_spin_unlock(QemuSpin *spin) >> +{ >> + printf("spinlock not implemented"); >> + abort(); >> +} >> + >> void qemu_cond_init(QemuCond *cond) >> { >> memset(cond, 0, sizeof(*cond)); >>