~kris/9p

9hist

ref: e263c22bc310d82606b8ea942bfb5df5acd9848d 9hist/ss/clock.c -rw-r--r-- 1.1 KiB
e263c22b — David du Colombier Plan 9 from Bell Labs 1993-01-08 33 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"

#include	"ureg.h"

void
delay(int ms)
{
	int i;

	ms *= 6666;		/* experimentally determined */
	if(conf.ss2)
		ms *= 2;
	for(i=0; i<ms; i++)
		;
}

typedef struct Ctr Ctr;
struct Ctr
{
	ulong	ctr0;
	ulong	lim0;
	ulong	ctr1;
	ulong	lim1;
};
Ctr	*ctr;

void
clockinit(void)
{
	KMap *k;

	k = kmappa(CLOCK, PTENOCACHE|PTEIO);
	ctr = (Ctr*)k->va;
	ctr->lim1 = (CLOCKFREQ/HZ)<<10;
}

void
clock(Ureg *ur)
{
	Proc *p;
	ulong i, nrun = 0;

	i = ctr->lim1;	/* clear interrupt */
	USED(i);
	m->ticks++;
	p = m->proc;
	if(p){
		nrun = 1;
		p->pc = ur->pc;
		if (p->state==Running)
			p->time[p->insyscall]++;
	}
	nrun = (nrdy+nrun)*1000;
	MACHP(0)->load = (MACHP(0)->load*19+nrun)/20;

	checkalarms();
	kbdclock();
	mouseclock();
	sccclock();
	kproftimer(ur->pc);
	if(m->fpunsafe)
		return;

	if((ur->psr&SPL(0xF))==0 && p && p->state==Running) {
		if(anyready()){
			if(p->hasspin)
				p->hasspin = 0;
			else
				sched();
		}
		if((ur->psr&PSRPSUPER) == 0)
			*(ulong*)(USTKTOP-BY2WD) += TK2MS(1);
	}
}