Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/carrera/clock.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname carrera/clock.c 1993/0903
## diff -e /dev/null /n/fornaxdump/1993/0903/sys/src/brazil/carrera/clock.c
0a
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"

#include	"ureg.h"

/*
 *  delay for l milliseconds more or less.  delayloop is set by
 *  clockinit() to match the actual CPU speed.
 */
void
delay(int l)
{
	ulong i, j;

	j = m->delayloop;
	while(l-- > 0)
		for(i=0; i < j; i++)
			;
}

void
clockinit(void)
{
	long x;

	m->delayloop = m->speed*100;
	do {
		x = rdcount();
		delay(10);
		x = rdcount() - x;
	} while(x < 0);

	/*
	 *  fix count
	 */
	m->delayloop = (m->delayloop*m->speed*1000*10)/x;
	if(m->delayloop == 0)
		m->delayloop = 1;

	wrcompare(rdcount()+(m->speed*1000000)/HZ);
}

void
clock(Ureg *ur)
{
	Proc *p;
	int i, nrun;

	wrcompare(rdcount()+(m->speed*1000000)/HZ);

	m->ticks++;
	if(m->proc)
		m->proc->pc = ur->pc;

	nrun = 0;
	if(m->machno == 0) {
		p = m->proc;
		if(p) {
			nrun++;
			p->time[p->insyscall]++;
		}
		for(i=1; i<conf.nmach; i++) {
			if(active.machs & (1<<i)) {
				p = MACHP(i)->proc;
				if(p) {
					p->time[p->insyscall]++;
					nrun++;
				}
			}
		}
		nrun = (nrdy+nrun)*1000;
		m->load = (m->load*19+nrun)/20;
	}

	kmapinval();

	if((active.machs&(1<<m->machno)) == 0)
		return;

	if(active.exiting && (active.machs & (1<<m->machno))) {
		print("someone's exiting\n");
		exit(0);
	}

	checkalarms();

	if(up == 0 || (ur->status&IE) == 0 || up->state != Running)
		return;

	if(anyready())
		sched(); /**/

	/* user profiling clock */
	if(ur->status & KUSER)
		(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);	
}
.
## diffname carrera/clock.c 1993/0904
## diff -e /n/fornaxdump/1993/0903/sys/src/brazil/carrera/clock.c /n/fornaxdump/1993/0904/sys/src/brazil/carrera/clock.c
95c
		sched();
.
## diffname carrera/clock.c 1993/1003
## diff -e /n/fornaxdump/1993/0904/sys/src/brazil/carrera/clock.c /n/fornaxdump/1993/1003/sys/src/brazil/carrera/clock.c
89a
	mouseclock();
.
## diffname carrera/clock.c 1993/1224
## diff -e /n/fornaxdump/1993/1003/sys/src/brazil/carrera/clock.c /n/fornaxdump/1993/1224/sys/src/brazil/carrera/clock.c
78a
	kproftimer(ur->pc);

.
## diffname carrera/clock.c 1994/0309
## diff -e /n/fornaxdump/1993/1224/sys/src/brazil/carrera/clock.c /n/fornaxdump/1994/0309/sys/src/brazil/carrera/clock.c
78a
	ifjab();

.
## diffname carrera/clock.c 1994/0817
## diff -e /n/fornaxdump/1994/0309/sys/src/brazil/carrera/clock.c /n/fornaxdump/1994/0817/sys/src/brazil/carrera/clock.c
96c
	if(up == 0 || up->state != Running)
.
## diffname carrera/clock.c 1994/0902
## diff -e /n/fornaxdump/1994/0817/sys/src/brazil/carrera/clock.c /n/fornaxdump/1994/0902/sys/src/brazil/carrera/clock.c
93a
	uartclock();
.
## diffname carrera/clock.c 1995/0104
## diff -e /n/fornaxdump/1994/0902/sys/src/brazil/carrera/clock.c /n/fornaxdump/1995/0104/sys/src/brazil/carrera/clock.c
59,77c
	accounttime();
