plan 9 kernel history: overview | file list | diff list

1999/0429/alphapc/clock.c (diff list | history)

1999/0415/sys/src/9/alphapc/clock.c:4,91999/0429/sys/src/9/alphapc/clock.c:4,10 (short | long | prev | next)
1999/0415    
#include	"dat.h" 
#include	"fns.h" 
#include	"io.h" 
1999/0429    
#include	"axp.h" 
1999/0415    
 
#include	"ureg.h" 
 
1999/0415/sys/src/9/alphapc/clock.c:34,901999/0429/sys/src/9/alphapc/clock.c:35,103
1999/0415    
	iunlock(&clock0lock); 
} 
 
                 
/* 
 *  delay for l milliseconds more or less.  delayloop is set by 
 *  clockinit() to match the actual CPU speed. 
 */ 
void 
delay(int l) 
1999/0429    
clockinit(void) 
1999/0415    
{ 
	ulong i, j; 
1999/0429    
} 
1999/0415    
 
	j = m->delayloop; 
	while(l-- > 0) 
		for(i=0; i < j; i++) 
			; 
1999/0429    
uvlong 
cycletimer(void) 
{ 
	ulong pcc; 
 
	pcc = rpcc(nil) & 0xFFFFFFFF; 
	if(m->cpuhz == 0){ 
		/* 
		 * pcclast is needed to detect wraparound of 
		 * the cycle timer which is only 32-bits. 
		 * m->cpuhz is set from the info passed from 
		 * the firmware. 
		 * This could be in clockinit if can 
		 * guarantee no wraparound between then and now. 
		 * 
		 * All the clock stuff needs work. 
		 */ 
		m->cpuhz = hwrpb->cfreq; 
		m->pcclast = pcc; 
	} 
	if(pcc < m->pcclast) 
		m->fastclock += 0x100000000LL; 
	m->fastclock += pcc; 
	m->pcclast = pcc; 
 
	return MACHP(0)->fastclock; 
1999/0415    
} 
 
void 
microdelay(int l) 
1999/0429    
vlong 
fastticks(uvlong* hz) 
1999/0415    
{ 
	ulong i, j; 
1999/0429    
	uvlong ticks; 
	int x; 
1999/0415    
 
//	j = m->delayloop/1000; 
j = 10000; 
	while(l-- > 0) 
		for(i=0; i < j; i++) 
			; 
1999/0429    
	x = splhi(); 
	ticks = cycletimer(); 
	splx(x); 
 
	if(hz) 
		*hz = m->cpuhz; 
 
	return (vlong)ticks; 
1999/0415    
} 
 
void 
clockinit(void) 
1999/0429    
microdelay(int us) 
1999/0415    
{ 
m->delayloop = 250*1000;	/* BUG */ 
#ifdef	NOTYET 
	long x; 
1999/0429    
	uvlong eot; 
1999/0415    
 
	m->delayloop = m->speed*100; 
	do { 
		x = rdcount(); 
		delay(10); 
		x = rdcount() - x; 
	} while(x < 0); 
1999/0429    
	eot = cycletimer() + (m->cpuhz/1000000)*us; 
	while(cycletimer() < eot) 
		; 
} 
1999/0415    
 
	/* 
	 *  fix count 
	 */ 
	m->delayloop = (m->delayloop*m->speed*1000*10)/x; 
	if(m->delayloop == 0) 
		m->delayloop = 1; 
                 
/*	wrcompare(rdcount()+(m->speed*1000000)/HZ); */ 
#endif 
1999/0429    
void 
/*milli*/delay(int ms) 
{ 
	microdelay(ms*1000); 
1999/0415    
} 
 
void 
1999/0415/sys/src/9/alphapc/clock.c:135,1461999/0429/sys/src/9/alphapc/clock.c:148,151
1999/0415    
		(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); 
		segclock(ur->pc); 
	} 
} 
                 
vlong 
fastticks(uvlong *hz) 
{ 
	if (hz) 
		*hz = 100; 
	return m->ticks; 
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)