2 #include "../port/lib.h"
11 Cyccntres = 2, /* counter advances at ½ clock rate */
12 Basetickfreq = 150*Mhz / Cyccntres, /* sgi/indy */
26 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
27 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
28 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
29 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
30 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
31 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
32 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
33 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
34 --i; --i; --i; --i; --i; --i; --i; --i; --i; --i;
35 --i; --i; --i; --i; --i;
36 /* omit 3 (--i) to account for conditional branch, nop & jump */
37 i -= 1+3; /* --i plus 3 omitted (--i) instructions */
39 return perfticks() - st;
42 /* estimate instructions/s. */
44 guessmips(long (*loop)(void), char *)
57 * Instrs instructions took cyc cycles @ Basetickfreq Hz.
60 return (((vlong)Basetickfreq * Instrs) / cyc + Mhz/2) / Mhz;
71 mips = guessmips(issue1loop, "single");
74 * m->delayloop should be the number of delay loop iterations
75 * needed to consume 1 ms, assuming 2 instr'ns in the delay loop.
77 m->delayloop = mips*Mhz / (1000 * 2);
84 m->maxperiod = Basetickfreq / HZ;
85 m->minperiod = Basetickfreq / (100*HZ);
86 wrcompare(rdcount()+m->maxperiod);
94 wrcompare(rdcount()+m->maxperiod); /* side-effect: dismiss intr */
103 while(µs() - now < n);
116 return fastticks2us(fastticks(nil));
120 fastticks(uvlong *hz)
128 /* avoid reentry on interrupt or trap, to prevent recursion */
131 if(rdcompare() - count > m->maxperiod)
132 wrcompare(count+m->maxperiod);
133 if (count < m->lastcount) /* wrapped around? */
134 delta = count + ((1ull<<32) - m->lastcount);
136 delta = count - m->lastcount;
137 m->lastcount = count;
138 m->fastticks += delta;
158 x = splhi(); /* don't let us get scheduled */
159 period = next - fastticks(nil);
160 if(period > m->maxperiod - m->minperiod)
161 period = m->maxperiod;
162 else if(period < m->minperiod)
163 period = m->minperiod;
164 wrcompare(rdcount()+period);