shithub: front

Download patch

ref: 706b44c15d09625d6c8ccf97b4690f423fccd9dd
parent: b0d33c09ff8fdb48e12843046033d1df68c9c54f
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;
--