[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HRT_FROM_8254() bug




HRT_TO_8254() is definitely broken, and also breaks rt_get_time() in
rtl_compat.h  I fixed my problems by replacing the function in
i386/rtl_time.h with my own hacked function, which just divides a long
long by 838.

long long nano2count(long long ns)
{
	unsigned long denom = 838;	// divisor
	long ms32 = ns >> 32;	// most significant 32 bits
	unsigned long ms32rem = ms32 % denom;	// remainder of ms32/denom
	unsigned long ls32 = ns;	// least significant 32 bits
	unsigned long ls32rem = ls32 % denom;
	unsigned long big = 0xffffffff;
	unsigned long big_rem = big % denom;
	unsigned long rem_rem;

	// divide most significant bits
	ns = ms32 / denom;
	ns = ns << 32;
	// add corrections due to rounding errors
	ns += ms32rem * (big / denom) + (ms32rem * (big_rem + 1)) / denom;
	// divide least significant bits
	ns += ls32 / denom;
	// add really small correction
	rem_rem = (ms32rem * (big_rem + 1)) % denom;
	ns += (ls32rem + rem_rem) / denom;

	return ns;
}

Frank