From: dlg Date: Tue, 15 Jun 2021 05:24:46 +0000 (+0000) Subject: factor out nsecuptime and getnsecuptime. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4ea724981d715fa6d48d9259aab2fa5feb58d23d;p=openbsd factor out nsecuptime and getnsecuptime. these functions were implemented in a bunch of places with comments saying it should be moved to kern_tc.c when more pop up, and i was about to add another one. i think it's time to move them to kern_tc.c. ok cheloa@ jmatthew@ --- diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index 376d26b5af1..f56ed182df1 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_tc.c,v 1.72 2021/04/30 13:52:48 bluhm Exp $ */ +/* $OpenBSD: kern_tc.c,v 1.73 2021/06/15 05:24:46 dlg Exp $ */ /* * Copyright (c) 2000 Poul-Henning Kamp @@ -195,6 +195,21 @@ binuptime(struct bintime *bt) } while (gen == 0 || gen != th->th_generation); } +void +getbinuptime(struct bintime *bt) +{ + struct timehands *th; + u_int gen; + + do { + th = timehands; + gen = th->th_generation; + membar_consumer(); + *bt = th->th_offset; + membar_consumer(); + } while (gen == 0 || gen != th->th_generation); +} + void nanouptime(struct timespec *tsp) { @@ -235,6 +250,34 @@ getuptime(void) #endif } +uint64_t +nsecuptime(void) +{ + struct bintime bt; + uint64_t nsec; + + binuptime(&bt); + + nsec = (1000000000ULL * (bt.frac >> 32)) >> 32; + nsec += bt.sec * 1000000000ULL; + + return (nsec); +} + +uint64_t +getnsecuptime(void) +{ + struct bintime bt; + uint64_t nsec; + + getbinuptime(&bt); + + nsec = (1000000000ULL * (bt.frac >> 32)) >> 32; + nsec += bt.sec * 1000000000ULL; + + return (nsec); +} + void binruntime(struct bintime *bt) { diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index ab38e8d3a3a..05768b71874 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.233 2021/03/10 10:21:47 jsg Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.234 2021/06/15 05:24:46 dlg Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -272,19 +272,6 @@ struct task pool_gc_task = TASK_INITIALIZER(pool_gc_pages, NULL); #define POOL_WAIT_FREE SEC_TO_NSEC(1) #define POOL_WAIT_GC SEC_TO_NSEC(8) -/* - * TODO Move getnsecuptime() to kern_tc.c and document it when we - * have callers in other modules. - */ -static uint64_t -getnsecuptime(void) -{ - struct timespec now; - - getnanouptime(&now); - return TIMESPEC_TO_NSEC(&now); -} - RBT_PROTOTYPE(phtree, pool_page_header, ph_node, phtree_compare); static inline int diff --git a/sys/kern/vfs_sync.c b/sys/kern/vfs_sync.c index b7d16fa3b6b..65ef86619a7 100644 --- a/sys/kern/vfs_sync.c +++ b/sys/kern/vfs_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_sync.c,v 1.65 2021/01/14 03:32:01 cheloha Exp $ */ +/* $OpenBSD: vfs_sync.c,v 1.66 2021/06/15 05:24:47 dlg Exp $ */ /* * Portions of this code are: @@ -131,19 +131,6 @@ vn_syncer_add_to_worklist(struct vnode *vp, int delay) splx(s); } -/* - * TODO Move getnsecuptime() to kern_tc.c and document it when we have - * more users in the kernel. - */ -static uint64_t -getnsecuptime(void) -{ - struct timespec now; - - getnanouptime(&now); - return TIMESPEC_TO_NSEC(&now); -} - /* * System filesystem synchronizer daemon. */ diff --git a/sys/net/bpf.c b/sys/net/bpf.c index b78067a5428..2c4a2a86447 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.204 2021/04/23 03:43:19 dlg Exp $ */ +/* $OpenBSD: bpf.c,v 1.205 2021/06/15 05:24:47 dlg Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -420,19 +420,6 @@ bpfclose(dev_t dev, int flag, int mode, struct proc *p) (d)->bd_slen = 0; \ (d)->bd_fbuf = NULL; -/* - * TODO Move nsecuptime() into kern_tc.c and document it when we have - * more users elsewhere in the kernel. - */ -static uint64_t -nsecuptime(void) -{ - struct timespec now; - - nanouptime(&now); - return TIMESPEC_TO_NSEC(&now); -} - /* * bpfread - read next chunk of packets from buffers */ diff --git a/sys/sys/time.h b/sys/sys/time.h index 019ea8153ea..7f1b0163b28 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -1,4 +1,4 @@ -/* $OpenBSD: time.h,v 1.59 2021/06/11 16:36:34 cheloha Exp $ */ +/* $OpenBSD: time.h,v 1.60 2021/06/15 05:24:47 dlg Exp $ */ /* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */ /* @@ -290,6 +290,7 @@ void binuptime(struct bintime *); void nanouptime(struct timespec *); void microuptime(struct timeval *); +void getbinuptime(struct bintime *); void getnanouptime(struct timespec *); void getmicrouptime(struct timeval *); @@ -303,6 +304,9 @@ void nanoruntime(struct timespec *); time_t gettime(void); time_t getuptime(void); +uint64_t nsecuptime(void); +uint64_t getnsecuptime(void); + struct proc; int clock_gettime(struct proc *, clockid_t, struct timespec *);