Browse Source

make sure that _starpu_get_worker_struct doesn't overflow. Inline starpu_worker_get_count to make it not too expensive

Samuel Thibault 9 years ago
parent
commit
6b863c6ee1
3 changed files with 11 additions and 3 deletions
  1. 3 2
      src/core/sched_ctx.c
  2. 1 1
      src/core/workers.c
  3. 7 0
      src/core/workers.h

+ 3 - 2
src/core/sched_ctx.c

@@ -450,9 +450,10 @@ static void _starpu_sched_ctx_create_hwloc_tree(struct _starpu_sched_ctx *sched_
 	workers->init_iterator(workers, &it);
 	while(workers->has_next(workers, &it))
 	{
-		worker = _starpu_get_worker_struct(workers->get_next(workers, &it));
-		if(!starpu_worker_is_combined_worker(worker->workerid))
+		unsigned workerid = workers->get_next(workers, &it);
+		if(!starpu_worker_is_combined_worker(workerid))
 		{
+			worker = _starpu_get_worker_struct(workerid);
 			hwloc_bitmap_or(sched_ctx->hwloc_workers_set,
 					sched_ctx->hwloc_workers_set,
 					worker->hwloc_cpu_set);

+ 1 - 1
src/core/workers.c

@@ -1573,7 +1573,7 @@ void starpu_shutdown(void)
 #endif
 }
 
-
+#undef starpu_worker_get_count
 unsigned starpu_worker_get_count(void)
 {
 	return _starpu_config.topology.nworkers;

+ 7 - 0
src/core/workers.h

@@ -417,6 +417,12 @@ void _starpu_driver_start(struct _starpu_worker *worker, unsigned fut_key, unsig
 /* This function initializes the current thread for the given worker */
 void _starpu_worker_start(struct _starpu_worker *worker, unsigned fut_key, unsigned sync);
 
+static inline unsigned _starpu_worker_get_count(void)
+{
+	return _starpu_config.topology.nworkers;
+}
+#define starpu_worker_get_count _starpu_worker_get_count
+
 /* The _starpu_worker structure describes all the state of a StarPU worker.
  * This function sets the pthread key which stores a pointer to this structure.
  * */
@@ -457,6 +463,7 @@ static inline struct _starpu_worker_set *_starpu_get_local_worker_set_key(void)
  * specified worker. */
 static inline struct _starpu_worker *_starpu_get_worker_struct(unsigned id)
 {
+	STARPU_ASSERT(id < starpu_worker_get_count());
 	return &_starpu_config.workers[id];
 }