Patchwork [V4,1/3] qemu: Add qemu-barrier support to qemu-thread framework.

login
register
mail settings
Submitter Gautham R Shenoy
Date June 16, 2010, 11:56 a.m.
Message ID <20100616115651.10988.91292.stgit@localhost.localdomain>
Download mbox | patch
Permalink /patch/55870/
State New
Headers show

Comments

Gautham R Shenoy - June 16, 2010, 11:56 a.m.
Signed-off-by: Gautham R Shenoy <ego@in.ibm.com>
---
 qemu-thread.c |   23 +++++++++++++++++++++++
 qemu-thread.h |    9 +++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)
Anthony Liguori - June 16, 2010, 2:40 p.m.
On 06/16/2010 06:56 AM, Gautham R Shenoy wrote:
> Signed-off-by: Gautham R Shenoy<ego@in.ibm.com>
>    

I don't see barrier being used and I don't think it ought to be used.  
threadlets are meant provide a means to execute a synchronous function 
asynchronously.  It should never be necessary to synchronize threadlets 
using a barrier.

Regards,

Anthony Liguori

> ---
>   qemu-thread.c |   23 +++++++++++++++++++++++
>   qemu-thread.h |    9 +++++++++
>   2 files changed, 32 insertions(+), 0 deletions(-)
>
> diff --git a/qemu-thread.c b/qemu-thread.c
> index 3923db7..7c445b6 100644
> --- a/qemu-thread.c
> +++ b/qemu-thread.c
> @@ -161,3 +161,26 @@ int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
>      return pthread_equal(thread1->thread, thread2->thread);
>   }
>
> +void qemu_barrier_init(QemuBarrier *barr1, int nr_threads)
> +{
> +    int err;
> +
> +    err = pthread_barrier_init(&barr1->barr, NULL, nr_threads);
> +
> +    if (err) {
> +        error_exit(err, __func__);
> +    }
> +}
> +
> +int qemu_barrier_wait(QemuBarrier *barr1)
> +{
> +    int ret;
> +
> +    ret = pthread_barrier_wait(&barr1->barr);
> +
> +    if (ret != 0&&  ret != PTHREAD_BARRIER_SERIAL_THREAD) {
> +        error_exit(ret, __func__);
> +    }
> +
> +    return ret;
> +}
> diff --git a/qemu-thread.h b/qemu-thread.h
> index 5ef4a3a..b3d36e0 100644
> --- a/qemu-thread.h
> +++ b/qemu-thread.h
> @@ -15,9 +15,14 @@ struct QemuThread {
>       pthread_t thread;
>   };
>
> +struct QemuBarrier {
> +    pthread_barrier_t barr;
> +};
> +
>   typedef struct QemuMutex QemuMutex;
>   typedef struct QemuCond QemuCond;
>   typedef struct QemuThread QemuThread;
> +typedef struct QemuBarrier QemuBarrier;
>
>   void qemu_mutex_init(QemuMutex *mutex);
>   void qemu_mutex_lock(QemuMutex *mutex);
> @@ -31,10 +36,14 @@ void qemu_cond_broadcast(QemuCond *cond);
>   void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex);
>   int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs);
>
> +void qemu_barrier_init(QemuBarrier *barr, int nr_threads);
> +
>   void qemu_thread_create(QemuThread *thread,
>                          void *(*start_routine)(void*),
>                          void *arg);
>   void qemu_thread_signal(QemuThread *thread, int sig);
>   void qemu_thread_self(QemuThread *thread);
>   int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2);
> +
> +int qemu_barrier_wait(QemuBarrier *barr);
>   #endif
>
>
Paolo Bonzini - June 16, 2010, 2:42 p.m.
On 06/16/2010 04:40 PM, Anthony Liguori wrote:
> On 06/16/2010 06:56 AM, Gautham R Shenoy wrote:
>> Signed-off-by: Gautham R Shenoy<ego@in.ibm.com>
>
> I don't see barrier being used and I don't think it ought to be used.
> threadlets are meant provide a means to execute a synchronous function
> asynchronously. It should never be necessary to synchronize threadlets
> using a barrier.

It's used for flush_threadlet_queue.

Paolo

Patch

diff --git a/qemu-thread.c b/qemu-thread.c
index 3923db7..7c445b6 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -161,3 +161,26 @@  int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
    return pthread_equal(thread1->thread, thread2->thread);
 }
 
+void qemu_barrier_init(QemuBarrier *barr1, int nr_threads)
+{
+    int err;
+
+    err = pthread_barrier_init(&barr1->barr, NULL, nr_threads);
+
+    if (err) {
+        error_exit(err, __func__);
+    }
+}
+
+int qemu_barrier_wait(QemuBarrier *barr1)
+{
+    int ret;
+
+    ret = pthread_barrier_wait(&barr1->barr);
+
+    if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
+        error_exit(ret, __func__);
+    }
+
+    return ret;
+}
diff --git a/qemu-thread.h b/qemu-thread.h
index 5ef4a3a..b3d36e0 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -15,9 +15,14 @@  struct QemuThread {
     pthread_t thread;
 };
 
+struct QemuBarrier {
+    pthread_barrier_t barr;
+};
+
 typedef struct QemuMutex QemuMutex;
 typedef struct QemuCond QemuCond;
 typedef struct QemuThread QemuThread;
+typedef struct QemuBarrier QemuBarrier;
 
 void qemu_mutex_init(QemuMutex *mutex);
 void qemu_mutex_lock(QemuMutex *mutex);
@@ -31,10 +36,14 @@  void qemu_cond_broadcast(QemuCond *cond);
 void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex);
 int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs);
 
+void qemu_barrier_init(QemuBarrier *barr, int nr_threads);
+
 void qemu_thread_create(QemuThread *thread,
                        void *(*start_routine)(void*),
                        void *arg);
 void qemu_thread_signal(QemuThread *thread, int sig);
 void qemu_thread_self(QemuThread *thread);
 int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2);
+
+int qemu_barrier_wait(QemuBarrier *barr);
 #endif