diff mbox series

[v3,4/7] linux-gen: schedule, queue: select scheduler/queue via environment

Message ID 1519142419-2141-5-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v3,1/7] linux-gen: queue: encapsulate queue init/term_global functions | expand

Commit Message

Github ODP bot Feb. 20, 2018, 4 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Use ODP_SCHEDULER environment variable to select scheduler/queue
implementation.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 467 (lumag:sched-env)
 ** https://github.com/Linaro/odp/pull/467
 ** Patch: https://github.com/Linaro/odp/pull/467.patch
 ** Base sha: d5419e8857b2bc61d3be17fe53f171550fee426b
 ** Merge commit sha: e203ffe9c0a48b78cb0d0f4aadbb16bb1f840b3c
 **/
 platform/linux-generic/m4/odp_schedule.m4 | 29 +++++----------------
 platform/linux-generic/odp_queue_if.c     | 31 +++++++++++++++++-----
 platform/linux-generic/odp_schedule_if.c  | 43 +++++++++++++++++++++----------
 3 files changed, 60 insertions(+), 43 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/m4/odp_schedule.m4 b/platform/linux-generic/m4/odp_schedule.m4
index 087cff87f..70be5a7d6 100644
--- a/platform/linux-generic/m4/odp_schedule.m4
+++ b/platform/linux-generic/m4/odp_schedule.m4
@@ -1,23 +1,6 @@ 
-AC_ARG_ENABLE([schedule-sp],
-    [  --enable-schedule-sp    enable strict priority scheduler],
-    [if test x$enableval = xyes; then
-	schedule_sp_enabled=yes
-	AC_DEFINE([ODP_SCHEDULE_SP], [1],
-		  [Define to 1 to enable strict priority scheduler])
-    fi])
-
-AC_ARG_ENABLE([schedule-iquery],
-    [  --enable-schedule-iquery    enable interests query (sparse bitmap) scheduler],
-    [if test x$enableval = xyes; then
-	schedule_iquery_enabled=yes
-	AC_DEFINE([ODP_SCHEDULE_IQUERY], [1],
-		  [Define to 1 to enable interests query scheduler])
-    fi])
-
-AC_ARG_ENABLE([schedule_scalable],
-    [  --enable-schedule-scalable   enable scalable scheduler],
-    [if test x$enableval = xyes; then
-	schedule_scalable_enabled=yes
-	AC_DEFINE([ODP_SCHEDULE_SCALABLE], [1],
-		  [Define to 1 to enable scalable scheduler])
-    fi])
+AC_ARG_ENABLE([scheduler-default],
+	      [AS_HELP_STRING([enable-scheduler-default],
+			      [Choose default scheduler (default is basic)])],
+	      [], [enable_scheduler_default=basic])
+AC_DEFINE_UNQUOTED([ODP_SCHEDULE_DEFAULT], ["$enable_scheduler_default"],
+		   [Define to name default scheduler])
diff --git a/platform/linux-generic/odp_queue_if.c b/platform/linux-generic/odp_queue_if.c
index d1c468485..08076ab3a 100644
--- a/platform/linux-generic/odp_queue_if.c
+++ b/platform/linux-generic/odp_queue_if.c
@@ -8,6 +8,10 @@ 
 
 #include <odp_queue_if.h>
 #include <odp_internal.h>
+#include <odp_debug_internal.h>
+
+#include <stdlib.h>
+#include <string.h>
 
 extern const queue_api_t queue_scalable_api;
 extern const queue_fn_t queue_scalable_fn;
@@ -15,13 +19,8 @@  extern const queue_fn_t queue_scalable_fn;
 extern const queue_api_t queue_basic_api;
 extern const queue_fn_t queue_basic_fn;
 
