BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / bb0cb7718204df7c0cbaf87484b1def3c4b2880f / task / time.c

// Related

Nucleus

Barry Per-CPU Scheduler bb0cb77 (3 years, 2 months ago)
diff --git a/task/time.c b/task/time.c
index d6a47d9..654795c 100644
--- a/task/time.c
+++ b/task/time.c
@@ -8,8 +8,9 @@
 #include <nucleus/cpu.h>
 #include <nucleus/task.h>
 
+void balance_scheduler(void);
+
 uint32_t monotonic = 0;
-uint8_t slice[MAX_CPUS] = {0};
 
 /* Timer interrupt */
 void
@@ -17,14 +18,17 @@ timer_handler(struct InterruptFrame *frame)
 {
 	if (cpu->id == 0)
 		monotonic++;
-
 	if (!current)
 		return;
-	slice[cpu->id]++;
+
+	/* Book-keep the scheduler */
+	Scheduler *s = cpu->scheduler;
+	if (monotonic % 300000 == 0)
+		balance_scheduler();
+	s->timeslice++;
 
 	/* Call scheduler */
-	if (slice[cpu->id] < (current->priority * 10))
+	if (s->timeslice < (current->priority * 10))
 		return;
-	slice[cpu->id] = 0;
 	schedule();
 }