Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177975482
D62048.1795694918.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D62048.1795694918.diff
View Options
diff --git a/sys/conf/NOTES b/sys/conf/NOTES
--- a/sys/conf/NOTES
+++ b/sys/conf/NOTES
@@ -194,11 +194,13 @@
#
# The options below select the schedulers that are compiled in. Specifying at
# least one is mandatory. Multiple ones can be compiled in. At boot, the
-# kernel will use ULE by default if present, with a fallback to one of the
-# compiled-in options. A specific scheduler can be requested by setting the
-# 'kern.sched.name' tunable to a scheduler name, i.e., one of the options below
-# with the SCHED_ prefix removed.
-#
+# kernel will try to use the scheduler specified with the DEFAULT_SCHEDULER
+# option below, with a fallback to ULE else one of the compiled-in options.
+# A specific scheduler can be requested by setting the 'kern.sched.name' tunable
+# to a scheduler name, i.e., one of the options below with the SCHED_ prefix
+# removed.
+options DEFAULT_SCHEDULER=4BSD
+
# SCHED_4BSD is the historical, proven, BSD scheduler. It has a global run
# queue and no CPU affinity which makes it suboptimal for SMP. It has very
# good interactivity and priority selection.
diff --git a/sys/conf/options b/sys/conf/options
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -74,6 +74,7 @@
# Scheduler options
SCHED_4BSD opt_sched.h
SCHED_ULE opt_sched.h
+DEFAULT_SCHEDULER opt_sched_shim.h
SCHED_STATS opt_sched.h
PREEMPTION opt_sched.h
IPI_PREEMPTION opt_sched.h
diff --git a/sys/kern/sched_shim.c b/sys/kern/sched_shim.c
--- a/sys/kern/sched_shim.c
+++ b/sys/kern/sched_shim.c
@@ -8,6 +8,7 @@
*/
#include "opt_sched.h"
+#include "opt_sched_shim.h"
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -22,7 +23,7 @@
#include <machine/ifunc.h>
-static const struct sched_instance *active_sched;
+static const struct sched_selection *selected_sched;
SCHED_STAT_DEFINE(ithread_demotions, "Interrupt thread priority demotions");
SCHED_STAT_DEFINE(ithread_preemptions,
@@ -52,6 +53,9 @@
dtrace_vtime_switch_func_t dtrace_vtime_switch_func;
#endif
+SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
+ "Scheduler");
+
/*
* Define dispatchers for all functions described by SCHED_ITF_DISPATCH().
*/
@@ -59,54 +63,77 @@
DEFINE_IFUNC(, ret_type, SCHED_ITF_FUNCTION_NAME(fn), \
(SCHED_ITF_ARGS_PROTO_NAME(__VA_ARGS__))) \
{ \
- return (active_sched->SCHED_ITF_FIELD_NAME(fn)); \
+ return (selected_sched->instance-> \
+ SCHED_ITF_FIELD_NAME(fn)); \
}
SCHED_ITF_DISPATCH(DEFINE_SHIM, );
#undef DEFINE_SHIM
-static char sched_name[32] = "ULE";
-
SET_DECLARE(sched_instance_set, struct sched_selection);
+#define SCHED_NAME_MAX_SIZE 32
+/* Kernel config option. */
+#ifndef DEFAULT_SCHEDULER
+#define DEFAULT_SCHEDULER ULE
+#endif
+
+static void
+sched_default_instance(char *buf, size_t size)
+{
+ if (TUNABLE_STR_FETCH("kern.sched.name", buf, size))
+ return;
+
+ /* If someone passed 0 as the size, he deserved what he got. */
+ MPASS(size != 0);
+ (void)strlcpy(buf, __STRING(DEFAULT_SCHEDULER), size);
+}
+
void
sched_instance_select(void)
{
struct sched_selection *s, **ss;
- int i;
+ char sched_name[SCHED_NAME_MAX_SIZE];
+
+ /* Fetches instance name from the tunable or uses DEFAULT_SCHEDULER. */
+ sched_default_instance(sched_name, sizeof(sched_name));
- TUNABLE_STR_FETCH("kern.sched.name", sched_name, sizeof(sched_name));
SET_FOREACH(ss, sched_instance_set) {
s = *ss;
- for (i = 0; s->name[i] == sched_name[i]; i++) {
- if (s->name[i] == '\0') {
- active_sched = s->instance;
- return;
- }
- }
+ if (strcmp(s->name, sched_name) == 0)
+ goto found;
}
/*
- * No scheduler matching the configuration was found. If
- * there is any scheduler compiled in, at all, use the first
- * scheduler from the linker set.
+ * No scheduler matched the configuration. Use the first scheduler from
+ * the linker set, if any.
*/
if (SET_BEGIN(sched_instance_set) < SET_LIMIT(sched_instance_set)) {
s = *SET_BEGIN(sched_instance_set);
- active_sched = s->instance;
- for (i = 0;; i++) {
- sched_name[i] = s->name[i];
- if (s->name[i] == '\0')
- break;
- }
+ goto found;
}
+
+ /*
+ * We should panic, but will defer that to sched_init() to ensure the
+ * console has been initialized.
+ */
+ return;
+
+found:
+ selected_sched = s;
}
void
sched_init(void)
{
- if (active_sched == NULL)
- panic("Cannot find scheduler %s", sched_name);
- active_sched->SCHED_ITF_FIELD_NAME(init)();
+ if (selected_sched == NULL)
+ panic("No scheduler compiled in!");
+
+ /* This has to be done before init(8)/rc(8) is started. */
+ SYSCTL_ADD_CONST_STRING(NULL, SYSCTL_STATIC_CHILDREN(_kern_sched),
+ OID_AUTO, "name", CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
+ selected_sched->name, "Scheduler name");
+
+ selected_sched->instance->SCHED_ITF_FIELD_NAME(init)();
}
struct cpu_group __read_mostly *cpu_top; /* CPU topology */
@@ -115,14 +142,15 @@
sched_setup(void)
{
cpu_top = smp_topo();
- active_sched->SCHED_ITF_FIELD_NAME(setup)();
+
+ selected_sched->instance->SCHED_ITF_FIELD_NAME(setup)();
}
SYSINIT(sched_setup, SI_SUB_RUN_QUEUE, SI_ORDER_FIRST, sched_setup, NULL);
static void
sched_initticks(void)
{
- active_sched->SCHED_ITF_FIELD_NAME(initticks)();
+ selected_sched->instance->SCHED_ITF_FIELD_NAME(initticks)();
}
SYSINIT(sched_initticks, SI_SUB_CLOCKS, SI_ORDER_THIRD, sched_initticks,
NULL);
@@ -130,17 +158,10 @@
static void
sched_sysinit(void)
{
- active_sched->SCHED_ITF_FIELD_NAME(sysinit)();
+ selected_sched->instance->SCHED_ITF_FIELD_NAME(sysinit)();
}
SYSINIT(sched_sysinit, SI_SUB_LAST, SI_ORDER_FIRST, sched_sysinit, NULL);
-SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
- "Scheduler");
-
-SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
- sched_name, 0,
- "Scheduler name");
-
static int
sysctl_kern_sched_available(SYSCTL_HANDLER_ARGS)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 26, 12:08 PM (22 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42012875
Default Alt Text
D62048.1795694918.diff (5 KB)
Attached To
Mode
D62048: sched_shim: Allow specifying the default scheduler at compile-time
Attached
Detach File
Event Timeline