+{
+ char sched_arg[SCHED_STRING_MAX_LENGTH] = { '\0' };
+
+ /* Check for runtime selection of the scheduler algorithm */
+ if (!PE_parse_boot_argn("sched", sched_arg, sizeof (sched_arg))) {
+ /* If no boot-args override, look in device tree */
+ if (!PE_get_default("kern.sched", sched_arg,
+ SCHED_STRING_MAX_LENGTH)) {
+ sched_arg[0] = '\0';
+ }
+ }
+
+ if (strlen(sched_arg) > 0) {
+ if (0) {
+ /* Allow pattern below */
+#if defined(CONFIG_SCHED_TRADITIONAL)
+ } else if (0 == strcmp(sched_arg, kSchedTraditionalString)) {
+ sched_current_dispatch = &sched_traditional_dispatch;
+ _sched_enum = sched_enum_traditional;
+ strlcpy(sched_string, kSchedTraditionalString, sizeof(sched_string));
+ kprintf("Scheduler: Runtime selection of %s\n", kSchedTraditionalString);
+ } else if (0 == strcmp(sched_arg, kSchedTraditionalWithPsetRunqueueString)) {
+ sched_current_dispatch = &sched_traditional_with_pset_runqueue_dispatch;
+ _sched_enum = sched_enum_traditional_with_pset_runqueue;
+ strlcpy(sched_string, kSchedTraditionalWithPsetRunqueueString, sizeof(sched_string));
+ kprintf("Scheduler: Runtime selection of %s\n", kSchedTraditionalWithPsetRunqueueString);
+#endif
+#if defined(CONFIG_SCHED_PROTO)
+ } else if (0 == strcmp(sched_arg, kSchedProtoString)) {
+ sched_current_dispatch = &sched_proto_dispatch;
+ _sched_enum = sched_enum_proto;
+ strlcpy(sched_string, kSchedProtoString, sizeof(sched_string));
+ kprintf("Scheduler: Runtime selection of %s\n", kSchedProtoString);
+#endif
+#if defined(CONFIG_SCHED_GRRR)
+ } else if (0 == strcmp(sched_arg, kSchedGRRRString)) {
+ sched_current_dispatch = &sched_grrr_dispatch;
+ _sched_enum = sched_enum_grrr;
+ strlcpy(sched_string, kSchedGRRRString, sizeof(sched_string));
+ kprintf("Scheduler: Runtime selection of %s\n", kSchedGRRRString);
+#endif
+#if defined(CONFIG_SCHED_FIXEDPRIORITY)
+ } else if (0 == strcmp(sched_arg, kSchedFixedPriorityString)) {
+ sched_current_dispatch = &sched_fixedpriority_dispatch;
+ _sched_enum = sched_enum_fixedpriority;
+ strlcpy(sched_string, kSchedFixedPriorityString, sizeof(sched_string));
+ kprintf("Scheduler: Runtime selection of %s\n", kSchedFixedPriorityString);
+ } else if (0 == strcmp(sched_arg, kSchedFixedPriorityWithPsetRunqueueString)) {
+ sched_current_dispatch = &sched_fixedpriority_with_pset_runqueue_dispatch;
+ _sched_enum = sched_enum_fixedpriority_with_pset_runqueue;
+ strlcpy(sched_string, kSchedFixedPriorityWithPsetRunqueueString, sizeof(sched_string));
+ kprintf("Scheduler: Runtime selection of %s\n", kSchedFixedPriorityWithPsetRunqueueString);
+#endif
+ } else {
+ panic("Unrecognized scheduler algorithm: %s", sched_arg);
+ }
+ } else {
+#if defined(CONFIG_SCHED_TRADITIONAL)
+ sched_current_dispatch = &sched_traditional_dispatch;
+ _sched_enum = sched_enum_traditional;
+ strlcpy(sched_string, kSchedTraditionalString, sizeof(sched_string));
+ kprintf("Scheduler: Default of %s\n", kSchedTraditionalString);
+#elif defined(CONFIG_SCHED_PROTO)
+ sched_current_dispatch = &sched_proto_dispatch;
+ _sched_enum = sched_enum_proto;
+ strlcpy(sched_string, kSchedProtoString, sizeof(sched_string));
+ kprintf("Scheduler: Default of %s\n", kSchedProtoString);
+#elif defined(CONFIG_SCHED_GRRR)
+ sched_current_dispatch = &sched_grrr_dispatch;
+ _sched_enum = sched_enum_grrr;
+ strlcpy(sched_string, kSchedGRRRString, sizeof(sched_string));
+ kprintf("Scheduler: Default of %s\n", kSchedGRRRString);
+#elif defined(CONFIG_SCHED_FIXEDPRIORITY)
+ sched_current_dispatch = &sched_fixedpriority_dispatch;
+ _sched_enum = sched_enum_fixedpriority;
+ strlcpy(sched_string, kSchedFixedPriorityString, sizeof(sched_string));
+ kprintf("Scheduler: Default of %s\n", kSchedFixedPriorityString);
+#else
+#error No default scheduler implementation
+#endif
+ }
+
+ SCHED(init)();
+ SCHED(fairshare_init)();
+ sched_realtime_init();
+ ast_init();
+
+ SCHED(pset_init)(&pset0);
+ SCHED(processor_init)(master_processor);
+}
+
+void
+sched_timebase_init(void)
+{
+ uint64_t abstime;
+
+ clock_interval_to_absolutetime_interval(1, NSEC_PER_SEC, &abstime);
+ sched_one_second_interval = abstime;
+
+ SCHED(timebase_init)();
+ sched_realtime_timebase_init();
+}
+
+#if defined(CONFIG_SCHED_TRADITIONAL)
+
+static void
+sched_traditional_init(void)