shithub: riscv

Download patch

ref: 3fce94e7850ab80d14fa15f2f393ae71259376e5
parent: 83865180a29d7feba2a1f460abf17315562141c3
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Tue Oct 25 16:17:39 EDT 2011

fix _tos->pcycles, make _tos->kcycles actually count cycles executing kernel code on behalf of the process

--- a/sys/src/9/kw/arch.c
+++ b/sys/src/9/kw/arch.c
@@ -50,7 +50,7 @@
 	tos = (Tos*)(USTKTOP-sizeof(Tos));
 	t = fastticks(nil);
 	tos->kcycles += t - up->kentry;
-	tos->pcycles = up->pcycles;
+	tos->pcycles = t + up->pcycles;
 	tos->cyclefreq = Frequency;
 	tos->pid = up->pid;
 
@@ -124,11 +124,16 @@
 procsetup(Proc* p)
 {
 	fpusysprocsetup(p);
+
+	cycles(&p->kentry);
+	p->pcycles = -p->kentry;
 }
 
 void
-procfork(Proc *)
+procfork(Proc* p)
 {
+	p->kentry = up->kentry;
+	p->pcycles = -p->kentry;
 }
 
 /*
@@ -141,6 +146,7 @@
 
 	cycles(&t);
 	p->pcycles += t;
+	p->kentry -= t;
 
 	fpuprocsave(p);
 }
@@ -152,8 +158,10 @@
 
 	if(p->kp)
 		return;
-	t = lcycles();
+
+	cycles(&t);
 	p->pcycles -= t;
+	p->kentry += t;
 
 	fpuprocrestore(p);
 }
--- a/sys/src/9/omap/arch.c
+++ b/sys/src/9/omap/arch.c
@@ -50,7 +50,7 @@
 	tos = (Tos*)(USTKTOP-sizeof(Tos));
 	cycles(&t);
 	tos->kcycles += t - up->kentry;
-	tos->pcycles = up->pcycles;
+	tos->pcycles = t + up->pcycles;
 	tos->cyclefreq = m->cpuhz;
 	tos->pid = up->pid;
 
@@ -124,11 +124,16 @@
 procsetup(Proc* p)
 {
 	fpusysprocsetup(p);
+
+	cycles(&p->kentry);
+	p->pcycles = -p->kentry;
 }
 
 void
-procfork(Proc*)
+procfork(Proc* p)
 {
+	p->kentry = up->kentry;
+	p->pcycles = -p->kentry;
 }
 
 /*
@@ -141,6 +146,7 @@
 
 	cycles(&t);
 	p->pcycles += t;
+	p->kentry -= t;
 
 // TODO: save and restore VFPv3 FP state once 5[cal] know the new registers.
 	fpuprocsave(p);
@@ -155,6 +161,7 @@
 		return;
 	cycles(&t);
 	p->pcycles -= t;
+	p->kentry += t;
 
 	fpuprocrestore(p);
 }
--- a/sys/src/9/omap4/trap.c
+++ b/sys/src/9/omap4/trap.c
@@ -124,7 +124,7 @@
 	tos = (Tos*) (USTKTOP - sizeof(Tos));
 	cycles(&t);
 	tos->kcycles += t - up->kentry;
-	tos->pcycles = up->pcycles;
+	tos->pcycles = t + up->pcycles;
 	tos->pid = up->pid;
 }
 
--- a/sys/src/9/pc/main.c
+++ b/sys/src/9/pc/main.c
@@ -580,11 +580,14 @@
  *  set up floating point for a new process
  */
 void
-procsetup(Proc*p)
+procsetup(Proc *p)
 {
 	p->fpstate = FPinit;
 	fpoff();
 
+	cycles(&p->kentry);
+	p->pcycles = -p->kentry;
+
 	memset(p->gdt, 0, sizeof(p->gdt));
 	p->ldt = nil;
 	p->nldt = 0;
@@ -593,6 +596,9 @@
 void
 procfork(Proc *p)
 {
+	p->kentry = up->kentry;
+	p->pcycles = -p->kentry;
+
 	/* inherit user descriptors */
 	memmove(p->gdt, up->gdt, sizeof(p->gdt));
 
@@ -611,7 +617,9 @@
 
 	if(p->kp)
 		return;
+
 	cycles(&t);
+	p->kentry += t;
 	p->pcycles -= t;
 }
 
@@ -624,7 +632,9 @@
 	uvlong t;
 
 	cycles(&t);
+	p->kentry -= t;
 	p->pcycles += t;
+
 	if(p->fpstate == FPactive){
 		if(p->state == Moribund)
 			fpclear();
--- a/sys/src/9/pc/trap.c
+++ b/sys/src/9/pc/trap.c
@@ -299,7 +299,7 @@
 	tos = (Tos*)(USTKTOP-sizeof(Tos));
 	cycles(&t);
 	tos->kcycles += t - up->kentry;
-	tos->pcycles = up->pcycles;
+	tos->pcycles = t + up->pcycles;
 	tos->pid = up->pid;
 }
 
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -356,10 +356,10 @@
 	 */
 	tos = (Tos*)(TSTKTOP - sizeof(Tos));
 	tos->cyclefreq = m->cyclefreq;
-	cycles((uvlong*)&tos->pcycles);
-	tos->pcycles = -tos->pcycles;
-	tos->kcycles = tos->pcycles;
+	tos->kcycles = 0;
+	tos->pcycles = 0;
 	tos->clock = 0;
+
 	argv = (char**)(TSTKTOP - ssize);
 	charp = (char*)(TSTKTOP - nbytes);
 	args = charp;
--- a/sys/src/9/ppc/main.c
+++ b/sys/src/9/ppc/main.c
@@ -284,11 +284,16 @@
 procsetup(Proc *p)
 {
 	p->fpstate = FPinit;
+
+	cycles(&p->kentry);
+	p->pcycles = -p->kentry;
 }
 
 void
-procfork(Proc *)
+procfork(Proc *p)
 {
+	p->kentry = up->kentry;
+	p->pcycles = -p->kentry;
 }
 
 void
@@ -300,6 +305,7 @@
 		return;
 	cycles(&t);
 	p->pcycles -= t;
+	p->kentry += t;
 }
 
 /*
@@ -312,6 +318,7 @@
 
 	cycles(&t);
 	p->pcycles += t;
+	p->kentry -= t;
 	if(p->fpstate == FPactive){
 		if(p->state != Moribund)
 			fpsave(&up->fpsave);
--- a/sys/src/9/ppc/trap.c
+++ b/sys/src/9/ppc/trap.c
@@ -150,7 +150,7 @@
 	tos = (Tos*)(USTKTOP-sizeof(Tos));
 	cycles(&t);
 	tos->kcycles += t - up->kentry;
-	tos->pcycles = up->pcycles;
+	tos->pcycles = t + up->pcycles;
 	tos->pid = up->pid;
 }