Task scheduler: Remove counter of done tasks
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 1 Mar 2017 11:45:51 +0000 (12:45 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 1 Mar 2017 11:45:51 +0000 (12:45 +0100)
This was only used for progress report, and it's wrong because:

- Pool might in theory be re-used by different tasks
- We should not make any decision based on scheduling stats

Proper way is to take care of progress by the task itself.

source/blender/blenlib/BLI_task.h
source/blender/blenlib/intern/task.c
source/blender/render/CMakeLists.txt
source/blender/render/intern/source/volume_precache.c

index 967e0be6d0a2081418d524674a88c2be47030799..08b9629610d777a4152f2ca4a22f4457f858e8e2 100644 (file)
@@ -113,9 +113,6 @@ void *BLI_task_pool_userdata(TaskPool *pool);
 /* optional mutex to use from run function */
 ThreadMutex *BLI_task_pool_user_mutex(TaskPool *pool);
 
-/* number of tasks done, for stats, don't use this to make decisions */
-size_t BLI_task_pool_tasks_done(TaskPool *pool);
-
 /* Parallel for routines */
 typedef void (*TaskParallelRangeFunc)(void *userdata, const int iter);
 typedef void (*TaskParallelRangeFuncEx)(void *userdata, void *userdata_chunk, const int iter, const int thread_id);
index fc2d9674c2f90401b85b1a4f8560a8b787fb16e0..c4761e9f7efa59b51909aa67457a8dc49dbeefca 100644 (file)
@@ -106,7 +106,6 @@ struct TaskPool {
        TaskScheduler *scheduler;
 
        volatile size_t num;
-       volatile size_t done;
        size_t num_threads;
        size_t currently_running_tasks;
        ThreadMutex num_mutex;
@@ -238,7 +237,6 @@ static void task_pool_num_decrease(TaskPool *pool, size_t done)
 
        pool->num -= done;
        atomic_sub_and_fetch_z(&pool->currently_running_tasks, done);
-       pool->done += done;
 
        if (pool->num == 0)
                BLI_condition_notify_all(&pool->num_cond);
@@ -504,7 +502,6 @@ static TaskPool *task_pool_create_ex(TaskScheduler *scheduler, void *userdata, c
 
        pool->scheduler = scheduler;
        pool->num = 0;
-       pool->done = 0;
        pool->num_threads = 0;
        pool->currently_running_tasks = 0;
        pool->do_cancel = false;
@@ -743,11 +740,6 @@ ThreadMutex *BLI_task_pool_user_mutex(TaskPool *pool)
        return &pool->user_mutex;
 }
 
-size_t BLI_task_pool_tasks_done(TaskPool *pool)
-{
-       return pool->done;
-}
-
 /* Parallel range routines */
 
 /**
index 9e40ab02ee417ceaf089c49e574cf7c63e153004..569b207c96669a76dc1950e1420d0441873d491e 100644 (file)
@@ -35,6 +35,7 @@ set(INC
        ../makesdna
        ../makesrna
        ../physics
+       ../../../intern/atomic
        ../../../intern/guardedalloc
        ../../../intern/mikktspace
        ../../../intern/smoke/extern
index 5377d0eba00ae51f0dadb3a02003fc14d62df39d..752a9df0b7955466e491744377b293738467507a 100644 (file)
@@ -60,6 +60,8 @@
 #include "volumetric.h"
 #include "volume_precache.h"
 
+#include "atomic_ops.h"
+
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
@@ -509,7 +511,8 @@ static void *vol_precache_part_test(void *data)
  */
 typedef struct VolPrecacheState {
        double lasttime;
-       int totparts;
+       unsigned int doneparts;
+       unsigned int totparts;
 } VolPrecacheState;
 
 static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UNUSED(threadid))
@@ -574,13 +577,15 @@ static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UN
                }
        }
 
+       unsigned int doneparts = atomic_add_and_fetch_u(&state->doneparts, 1);
+
        time = PIL_check_seconds_timer();
        if (time - state->lasttime > 1.0) {
                ThreadMutex *mutex = BLI_task_pool_user_mutex(pool);
 
                if (BLI_mutex_trylock(mutex)) {
                        char str[64];
-                       float ratio = (float)BLI_task_pool_tasks_done(pool)/(float)state->totparts;
+                       float ratio = (float)doneparts/(float)state->totparts;
                        BLI_snprintf(str, sizeof(str), IFACE_("Precaching volume: %d%%"), (int)(100.0f * ratio));
                        re->i.infostr = str;
                        re->stats_draw(re->sdh, &re->i);
@@ -631,6 +636,7 @@ static void precache_launch_parts(Render *re, RayObject *tree, ShadeInput *shi,
        
        /* setup task scheduler */
        memset(&state, 0, sizeof(state));
+       state.doneparts = 0;
        state.totparts = parts[0]*parts[1]*parts[2];
        state.lasttime = PIL_check_seconds_timer();