浏览代码

factorize some schedctx details

Samuel Thibault 6 年之前
父节点
当前提交
d7b151cc48

+ 13 - 1
src/core/sched_ctx.h

@@ -2,7 +2,7 @@
  *
  *
  * Copyright (C) 2011-2018                                Inria
  * Copyright (C) 2011-2018                                Inria
  * Copyright (C) 2012-2014,2017                           CNRS
  * Copyright (C) 2012-2014,2017                           CNRS
- * Copyright (C) 2011-2013,2015-2017                      Université de Bordeaux
+ * Copyright (C) 2011-2013,2015-2017,2019                 Université de Bordeaux
  * Copyright (C) 2016                                     Uppsala University
  * Copyright (C) 2016                                     Uppsala University
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
@@ -301,6 +301,18 @@ static inline void _starpu_sched_ctx_unlock_read(unsigned sched_ctx_id)
 	STARPU_PTHREAD_RWLOCK_UNLOCK(&sched_ctx->rwlock);
 	STARPU_PTHREAD_RWLOCK_UNLOCK(&sched_ctx->rwlock);
 }
 }
 
 
+static inline unsigned _starpu_sched_ctx_worker_is_master_for_child_ctx(unsigned sched_ctx_id, unsigned workerid, struct starpu_task *task)
+{
+	unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
+	if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
+	{
+		starpu_sched_ctx_move_task_to_ctx_locked(task, child_sched_ctx, 1);
+		starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, task->flops);
+		return 1;
+	}
+	return 0;
+}
+
 /* Go through the list of deferred ctx changes of the current worker and apply
 /* Go through the list of deferred ctx changes of the current worker and apply
  * any ctx change operation found until the list is empty */
  * any ctx change operation found until the list is empty */
 void _starpu_worker_apply_deferred_ctx_changes(void);
 void _starpu_worker_apply_deferred_ctx_changes(void);

+ 9 - 12
src/sched_policies/deque_modeling_policy_data_aware.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
  * Copyright (C) 2011-2017                                Inria
  * Copyright (C) 2011-2017                                Inria
- * Copyright (C) 2009-2018                                Université de Bordeaux
+ * Copyright (C) 2009-2019                                Université de Bordeaux
  * Copyright (C) 2013                                     Joris Pablo
  * Copyright (C) 2013                                     Joris Pablo
  * Copyright (C) 2010-2018                                CNRS
  * Copyright (C) 2010-2018                                CNRS
  * Copyright (C) 2013                                     Simon Archipoff
  * Copyright (C) 2013                                     Simon Archipoff
@@ -345,23 +345,20 @@ static int push_task_on_best_worker(struct starpu_task *task, int best_workerid,
 				    double predicted, double predicted_transfer,
 				    double predicted, double predicted_transfer,
 				    int prio, unsigned sched_ctx_id)
 				    int prio, unsigned sched_ctx_id)
 {
 {
-	_starpu_worker_relax_on();
-	_starpu_sched_ctx_lock_write(sched_ctx_id);
-	_starpu_worker_relax_off();
 	struct _starpu_dmda_data *dt = (struct _starpu_dmda_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
 	struct _starpu_dmda_data *dt = (struct _starpu_dmda_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
 	/* make sure someone could execute that task ! */
 	/* make sure someone could execute that task ! */
 	STARPU_ASSERT(best_workerid != -1);
 	STARPU_ASSERT(best_workerid != -1);
-	unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(best_workerid, sched_ctx_id);
 
 
-        if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
-        {
-                starpu_sched_ctx_move_task_to_ctx_locked(task, child_sched_ctx, 1);
-		starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, task->flops);
-		_starpu_sched_ctx_unlock_write(sched_ctx_id);
+	_starpu_worker_relax_on();
+	_starpu_sched_ctx_lock_write(sched_ctx_id);
+	_starpu_worker_relax_off();
+	if (_starpu_sched_ctx_worker_is_master_for_child_ctx(sched_ctx_id, best_workerid, task))
+		task = NULL;
+	_starpu_sched_ctx_unlock_write(sched_ctx_id);
+
+	if (!task)
                 return 0;
                 return 0;
-        }
 
 
-	_starpu_sched_ctx_unlock_write(sched_ctx_id);
 	struct _starpu_fifo_taskq *fifo = dt->queue_array[best_workerid];
 	struct _starpu_fifo_taskq *fifo = dt->queue_array[best_workerid];
 
 
 	double now = starpu_timing_now();
 	double now = starpu_timing_now();

+ 2 - 7
src/sched_policies/eager_central_policy.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
  * Copyright (C) 2011-2017                                Inria
  * Copyright (C) 2011-2017                                Inria
- * Copyright (C) 2008-2018                                Université de Bordeaux
+ * Copyright (C) 2008-2019                                Université de Bordeaux
  * Copyright (C) 2010-2013,2015-2017                      CNRS
  * Copyright (C) 2010-2013,2015-2017                      CNRS
  * Copyright (C) 2013                                     Simon Archipoff
  * Copyright (C) 2013                                     Simon Archipoff
  * Copyright (C) 2016                                     Uppsala University
  * Copyright (C) 2016                                     Uppsala University
@@ -195,13 +195,8 @@ static struct starpu_task *pop_task_eager_policy(unsigned sched_ctx_id)
 		_starpu_worker_relax_off();
 		_starpu_worker_relax_off();
 		starpu_sched_ctx_list_task_counters_decrement_all_ctx_locked(chosen_task, sched_ctx_id);
 		starpu_sched_ctx_list_task_counters_decrement_all_ctx_locked(chosen_task, sched_ctx_id);
 
 
-		unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
-		if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
-		{
-			starpu_sched_ctx_move_task_to_ctx_locked(chosen_task, child_sched_ctx, 1);
-			starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, chosen_task->flops);
+		if (_starpu_sched_ctx_worker_is_master_for_child_ctx(sched_ctx_id, workerid, chosen_task))
 			chosen_task = NULL;
 			chosen_task = NULL;
-		}
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 	}
 	}
 
 

