[Bf-blender-cvs] [97ae0f2] master: Depsgraph debug: Remove hardcoded array of BLENDER_MAX_THREADS elements

Sergey Sharybin noreply at git.blender.org
Mon Apr 13 11:41:16 CEST 2015


Commit: 97ae0f22cd5709e4a1af532d594012426c2b364e
Author: Sergey Sharybin
Date:   Mon Apr 13 14:37:12 2015 +0500
Branches: master
https://developer.blender.org/rB97ae0f22cd5709e4a1af532d594012426c2b364e

Depsgraph debug: Remove hardcoded array of BLENDER_MAX_THREADS elements

Allocate statistics array dynamically, so increasing max number of threads does
not increase sloppyness of the memory usage.

For the further cleanups: we can try alloca-ing this array, but it's also not
really safe because we can have quite huge number of threads in the future.
Plus statistics will allocate memory for each individual entry, so using alloca
is not going to give anything beneficial here.

===================================================================

M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenlib/BLI_task.h
M	source/blender/blenlib/intern/task.c

===================================================================

diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 443671f..60b05ce 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1373,13 +1373,13 @@ typedef struct ThreadedObjectUpdateState {
 	Scene *scene_parent;
 	double base_time;
 
-	/* Execution statistics */
-	ListBase statistics[BLENDER_MAX_THREADS];
-	bool has_updated_objects;
-
 #ifdef MBALL_SINGLETHREAD_HACK
 	bool has_mballs;
 #endif
+
+	/* Execution statistics */
+	bool has_updated_objects;
+	ListBase *statistics;
 } ThreadedObjectUpdateState;
 
 static void scene_update_object_add_task(void *node, void *user_data);
@@ -1448,6 +1448,8 @@ static void scene_update_object_func(TaskPool *pool, void *taskdata, int threadi
 		if (add_to_stats) {
 			StatisicsEntry *entry;
 
+			BLI_assert(threadid < BLI_pool_get_num_threads(pool));
+
 			entry = MEM_mallocN(sizeof(StatisicsEntry), "update thread statistics");
 			entry->object = object;
 			entry->start_time = start_time;
@@ -1576,7 +1578,9 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene
 
 	/* Those are only needed when blender is run with --debug argument. */
 	if (G.debug & G_DEBUG_DEPSGRAPH) {
-		memset(state.statistics, 0, sizeof(state.statistics));
+		const int tot_thread = BLI_task_scheduler_num_threads(task_scheduler);
+		state.statistics = MEM_callocN(tot_thread * sizeof(*state.statistics),
+		                               "scene update objects stats");
 		state.has_updated_objects = false;
 		state.base_time = PIL_check_seconds_timer();
 	}
@@ -1593,6 +1597,7 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene
 
 	if (G.debug & G_DEBUG_DEPSGRAPH) {
 		print_threads_statistics(&state);
+		MEM_freeN(state.statistics);
 	}
 
 	/* We do single thread pass to update all the objects which are in cyclic dependency.
diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h
index 2eaec02..780b0bf 100644
--- a/source/blender/blenlib/BLI_task.h
+++ b/source/blender/blenlib/BLI_task.h
@@ -88,6 +88,9 @@ void BLI_task_pool_cancel(TaskPool *pool);
 /* stop all worker threads */
 void BLI_task_pool_stop(TaskPool *pool);
 
+/* get number of threads allowed to be used by this pool */
+int BLI_pool_get_num_threads(TaskPool *pool);
+
 /* set number of threads allowed to be used by this pool */
 void BLI_pool_set_num_threads(TaskPool *pool, int num_threads);
 
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index d187a8d..f442a62 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -417,6 +417,16 @@ void BLI_task_pool_work_and_wait(TaskPool *pool)
 	BLI_mutex_unlock(&pool->num_mutex);
 }
 
+int BLI_pool_get_num_threads(TaskPool *pool)
+{
+	if (pool->num_threads != 0) {
+		return pool->num_threads;
+	}
+	else {
+		return BLI_task_scheduler_num_threads(pool->scheduler);
+	}
+}
+
 void BLI_pool_set_num_threads(TaskPool *pool, int num_threads)
 {
 	/* NOTE: Don't try to modify threads while tasks are running! */




More information about the Bf-blender-cvs mailing list