[gegl] operation: use g_usleep instead of g_cond_wait/signal



commit 5fbc6e267afcb670a55137092da99f84c51a44cc
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Jun 30 23:09:13 2014 +0200

    operation: use g_usleep instead of g_cond_wait/signal
    
    This has enough impact on performance that without it paralellize gaussian
    blur decreases rather than increases when using 2 threads on 2 cores.

 gegl/operation/gegl-operation-composer.c        |   19 ++++---------------
 gegl/operation/gegl-operation-composer3.c       |   18 +++---------------
 gegl/operation/gegl-operation-filter.c          |   21 ++++-----------------
 gegl/operation/gegl-operation-point-composer3.c |    1 +
 gegl/operation/gegl-operation-point-render.c    |    1 -
 gegl/operation/gegl-operation-source.c          |   19 +++----------------
 gegl/process/gegl-processor.c                   |    7 ++++++-
 7 files changed, 21 insertions(+), 65 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-composer.c b/gegl/operation/gegl-operation-composer.c
index e9e46b9..321895c 100644
--- a/gegl/operation/gegl-operation-composer.c
+++ b/gegl/operation/gegl-operation-composer.c
@@ -50,8 +50,8 @@ gegl_operation_composer_class_init (GeglOperationComposerClass * klass)
 {
   GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
 
-  operation_class->threaded = TRUE;
   operation_class->process = gegl_operation_composer_process;
+  operation_class->threaded = TRUE;
   operation_class->attach = attach;
   operation_class->detect = detect;
   operation_class->get_bounding_box = get_bounding_box;
@@ -110,9 +110,6 @@ typedef struct ThreadData
   GeglRectangle               roi;
 } ThreadData;
 
-static GMutex pool_mutex = {0,};
-static GCond  pool_cond  = {0,};
-
 static void thread_process (gpointer thread_data, gpointer unused)
 {
   ThreadData *data = thread_data;
@@ -120,12 +117,6 @@ static void thread_process (gpointer thread_data, gpointer unused)
                        data->input, data->aux, data->output, &data->roi, data->level))
     data->success = FALSE;
   g_atomic_int_add (data->pending, -1);
-  if (*data->pending == 0)
-  {
-    g_mutex_lock (&pool_mutex);
-    g_cond_signal (&pool_cond);
-    g_mutex_unlock (&pool_mutex);
-  }
 }
 
 static GThreadPool *thread_pool (void)
@@ -214,15 +205,13 @@ gegl_operation_composer_process (GeglOperation        *operation,
           thread_data[i].success = TRUE;
         }
 
-        g_mutex_lock (&pool_mutex);
-
-        for (gint i = 0; i < threads; i++)
+        for (gint i = 1; i < threads; i++)
           g_thread_pool_push (pool, &thread_data[i], NULL);
+        thread_process (&thread_data[0], NULL);
 
         while (pending != 0)
-          g_cond_wait (&pool_cond, &pool_mutex);
+          g_usleep (1);
 
-        g_mutex_unlock (&pool_mutex);
         success = thread_data[0].success;
       }
       else
diff --git a/gegl/operation/gegl-operation-composer3.c b/gegl/operation/gegl-operation-composer3.c
index 4b1429f..baa0ea0 100644
--- a/gegl/operation/gegl-operation-composer3.c
+++ b/gegl/operation/gegl-operation-composer3.c
@@ -120,9 +120,6 @@ typedef struct ThreadData
   GeglRectangle                roi;
 } ThreadData;
 
-static GMutex pool_mutex = {0,};
-static GCond  pool_cond  = {0,};
-
 static void thread_process (gpointer thread_data, gpointer unused)
 {
   ThreadData *data = thread_data;
@@ -131,12 +128,6 @@ static void thread_process (gpointer thread_data, gpointer unused)
         data->output, &data->roi, data->level))
     data->success = FALSE;
   g_atomic_int_add (data->pending, -1);
-  if (*data->pending == 0)
-    {
-      g_mutex_lock (&pool_mutex);
-      g_cond_signal (&pool_cond);
-      g_mutex_unlock (&pool_mutex);
-    }
 }
 
 static GThreadPool *thread_pool (void)
@@ -237,16 +228,13 @@ gegl_operation_composer3_process (GeglOperation        *operation,
           thread_data[i].success = TRUE;
         }
 
-        g_mutex_lock (&pool_mutex);
-
-        for (gint i = 0; i < threads; i++)
+        for (gint i = 1; i < threads; i++)
           g_thread_pool_push (pool, &thread_data[i], NULL);
+        thread_process (&thread_data[0], NULL);
 
         while (pending != 0)
-          g_cond_wait (&pool_cond, &pool_mutex);
+          g_usleep (1);
         
-        g_mutex_unlock (&pool_mutex);
-
         success = thread_data[0].success;
       }
       else
diff --git a/gegl/operation/gegl-operation-filter.c b/gegl/operation/gegl-operation-filter.c
index c9a7afa..fb97188 100644
--- a/gegl/operation/gegl-operation-filter.c
+++ b/gegl/operation/gegl-operation-filter.c
@@ -53,11 +53,11 @@ gegl_operation_filter_class_init (GeglOperationFilterClass * klass)
   GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
 
   operation_class->process                 = gegl_operation_filter_process;
+  operation_class->threaded                = TRUE;
   operation_class->attach                  = attach;
   operation_class->detect                  = detect;
   operation_class->get_bounding_box        = get_bounding_box;
   operation_class->get_required_for_output = get_required_for_output;
