shithub: riscv

Download patch

ref: 6cb359cc00bdc8204b011db46b8746c446f2c4de
parent: a2eafd2cb0d6206ddaa846d50c320a309a17f05e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jan 22 15:39:14 EST 2017

sgi: cleanup timer code

- no need to splhi() in timerset, always called with
  interrupts off.

- make timerset always update the period (next == 0)

- remove period update in fastticks(), simplify
  delta calculation.

--- a/sys/src/9/sgi/clock.c
+++ b/sys/src/9/sgi/clock.c
@@ -83,7 +83,8 @@
 
 	m->maxperiod = Basetickfreq / HZ;
 	m->minperiod = Basetickfreq / (100*HZ);
-	wrcompare(rdcount()+m->maxperiod);
+	m->lastcount = rdcount();
+	wrcompare(m->lastcount+m->maxperiod);
 
 	intron(INTR7);
 }
@@ -128,12 +129,7 @@
 	/* avoid reentry on interrupt or trap, to prevent recursion */
 	x = splhi();
 	count = rdcount();
-	if(rdcompare() - count > m->maxperiod)
-		wrcompare(count+m->maxperiod);
-	if (count < m->lastcount)		/* wrapped around? */
-		delta = count + ((1ull<<32) - m->lastcount);
-	else
-		delta = count - m->lastcount;
+	delta = count - m->lastcount;
 	m->lastcount = count;
 	m->fastticks += delta;
 	splx(x);
@@ -150,18 +146,16 @@
 void
 timerset(Tval next)
 {
-	int x;
 	long period;
 
 	if(next == 0)
-		return;
-	x = splhi();			/* don't let us get scheduled */
-	period = next - fastticks(nil);
-	if(period > m->maxperiod - m->minperiod)
 		period = m->maxperiod;
-	else if(period < m->minperiod)
-		period = m->minperiod;
+	else {
+		period = next - fastticks(nil);
+		if(period > m->maxperiod)
+			period = m->maxperiod;
+		else if(period < m->minperiod)
+			period = m->minperiod;
+	}
 	wrcompare(rdcount()+period);
-	splx(x);
-
 }