Exemplo n.º 1
0
/*
 *  convert milliseconds to fast ticks
 */
uvlong
ms2fastticks(ulong ms)
{
	if(!tod.init)
		todinit();
	return (tod.hz*ms)/1000ULL;
}
Exemplo n.º 2
0
/*
 *  Set the time of day struct
 */
void
todset(vlong t, vlong delta, int n)
{
	if(!tod.init)
		todinit();

	ilock(&tod);
	if(t >= 0){
		tod.off = t;
		tod.last = fastticks(nil);
		tod.lasttime = 0;
		tod.delta = 0;
		tod.sstart = tod.send;
	} else {
		if(n <= 0)
			n = 1;
		n *= HZ;
		if(delta < 0 && n > -delta)
			n = -delta;
		if(delta > 0 && n > delta)
			n = delta;
		if (n == 0) {
			iprint("todset: n == 0, delta == %lld\n", delta);
			delta = 0;
		} else
			delta /= n;
		tod.sstart = MACHP(0)->ticks;
		tod.send = tod.sstart + n;
		tod.delta = delta;
	}
	iunlock(&tod);
}
Exemplo n.º 3
0
Arquivo: tod.c Projeto: Requaos/harvey
/*
 *  Set the time of day struct
 */
void
todset(int64_t t, int64_t delta, int n)
{
	if(!tod.init)
		todinit();

	ilock(&tod.Lock);
	if(t >= 0){
		tod.off = t;
		tod.last = fastticks(nil);
		tod.lasttime = 0;
		tod.delta = 0;
		tod.sstart = tod.send;
	} else {
		if(n <= 0)
			n = 1;
		n *= HZ;
		if(delta < 0 && n > -delta)
			n = -delta;
		if(delta > 0 && n > delta)
			n = delta;
		delta = delta/n;
		tod.sstart = sys->ticks;
		tod.send = tod.sstart + n;
		tod.delta = delta;
	}
	iunlock(&tod.Lock);
}
Exemplo n.º 4
0
Arquivo: tod.c Projeto: Requaos/harvey
/*
 *  convert milliseconds to fast ticks
 */
uint64_t
ms2fastticks(uint32_t ms)
{
	if(!tod.init)
		todinit();
	return (tod.hz*ms)/1000ULL;
}
Exemplo n.º 5
0
/*
 *  convert fast ticks to ns
 */
uvlong
fastticks2ns(uvlong ticks)
{
	uvlong res;

	if(!tod.init)
		todinit();
	mul64fract(&res, ticks, tod.multiplier);
	return res;
}
Exemplo n.º 6
0
/*
 *  convert nanoseconds to fast ticks
 */
uvlong
ns2fastticks(uvlong ns)
{
	uvlong res;

	if(!tod.init)
		todinit();
	mul64fract(&res, ns, tod.divider);
	return res;
}
Exemplo n.º 7
0
Arquivo: tod.c Projeto: Requaos/harvey
/*
 *  convert fast ticks to ns
 */
uint64_t
fastticks2ns(uint64_t ticks)
{
	uint64_t res;

	if(!tod.init)
		todinit();
	mul64fract(&res, ticks, tod.multiplier);
	return res;
}
Exemplo n.º 8
0
Arquivo: tod.c Projeto: Requaos/harvey
/*
 *  convert nanoseconds to fast ticks
 */
uint64_t
ns2fastticks(uint64_t ns)
{
	uint64_t res;

	if(!tod.init)
		todinit();
	mul64fract(&res, ns, tod.divider);
	return res;
}
Exemplo n.º 9
0
static void consinit(void)
{
#if 0
    todinit();
#endif
    /*
     * at 115200 baud, the 1024 char buffer takes 56 ms to process,
     * processing it every 22 ms should be fine
     */
#if 0
    addclock0link(kbdputcclock, 22);
#endif
}
Exemplo n.º 10
0
/*
 *  get time of day
 */
vlong
todget(vlong *ticksp)
{
	uvlong x;
	vlong ticks, diff;
	ulong t;

	if(!tod.init)
		todinit();

	/*
	 * we don't want time to pass twixt the measuring of fastticks
	 * and grabbing tod.last.  Also none of the vlongs are atomic so
	 * we have to look at them inside the lock.
	 */
	ilock(&tod);
	tod.cnt++;
	ticks = fastticks(nil);

	/* add in correction */
	if(tod.sstart != tod.send){
		t = MACHP(0)->ticks;
		if(t >= tod.send)
			t = tod.send;
		tod.off = tod.off + tod.delta*(t - tod.sstart);
		tod.sstart = t;
	}

	/* convert to epoch */
	diff = ticks - tod.last;
	if(diff < 0)
		diff = 0;
	mul64fract(&x, diff, tod.multiplier);
	x += tod.off;

	/* time can't go backwards */
	if(x < tod.lasttime)
		x = tod.lasttime;
	else
		tod.lasttime = x;

	iunlock(&tod);

	if(ticksp != nil)
		*ticksp = ticks;

	return x;
}
Exemplo n.º 11
0
void
timersinit(void)
{
	Timer *t;

	/*
	 * T->tf == nil means the HZ clock for this processor.
	 */
	todinit();
	t = malloc(sizeof(*t));
	t->tmode = Tperiodic;
	t->tt = nil;
	t->tns = 1000000000/HZ;
	t->tf = nil;
	timeradd(t);
}
Exemplo n.º 12
0
static void
consinit(void)
{
	todinit();
}
Exemplo n.º 13
0
static void
consinit(void)
{
	todinit();
	randominit();
}