summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sys/include/sys/cpuvar.h30
-rw-r--r--src/sys/os/os_sched.c36
2 files changed, 66 insertions, 0 deletions
diff --git a/src/sys/include/sys/cpuvar.h b/src/sys/include/sys/cpuvar.h
index a41131b..e4f3cd1 100644
--- a/src/sys/include/sys/cpuvar.h
+++ b/src/sys/include/sys/cpuvar.h
@@ -33,6 +33,7 @@
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/proc.h>
+#include <sys/param.h>
#if defined(_KERNEL)
#include <os/sched.h>
#include <machine/mdcpu.h>
@@ -60,6 +61,35 @@ struct pcore {
};
#if defined(_KERNEL)
+
+typedef enum {
+ CORE_ARBITER_RR, /* Round robin */
+} arbiter_type_t;
+
+/*
+ * The processor core arbiter assists in scheduling
+ * processor cores to be used for execution.
+ *
+ * @rr_id: Round robin ID; next processor to be scheduled
+ * @type: Arbitration policy (CORE_ARBITER_RR is default)
+ * @lock: Protects the ID
+ */
+struct core_arbiter {
+ size_t rr_id;
+ arbiter_type_t type;
+ struct spinlock lock;
+} __aligned(COHERENCY_UNIT);
+
+/*
+ * Return a pointer to the next processor that
+ * is ready for queues to be assigned to them
+ *
+ * [MI]
+ *
+ * Returns NULL on failure
+ */
+struct pcore *cpu_sched(void);
+
/*
* Configure a processor core on the system
*
diff --git a/src/sys/os/os_sched.c b/src/sys/os/os_sched.c
index f1bcc8c..e7cc832 100644
--- a/src/sys/os/os_sched.c
+++ b/src/sys/os/os_sched.c
@@ -33,6 +33,7 @@
*/
#include <sys/types.h>
+#include <sys/cdefs.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <sys/panic.h>
@@ -40,6 +41,41 @@
#include <sys/cpuvar.h>
#include <os/sched.h>
+__cacheline_aligned
+static struct core_arbiter arbiter = {
+ .rr_id = 0,
+ .type = CORE_ARBITER_RR
+};
+
+/*
+ * Schedule the next processor core
+ */
+struct pcore *
+cpu_sched(void)
+{
+ struct pcore *retval;
+
+ spinlock_acquire(&arbiter.lock);
+ switch (arbiter.type) {
+ case CORE_ARBITER_RR:
+ retval = cpu_get(arbiter.rr_id++);
+
+ /*
+ * If we made it at the end, wrap to the beginning.
+ * XXX: Us getting entry 0 would make the next be 1.
+ */
+ if (retval == NULL) {
+ arbiter.rr_id = 1;
+ retval = cpu_get(0);
+ }
+
+ break;
+ }
+
+ spinlock_release(&arbiter.lock);
+ return retval;
+}
+
/*
* Enqueue a process into a queue
*/