-  operation_class->threaded                = TRUE;
 }
 
 static void
@@ -117,9 +117,6 @@ typedef struct ThreadData
   GeglRectangle             roi;
 } ThreadData;
 
-static GMutex pool_mutex = {0,};
-static GCond  pool_cond  = {0,};
-
 static void thread_process (gpointer thread_data, gpointer unused)
 {
   ThreadData *data = thread_data;
@@ -127,12 +124,6 @@ static void thread_process (gpointer thread_data, gpointer unused)
                        data->input, data->output, &data->roi, data->level))
     data->success = FALSE;
   g_atomic_int_add (data->pending, -1);
-  if (*data->pending == 0)
-  {
-    g_mutex_lock (&pool_mutex);
-    g_cond_signal (&pool_cond);
-    g_mutex_unlock (&pool_mutex);
-  }
 }
 
 static GThreadPool *thread_pool (void)
@@ -216,15 +207,11 @@ gegl_operation_filter_process (GeglOperation        *operation,
       thread_data[i].success = TRUE;
     }
 
-    g_mutex_lock (&pool_mutex);
-
-    for (gint i = 0; i < threads; i++)
+    for (gint i = 1; i < threads; i++)
       g_thread_pool_push (pool, &thread_data[i], NULL);
+    thread_process (&thread_data[0], NULL);
 
-    while (pending != 0)
-      g_cond_wait (&pool_cond, &pool_mutex);
-
-    g_mutex_unlock (&pool_mutex);
+    while (pending != 0) g_usleep (1);
 
 
     success = thread_data[0].success;
diff --git a/gegl/operation/gegl-operation-point-composer3.c b/gegl/operation/gegl-operation-point-composer3.c
index aceda5b..7161652 100644
--- a/gegl/operation/gegl-operation-point-composer3.c
+++ b/gegl/operation/gegl-operation-point-composer3.c
@@ -57,6 +57,7 @@ gegl_operation_point_composer3_class_init (GeglOperationPointComposer3Class *kla
   operation_class->prepare = prepare;
   operation_class->no_cache = TRUE;
   operation_class->want_in_place = TRUE;
+  operation_class->threaded = TRUE;
 }
 
 static void
diff --git a/gegl/operation/gegl-operation-point-render.c b/gegl/operation/gegl-operation-point-render.c
index b26a43f..e46c2db 100644
--- a/gegl/operation/gegl-operation-point-render.c
+++ b/gegl/operation/gegl-operation-point-render.c
@@ -57,7 +57,6 @@ gegl_operation_point_render_class_init (GeglOperationPointRenderClass *klass)
 
   operation_class->detect = detect;
   operation_class->no_cache = FALSE;
-  operation_class->threaded = TRUE;
   operation_class->get_cached_region = NULL; /* we are able to compute anything
                                                  anywhere when we're our kind
                                                  of class */
diff --git a/gegl/operation/gegl-operation-source.c b/gegl/operation/gegl-operation-source.c
index 7eac026..7246f2e 100644
--- a/gegl/operation/gegl-operation-source.c
+++ b/gegl/operation/gegl-operation-source.c
@@ -91,9 +91,6 @@ typedef struct ThreadData
   GeglRectangle             roi;
 } ThreadData;
 
-static GMutex pool_mutex = {0,};
-static GCond  pool_cond  = {0,};
-
 static void thread_process (gpointer thread_data, gpointer unused)
 {
   ThreadData *data = thread_data;
@@ -101,13 +98,6 @@ static void thread_process (gpointer thread_data, gpointer unused)
                        data->output, &data->roi, data->level))
     data->success = FALSE;
   g_atomic_int_add (data->pending, -1);
-
-  if (*data->pending == 0)
-  {
-    g_mutex_lock (&pool_mutex);
-    g_cond_signal (&pool_cond);
-    g_mutex_unlock (&pool_mutex);
-  }
 }
 
 static GThreadPool *thread_pool (void)
@@ -182,15 +172,12 @@ gegl_operation_source_process (GeglOperation        *operation,
       thread_data[i].success = TRUE;
     }
 
-    g_mutex_lock (&pool_mutex);
-
-    for (gint i = 0; i < threads; i++)
+    for (gint i = 1; i < threads; i++)
       g_thread_pool_push (pool, &thread_data[i], NULL);
+    thread_process (&thread_data[0], NULL);
 
     while (pending != 0)
-      g_cond_wait (&pool_cond, &pool_mutex);
-
-    g_mutex_unlock (&pool_mutex);
+      g_usleep (1);
 
     success = thread_data[0].success;
   }
diff --git a/gegl/process/gegl-processor.c b/gegl/process/gegl-processor.c
index 4024459..b5241cf 100644
--- a/gegl/process/gegl-processor.c
+++ b/gegl/process/gegl-processor.c
@@ -387,7 +387,12 @@ gegl_processor_get_band_size (gint size)
 
   /* try to make the rects generated match better with potential 2^n sized
    * tiles, XXX: should be improved to make the next slice fit as well. */
-  if (band_size <= 256)
+  if (band_size <= 128)
+    {
+      band_size = MIN(band_size, 64); /* prefer a band_size of 128,
+                                          hoping to hit tiles */
+    }
+  else if (band_size <= 256)
     {
       band_size = MIN(band_size, 128); /* prefer a band_size of 128,
                                           hoping to hit tiles */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]