Task scheduler: Remove counter of done tasks

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.
This commit is contained in:
Sergey Sharybin 2017-03-01 12:45:51 +01:00
parent 351c9239ed
commit f0cf15b5c6
4 changed files with 9 additions and 13 deletions

@ -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);

@ -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 */
/**

@ -35,6 +35,7 @@ set(INC
../makesdna
../makesrna
../physics
../../../intern/atomic
../../../intern/guardedalloc
../../../intern/mikktspace
../../../intern/smoke/extern

@ -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();