clock.c

来自「这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易」· C语言 代码 · 共 107 行

C
107
字号
#include	"u.h"#include	"../port/lib.h"#include	"mem.h"#include	"dat.h"#include	"fns.h"#include	"io.h"#include	"axp.h"#include	"ureg.h"voidclockinit(void){}uvlongcycletimer(void){	ulong pcc;	vlong delta;	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;	}	delta = pcc - m->pcclast;	if(delta < 0)		delta += 0x100000000LL;	m->pcclast = pcc;	m->fastclock += delta;	return MACHP(0)->fastclock;}uvlongfastticks(uvlong* hz){	uvlong ticks;	int x;	x = splhi();	ticks = cycletimer();	splx(x);	if(hz)		*hz = m->cpuhz;	return ticks;}/*   *  performance measurement ticks.  must be low overhead. *  doesn't have to count over a second. */ulongperfticks(void){	return rpcc(nil);}voidtimerset(uvlong){}voidmicrodelay(int us){	uvlong eot;	eot = fastticks(nil) + (m->cpuhz/1000000)*us;	while(fastticks(nil) < eot)		;}voiddelay(int millisecs){	microdelay(millisecs*1000);}voidclock(Ureg *ureg){	static int count;	cycletimer();	/* HZ == 100, timer == 1024Hz.  error < 1ms */	count += 100;	if (count < 1024)		return;	count -= 1024;	timerintr(ureg, 0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?