]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: decay-based scheduler — priority decay on time slice exhaustion, boost on sleep...
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 04:13:13 +0000 (01:13 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:20:50 +0000 (23:20 -0300)
src/kernel/scheduler.c

index b23e80c961a966496e061d62fcc244af6b446462..654f07d92de15200692a509e19d49ed637982f1d 100644 (file)
@@ -743,8 +743,10 @@ void schedule(void) {
     struct process* prev = current_process;
 
     // Put prev back into expired runqueue if it's still runnable.
+    // Priority decay: penalize CPU-bound processes that exhaust their slice.
     if (prev->state == PROCESS_RUNNING) {
         prev->state = PROCESS_READY;
+        if (prev->priority < SCHED_NUM_PRIOS - 1) prev->priority++;
         rq_enqueue(rq_expired, prev);
     }
 
@@ -846,6 +848,8 @@ void process_wake_check(uint32_t current_tick) {
         if (iter->state == PROCESS_SLEEPING) {
             if (current_tick >= iter->wake_at_tick) {
                 iter->state = PROCESS_READY;
+                /* Priority boost: reward I/O-bound processes that sleep */
+                if (iter->priority > 0) iter->priority--;
                 rq_enqueue(rq_active, iter);
             }
         }