.
50,52d
## diffname carrera/clock.c 1995/0108
## diff -e /n/fornaxdump/1995/0104/sys/src/brazil/carrera/clock.c /n/fornaxdump/1995/0108/sys/src/brazil/carrera/clock.c
79,80c
	if(anyready()) {
		n = up->inlock;
		if(n == 0)
			sched();
		else
			up->inlock = n-1;
	}
.
49a
	int n;

.
## diffname carrera/clock.c 1995/0109
## diff -e /n/fornaxdump/1995/0108/sys/src/brazil/carrera/clock.c /n/fornaxdump/1995/0109/sys/src/brazil/carrera/clock.c
81,87c
	if(anyready() && !up->inlock)
		sched();
.
## diffname carrera/clock.c 1995/0110
## diff -e /n/fornaxdump/1995/0109/sys/src/brazil/carrera/clock.c /n/fornaxdump/1995/0110/sys/src/brazil/carrera/clock.c
81c
	if(anyready())
.
50d
## diffname carrera/clock.c 1995/1011
## diff -e /n/fornaxdump/1995/0110/sys/src/brazil/carrera/clock.c /n/fornaxdump/1995/1011/sys/src/brazil/carrera/clock.c
75a
	randomclock();
.
## diffname carrera/clock.c 1996/0303
## diff -e /n/fornaxdump/1995/1011/sys/src/brazil/carrera/clock.c /n/fornaxdump/1996/0303/sys/src/brazil/carrera/clock.c
85,86c
	if(ur->status & KUSER) {
		(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
		segclock(ur->pc);
	}
.
49a
	int l;
	Segment *s;
.
## diffname carrera/clock.c 1996/0315
## diff -e /n/fornaxdump/1996/0303/sys/src/brazil/carrera/clock.c /n/fornaxdump/1996/0315/sys/src/brazil/carrera/clock.c
50,52d
## diffname carrera/clock.c 1997/0117
## diff -e /n/fornaxdump/1996/0315/sys/src/brazil/carrera/clock.c /n/fornaxdump/1997/0117/sys/src/brazil/carrera/clock.c
59c
*/
.
57c
/*
.
## diffname carrera/clock.c 1997/0327
## diff -e /n/fornaxdump/1997/0117/sys/src/brazil/carrera/clock.c /n/emeliedump/1997/0327/sys/src/brazil/carrera/clock.c
73,75c
	if(m->machno == 0){
		lock(&clock0lock);
		for(lp = clock0link; lp; lp = lp->link)
			lp->clock();
		unlock(&clock0lock);
	}
.
61a
	if(kproftimer != nil)
		kproftimer(ur->pc);

.
57,60d
49a
	Clock0link *lp;

.
9a
void (*kproftimer)(ulong);

typedef struct Clock0link Clock0link;
typedef struct Clock0link {
	void		(*clock)(void);
	Clock0link*	link;
} Clock0link;

static Clock0link *clock0link;
static Lock clock0lock;

void
addclock0link(void (*clock)(void))
{
	Clock0link *lp;

	if((lp = malloc(sizeof(Clock0link))) == 0){
		print("addclock0link: too many links\n");
		return;
	}
	ilock(&clock0lock);
	lp->clock = clock;
	lp->link = clock0link;
	clock0link = lp;
	iunlock(&clock0lock);
}

.
## diffname carrera/clock.c 1998/0721
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/carrera/clock.c /n/emeliedump/1998/0721/sys/src/brazil/carrera/clock.c
119a

uvlong
fastticks(uvlong *hz)
{
	if(hz)
		*hz = HZ;
	return m->ticks;
}
.
## diffname carrera/clock.c 1998/0725
## diff -e /n/emeliedump/1998/0721/sys/src/brazil/carrera/clock.c /n/emeliedump/1998/0725/sys/src/brazil/carrera/clock.c
107a
	if(m->flushmmu){
		if(up)
			flushmmu();
		m->flushmmu = 0;
	}

.
## diffname carrera/clock.c 1999/0228
## diff -e /n/emeliedump/1998/0725/sys/src/brazil/carrera/clock.c /n/emeliedump/1999/0228/sys/src/brazil/carrera/clock.c
131,132c
		*hz = HZ*100;
	return (vlong)m->ticks*100;
.
127c
vlong
.
## diffname carrera/clock.c 1999/0301
## diff -e /n/emeliedump/1999/0228/sys/src/brazil/carrera/clock.c /n/emeliedump/1999/0301/sys/src/brazil/carrera/clock.c
131,132c
		*hz = fasthz;

	return (vlong)cyclecount;
.
129a
	uvlong cyclecount;
	int x;

	x = splhi();
	cyclecount = updatefastclock(rdcount());
	splx(x);

.
79c
	count = rdcount();
	wrcompare(count+incr);
	updatefastclock(count);
.
77a
	ulong count;
.
73a
uvlong
updatefastclock(ulong count)
{
	uvlong cyclecount;

	/* keep track of higher precision time */
	cyclecount = count;
	if(cyclecount < m->lastcyclecount)
		m->fastclock += (0x100000000LL - m->lastcyclecount) + cyclecount;
	else
		m->fastclock += cyclecount - m->lastcyclecount;
	m->lastcyclecount = cyclecount;
	return m->fastclock;
}

