Selaa lähdekoodia

The scheduling strategy may now select the min/max priority levels. The
"default" priority is 0 by convention so that we are able to statically
allocate a task with default priority.

Cédric Augonnet 14 vuotta sitten
vanhempi
commit
0a93ca40d1

+ 14 - 0
include/starpu_scheduler.h

@@ -100,4 +100,18 @@ would be used to block and wake up all workers.  The initialization method of a
 scheduling strategy (init_sched) must call this function once per worker. */
 void starpu_worker_set_sched_condition(int workerid, pthread_cond_t *sched_cond, pthread_mutex_t *sched_mutex);
 
+/* Provided for legacy reasons */
+#define STARPU_MIN_PRIO		(starpu_sched_get_min_priority())
+#define STARPU_MAX_PRIO		(starpu_sched_get_max_priority())
+
+/* By convention, the default priority level should be 0 so that we can
+ * statically allocate tasks with a default priority. */
+#define STARPU_DEFAULT_PRIO	0
+
+int starpu_sched_get_min_priority(void);
+int starpu_sched_get_max_priority(void);
+
+void starpu_sched_set_min_priority(int min_prio);
+void starpu_sched_set_max_priority(int max_prio);
+
 #endif // __STARPU_SCHEDULER_H__

+ 1 - 5
include/starpu_task.h

@@ -33,10 +33,6 @@
 #define STARPU_GORDON	((1ULL)<<5)
 #define STARPU_OPENCL	((1ULL)<<6)
 
-#define STARPU_MIN_PRIO        (-4)
-#define STARPU_MAX_PRIO        5
-#define STARPU_DEFAULT_PRIO	0
-
 /* task status */
 #define STARPU_TASK_INVALID	0
 #define STARPU_TASK_BLOCKED	1
@@ -151,7 +147,7 @@ struct starpu_task {
 	.cl_arg_size = 0,				\
 	.callback_func = NULL,				\
 	.callback_arg = NULL,				\
-	.priority = STARPU_DEFAULT_PRIO,                \
+	.priority = STARPU_DEFAULT_PRIO,		\
 	.use_tag = 0,					\
 	.synchronous = 0,				\
 	.execute_on_a_specific_worker = 0,		\

+ 1 - 0
src/Makefile.am

@@ -127,6 +127,7 @@ libstarpu_la_SOURCES = 						\
 	core/perfmodel/perfmodel.c				\
 	core/perfmodel/regression.c				\
 	core/sched_policy.c					\
+	core/priorities.c					\
 	sched_policies/eager_central_policy.c			\
 	sched_policies/eager_central_priority_policy.c		\
 	sched_policies/work_stealing_policy.c			\

+ 49 - 0
src/core/priorities.c

@@ -0,0 +1,49 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu.h>
+#include <starpu_scheduler.h>
+#include <common/config.h>
+
+/* By default we have a binary type of priority: either a task is a priority
+ * task (level 1) or it is not (level 0). */
+static int sched_min_prio = 0;
+static int sched_max_prio = 1;
+
+/* The scheduling policy may set its own priority bounds in case it supports
+ * different priority levels. These methods should only be called from the
+ * scheduling policy. */
+void starpu_sched_set_min_priority(int min_prio)
+{
+	sched_min_prio = min_prio;
+}
+
+void starpu_sched_set_max_priority(int max_prio)
+{
+	sched_max_prio = max_prio;
+}
+
+/* Returns the minimum priority level supported by the scheduling policy. */
+int starpu_sched_get_min_priority(void)
+{
+	return sched_min_prio;
+}
+
+/* Returns the maximum priority level supported by the scheduling policy. */
+int starpu_sched_get_max_priority(void)
+{
+	return sched_max_prio;
+}

+ 9 - 1
src/sched_policies/eager_central_priority_policy.c

@@ -20,11 +20,15 @@
  */
 
 #include <starpu.h>
+#include <starpu_scheduler.h>
 #include <common/config.h>
 #include <core/workers.h>
 #include <common/utils.h>
 
-#define NPRIO_LEVELS	((STARPU_MAX_PRIO) - (STARPU_MIN_PRIO) + 1)
+#define MIN_LEVEL	(-5)
+#define MAX_LEVEL	(+5)
+
+#define NPRIO_LEVELS	(MAX_LEVEL - MIN_LEVEL + 1)
 
 struct starpu_priority_taskq_s {
 	/* the actual lists 
@@ -72,6 +76,10 @@ static void _starpu_destroy_priority_taskq(struct starpu_priority_taskq_s *prior
 static void initialize_eager_center_priority_policy(struct starpu_machine_topology_s *topology, 
 			__attribute__ ((unused))	struct starpu_sched_policy_s *_policy) 
 {
+	/* In this policy, we support more than two levels of priority. */
+	starpu_sched_set_min_priority(MIN_LEVEL);
+	starpu_sched_set_max_priority(MAX_LEVEL);
+
 	/* only a single queue (even though there are several internaly) */
 	taskq = _starpu_create_priority_taskq();