+ 3 - 7
src/sched_policies/eager_central_priority_policy.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
  * Copyright (C) 2011-2013,2015-2017                      Inria
  * Copyright (C) 2011-2013,2015-2017                      Inria
- * Copyright (C) 2008-2018                                Université de Bordeaux
+ * Copyright (C) 2008-2019                                Université de Bordeaux
  * Copyright (C) 2010-2013,2015-2017                      CNRS
  * Copyright (C) 2010-2013,2015-2017                      CNRS
  * Copyright (C) 2016                                     Uppsala University
  * Copyright (C) 2016                                     Uppsala University
  *
  *
@@ -220,13 +220,9 @@ static struct starpu_task *_starpu_priority_pop_task(unsigned sched_ctx_id)
 		_starpu_worker_relax_off();
 		_starpu_worker_relax_off();
 		starpu_sched_ctx_list_task_counters_decrement_all_ctx_locked(chosen_task, sched_ctx_id);
 		starpu_sched_ctx_list_task_counters_decrement_all_ctx_locked(chosen_task, sched_ctx_id);
 
 
-                unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
-		if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
-		{
-			starpu_sched_ctx_move_task_to_ctx_locked(chosen_task, child_sched_ctx, 1);
-			starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, chosen_task->flops);
+		if (_starpu_sched_ctx_worker_is_master_for_child_ctx(sched_ctx_id, workerid, chosen_task))
 			chosen_task = NULL;
 			chosen_task = NULL;
-		}
+
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 	}
 	}
 
 

+ 3 - 9
src/sched_policies/heteroprio.c

@@ -2,7 +2,7 @@
  *
  *
  * Copyright (C) 2015-2017                                Inria
  * Copyright (C) 2015-2017                                Inria
  * Copyright (C) 2015-2017                                CNRS
  * Copyright (C) 2015-2017                                CNRS
- * Copyright (C) 2015-2018                                Université de Bordeaux
+ * Copyright (C) 2015-2019                                Université de Bordeaux
  * Copyright (C) 2016                                     Uppsala University
  * Copyright (C) 2016                                     Uppsala University
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
@@ -625,14 +625,8 @@ done:		;
 		_starpu_worker_relax_on();
 		_starpu_worker_relax_on();
 		_starpu_sched_ctx_lock_write(sched_ctx_id);
 		_starpu_sched_ctx_lock_write(sched_ctx_id);
 		_starpu_worker_relax_off();
 		_starpu_worker_relax_off();
-		unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
-		if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
-		{
-			starpu_sched_ctx_move_task_to_ctx_locked(task, child_sched_ctx, 1);
-			starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, task->flops);
-			_starpu_sched_ctx_unlock_write(sched_ctx_id);
-			return NULL;
-		}
+		if (_starpu_sched_ctx_worker_is_master_for_child_ctx(sched_ctx_id, workerid, task))
+			task = NULL;
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 	}
 	}
 
 

+ 6 - 15
src/sched_policies/work_stealing_policy.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
  * Copyright (C) 2011-2013,2015-2017                      Inria
  * Copyright (C) 2011-2013,2015-2017                      Inria
- * Copyright (C) 2008-2018                                Université de Bordeaux
+ * Copyright (C) 2008-2019                                Université de Bordeaux
  * Copyright (C) 2010-2013,2015-2017                      CNRS
  * Copyright (C) 2010-2013,2015-2017                      CNRS
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
@@ -551,13 +551,8 @@ static struct starpu_task *ws_pop_task(unsigned sched_ctx_id)
 		_starpu_sched_ctx_lock_write(sched_ctx_id);
 		_starpu_sched_ctx_lock_write(sched_ctx_id);
 		_starpu_worker_relax_off();
 		_starpu_worker_relax_off();
 		starpu_sched_ctx_list_task_counters_decrement(sched_ctx_id, workerid);
 		starpu_sched_ctx_list_task_counters_decrement(sched_ctx_id, workerid);
-		unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
-		if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
-		{
-			starpu_sched_ctx_move_task_to_ctx_locked(task, child_sched_ctx, 1);
-			starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, task->flops);
+		if (_starpu_sched_ctx_worker_is_master_for_child_ctx(sched_ctx_id, workerid, task))
 			task = NULL;
 			task = NULL;
-		}
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 		return task;
 		return task;
 	}
 	}
@@ -615,15 +610,11 @@ static struct starpu_task *ws_pop_task(unsigned sched_ctx_id)
 		_starpu_worker_relax_on();
 		_starpu_worker_relax_on();
 		_starpu_sched_ctx_lock_write(sched_ctx_id);
 		_starpu_sched_ctx_lock_write(sched_ctx_id);
 		_starpu_worker_relax_off();
 		_starpu_worker_relax_off();
-		unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
-		if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
-		{
-			starpu_sched_ctx_move_task_to_ctx_locked(task, child_sched_ctx, 1);
-			starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, task->flops);
-			_starpu_sched_ctx_unlock_write(sched_ctx_id);
-			return NULL;
-		}
+		if (_starpu_sched_ctx_worker_is_master_for_child_ctx(sched_ctx_id, workerid, task))
+			task = NULL;
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
 		_starpu_sched_ctx_unlock_write(sched_ctx_id);
+		if (!task)
+			return NULL;
 	}
 	}
 	ws->per_worker[workerid].busy = !!task;
 	ws->per_worker[workerid].busy = !!task;
 	return task;
 	return task;