.
71c
	incr = (m->speed*1000000)/HZ;
	fasthz = m->speed*1000000;
	wrcompare(rdcount()+incr);
.
19a
static ulong		incr;		/* compare register increment */
static uvlong		fasthz;		/* ticks/sec of fast clock */
.
## diffname carrera/clock.c 1999/0302
## diff -e /n/emeliedump/1999/0301/sys/src/brazil/carrera/clock.c /n/emeliedump/1999/0302/sys/src/brazil/carrera/clock.c
84,89c
	delta = count - m->lastcyclecount;
	if(delta < 0)
		delta += 0x100000000LL;
	m->lastcyclecount = count;
	m->fastclock += delta;

.
81c
	vlong delta;
.
## diffname carrera/clock.c 1999/0327
## diff -e /n/emeliedump/1999/0302/sys/src/brazil/carrera/clock.c /n/emeliedump/1999/0327/sys/src/brazil/carrera/clock.c
162a
}

ulong timewarp;

void
idlehands(void)
{
	ulong cnt, cmp, d;
	int x;

	x = splhi();
	cnt = rdcount();
	cmp = rdcompare();
	cnt -= 100;		/* to cover for time from splhi to rdcount */
	d = cmp - cnt;
	if(d > incr+100){
		wrcompare(lastcmp = cnt+incr);
		timewarp++;
//		print("%lud %lud %d %lux\n", cnt, cmp, cnt-cmp, d);
	}
	splx(x);
.
146a

	if(anyready())
		sched();
.
139,141d
100c
	wrcompare(lastcmp = count+incr);
.
85,86d
81c
	ulong delta;
.
75c
	wrcompare(lastcmp = rdcount()+incr);
.
53a
ulong lastcmp;

.
## diffname carrera/clock.c 1999/0328
## diff -e /n/emeliedump/1999/0327/sys/src/brazil/carrera/clock.c /n/emeliedump/1999/0328/sys/src/brazil/carrera/clock.c
183a
#endif
.
169a
#ifdef adsfasdf
.
165,166d
156c
	cnt = rdcount();
	cyclecount = updatefastclock(cnt);
	d = lastcmp - cnt + 100;
	if(d > incr+100){
		wrcompare(lastcmp = cnt+incr);
		timewarp++;
	}
.
152a
	ulong cnt, d;
.
148a
ulong timewarp;

.
## diffname carrera/clock.c 1999/0402
## diff -e /n/emeliedump/1999/0328/sys/src/brazil/carrera/clock.c /n/emeliedump/1999/0402/sys/src/brazil/carrera/clock.c
154,192c
	if(hz != nil)
		*hz = HZ*100;
	return m->ticks*100;
.
149,150d
100,101c
	if(lastcmp+incr < count+100)
		lastcmp = count+incr;
	else
		lastcmp += incr;
	wrcompare(lastcmp);
.
80,92d
76d
54,55d
22a

.
21c
static ulong		lastcmp;
.
## diffname carrera/clock.c 2001/0527 # deleted
## diff -e /n/emeliedump/1999/0402/sys/src/brazil/carrera/clock.c /n/emeliedump/2001/0527/sys/src/9/carrera/clock.c
1,143d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.