changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: kernel: insert memory barrier in the scheduler before setting up->mach = nil

changeset 7180: c34b759d11c6
parent 7179: b3b84087ac92
child 7181: 0949b361c51e
author: cinap_lenrek@felloff.net
date: Wed, 01 May 2019 09:35:51 +0200
files: sys/src/9/port/proc.c
description: kernel: insert memory barrier in the scheduler before setting up->mach = nil

we have to ensure that all stores saving the process state
have completed before setting up->mach = nil in the scheduler.
otherwise, another cpu could observe up->mach == nil while
the stores such as the processes p->sched label have not finnished.
     1.1--- a/sys/src/9/port/proc.c
     1.2+++ b/sys/src/9/port/proc.c
     1.3@@ -70,6 +70,9 @@ schedinit(void)		/* never returns */
     1.4 			edfrecord(up);
     1.5 		m->proc = nil;
     1.6 		switch(up->state) {
     1.7+		default:
     1.8+			updatecpu(up);
     1.9+			break;
    1.10 		case Running:
    1.11 			ready(up);
    1.12 			break;
    1.13@@ -88,8 +91,8 @@ schedinit(void)		/* never returns */
    1.14 			mmurelease(up);
    1.15 			unlock(&palloc);
    1.16 
    1.17+			updatecpu(up);
    1.18 			up->mach = nil;
    1.19-			updatecpu(up);
    1.20 
    1.21 			up->qnext = procalloc.free;
    1.22 			procalloc.free = up;
    1.23@@ -99,8 +102,8 @@ schedinit(void)		/* never returns */
    1.24 			unlock(&procalloc);
    1.25 			sched();
    1.26 		}
    1.27+		coherence();
    1.28 		up->mach = nil;
    1.29-		updatecpu(up);
    1.30 		up = nil;
    1.31 	}
    1.32 	sched();