View | Details | Raw Unified | Return to bug 262215 | Differences between
and this patch

Collapse All | Expand All

(-)12.3-my/sys/kern/kern_tc.c (-9 / +3 lines)
Lines 2094-2113 Link Here
2094
 * years) and in 64 bits at 4 GHz (146 years), but if we do a multiply
2094
 * years) and in 64 bits at 4 GHz (146 years), but if we do a multiply
2095
 * before divide conversion (to retain precision) we find that the
2095
 * before divide conversion (to retain precision) we find that the
2096
 * margin shrinks to 1.5 hours (one millionth of 146y).
2096
 * margin shrinks to 1.5 hours (one millionth of 146y).
2097
 * With a three prong approach we never lose significant bits, no
2098
 * matter what the cputick rate and length of timeinterval is.
2099
 */
2097
 */
2100
2098
2101
uint64_t
2099
uint64_t
2102
cputick2usec(uint64_t tick)
2100
cputick2usec(uint64_t tick)
2103
{
2101
{
2104
2102
	uint64_t tr;
2105
	if (tick > 18446744073709551LL)		/* floor(2^64 / 1000) */
2103
	tr = cpu_tickrate();
2106
		return (tick / (cpu_tickrate() / 1000000LL));
2104
	return ((tick / tr) * 1000000ULL) + ((tick % tr) * 1000000ULL) / tr;
2107
	else if (tick > 18446744073709LL)	/* floor(2^64 / 1000000) */
2108
		return ((tick * 1000LL) / (cpu_tickrate() / 1000LL));
2109
	else
2110
		return ((tick * 1000000LL) / cpu_tickrate());
2111
}
2105
}
2112
2106
2113
cpu_tick_f	*cpu_ticks = tc_cpu_ticks;
2107
cpu_tick_f	*cpu_ticks = tc_cpu_ticks;
(-)12.3-my/sys/kern/kern_time.c (-7 / +5 lines)
Lines 243-251 Link Here
243
static inline void
243
static inline void
244
cputick2timespec(uint64_t runtime, struct timespec *ats)
244
cputick2timespec(uint64_t runtime, struct timespec *ats)
245
{
245
{
246
	runtime = cputick2usec(runtime);
246
	uint64_t tr;
247
	ats->tv_sec = runtime / 1000000;
247
	tr = cpu_tickrate();
248
	ats->tv_nsec = runtime % 1000000 * 1000;
248
	ats->tv_sec = runtime / tr;
249
	ats->tv_nsec = ((runtime % tr) * 1000000000ULL) / tr;
249
}
250
}
250
251
251
void
252
void
Lines 474-483 Link Here
474
	case CLOCK_THREAD_CPUTIME_ID:
475
	case CLOCK_THREAD_CPUTIME_ID:
475
	case CLOCK_PROCESS_CPUTIME_ID:
476
	case CLOCK_PROCESS_CPUTIME_ID:
476
	cputime:
477
	cputime:
477
		/* sync with cputick2usec */
478
		ts->tv_nsec = 1000000000 / cpu_tickrate() + 1;
478
		ts->tv_nsec = 1000000 / cpu_tickrate();
479
		if (ts->tv_nsec == 0)
480
			ts->tv_nsec = 1000;
481
		break;
479
		break;
482
	default:
480
	default:
483
		if ((int)clock_id < 0)
481
		if ((int)clock_id < 0)

Return to bug 262215