-/* $OpenBSD: kern_tc.c,v 1.73 2021/06/15 05:24:46 dlg Exp $ */
+/* $OpenBSD: kern_tc.c,v 1.74 2021/06/19 13:49:39 cheloha Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
nsecuptime(void)
{
struct bintime bt;
- uint64_t nsec;
binuptime(&bt);
-
- nsec = (1000000000ULL * (bt.frac >> 32)) >> 32;
- nsec += bt.sec * 1000000000ULL;
-
- return (nsec);
+ return BINTIME_TO_NSEC(&bt);
}
uint64_t
getnsecuptime(void)
{
struct bintime bt;
- uint64_t nsec;
getbinuptime(&bt);
-
- nsec = (1000000000ULL * (bt.frac >> 32)) >> 32;
- nsec += bt.sec * 1000000000ULL;
-
- return (nsec);
+ return BINTIME_TO_NSEC(&bt);
}
void
#ifndef SMALL_KERNEL
/* convert the bintime to ticks */
bintimesub(&new_naptime, &old_naptime, &elapsed);
- adj_ticks = (uint64_t)hz * elapsed.sec +
- (((uint64_t)1000000 * (uint32_t)(elapsed.frac >> 32)) >> 32) / tick;
+ adj_ticks = BINTIME_TO_NSEC(&elapsed) / tick_nsec;
if (adj_ticks > 0) {
if (adj_ticks > INT_MAX)
adj_ticks = INT_MAX;
-/* $OpenBSD: time.h,v 1.60 2021/06/15 05:24:47 dlg Exp $ */
+/* $OpenBSD: time.h,v 1.61 2021/06/19 13:49:39 cheloha Exp $ */
/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */
/*
* time_second ticks after N.999999999 not after N.4999999999
*/
+static inline uint32_t
+FRAC_TO_NSEC(uint64_t frac)
+{
+ return ((frac >> 32) * 1000000000ULL) >> 32;
+}
+
static inline void
BINTIME_TO_TIMESPEC(const struct bintime *bt, struct timespec *ts)
{
ts->tv_sec = bt->sec;
- ts->tv_nsec = (long)(((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32);
+ ts->tv_nsec = FRAC_TO_NSEC(bt->frac);
}
static inline void
return ts->tv_sec * 1000000000ULL + ts->tv_nsec;
}
+static inline uint64_t
+BINTIME_TO_NSEC(const struct bintime *bt)
+{
+ return bt->sec * 1000000000ULL + FRAC_TO_NSEC(bt->frac);
+}
+
#else /* !_KERNEL */
#include <time.h>