git: 9front

Download patch

ref: 23ac5c92c66adc87585ee742079ed4b8b6b50c04
parent: 6e5002723caf6a2bb7da8ec796049aeac469553d
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jul 21 08:44:23 EDT 2024

kernel: fix wrong updatecpu() context regression

In the sched() function, the call to reprioritize()
must be done before we set up, as reprioritize()
calls updatecpu(), which determines if the process
was running or not based on p == up. So move
the call to runproc() itself.

--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -206,8 +206,6 @@
 		return;
 	}
 	up = runproc();
-	if(up->edf == nil)
-		up->priority = reprioritize(up);
 	if(up != m->readied)
 		m->schedticks = m->ticks + HZ/10;
 	m->readied = nil;
@@ -352,6 +350,7 @@
 	int fairshare, n, load, ratio;
 
 	updatecpu(p);
+
 	load = MACHP(0)->load;
 	if(load == 0)
 		return p->basepri;
@@ -405,6 +404,7 @@
 	}
 	p->state = Ready;
 	p->priority = pri;
+
 	if(pri == PriEdf){
 		Proc *pp, *l;
 
@@ -640,6 +640,8 @@
 	if(edflock(p)){
 		edfrun(p, rq == &runq[PriEdf]);	/* start deadline timer and do admin */
 		edfunlock();
+	} else {
+		p->priority = reprioritize(p);
 	}
 	pt = proctrace;
 	if(pt != nil)
@@ -709,8 +711,9 @@
 	p->lastlock = nil;
 	p->lastilock = nil;
 	p->nlocks = 0;
-	p->delaysched = 0;
 	p->trace = 0;
+	p->preempted = 0;
+	p->delaysched = 0;
 
 	/* sched params */
 	p->mp = nil;
--