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

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


## diffname pc/clock.c 1991/0704
## diff -e /dev/null /n/bootesdump/1991/0704/sys/src/9/safari/clock.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"ureg.h"

void
clockinit(void)
{
	setvec(Clockvec, clock, SEGIG);
}

.
## diffname pc/clock.c 1991/0705
## diff -e /n/bootesdump/1991/0704/sys/src/9/safari/clock.c /n/bootesdump/1991/0705/sys/src/9/safari/clock.c
14a
void
clock(void *arg)
{
	m->ticks++;
	if((m->ticks%185)==0)
		print("%d secs\n", TK2SEC(m->ticks));
	INT0ENABLE;
}
.
8a
/*
 *  8253 timer
 */
enum
{
	Timerctl=	0x43,		/* control port */
	Timercnt=	0x40,		/* timer count port (outb count-1) */
	Timericnt=	0x41,		/* timer count input port */

	Timerlatch=	0x40,		/* latch count into Timericnt */
};

.
7d
## diffname pc/clock.c 1991/0706
## diff -e /n/bootesdump/1991/0705/sys/src/9/safari/clock.c /n/bootesdump/1991/0706/sys/src/9/safari/clock.c
30,32c
	p = m->proc;
	if(p){
		p->pc = ur->eip;
		if (p->state==Running)
			p->time[p->insyscall]++;
	}

	if((m->ticks%185) == 92)
		floppystart();
	else if((m->ticks%185) == 0)
		floppystop();
.
28a
	Proc *p;

.
27c
clock(Ureg *ur)
.
6a
#include	"ureg.h"
.
## diffname pc/clock.c 1991/0709
## diff -e /n/bootesdump/1991/0706/sys/src/9/safari/clock.c /n/bootesdump/1991/0709/sys/src/9/safari/clock.c
39,43d
30a
	static int last;
.
24a

	/*
	 *  make clock output a square wave with a 1/HZ period
	 */
	outb(Tmode, Load0square);
	outb(T0cntr, (Freq/HZ));	/* low byte */
	outb(T0cntr, (Freq/HZ)>>8);	/* high byte */
.
23a
	/*
	 *  set vector for clock interrupts
	 */
.
18c
	Load0square=	0x36,		/*  load counter 0 with 2 bytes,
					 *  output a square wave whose
					 *  period is the counter period
					 */
	Freq=		1193182,	/* Real clock frequency */
.
14,16c
	T0cntr=	0x40,		/* counter ports */
	T1cntr=	0x41,		/* ... */
	T2cntr=	0x42,		/* ... */
	Tmode=	0x43,		/* mode port */
.
## diffname pc/clock.c 1991/0711
## diff -e /n/bootesdump/1991/0709/sys/src/9/safari/clock.c /n/bootesdump/1991/0711/sys/src/9/safari/clock.c
51c
		p->pc = ur->pc;
.
48a

	checkalarms();

.
46d
## diffname pc/clock.c 1991/0716
## diff -e /n/bootesdump/1991/0711/sys/src/9/safari/clock.c /n/bootesdump/1991/0716/sys/src/9/safari/clock.c
32c
	setvec(Clockvec, clock);
.
## diffname pc/clock.c 1991/0719
## diff -e /n/bootesdump/1991/0716/sys/src/9/safari/clock.c /n/bootesdump/1991/0719/sys/src/9/safari/clock.c
25a
/*
 *  delay for l milliseconds
 */
void
delay(int l)
{
	int i;

	while(--l){
		for(i=0; i < 404; i++)
			;
	}
}

.
## diffname pc/clock.c 1991/0730
## diff -e /n/bootesdump/1991/0719/sys/src/9/safari/clock.c /n/bootesdump/1991/0730/sys/src/9/safari/clock.c
70a
/*
	if(u && (ur->flags&IFLAG) && p && p->state==Running){
		if(anyready()){
			if(p->hasspin)
				p->hasspin = 0;
			else
				sched();
		}
	}
/**/
.
63a
	mouseclock();
.
## diffname pc/clock.c 1991/0801
## diff -e /n/bootesdump/1991/0730/sys/src/9/safari/clock.c /n/bootesdump/1991/0801/sys/src/9/safari/clock.c
80,81c
	}/**/
.
72,73c

/*	if(u && p && p->state==Running){
.
## diffname pc/clock.c 1991/0802
## diff -e /n/bootesdump/1991/0801/sys/src/9/safari/clock.c /n/bootesdump/1991/0802/sys/src/9/safari/clock.c
80c
		if((ur->cs&0xffff) == UESEL){ /* if was in user mode */
			if(u->nnote)
				notify(ur);
		}
	}