-#ifdef ODP_SCHEDULE_SCALABLE
-const queue_api_t *queue_api = &queue_scalable_api;
-const queue_fn_t *queue_fn = &queue_scalable_fn;
-#else
-const queue_api_t *queue_api = &queue_basic_api;
-const queue_fn_t *queue_fn = &queue_basic_fn;
-#endif
+const queue_api_t *queue_api;
+const queue_fn_t *queue_fn;
 
 odp_queue_t odp_queue_create(const char *name, const odp_queue_param_t *param)
 {
@@ -115,6 +114,24 @@  int odp_queue_info(odp_queue_t queue, odp_queue_info_t *info)
 
 int _odp_queue_init_global(void)
 {
+	const char *sched = getenv("ODP_SCHEDULER");
+
+	if (sched == NULL || !strcmp(sched, "default"))
+		sched = ODP_SCHEDULE_DEFAULT;
+
+	if (!strcmp(sched, "basic") ||
+	    !strcmp(sched, "sp") ||
+	    !strcmp(sched, "iquery")) {
+		queue_fn = &queue_basic_fn;
+		queue_api = &queue_basic_api;
+	} else if (!strcmp(sched, "scalable")) {
+		queue_fn = &queue_scalable_fn;
+		queue_api = &queue_scalable_api;
+	} else {
+		ODP_ABORT("Unknown scheduler specified via ODP_SCHEDULER\n");
+		return -1;
+	}
+
 	return queue_fn->init_global();
 }
 
diff --git a/platform/linux-generic/odp_schedule_if.c b/platform/linux-generic/odp_schedule_if.c
index 049777516..2244eb557 100644
--- a/platform/linux-generic/odp_schedule_if.c
+++ b/platform/linux-generic/odp_schedule_if.c
@@ -8,6 +8,10 @@ 
 
 #include <odp_schedule_if.h>
 #include <odp_internal.h>
+#include <odp_debug_internal.h>
+
+#include <stdlib.h>
+#include <string.h>
 
 extern const schedule_fn_t schedule_sp_fn;
 extern const schedule_api_t schedule_sp_api;
@@ -21,19 +25,8 @@  extern const schedule_api_t schedule_iquery_api;
 extern const schedule_fn_t  schedule_scalable_fn;
 extern const schedule_api_t schedule_scalable_api;
 
-#ifdef ODP_SCHEDULE_SP
-const schedule_fn_t *sched_fn   = &schedule_sp_fn;
-const schedule_api_t *sched_api = &schedule_sp_api;
-#elif defined(ODP_SCHEDULE_IQUERY)
-const schedule_fn_t *sched_fn   = &schedule_iquery_fn;
-const schedule_api_t *sched_api = &schedule_iquery_api;
-#elif defined(ODP_SCHEDULE_SCALABLE)
-const schedule_fn_t  *sched_fn  = &schedule_scalable_fn;
-const schedule_api_t *sched_api = &schedule_scalable_api;
-#else
-const schedule_fn_t  *sched_fn  = &schedule_basic_fn;
-const schedule_api_t *sched_api = &schedule_basic_api;
-#endif
+const schedule_fn_t *sched_fn;
+const schedule_api_t *sched_api;
 
 uint64_t odp_schedule_wait_time(uint64_t ns)
 {
@@ -138,6 +131,30 @@  void odp_schedule_order_unlock_lock(uint32_t unlock_index, uint32_t lock_index)
 
 int _odp_schedule_init_global(void)
 {
+	const char *sched = getenv("ODP_SCHEDULER");
+
+	if (sched == NULL || !strcmp(sched, "default"))
+		sched = ODP_SCHEDULE_DEFAULT;
+
+	ODP_PRINT("Using scheduler '%s'\n", sched);
+
+	if (!strcmp(sched, "basic")) {
+		sched_fn = &schedule_basic_fn;
+		sched_api = &schedule_basic_api;
+	} else if (!strcmp(sched, "sp")) {
+		sched_fn = &schedule_sp_fn;
+		sched_api = &schedule_sp_api;
+	} else if (!strcmp(sched, "iquery")) {
+		sched_fn = &schedule_iquery_fn;
+		sched_api = &schedule_iquery_api;
+	} else if (!strcmp(sched, "scalable")) {
+		sched_fn = &schedule_scalable_fn;
+		sched_api = &schedule_scalable_api;
+	} else {
+		ODP_ABORT("Unknown scheduler specified via ODP_SCHEDULER\n");
+		return -1;
+	}
+
 	return sched_fn->init_global();
 }