Exemple #1
0
/*
 *  called regularly to avoid calculation overflows
 */
static void
todfix(void)
{
	vlong ticks, diff;
	uvlong x;

	ticks = fastticks(nil);
	diff = ticks - tod.last;
	if(diff <= tod.hz)
		return;

	ilock(&tod);
	diff = ticks - tod.last;
	if(diff > tod.hz){
		/* convert to epoch */
		mul64fract(&x, diff, tod.multiplier);
if(x > 30000000000ULL) iprint("todfix %llud\n", x);
		x += tod.off;

		/* protect against overflows */
		tod.last = ticks;
		tod.off = x;
	}
	iunlock(&tod);
}
Exemple #2
0
/*
 *  convert fast ticks to ns
 */
uvlong
fastticks2ns(uvlong ticks)
{
	uvlong res;

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

	if(!tod.init)
		todinit();
	mul64fract(&res, ns, tod.divider);
	return res;
}
Exemple #4
0
/*
 *  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;
}
Exemple #5
0
/*
 *  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;
}
Exemple #6
0
/*
 *  convert time of day to ticks
 */
uvlong
tod2fastticks(vlong ns)
{
	uvlong x;

	ilock(&tod);
	mul64fract(&x, ns-tod.off, tod.divider);
	x += tod.last;
	iunlock(&tod);
	return x;
}
Exemple #7
0
/*
 *  convert time of day to ticks
 */
uint64_t
tod2fastticks(int64_t ns)
{
	uint64_t x;

	ilock(&tod.Lock);
	mul64fract(&x, ns-tod.off, tod.divider);
	x += tod.last;
	iunlock(&tod.Lock);
	return x;
}
Exemple #8
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;
}
Exemple #9
0
/*
 *  called regularly to avoid calculation overflows
 */
static void
todfix(void)
{
	int64_t ticks, diff;
	uint64_t x;

	ticks = fastticks(nil);

	diff = ticks - tod.last;
	if(diff > tod.hz){
		ilock(&tod.Lock);

		/* convert to epoch */
		mul64fract(&x, diff, tod.multiplier);
if(x > 30000000000ULL) print("todfix %llu\n", x);
		x += tod.off;

		/* protect against overflows */
		tod.last = ticks;
		tod.off = x;

		iunlock(&tod.Lock);
	}
}
Exemple #10
0
Fichier : tod.c Projet : 8l/inferno
/*
 *  called regularly to avoid calculation overflows
 */
void
todfix(void)
{
	vlong ticks, diff;
	uvlong x;

	ticks = fastticks(nil);

	diff = ticks - tod.last;
	if(diff > tod.hz){
		ilock(&tod);
	
		// convert to epoch
		mul64fract(&x, diff, tod.multiplier);
if(x > 30000000000ULL) print("todfix %llud\n", x);
		x += tod.off;
	
		// protect against overflows
		tod.last = ticks;
		tod.off = x;
	
		iunlock(&tod);
	}
}