.
73c
	if(u && p && p->state==Running){
.
## diffname pc/clock.c 1991/0806
## diff -e /n/bootesdump/1991/0802/sys/src/9/safari/clock.c /n/bootesdump/1991/0806/sys/src/9/safari/clock.c
64a
	uartintr0(ur);
.
## diffname pc/clock.c 1991/0807
## diff -e /n/bootesdump/1991/0806/sys/src/9/safari/clock.c /n/bootesdump/1991/0807/sys/src/9/safari/clock.c
65d
62a
	uartintr0(ur);

	if(m->ticks % 50)
		return;

.
## diffname pc/clock.c 1991/0808
## diff -e /n/bootesdump/1991/0807/sys/src/9/safari/clock.c /n/bootesdump/1991/0808/sys/src/9/safari/clock.c
89a
}

/*
 *  a faster (1 MS) clock tick for a non-interrupting serial port or
 *  kernel profiling.  m->ticks still increments as usual.
 */
void
fclock(Ureg *ur)
{
	static ulong ticks;

	uartintr0(ur);		/* poll the serial port */
	if((ticks++ % (FHZ/HZ)) == 0)
		clock(ur);
}

void
fclockinit(void)
{
	int x;

	/*
	 *  set vector for clock interrupts
	 */
	setvec(Clockvec, fclock);

	/*
	 *  make clock output a square wave with a 1/FHZ period
	 */
	x = splhi();
	outb(Tmode, Load0square);
	outb(T0cntr, (Freq/FHZ));	/* low byte */
	outb(T0cntr, (Freq/FHZ)>>8);	/* high byte */
	splx(x);
.
85c
		/*
		 *  notes for processes that might be spinning
		 *  in user mode.
		 */
		if((ur->cs&0xffff) == UESEL){
.
78a
		/*
		 *  preemption
		 */
.
70a
	/*
	 *  process time accounting
	 */
.
63,67d
23a
	FHZ=		1000,		/* hertz for fast clock */
.
## diffname pc/clock.c 1991/0822
## diff -e /n/bootesdump/1991/0808/sys/src/9/safari/clock.c /n/bootesdump/1991/0822/sys/src/9/safari/clock.c
97,130d
## diffname pc/clock.c 1991/0823
## diff -e /n/bootesdump/1991/0822/sys/src/9/safari/clock.c /n/bootesdump/1991/0823/sys/src/9/safari/clock.c
65d
## diffname pc/clock.c 1991/1112
## diff -e /n/bootesdump/1991/0823/sys/src/9/safari/clock.c /n/bootesdump/1991/1112/sys/src/9/safari/clock.c
90,93c
		if((ur->cs&0xffff) == UESEL)
			notify(ur);
.
## diffname pc/clock.c 1991/1113
## diff -e /n/bootesdump/1991/1112/sys/src/9/safari/clock.c /n/bootesdump/1991/1113/sys/src/9/safari/clock.c
74a
	nrun = (nrdy+nrun)*1000;
	MACHP(0)->load = (MACHP(0)->load*19+nrun)/20;
.
70a
		nrun = 1;
.
64a
	uartclock();
.
60a
	int nrun = 0;
.
24d
## diffname pc/clock.c 1991/1115
## diff -e /n/bootesdump/1991/1113/sys/src/9/safari/clock.c /n/bootesdump/1991/1115/sys/src/9/safari/clock.c
90,95c
		if((ur->cs&0xffff) == UESEL){
			spllo();		/* in case we fault */
			(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);	/* profiling clock */
			splhi();
		}
.
## diffname pc/clock.c 1991/1116
## diff -e /n/bootesdump/1991/1115/sys/src/9/safari/clock.c /n/bootesdump/1991/1116/sys/src/9/safari/clock.c
94a
#endif asdf
.
89a
#ifdef asdf
.
## diffname pc/clock.c 1992/0321
## diff -e /n/bootesdump/1991/1116/sys/src/9/safari/clock.c /n/bootesdump/1992/0321/sys/src/9/safari/clock.c
2c
#include	"../port/lib.h"
.
## diffname pc/clock.c 1992/0820
## diff -e /n/bootesdump/1992/0808/sys/src/9/safari/clock.c /n/bootesdump/1992/0820/sys/src/9/pc/clock.c
96d
90d
## diffname pc/clock.c 1992/0922
## diff -e /n/bootesdump/1992/0820/sys/src/9/pc/clock.c /n/bootesdump/1992/0922/sys/src/9/pc/clock.c
53a

	/*
	 *  measure cpu speed to make delay() system
	 *  independent
	 */
	delay(100);
	outb(Tmode, Latch0);
	dc = inb(T0cntr);
	dc |= inb(T0cntr)<<8;
.
42a
	ulong dc;	/* change in counter */

.
22a
	Latch0=		0x06,
.
## diffname pc/clock.c 1992/0923
## diff -e /n/bootesdump/1992/0922/sys/src/9/pc/clock.c /n/bootesdump/1992/0923/sys/src/9/pc/clock.c
64,65c
	x = inb(T0cntr);
	x |= inb(T0cntr)<<8;
	delay(10);
	outb(Tmode, Latch0);
	y = inb(T0cntr);
	y |= inb(T0cntr)<<8;
	x -= y;

	/*
	 *  fix count, the factor of 2 is a hack
	 */
	delayloop = (delayloop*1193*10)/x;
	if(delayloop == 0)
		delayloop = 1;
.
62d
59,60c
	 *  measure time for delay(10) with current delayloop count
.
54c
	outb(Tmode, Load0|Square);
.
44c
	ulong x, y;	/* change in counter */
.
38d
35,36c
	while(l-- > 0)
		for(i=0; i < delayloop; i++)
.
33c
	ulong i;
.
28c
 *  delay for l milliseconds more or less.  delayloop is set by
 *  clockinit() to match the actual CPU speed.
.
26a
static ulong delayloop = 1000;

.
19,24c
	/* commands */
	Latch0=	0x00,		/* latch counter 0's value */
	Load0=	0x30,		/* load counter 0 with 2 bytes */

	/* modes */
	Square=	0x36,		/* perioic square wave */

	Freq=	1193182,	/* Real clock frequency */
.
## diffname pc/clock.c 1993/0226
## diff -e /n/bootesdump/1992/0923/sys/src/9/pc/clock.c /n/bootesdump/1993/0226/sys/src/9/pc/clock.c
91a
	mouseclock();
.
## diffname pc/clock.c 1993/0915
## diff -e /n/bootesdump/1993/0226/sys/src/9/pc/clock.c /n/fornaxdump/1993/0915/sys/src/brazil/pc/clock.c
107,122c
	if(up == 0 || (ur->cs&0xffff) != UESEL || up->state != Running)
		return;

	if(anyready())
		sched();

	/* user profiling clock */
	spllo();		/* in case we fault */
	(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
	splhi();
.
75c
	 *  fix count
.
## diffname pc/clock.c 1993/1113
## diff -e /n/fornaxdump/1993/0915/sys/src/brazil/pc/clock.c /n/fornaxdump/1993/1113/sys/src/brazil/pc/clock.c
91d
## diffname pc/clock.c 1993/1124
## diff -e /n/fornaxdump/1993/1113/sys/src/brazil/pc/clock.c /n/fornaxdump/1993/1124/sys/src/brazil/pc/clock.c
80,115d
53c
	setvec(Clockvec, clock, 0);
.
44a
static void
clock(Ureg *ur, void *arg)
{
	Proc *p;
	int nrun = 0;

	USED(arg);

	m->ticks++;

	checkalarms();
	mouseclock();

	/*
	 *  process time accounting
	 */
	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;

	if(up == 0 || (ur->cs&0xffff) != UESEL || up->state != Running)
		return;

	if(anyready())
		sched();

	/* user profiling clock */
	spllo();		/* in case we fault */
	(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
	splhi();
}

.
## diffname pc/clock.c 1994/0128
## diff -e /n/fornaxdump/1993/1124/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0128/sys/src/brazil/pc/clock.c
56a
	hardclock();
.
## diffname pc/clock.c 1994/0219
## diff -e /n/fornaxdump/1994/0128/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0219/sys/src/brazil/pc/clock.c
57a
	uartclock();
.
## diffname pc/clock.c 1994/0302
## diff -e /n/fornaxdump/1994/0219/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0302/sys/src/brazil/pc/clock.c
84a
/*
 *  experimentally determined and justified by counting cycles in
 *  delay()'s inner loop
 */
enum
{
	mul386=	380,
	mul486=	121,
};

void
printcpufreq(void)
{
	ulong freq;
	int cpu;

	switch(cpu = x86()){
	default:
	case 486:
		freq = mul486;
		break;
	case 386:
		freq = mul386;
		break;
	}
	freq *= delayloop;
	freq /= 10000;
	print("CPU is a %ud MHz %d\n", freq, cpu);
}

.
## diffname pc/clock.c 1994/0507
## diff -e /n/fornaxdump/1994/0302/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0507/sys/src/brazil/pc/clock.c
76,82c
	/* last because it could spllo() */
	mouseclock();
.
73,74c
	if(up && (ur->cs&0xffff) == UESEL && up->state == Running){
		if(anyready())
			sched();
	
		/* user profiling clock */
		spllo();		/* in case we fault */
		(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
		splhi();
	}
.
56d
## diffname pc/clock.c 1994/0510
## diff -e /n/fornaxdump/1994/0507/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0510/sys/src/brazil/pc/clock.c
83c
	if(hwcursor)
		mouseclock();
	else {
		spllo();
		mouseclock();
		splhi();
	}
.
57d
54a
	uartclock();
.
49a
	extern int hwcursor;
.
## diffname pc/clock.c 1994/0512
## diff -e /n/fornaxdump/1994/0510/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0512/sys/src/brazil/pc/clock.c
136c
	outb(Tmode, Load0|Trigger);
.
134c
	 *  set clock for 1/HZ seconds
.
90a

	if(islow)
		splhi();
.
89d
87c
		if(!islow){
			islow = 1;
			spllo();
		}
.
82a
	/*
	 *  anything from here down can be running spllo()
	 */

.
80d
77a
		islow = 1;
.
53a
	/*
	 *  set clock for 1/HZ seconds
	 */
	outb(Tmode, Load0|Trigger);
	outb(T0cntr, (Freq/HZ));	/* low byte */
	outb(T0cntr, (Freq/HZ)>>8);	/* high byte */

.
49a
	int islow = 0;
.
24a
	Trigger= 0x30,		/* interrupt on terminal count */
.
## diffname pc/clock.c 1994/0525
## diff -e /n/fornaxdump/1994/0512/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0525/sys/src/brazil/pc/clock.c
105a

	mouseclock();
.
95,104c
	if(!islow){
		islow = 1;
		spllo();
.
52d
## diffname pc/clock.c 1994/0603
## diff -e /n/fornaxdump/1994/0525/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0603/sys/src/brazil/pc/clock.c
148c
	outb(Tmode, Load0|Square);
.
55,61d
## diffname pc/clock.c 1994/0610
## diff -e /n/fornaxdump/1994/0603/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0610/sys/src/brazil/pc/clock.c
115a
	case 586:
		freq = mul586;
		break;
.
105a
	mul586=	121,
.
99,100c
 *  experimentally determined
.
## diffname pc/clock.c 1994/0715
## diff -e /n/fornaxdump/1994/0610/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0715/sys/src/brazil/pc/clock.c
59a
	uartclock();
.
57d
## diffname pc/clock.c 1994/0716
## diff -e /n/fornaxdump/1994/0715/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0716/sys/src/brazil/pc/clock.c
163,165c
	x >>= 1;

	/*
 	 *  figure out clock frequency and a loop multiplier for delay().
	 */
	switch(cputype = x86()){
	case 386:
		cycles = 30;
		break;
	case 486:
		cycles = 24;
		break;
	default:
		cycles = 23;
		break;
	}
	cpufreq = (cycles*loops) * (Freq/x);
	loopconst = (cpufreq/1000)/cycles;	/* AAM+LOOP's for 1 ms */
.
161c
	 *  counter  goes at twice the frequency, once per transition,
	 *  i.e., twice per the square wave
.
154c
	aamloop(loops);
.
150a
	loops = 10000;
.
149c
	 *  measure time for the loop
	 *
	 *			MOVL	loops,CX
	 *	aaml1:	 	AAM
	 *			LOOP	aaml1
	 *
	 *  the time for the loop should be independent from external
	 *  cache's and memory system since it fits in the execution
	 *  prefetch buffer.
	 *
.
134a
	ulong cycles, loops;
.
111,128c
	print("CPU is a %ud Hz %d\n", cpufreq, cputype);
.
103,106c
	aamloop(l*loopconst);
}
.
101c
void
delay(int l)
.
99c
 *  delay for l milliseconds more or less.  delayloop is set by
 *  clockinit() to match the actual CPU speed.
.
97a

.
32,45d
30c
static int cpufreq = 66;
static int cputype = 486;
static int loopconst = 100;
.
## diffname pc/clock.c 1994/0717
## diff -e /n/fornaxdump/1994/0716/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0717/sys/src/brazil/pc/clock.c
163c
	cpufreq = loops*((cycles*Freq)/x);
.
157c
		cycles = 22;
.
86d
## diffname pc/clock.c 1994/0719
## diff -e /n/fornaxdump/1994/0717/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0719/sys/src/brazil/pc/clock.c
163a

	/* convert to MHz */
	cpufreq = cpufreq/1000000;
.
153c
		cycles = 32;
.
99c
	print("CPU is a %ud MHz %d\n", cpufreq, cputype);
.
## diffname pc/clock.c 1994/0806
## diff -e /n/fornaxdump/1994/0719/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0806/sys/src/brazil/pc/clock.c
159c
		cycles = 24;
.
## diffname pc/clock.c 1994/0809
## diff -e /n/fornaxdump/1994/0806/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0809/sys/src/brazil/pc/clock.c
165,166c
	/*
	 *  add in possible .1% error and convert to MHz
	 */
	cpumhz = (cpufreq + cpufreq/1000)/1000000;
.
151,161d
144c
	 *  i.e., twice per square wave
.
132d
119a

.
107a
	switch(cputype = x86()){
	case 386:
		loops = 10000;
		cycles = 32;
		break;
	case 486:
		loops = 10000;
		cycles = 22;
		break;
	default:
		loops = 30000;
		cycles = 23;
		break;
	}

.
99c
	print("CPU is a %ud MHz (%ud Hz) %d\n", cpumhz, cpufreq, cputype);
.
67,69c
		if((ur->cs&0xffff) == UESEL){
			islow = 1;
			spllo();		/* in case we fault */
			(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
		}
.
62c
	if(up && up->state == Running){
.
30c
static int cpufreq = 66000000;
static int cpumhz = 66;
.
## diffname pc/clock.c 1994/0810
## diff -e /n/fornaxdump/1994/0809/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/0810/sys/src/brazil/pc/clock.c
84,86d
75,82d
72d
68,70c
		if((ur->cs&0xffff) == UESEL)
.
40d
## diffname pc/clock.c 1994/1029
## diff -e /n/fornaxdump/1994/0810/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1029/sys/src/brazil/pc/clock.c
87c
	print("CPU is a %ud Hz %d (CPUID: AX=0x%8.8lux, DX=0x%8.8lux)\n",
		cpufreq, cputype, cpuidax, cpuiddx);
.
33a
ulong cpuidax, cpuiddx;
.
## diffname pc/clock.c 1994/1031
## diff -e /n/fornaxdump/1994/1029/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1031/sys/src/brazil/pc/clock.c
147,157c
		/*
	 	 *  figure out clock frequency and a loop multiplier for delay().
		 */
		cpufreq = loops*((t->aalcycles*Freq)/x);
		loopconst = (cpufreq/1000)/t->aalcycles;	/* AAM+LOOP's for 1 ms */
	} while(x > 0);
.
126,145c
		if(x < 0)
			x += 2^16;
		if(x > (2^15))
			break;
	
		/*
		 *  counter  goes at twice the frequency, once per transition,
		 *  i.e., twice per square wave
		 */
		x >>= 1;
.
124a
	/* use biggest loop that works */
	for(loops = 10000; ; loops += 5000) {
		/*
		 *  measure time for the loop
		 *
		 *			MOVL	loops,CX
		 *	aaml1:	 	AAM
		 *			LOOP	aaml1
		 *
		 *  the time for the loop should be independent of external
		 *  cache and memory system since it fits in the execution
		 *  prefetch buffer.
		 *
		 */
		outb(Tmode, Latch0);
		x = inb(T0cntr);
		x |= inb(T0cntr)<<8;
		aamloop(loops);
		outb(Tmode, Latch0);
		y = inb(T0cntr);
		y |= inb(T0cntr)<<8;
		x -= y;
.
118a
	 *  figure out what we are
	 */
	x86cpuid(&cpuidax, &cpuiddx);
	family = FAMILY(cpuidax);
	model = MODEL(cpuidax);
	for(t = x86type; t->name; t++)
		if((t->family == family && t->model == model)
		|| (t->family == family && t->model == -1)
		|| (t->family == -1))
			break;
	cputype = t;

	/*
.
98,112d
95,96c
	int x, y;	/* change in counter */
	int family, model, loops;
	X86type *t;
.
91a
int
x86(void)
{
	return cputype->family;
}

.
74a
#define STEPPING(x)	((x)&0xf)
#define MODEL(x)	(((x)>>4)&0xf)
#define FAMILY(x)	(((x)>>8)&0xf)

enum
{
	/* flags */
	CpuidFPU	= 0x001,	/* on-chip floating point unit */
	CpuidMCE	= 0x080,	/* machine check exception */
	CpuidCX8	= 0x100,	/* CMPXCHG8B instruction */
};

typedef struct
{
	int family;
	int model;
	int aalcycles;
	char *name;
} X86type;

X86type x86type[] =
{
	/* from the cpuid instruction */
	{ 4,	0,	22,	"Intel486DX", },
	{ 4,	1,	22,	"Intel486DX", },
	{ 4,	2,	22,	"Intel486SX", },
	{ 4,	4,	22,	"Intel486DX2", },
	{ 4,	5,	22,	"Intel486SL", },
	{ 4,	8,	22,	"IntelDX4", },
	{ 5,	1,	23,	"Pentium510", },
	{ 5,	2,	23,	"Pentium735", },

	/* family defaults */
	{ 3,	-1,	32,	"Intel386", },
	{ 4,	-1,	22,	"Intel486", },
	{ 5,	-1,	23,	"Pentium", },

	/* total default */
	{ -1,	-1,	23,	"unknown", },
};

static X86type	*cputype;

.
34c
static int cpuidax, cpuiddx;
.
32d
## diffname pc/clock.c 1994/1101
## diff -e /n/fornaxdump/1994/1031/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1101/sys/src/brazil/pc/clock.c
206,211c
	if(x < 0)
		x += 2^16;

	/*
	 *  counter  goes at twice the frequency, once per transition,
	 *  i.e., twice per square wave
	 */
	x >>= 1;

	/*
 	 *  figure out clock frequency and a loop multiplier for delay().
	 */
	cpufreq = loops*((t->aalcycles*Freq)/x);
	loopconst = (cpufreq/1000)/t->aalcycles;	/* AAM+LOOP's for 1 ms */
.
195,204c
	/*
	 *  measure time for the loop
	 *
	 *			MOVL	loops,CX
	 *	aaml1:	 	AAM
	 *			LOOP	aaml1
	 *
	 *  the time for the loop should be independent of external
	 *  cache and memory system since it fits in the execution
	 *  prefetch buffer.
	 *
	 */
	outb(Tmode, Latch0);
	x = inb(T0cntr);
	x |= inb(T0cntr)<<8;
	aamloop(loops);
	outb(Tmode, Latch0);
	y = inb(T0cntr);
	y |= inb(T0cntr)<<8;
	x -= y;
.
173,193c
	if(t->family == 3)
		loops = 10000;
	else
		loops = 30000;
.
130,131c
	print("CPU is a %d MHz %s (cpuid: ax %lux dx %lux)\n",
		cpumhz, cputype->name, cpuidax, cpuiddx);
.
## diffname pc/clock.c 1994/1102
## diff -e /n/fornaxdump/1994/1101/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1102/sys/src/brazil/pc/clock.c
108c
	{ 4,	-1,	24,	"Intel486", },
.
97,102c
	{ 4,	0,	24,	"Intel486DX", },
	{ 4,	1,	24,	"Intel486DX", },
	{ 4,	2,	24,	"Intel486SX", },
	{ 4,	4,	24,	"Intel486DX2", },
	{ 4,	5,	24,	"Intel486SL", },
	{ 4,	8,	24,	"IntelDX4", },
.
## diffname pc/clock.c 1994/1116
## diff -e /n/fornaxdump/1994/1102/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1116/sys/src/brazil/pc/clock.c
99a
	{ 4,	3,	24,	"Intel486DX2", },
.
## diffname pc/clock.c 1994/1120
## diff -e /n/fornaxdump/1994/1116/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1120/sys/src/brazil/pc/clock.c
109c
	{ 4,	-1,	22,	"Intel486", },
.
97,103c
	{ 4,	0,	22,	"Intel486DX", },
	{ 4,	1,	22,	"Intel486DX", },
	{ 4,	2,	22,	"Intel486SX", },
	{ 4,	3,	22,	"Intel486DX2", },
	{ 4,	4,	22,	"Intel486DX2", },
	{ 4,	5,	22,	"Intel486SL", },
	{ 4,	8,	22,	"IntelDX4", },
.
## diffname pc/clock.c 1994/1201
## diff -e /n/fornaxdump/1994/1120/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1201/sys/src/brazil/pc/clock.c
218c
	cpumhz = (cpufreq + cpufreq/500)/1000000;
.
216c
	 *  add in possible .2% error and convert to MHz
.
200,202d
179,198c
		if(x > Freq/(3*HZ))
			break;
	}
.
173,177c
	/* find biggest loop that doesn't wrap */
	incr = 16000000/(t->aalcycles*HZ*2);
	for(loops = incr; loops < 64*1024; loops += incr) {
	
		/*
		 *  measure time for the loop
		 *
		 *			MOVL	loops,CX
		 *	aaml1:	 	AAM
		 *			LOOP	aaml1
		 *
		 *  the time for the loop should be independent of external
		 *  cache and memory system since it fits in the execution
		 *  prefetch buffer.
		 *
		 */
		outb(Tmode, Latch0);
		x = inb(T0cntr);
		x |= inb(T0cntr)<<8;
		aamloop(loops);
		outb(Tmode, Latch0);
		y = inb(T0cntr);
		y |= inb(T0cntr)<<8;
		x -= y;
	
		if(x < 0)
			x += Freq/HZ;
.
145c
	int family, model, loops, incr;
.
## diffname pc/clock.c 1994/1206
## diff -e /n/fornaxdump/1994/1201/sys/src/brazil/pc/clock.c /n/fornaxdump/1994/1206/sys/src/brazil/pc/clock.c
174a
	x = 2000;
.
## diffname pc/clock.c 1995/0104
## diff -e /n/fornaxdump/1994/1206/sys/src/brazil/pc/clock.c /n/fornaxdump/1995/0104/sys/src/brazil/pc/clock.c
48,60d
44a
	accounttime();
.
38,40d
## diffname pc/clock.c 1995/0109
## diff -e /n/fornaxdump/1995/0104/sys/src/brazil/pc/clock.c /n/fornaxdump/1995/0109/sys/src/brazil/pc/clock.c
48c
		if(anyready() && !up->inlock)
.
## diffname pc/clock.c 1995/0110
## diff -e /n/fornaxdump/1995/0109/sys/src/brazil/pc/clock.c /n/fornaxdump/1995/0110/sys/src/brazil/pc/clock.c
48c
		if(anyready())
.
## diffname pc/clock.c 1995/0215
## diff -e /n/fornaxdump/1995/0110/sys/src/brazil/pc/clock.c /n/fornaxdump/1995/0215/sys/src/brazil/pc/clock.c
110c
	l *= loopconst;
	if(l <= 0)
		l = 1;
	aamloop(l);
}

/*
 *  microsecond delay
 */
void
microdelay(int l)
{
	l *= loopconst;
	l /= 1000;
	if(l <= 0)
		l = 1;
	aamloop(l);
.
## diffname pc/clock.c 1995/0527
## diff -e /n/fornaxdump/1995/0215/sys/src/brazil/pc/clock.c /n/fornaxdump/1995/0527/sys/src/brazil/pc/clock.c
165a

	switch(cputype->family){
	case 3:
		conf.copymode = 1;	/* copy on reference */
		break;
	default:
		conf.copymode = 0;	/* copy on write */
		break;
	}
.
136,141d
## diffname pc/clock.c 1995/0812
## diff -e /n/fornaxdump/1995/0527/sys/src/brazil/pc/clock.c /n/fornaxdump/1995/0812/sys/src/brazil/pc/clock.c
55,56d
45a
	mouseclock();
.
## diffname pc/clock.c 1995/0910
## diff -e /n/fornaxdump/1995/0812/sys/src/brazil/pc/clock.c /n/fornaxdump/1995/0910/sys/src/brazil/pc/clock.c
46a
	randomclock();
.
## diffname pc/clock.c 1996/0202
## diff -e /n/fornaxdump/1995/0910/sys/src/brazil/pc/clock.c /n/fornaxdump/1996/0202/sys/src/brazil/pc/clock.c
41a
	if(active.exiting && (active.machs & (1<<m->machno)))
		exit(0);

.
## diffname pc/clock.c 1996/0303
## diff -e /n/fornaxdump/1996/0202/sys/src/brazil/pc/clock.c /n/fornaxdump/1996/0303/sys/src/brazil/pc/clock.c
58a
			segclock(ur->pc);
		}
.
57c
		if((ur->cs&0xffff) == UESEL) {
.
## diffname pc/clock.c 1996/0928
## diff -e /n/fornaxdump/1996/0303/sys/src/brazil/pc/clock.c /n/fornaxdump/1996/0928/sys/src/brazil/pc/clock.c
100a
	{ 6,	-1,	16,	"PentiumPro", },
.
95a
	{ 6,	1,	16,	"PentiumPro", },/* determined by trial and error */
.
## diffname pc/clock.c 1997/0103
## diff -e /n/fornaxdump/1996/0928/sys/src/brazil/pc/clock.c /n/fornaxdump/1997/0103/sys/src/brazil/pc/clock.c
24c
	Square=	0x36,		/* periodic square wave */
.
## diffname pc/clock.c 1997/0327
## diff -e /n/fornaxdump/1997/0103/sys/src/brazil/pc/clock.c /n/emeliedump/1997/0327/sys/src/brazil/pc/clock.c
129,232c
	microsecs *= m->loopconst;
	microsecs /= 1000;
	if(microsecs <= 0)
		microsecs = 1;
	aamloop(microsecs);
.
127c
microdelay(int microsecs)
.
123,125d
117,120c
	millisecs *= m->loopconst;
	if(millisecs <= 0)
		millisecs = 1;
	aamloop(millisecs);
.
115c
delay(int millisecs)
.
64,113d
56,60c
	if((ureg->cs & 0xFFFF) == UESEL) {
		(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
		segclock(ureg->pc);
.
52,54c
	if(up == 0 || up->state != Running)
		return;

	if(anyready())
		sched();
.
47,50c
	if(m->machno == 0){
		lock(&clock0lock);
		for(lp = clock0link; lp; lp = lp->link)
			lp->clock();
		unlock(&clock0lock);
	}
.
45d
41a
	accounttime();
	if(kproftimer != nil)
		kproftimer(ureg->pc);
	if((active.machs & (1<<m->machno)) == 0)
		return;
.
40a
	if(m->proc)
		m->proc->pc = ureg->pc;
.
38c
	Clock0link *lp;
.
35,36c
void
clockintr(Ureg* ureg, void*)
.
30,33c
	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);
}
.
27,28c
void
addclock0link(void (*clock)(void))
{
	Clock0link *lp;
.
23,25c
static Clock0link *clock0link;
static Lock clock0lock;
.
19,21c
typedef struct Clock0link Clock0link;
typedef struct Clock0link {
	void		(*clock)(void);
	Clock0link*	link;
} Clock0link;
.
9,17c
void (*kproftimer)(ulong);
.
1,7c
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "ureg.h"
.
## diffname pc/clock.c 1998/0331
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/pc/clock.c /n/emeliedump/1998/0331/sys/src/brazil/pc/clock.c
58c
		iunlock(&clock0lock);
.
55c
		ilock(&clock0lock);
.
## diffname pc/clock.c 1998/0710
## diff -e /n/emeliedump/1998/0331/sys/src/brazil/pc/clock.c /n/emeliedump/1998/0710/sys/src/brazil/pc/clock.c
90a

.
## diffname pc/clock.c 1998/0717
## diff -e /n/emeliedump/1998/0710/sys/src/brazil/pc/clock.c /n/emeliedump/1998/0717/sys/src/brazil/pc/clock.c
40a
	fastticks(nil);
.
## diffname pc/clock.c 1998/0725
## diff -e /n/emeliedump/1998/0717/sys/src/brazil/pc/clock.c /n/emeliedump/1998/0725/sys/src/brazil/pc/clock.c
61a
	if(m->flushmmu){
		if(up)
			flushmmu();
		m->flushmmu = 0;
	}

.
## diffname pc/clock.c 1999/0129
## diff -e /n/emeliedump/1998/0725/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0129/sys/src/brazil/pc/clock.c
98a
vlong
fastticks(uvlong *hz)
{
	return (*arch->fastclock)(hz) + fastoff;
}

void
syncfastticks(vlong secs)
{
	vlong x, ofastoff;
	vlong err, deltat;

	/* set new offset */
	x = (*arch->fastclock)(nil);
	ofastoff = fastoff;
	fastoff = secs*fasthz - x;

	/* calculate first order diversion rate */
	err = fastoff - ofastoff;
	deltat = secs - fastsecs;
	fastsecs = secs;
	deltat *= fasthz;
}
.
19a
/* for fast clock */
static	vlong	fastoff;
static	vlong	fastsecs;
	uvlong	fasthz;

.
## diffname pc/clock.c 1999/0130
## diff -e /n/emeliedump/1999/0129/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0130/sys/src/brazil/pc/clock.c
102,125d
20,24d
## diffname pc/clock.c 1999/0205
## diff -e /n/emeliedump/1999/0130/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0205/sys/src/brazil/pc/clock.c
97a

ulong
TK2MS(ulong ticks)
{
	uvlong t, hz;

	t = ticks;
	hz = HZ;
	t *= 1000L;
	t = t/hz;
	ticks = t;
	return ticks;
}
.
## diffname pc/clock.c 1999/0217
## diff -e /n/emeliedump/1999/0205/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0217/sys/src/brazil/pc/clock.c
41d
## diffname pc/clock.c 1999/0218
## diff -e /n/emeliedump/1999/0217/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0218/sys/src/brazil/pc/clock.c
43a
	fixtod();
.
40a
	fastticks(nil);
.
## diffname pc/clock.c 1999/0219
## diff -e /n/emeliedump/1999/0218/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0219/sys/src/brazil/pc/clock.c
45d
## diffname pc/clock.c 1999/0228
## diff -e /n/emeliedump/1999/0219/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0228/sys/src/brazil/pc/clock.c
98,110d
## diffname pc/clock.c 1999/0301
## diff -e /n/emeliedump/1999/0228/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0301/sys/src/brazil/pc/clock.c
97a

ulong
TK2MS(ulong ticks)
{
	uvlong t, hz;

	t = ticks;
	hz = HZ;
	t *= 1000L;
	t = t/hz;
	ticks = t;
	return ticks;
}
.
## diffname pc/clock.c 1999/0310
## diff -e /n/emeliedump/1999/0301/sys/src/brazil/pc/clock.c /n/emeliedump/1999/0310/sys/src/brazil/pc/clock.c
40a
	// this needs to be here for synchronizing mp clocks
	// see mp.c's squidboy()
.
## diffname pc/clock.c 2000/1106
## diff -e /n/emeliedump/1999/0310/sys/src/brazil/pc/clock.c /n/emeliedump/2000/1106/sys/src/9/pc/clock.c
70,79c
	portclock(ureg);
.
48,63d
44,46d
39,40d
21,36d
9,19d
## diffname pc/clock.c 2001/0710
## diff -e /n/emeliedump/2000/1106/sys/src/9/pc/clock.c /n/emeliedump/2001/0710/sys/src/9/pc/clock.c
13c
	// see pc/mp.c's squidboy()
.
## diffname pc/clock.c 2001/0711
## diff -e /n/emeliedump/2001/0710/sys/src/9/pc/clock.c /n/emeliedump/2001/0711/sys/src/9/pc/clock.c
44,55d
## diffname pc/clock.c 2001/0905
## diff -e /n/emeliedump/2001/0711/sys/src/9/pc/clock.c /n/emeliedump/2001/0905/sys/src/9/pc/clock.c
43a
ulong
TK2MS(ulong ticks)
{
	uvlong t, hz;

	t = ticks;
	hz = HZ;
	t *= 1000L;
	t = t/hz;
	ticks = t;
	return ticks;
}
.
## diffname pc/clock.c 2002/0405
## diff -e /n/emeliedump/2001/0905/sys/src/9/pc/clock.c /n/emeliedump/2002/0405/sys/src/9/pc/clock.c
12,13c
nclockintr++;
	/* this has to get called every tick or the 8253 timer will overflow */
.
8a
/*
 *  this is called both by the mp's clock interrupt and
 *  by the clockintr0 for the i8253
 */
int nclockintr;
.
## diffname pc/clock.c 2002/0406
## diff -e /n/emeliedump/2002/0405/sys/src/9/pc/clock.c /n/emeliedump/2002/0406/sys/src/9/pc/clock.c
17d
13d
## diffname pc/clock.c 2002/0710
## diff -e /n/emeliedump/2002/0406/sys/src/9/pc/clock.c /n/emeliedump/2002/0710/sys/src/9/pc/clock.c
46,58d
## diffname pc/clock.c 2002/0822
## diff -e /n/emeliedump/2002/0710/sys/src/9/pc/clock.c /n/emeliedump/2002/0822/sys/src/9/pc/clock.c
45a

/*  
 *  performance measurement ticks.  must be low overhead.
 *  doesn't have to count over a second.
 */
ulong
perfticks(void)
{
	uvlong x;

	if(!m->havetsc)
		return ticks;
	rdtsc(&x);
	return x;
}
.
## diffname pc/clock.c 2002/0928 # deleted
## diff -e /n/emeliedump/2002/0822/sys/src/9/pc/clock.c /n/emeliedump/2002/0928/sys/src/9/pc/clock.c
1,60d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].