From 6040822c4e20fb46638ecaaad543fc56f6ec2b0f Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 30 Jul 2018 15:46:40 +0000 Subject: [PATCH] Make timespecadd(3) and friends public The timespecadd(3) family of macros were imported from NetBSD back in r35029. However, they were initially guarded by #ifdef _KERNEL. In the meantime, we have grown at least 28 syscalls that use timespecs in some way, leading many programs both inside and outside of the base system to redefine those macros. It's better just to make the definitions public. Our kernel currently defines two-argument versions of timespecadd and timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define three-argument versions. Solaris also defines a three-argument version, but only in its kernel. This revision changes our definition to match the common three-argument version. Bump _FreeBSD_version due to the breaking KPI change. Discussed with: cem, jilles, ian, bde Differential Revision: https://reviews.freebsd.org/D14725 --- lib/libnetbsd/sys/time.h | 65 -------------- sbin/fsck_ffs/fsutil.c | 33 ++----- share/man/man3/Makefile | 7 +- share/man/man3/timeradd.3 | 88 ++++++++++++++----- sys/compat/linux/linux_event.c | 16 ++-- sys/compat/linux/linux_futex.c | 4 +- sys/compat/linux/linux_misc.c | 4 +- sys/compat/linux/linux_socket.c | 4 +- .../linuxkpi/common/include/linux/time.h | 4 +- sys/dev/acpica/acpi_cmbat.c | 2 +- sys/dev/acpica/acpi_smbat.c | 2 +- sys/dev/acpica/acpi_thermal.c | 2 +- sys/dev/drm2/i915/i915_gem.c | 4 +- sys/dev/drm2/i915/intel_pm.c | 3 +- sys/dev/efidev/efirtc.c | 2 +- sys/dev/isp/isp_freebsd.c | 5 +- sys/dev/joy/joy.c | 8 +- sys/dev/xen/timer/timer.c | 2 +- sys/kern/kern_sig.c | 6 +- sys/kern/kern_tc.c | 2 +- sys/kern/kern_time.c | 20 +++-- sys/kern/kern_umtx.c | 10 +-- sys/kern/subr_rtc.c | 4 +- sys/kern/uipc_mqueue.c | 6 +- sys/kern/uipc_sem.c | 2 +- sys/mips/ingenic/jz4780_smb.c | 4 +- sys/netinet/ip_input.c | 2 +- sys/netinet6/ip6_input.c | 2 +- sys/netsmb/smb_iod.c | 6 +- sys/netsmb/smb_trantcp.c | 9 +- sys/opencrypto/crypto.c | 2 +- sys/sys/param.h | 2 +- sys/sys/time.h | 28 +++--- sys/ufs/ffs/ffs_snapshot.c | 2 +- sys/x86/iommu/intel_dmar.h | 3 +- tools/regression/posixsem/posixsem.c | 35 +------- .../sockets/udp_pingpong/udp_pingpong.c | 41 ++------- .../sockets/unix_cmsg/uc_check_time.c | 18 +--- tools/tools/netrate/juggle/juggle.c | 19 +--- tools/tools/netrate/tcpp/tcpp_client.c | 12 +-- tools/tools/syscall_timing/syscall_timing.c | 12 +-- usr.bin/truss/setup.c | 5 +- usr.bin/truss/syscalls.c | 3 +- usr.bin/truss/truss.h | 20 ----- usr.sbin/camdd/camdd.c | 19 +--- 45 files changed, 187 insertions(+), 362 deletions(-) delete mode 100644 lib/libnetbsd/sys/time.h diff --git a/lib/libnetbsd/sys/time.h b/lib/libnetbsd/sys/time.h deleted file mode 100644 index c54be7d58d76..000000000000 --- a/lib/libnetbsd/sys/time.h +++ /dev/null @@ -1,65 +0,0 @@ -/* $FreeBSD$ */ - -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)time.h 8.5 (Berkeley) 5/4/95 - */ - -#ifndef _LIBNETBSD_SYS_TIME_H_ -#define _LIBNETBSD_SYS_TIME_H_ - -#include_next - -/* Operations on timespecs. */ -#define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L) -#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) -#define timespeccmp(tsp, usp, cmp) \ - (((tsp)->tv_sec == (usp)->tv_sec) ? \ - ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ - ((tsp)->tv_sec cmp (usp)->tv_sec)) -#define timespecadd(tsp, usp, vsp) \ - do { \ - (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ - (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ - if ((vsp)->tv_nsec >= 1000000000L) { \ - (vsp)->tv_sec++; \ - (vsp)->tv_nsec -= 1000000000L; \ - } \ - } while (/* CONSTCOND */ 0) -#define timespecsub(tsp, usp, vsp) \ - do { \ - (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ - (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ - if ((vsp)->tv_nsec < 0) { \ - (vsp)->tv_sec--; \ - (vsp)->tv_nsec += 1000000000L; \ - } \ - } while (/* CONSTCOND */ 0) - -#endif diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index d4a5f81bbfa7..91be4234ae48 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -297,28 +297,6 @@ getdatablk(ufs2_daddr_t blkno, long size, int type) return (bp); } -/* - * Timespec operations (from ). - */ -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) -#define timespecadd(vvp, uvp) \ - do { \ - (vvp)->tv_sec += (uvp)->tv_sec; \ - (vvp)->tv_nsec += (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec >= 1000000000) { \ - (vvp)->tv_sec++; \ - (vvp)->tv_nsec -= 1000000000; \ - } \ - } while (0) - void getblk(struct bufarea *bp, ufs2_daddr_t blk, long size) { @@ -337,8 +315,9 @@ getblk(struct bufarea *bp, ufs2_daddr_t blk, long size) bp->b_errs = blread(fsreadfd, bp->b_un.b_buf, dblk, size); if (debug) { clock_gettime(CLOCK_REALTIME_PRECISE, &finish); - timespecsub(&finish, &start); - timespecadd(&readtime[bp->b_type], &finish); + timespecsub(&finish, &start, &finish); + timespecadd(&readtime[bp->b_type], &finish, + &readtime[bp->b_type]); } bp->b_bno = dblk; bp->b_size = size; @@ -509,7 +488,7 @@ IOstats(char *what) totaldiskreads += diskreads; diskreads = 0; for (i = 0; i < BT_NUMBUFTYPES; i++) { - timespecadd(&totalreadtime[i], &readtime[i]); + timespecadd(&totalreadtime[i], &readtime[i], &totalreadtime[i]); totalreadcnt[i] += readcnt[i]; readtime[i].tv_sec = readtime[i].tv_nsec = 0; readcnt[i] = 0; @@ -529,7 +508,7 @@ finalIOstats(void) diskreads = totaldiskreads; startpass = startprog; for (i = 0; i < BT_NUMBUFTYPES; i++) { - timespecadd(&totalreadtime[i], &readtime[i]); + timespecadd(&totalreadtime[i], &readtime[i], &totalreadtime[i]); totalreadcnt[i] += readcnt[i]; readtime[i] = totalreadtime[i]; readcnt[i] = totalreadcnt[i]; @@ -543,7 +522,7 @@ static void printIOstats(void) int i; clock_gettime(CLOCK_REALTIME_PRECISE, &finishpass); - timespecsub(&finishpass, &startpass); + timespecsub(&finishpass, &startpass, &finishpass); printf("Running time: %jd.%03ld sec\n", (intmax_t)finishpass.tv_sec, finishpass.tv_nsec / 1000000); printf("buffer reads by type:\n"); diff --git a/share/man/man3/Makefile b/share/man/man3/Makefile index 19e65986edbc..6197b0affb4d 100644 --- a/share/man/man3/Makefile +++ b/share/man/man3/Makefile @@ -164,7 +164,12 @@ MLINKS+= stdarg.3 va_arg.3 \ MLINKS+= timeradd.3 timerclear.3 \ timeradd.3 timercmp.3 \ timeradd.3 timerisset.3 \ - timeradd.3 timersub.3 + timeradd.3 timersub.3 \ + timeradd.3 timespecadd.3 \ + timeradd.3 timespecsub.3 \ + timeradd.3 timespecclear.3 \ + timeradd.3 timespecisset.3 \ + timeradd.3 timespeccmp.3 MLINKS+= tree.3 RB_EMPTY.3 \ tree.3 RB_ENTRY.3 \ tree.3 RB_FIND.3 \ diff --git a/share/man/man3/timeradd.3 b/share/man/man3/timeradd.3 index 7b6293f0dbfb..86e6b2816f1f 100644 --- a/share/man/man3/timeradd.3 +++ b/share/man/man3/timeradd.3 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 11, 1999 +.Dd July 30, 2018 .Dt TIMERADD 3 .Os .Sh NAME @@ -35,8 +35,13 @@ .Nm timersub , .Nm timerclear , .Nm timerisset , -.Nm timercmp -.Nd operations on timevals +.Nm timercmp , +.Nm timespecadd , +.Nm timespecsub , +.Nm timespecclear , +.Nm timespecisset , +.Nm timespeccmp +.Nd operations on timevals and timespecs .Sh SYNOPSIS .In sys/time.h .Ft void @@ -49,15 +54,31 @@ .Fn timerisset "struct timeval *tvp" .Ft int .Fn timercmp "struct timeval *a" "struct timeval *b" CMP +.Ft void +.Fn timespecadd "struct timespec *a" "struct timespec *b" "struct timespec *res" +.Ft void +.Fn timespecsub "struct timespec *a" "struct timespec *b" "struct timespec *res" +.Ft void +.Fn timespecclear "struct timespec *ts" +.Ft int +.Fn timespecisset "struct timespec *ts" +.Ft int +.Fn timespeccmp "struct timespec *a" "struct timespec *b" CMP .Sh DESCRIPTION These macros are provided for manipulating .Fa timeval +and +.Fa timespec structures for use with the +.Xr clock_gettime 2 , +.Xr clock_settime 2 , .Xr gettimeofday 2 and .Xr settimeofday 2 calls. -The structure is defined in +The +.Fa timeval +structure is defined in .In sys/time.h as: .Bd -literal @@ -66,50 +87,67 @@ struct timeval { long tv_usec; /* and microseconds */ }; .Ed +And the +.Fa timespec +structure is defined in +.In time.h +as: +.Bd -literal +struct timespec { + time_t tv_nsec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +.Ed .Pp .Fn timeradd -adds the time information stored in +and +.Fn timespecadd +add the time information stored in .Fa a to .Fa b -and stores the resulting -.Vt timeval -in +and store the result in .Fa res . The results are simplified such that the value of .Fa res->tv_usec -is always less than 1,000,000 (1 second). +or +.Fa res->tv_nsec +is always less than 1 second. .Pp .Fn timersub -subtracts the time information stored in +and +.Fn timespecsub +subtract the time information stored in .Fa b from .Fa a -and stores the resulting -.Vt timeval +and store the result in .Fa res . .Pp .Fn timerclear -initializes -.Fa tvp -to midnight (0 hour) January 1st, 1970 (the Epoch). +and +.Fn timespecclear +initialize their argument to midnight (0 hour) January 1st, 1970 (the Epoch). .Pp .Fn timerisset -returns true if -.Fa tvp -is set to any time value other than the Epoch. +and +.Fn timespecisset +return true if their argument is set to any time value other than the Epoch. .Pp .Fn timercmp -compares +and +.Fn timespeccmp +compare .Fa a to .Fa b using the comparison operator given in .Fa CMP , -and returns the result of that comparison. +and return the result of that comparison. .Sh SEE ALSO -.Xr gettimeofday 2 +.Xr gettimeofday 2 , +.Xr clock_gettime 2 .Sh HISTORY The .Fn timeradd @@ -117,3 +155,11 @@ family of macros were imported from .Nx 1.1 , and appeared in .Fx 2.2.6 . +The +.Fn timespecadd +family of macros were imported from +.Nx 1.3 +into +.Fx 3.0 , +though they were not exposed to userland until +.Fx 12.0 . diff --git a/sys/compat/linux/linux_event.c b/sys/compat/linux/linux_event.c index ae6cb83c9e7a..bb4825574ed5 100644 --- a/sys/compat/linux/linux_event.c +++ b/sys/compat/linux/linux_event.c @@ -1183,7 +1183,7 @@ linux_timerfd_curval(struct timerfd *tfd, struct itimerspec *ots) linux_timerfd_clocktime(tfd, &cts); *ots = tfd->tfd_time; if (ots->it_value.tv_sec != 0 || ots->it_value.tv_nsec != 0) { - timespecsub(&ots->it_value, &cts); + timespecsub(&ots->it_value, &cts, &ots->it_value); if (ots->it_value.tv_sec < 0 || (ots->it_value.tv_sec == 0 && ots->it_value.tv_nsec == 0)) { @@ -1265,9 +1265,10 @@ linux_timerfd_settime(struct thread *td, struct linux_timerfd_settime_args *args linux_timerfd_clocktime(tfd, &cts); ts = nts.it_value; if ((args->flags & LINUX_TFD_TIMER_ABSTIME) == 0) { - timespecadd(&tfd->tfd_time.it_value, &cts); + timespecadd(&tfd->tfd_time.it_value, &cts, + &tfd->tfd_time.it_value); } else { - timespecsub(&ts, &cts); + timespecsub(&ts, &cts, &ts); } TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&tfd->tfd_callout, tvtohz(&tv), @@ -1303,13 +1304,13 @@ linux_timerfd_expire(void *arg) if (timespeccmp(&cts, &tfd->tfd_time.it_value, >=)) { if (timespecisset(&tfd->tfd_time.it_interval)) timespecadd(&tfd->tfd_time.it_value, - &tfd->tfd_time.it_interval); + &tfd->tfd_time.it_interval, + &tfd->tfd_time.it_value); else /* single shot timer */ timespecclear(&tfd->tfd_time.it_value); if (timespecisset(&tfd->tfd_time.it_value)) { - ts = tfd->tfd_time.it_value; - timespecsub(&ts, &cts); + timespecsub(&tfd->tfd_time.it_value, &cts, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&tfd->tfd_callout, tvtohz(&tv), linux_timerfd_expire, tfd); @@ -1319,8 +1320,7 @@ linux_timerfd_expire(void *arg) selwakeup(&tfd->tfd_sel); wakeup(&tfd->tfd_count); } else if (timespecisset(&tfd->tfd_time.it_value)) { - ts = tfd->tfd_time.it_value; - timespecsub(&ts, &cts); + timespecsub(&tfd->tfd_time.it_value, &cts, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&tfd->tfd_callout, tvtohz(&tv), linux_timerfd_expire, tfd); diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index a82672eaa4f1..7c15af2d89c2 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -290,10 +290,10 @@ futex_copyin_timeout(int op, struct l_timespec *luts, int clockrt, return (error); if (clockrt) { nanotime(&kts); - timespecsub(ts, &kts); + timespecsub(ts, &kts, ts); } else if (op == LINUX_FUTEX_WAIT_BITSET) { nanouptime(&kts); - timespecsub(ts, &kts); + timespecsub(ts, &kts, ts); } return (error); } diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 95a8ab174e9d..516952fac490 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -2382,8 +2382,8 @@ linux_ppoll(struct thread *td, struct linux_ppoll_args *args) if (error == 0 && args->tsp != NULL) { if (td->td_retval[0]) { nanotime(&ts1); - timespecsub(&ts1, &ts0); - timespecsub(&uts, &ts1); + timespecsub(&ts1, &ts0, &ts1); + timespecsub(&uts, &ts1, &uts); if (uts.tv_sec < 0) timespecclear(&uts); } else diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 604627048ed0..d4f567b5192f 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1463,7 +1463,7 @@ linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args) if (error != 0) return (error); getnanotime(&tts); - timespecadd(&tts, &ts); + timespecadd(&tts, &ts, &tts); } msg = PTRIN(args->msg); @@ -1492,7 +1492,7 @@ linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args) */ if (args->timeout) { getnanotime(&ts); - timespecsub(&ts, &tts); + timespecsub(&ts, &tts, &ts); if (!timespecisset(&ts) || ts.tv_sec > 0) break; } diff --git a/sys/compat/linuxkpi/common/include/linux/time.h b/sys/compat/linuxkpi/common/include/linux/time.h index 9f69e95f6bf5..1c07c69a67a6 100644 --- a/sys/compat/linuxkpi/common/include/linux/time.h +++ b/sys/compat/linuxkpi/common/include/linux/time.h @@ -76,9 +76,7 @@ timespec_sub(struct timespec lhs, struct timespec rhs) { struct timespec ts; - ts.tv_sec = lhs.tv_sec; - ts.tv_nsec = lhs.tv_nsec; - timespecsub(&ts, &rhs); + timespecsub(&lhs, &rhs, &ts); return ts; } diff --git a/sys/dev/acpica/acpi_cmbat.c b/sys/dev/acpica/acpi_cmbat.c index 7dbfa0334559..b4835bb66cda 100644 --- a/sys/dev/acpica/acpi_cmbat.c +++ b/sys/dev/acpica/acpi_cmbat.c @@ -229,7 +229,7 @@ acpi_cmbat_info_expired(struct timespec *lastupdated) return (TRUE); getnanotime(&curtime); - timespecsub(&curtime, lastupdated); + timespecsub(&curtime, lastupdated, &curtime); return (curtime.tv_sec < 0 || curtime.tv_sec > acpi_battery_get_info_expire()); } diff --git a/sys/dev/acpica/acpi_smbat.c b/sys/dev/acpica/acpi_smbat.c index dfc9938e0302..af09f383b843 100644 --- a/sys/dev/acpica/acpi_smbat.c +++ b/sys/dev/acpica/acpi_smbat.c @@ -170,7 +170,7 @@ acpi_smbat_info_expired(struct timespec *lastupdated) return (TRUE); getnanotime(&curtime); - timespecsub(&curtime, lastupdated); + timespecsub(&curtime, lastupdated, &curtime); return (curtime.tv_sec < 0 || curtime.tv_sec > acpi_battery_get_info_expire()); } diff --git a/sys/dev/acpica/acpi_thermal.c b/sys/dev/acpica/acpi_thermal.c index b2b2a13aa889..f3ff8242591a 100644 --- a/sys/dev/acpica/acpi_thermal.c +++ b/sys/dev/acpica/acpi_thermal.c @@ -535,7 +535,7 @@ acpi_tz_monitor(void *Context) (newactive == TZ_ACTIVE_NONE || newactive > sc->tz_active)) { getnanotime(&curtime); - timespecsub(&curtime, &sc->tz_cooling_started); + timespecsub(&curtime, &sc->tz_cooling_started, &curtime); if (curtime.tv_sec < acpi_tz_min_runtime) newactive = sc->tz_active; } diff --git a/sys/dev/drm2/i915/i915_gem.c b/sys/dev/drm2/i915/i915_gem.c index 33f0d9953ecd..4dfb90753b6c 100644 --- a/sys/dev/drm2/i915/i915_gem.c +++ b/sys/dev/drm2/i915/i915_gem.c @@ -1135,8 +1135,8 @@ static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno, #undef EXIT_COND if (timeout) { - timespecsub(&now, &before); - timespecsub(timeout, &now); + timespecsub(&now, &before, &now); + timespecsub(timeout, &now, timeout); } switch (end) { diff --git a/sys/dev/drm2/i915/intel_pm.c b/sys/dev/drm2/i915/intel_pm.c index 143c92a97200..a2c409f15dfe 100644 --- a/sys/dev/drm2/i915/intel_pm.c +++ b/sys/dev/drm2/i915/intel_pm.c @@ -3102,8 +3102,7 @@ static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) mtx_assert(&mchdev_lock, MA_OWNED); nanotime(&now); - diff1 = now; - timespecsub(&diff1, &dev_priv->ips.last_time2); + timespecsub(&now, &dev_priv->ips.last_time2, &diff1); /* Don't divide by 0 */ diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000; diff --git a/sys/dev/efidev/efirtc.c b/sys/dev/efidev/efirtc.c index 1e5784b19263..b9e06bcc362e 100644 --- a/sys/dev/efidev/efirtc.c +++ b/sys/dev/efidev/efirtc.c @@ -163,7 +163,7 @@ efirtc_settime(device_t dev, struct timespec *ts) */ ts->tv_sec -= utc_offset(); if (!efirtc_zeroes_subseconds) - timespecadd(ts, &efirtc_resadj); + timespecadd(ts, &efirtc_resadj, ts); clock_ts_to_ct(ts, &ct); clock_dbgprint_ct(dev, CLOCK_DBG_WRITE, &ct); diff --git a/sys/dev/isp/isp_freebsd.c b/sys/dev/isp/isp_freebsd.c index 3f7850829b91..693df8f66463 100644 --- a/sys/dev/isp/isp_freebsd.c +++ b/sys/dev/isp/isp_freebsd.c @@ -4083,8 +4083,9 @@ uint64_t isp_nanotime_sub(struct timespec *b, struct timespec *a) { uint64_t elapsed; - struct timespec x = *b; - timespecsub(&x, a); + struct timespec x; + + timespecsub(b, a, &x); elapsed = GET_NANOSEC(&x); if (elapsed == 0) elapsed++; diff --git a/sys/dev/joy/joy.c b/sys/dev/joy/joy.c index 6b8811f4faef..15f4f8e221a3 100644 --- a/sys/dev/joy/joy.c +++ b/sys/dev/joy/joy.c @@ -171,14 +171,14 @@ joyread(struct cdev *dev, struct uio *uio, int flag) nanotime(&t); end.tv_sec = 0; end.tv_nsec = joy->timeout[joypart(dev)] * 1000; - timespecadd(&end, &t); + timespecadd(&end, &t, &end); for (; timespeccmp(&t, &end, <) && (bus_space_read_1(bt, port, 0) & 0x0f); nanotime(&t)) ; /* nothing */ bus_space_write_1 (bt, port, 0, 0xff); nanotime(&start); end.tv_sec = 0; end.tv_nsec = joy->timeout[joypart(dev)] * 1000; - timespecadd(&end, &start); + timespecadd(&end, &start, &end); t = start; timespecclear(&x); timespecclear(&y); @@ -200,12 +200,12 @@ joyread(struct cdev *dev, struct uio *uio, int flag) enable_intr (); #endif if (timespecisset(&x)) { - timespecsub(&x, &start); + timespecsub(&x, &start, &x); c.x = joy->x_off[joypart(dev)] + x.tv_nsec / 1000; } else c.x = 0x80000000; if (timespecisset(&y)) { - timespecsub(&y, &start); + timespecsub(&y, &start, &y); c.y = joy->y_off[joypart(dev)] + y.tv_nsec / 1000; } else c.y = 0x80000000; diff --git a/sys/dev/xen/timer/timer.c b/sys/dev/xen/timer/timer.c index 465d978fbbb9..ecd4e0990652 100644 --- a/sys/dev/xen/timer/timer.c +++ b/sys/dev/xen/timer/timer.c @@ -262,7 +262,7 @@ xentimer_gettime(device_t dev, struct timespec *ts) timespecclear(ts); xen_fetch_wallclock(ts); xen_fetch_uptime(&u_ts); - timespecadd(ts, &u_ts); + timespecadd(ts, &u_ts, ts); return (0); } diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 9c25ed85e4ba..a2b07974bdb5 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1261,8 +1261,7 @@ kern_sigtimedwait(struct thread *td, sigset_t waitset, ksiginfo_t *ksi, if (timeout->tv_nsec >= 0 && timeout->tv_nsec < 1000000000) { timevalid = 1; getnanouptime(&rts); - ets = rts; - timespecadd(&ets, timeout); + timespecadd(&rts, timeout, &ets); } } ksiginfo_init(ksi); @@ -1302,8 +1301,7 @@ kern_sigtimedwait(struct thread *td, sigset_t waitset, ksiginfo_t *ksi, error = EAGAIN; break; } - ts = ets; - timespecsub(&ts, &rts); + timespecsub(&ets, &rts, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); timo = tvtohz(&tv); } else { diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index e3eb37bce322..e55290df7852 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -1847,7 +1847,7 @@ pps_event(struct pps_state *pps, int event) *tsp = ts; if (foff) { - timespecadd(tsp, osp); + timespecadd(tsp, osp, tsp); if (tsp->tv_nsec < 0) { tsp->tv_nsec += 1000000000; tsp->tv_sec -= 1; diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index be9e5c830ab0..3b6b42b64b31 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -543,7 +543,7 @@ kern_clock_nanosleep(struct thread *td, clockid_t clock_id, int flags, atomic_load_acq_int(&rtc_generation); error = kern_clock_gettime(td, clock_id, &now); KASSERT(error == 0, ("kern_clock_gettime: %d", error)); - timespecsub(&ts, &now); + timespecsub(&ts, &now, &ts); } if (ts.tv_sec < 0 || (ts.tv_sec == 0 && ts.tv_nsec == 0)) { error = EWOULDBLOCK; @@ -1520,7 +1520,7 @@ realtimer_gettime(struct itimer *it, struct itimerspec *ovalue) realtimer_clocktime(it->it_clockid, &cts); *ovalue = it->it_time; if (ovalue->it_value.tv_sec != 0 || ovalue->it_value.tv_nsec != 0) { - timespecsub(&ovalue->it_value, &cts); + timespecsub(&ovalue->it_value, &cts, &ovalue->it_value); if (ovalue->it_value.tv_sec < 0 || (ovalue->it_value.tv_sec == 0 && ovalue->it_value.tv_nsec == 0)) { @@ -1561,9 +1561,10 @@ realtimer_settime(struct itimer *it, int flags, ts = val.it_value; if ((flags & TIMER_ABSTIME) == 0) { /* Convert to absolute time. */ - timespecadd(&it->it_time.it_value, &cts); + timespecadd(&it->it_time.it_value, &cts, + &it->it_time.it_value); } else { - timespecsub(&ts, &cts); + timespecsub(&ts, &cts, &ts); /* * We don't care if ts is negative, tztohz will * fix it. @@ -1631,22 +1632,23 @@ realtimer_expire(void *arg) if (timespeccmp(&cts, &it->it_time.it_value, >=)) { if (timespecisset(&it->it_time.it_interval)) { timespecadd(&it->it_time.it_value, - &it->it_time.it_interval); + &it->it_time.it_interval, + &it->it_time.it_value); while (timespeccmp(&cts, &it->it_time.it_value, >=)) { if (it->it_overrun < INT_MAX) it->it_overrun++; else it->it_ksi.ksi_errno = ERANGE; timespecadd(&it->it_time.it_value, - &it->it_time.it_interval); + &it->it_time.it_interval, + &it->it_time.it_value); } } else { /* single shot timer ? */ timespecclear(&it->it_time.it_value); } if (timespecisset(&it->it_time.it_value)) { - ts = it->it_time.it_value; - timespecsub(&ts, &cts); + timespecsub(&it->it_time.it_value, &cts, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&it->it_callout, tvtohz(&tv), realtimer_expire, it); @@ -1658,7 +1660,7 @@ realtimer_expire(void *arg) itimer_leave(it); } else if (timespecisset(&it->it_time.it_value)) { ts = it->it_time.it_value; - timespecsub(&ts, &cts); + timespecsub(&ts, &cts, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&it->it_callout, tvtohz(&tv), realtimer_expire, it); diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index 63e394eafe7a..8beea32666a6 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -772,8 +772,7 @@ abs_timeout_init(struct abs_timeout *timo, int clockid, int absolute, if (!absolute) { timo->is_abs_real = false; abs_timeout_update(timo); - timo->end = timo->cur; - timespecadd(&timo->end, timeout); + timespecadd(&timo->cur, timeout, &timo->end); } else { timo->end = *timeout; timo->is_abs_real = clockid == CLOCK_REALTIME || @@ -811,8 +810,7 @@ abs_timeout_gethz(struct abs_timeout *timo) if (timespeccmp(&timo->end, &timo->cur, <=)) return (-1); - tts = timo->end; - timespecsub(&tts, &timo->cur); + timespecsub(&timo->end, &timo->cur, &tts); return (tstohz(&tts)); } @@ -3247,8 +3245,8 @@ do_sem2_wait(struct thread *td, struct _usem2 *sem, struct _umtx_time *timeout) error = EINTR; if (error == EINTR) { abs_timeout_update(&timo); - timeout->_timeout = timo.end; - timespecsub(&timeout->_timeout, &timo.cur); + timespecsub(&timo.end, &timo.cur, + &timeout->_timeout); } } } diff --git a/sys/kern/subr_rtc.c b/sys/kern/subr_rtc.c index 66cde8fb2e07..82c276f210a2 100644 --- a/sys/kern/subr_rtc.c +++ b/sys/kern/subr_rtc.c @@ -144,7 +144,7 @@ settime_task_func(void *arg, int pending) getnanotime(&ts); if (!(rtc->flags & CLOCKF_SETTIME_NO_ADJ)) { ts.tv_sec -= utc_offset(); - timespecadd(&ts, &rtc->resadj); + timespecadd(&ts, &rtc->resadj, &ts); } } else { ts.tv_sec = 0; @@ -301,7 +301,7 @@ read_clocks(struct timespec *ts, bool debug_read) continue; } if (!(rtc->flags & CLOCKF_GETTIME_NO_ADJ)) { - timespecadd(ts, &rtc->resadj); + timespecadd(ts, &rtc->resadj, ts); ts->tv_sec += utc_offset(); } if (!debug_read) { diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c index 26c9dee23796..4751635e2aee 100644 --- a/sys/kern/uipc_mqueue.c +++ b/sys/kern/uipc_mqueue.c @@ -1735,9 +1735,8 @@ mqueue_send(struct mqueue *mq, const char *msg_ptr, goto bad; } for (;;) { - ts2 = *abs_timeout; getnanotime(&ts); - timespecsub(&ts2, &ts); + timespecsub(abs_timeout, &ts, &ts2); if (ts2.tv_sec < 0 || (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) { error = ETIMEDOUT; break; @@ -1887,9 +1886,8 @@ mqueue_receive(struct mqueue *mq, char *msg_ptr, } for (;;) { - ts2 = *abs_timeout; getnanotime(&ts); - timespecsub(&ts2, &ts); + timespecsub(abs_timeout, &ts, &ts2); if (ts2.tv_sec < 0 || (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) { error = ETIMEDOUT; return (error); diff --git a/sys/kern/uipc_sem.c b/sys/kern/uipc_sem.c index f4e36026a90c..faa61bfea352 100644 --- a/sys/kern/uipc_sem.c +++ b/sys/kern/uipc_sem.c @@ -843,7 +843,7 @@ kern_sem_wait(struct thread *td, semid_t id, int tryflag, for (;;) { ts1 = *abstime; getnanotime(&ts2); - timespecsub(&ts1, &ts2); + timespecsub(&ts1, &ts2, &ts1); TIMESPEC_TO_TIMEVAL(&tv, &ts1); if (tv.tv_sec < 0) { error = ETIMEDOUT; diff --git a/sys/mips/ingenic/jz4780_smb.c b/sys/mips/ingenic/jz4780_smb.c index c910b05bd683..a69b6cbd198c 100644 --- a/sys/mips/ingenic/jz4780_smb.c +++ b/sys/mips/ingenic/jz4780_smb.c @@ -248,7 +248,7 @@ jzsmb_transfer_read(device_t dev, struct iic_msg *msg) SMB_WRITE(sc, SMBDC, SMBDC_CMD); for (;;) { getnanouptime(&diff); - timespecsub(&diff, &start); + timespecsub(&diff, &start, &diff); if ((SMB_READ(sc, SMBST) & SMBST_RFNE) != 0) { msg->buf[msg->len - resid] = SMB_READ(sc, SMBDC) & SMBDC_DAT; @@ -293,7 +293,7 @@ jzsmb_transfer_write(device_t dev, struct iic_msg *msg, int stop_hold) for (resid = msg->len; resid > 0; resid--) { for (;;) { getnanouptime(&diff); - timespecsub(&diff, &start); + timespecsub(&diff, &start, &diff); if ((SMB_READ(sc, SMBST) & SMBST_TFNF) != 0) { SMB_WRITE(sc, SMBDC, msg->buf[msg->len - resid]); diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index fcdeff9cb338..882b2aea119a 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1193,7 +1193,7 @@ ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip, mbuf_tstmp2timespec(m, &ts); getboottimebin(&boottimebin); bintime2timespec(&boottimebin, &ts1); - timespecadd(&ts, &ts1); + timespecadd(&ts, &ts1, &ts); } else { nanotime(&ts); } diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 87788cb3b6d0..84bf56fc3ac2 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1267,7 +1267,7 @@ ip6_savecontrol_v4(struct inpcb *inp, struct mbuf *m, struct mbuf **mp, mbuf_tstmp2timespec(m, &t.ts); getboottimebin(&boottimebin); bintime2timespec(&boottimebin, &ts1); - timespecadd(&t.ts, &ts1); + timespecadd(&t.ts, &ts1, &t.ts); } else { nanotime(&t.ts); } diff --git a/sys/netsmb/smb_iod.c b/sys/netsmb/smb_iod.c index 29407b7a0567..e93787c3bb1d 100644 --- a/sys/netsmb/smb_iod.c +++ b/sys/netsmb/smb_iod.c @@ -557,9 +557,9 @@ smb_iod_sendall(struct smbiod *iod) break; case SMBRQ_SENT: SMB_TRAN_GETPARAM(vcp, SMBTP_TIMEOUT, &tstimeout); - timespecadd(&tstimeout, &tstimeout); + timespecadd(&tstimeout, &tstimeout, &tstimeout); getnanotime(&ts); - timespecsub(&ts, &tstimeout); + timespecsub(&ts, &tstimeout, &ts); if (timespeccmp(&ts, &rqp->sr_timesent, >)) { smb_iod_rqprocessed(rqp, ETIMEDOUT); } @@ -630,7 +630,7 @@ smb_iod_main(struct smbiod *iod) #if 0 if (iod->iod_state == SMBIOD_ST_VCACTIVE) { getnanotime(&tsnow); - timespecsub(&tsnow, &iod->iod_pingtimo); + timespecsub(&tsnow, &iod->iod_pingtimo, &tsnow); if (timespeccmp(&tsnow, &iod->iod_lastrqsent, >)) { smb_smb_echo(vcp, &iod->iod_scred); } diff --git a/sys/netsmb/smb_trantcp.c b/sys/netsmb/smb_trantcp.c index 2c2f7ed19908..8101993277a3 100644 --- a/sys/netsmb/smb_trantcp.c +++ b/sys/netsmb/smb_trantcp.c @@ -546,15 +546,14 @@ smb_nbst_connect(struct smb_vc *vcp, struct sockaddr *sap, struct thread *td) if (error) return error; getnanotime(&ts2); - timespecsub(&ts2, &ts1); + timespecsub(&ts2, &ts1, &ts2); if (ts2.tv_sec == 0) { ts2.tv_sec = 1; ts2.tv_nsec = 0; } - nbp->nbp_timo = ts2; - timespecadd(&nbp->nbp_timo, &ts2); - timespecadd(&nbp->nbp_timo, &ts2); - timespecadd(&nbp->nbp_timo, &ts2); /* * 4 */ + timespecadd(&ts2, &ts2, &nbp->nbp_timo); + timespecadd(&nbp->nbp_timo, &ts2, &nbp->nbp_timo); + timespecadd(&nbp->nbp_timo, &ts2, &nbp->nbp_timo); /* * 4 */ error = nbssn_rq_request(nbp, td); if (error) smb_nbst_disconnect(vcp, td); diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index a6c5920eb857..f3a3bba2e59b 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -1188,7 +1188,7 @@ crypto_tstat(struct cryptotstat *ts, struct bintime *bt) if (u < delta.frac) delta.sec--; bintime2timespec(&delta, &t); - timespecadd(&ts->acc, &t); + timespecadd(&ts->acc, &t, &ts->acc); if (timespeccmp(&t, &ts->min, <)) ts->min = t; if (timespeccmp(&t, &ts->max, >)) diff --git a/sys/sys/param.h b/sys/sys/param.h index 4798ac50e04a..fc8650e5abb7 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -60,7 +60,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1200075 /* Master, propagated to newvers */ +#define __FreeBSD_version 1200076 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, diff --git a/sys/sys/time.h b/sys/sys/time.h index cd517d856d76..6fea11c680b5 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -306,6 +306,7 @@ tvtosbt(struct timeval _tv) #define USEC_2_TICKS(u) max(1, (uint32_t)((hz == 1000) ? \ ((u) / 1000) : ((uint64_t)(u) * (uint64_t)hz)/(uint64_t)1000000)) +#endif /* Operations on timespecs */ #define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) #define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) @@ -313,25 +314,28 @@ tvtosbt(struct timeval _tv) (((tvp)->tv_sec == (uvp)->tv_sec) ? \ ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ ((tvp)->tv_sec cmp (uvp)->tv_sec)) -#define timespecadd(vvp, uvp) \ + +#define timespecadd(tsp, usp, vsp) \ do { \ - (vvp)->tv_sec += (uvp)->tv_sec; \ - (vvp)->tv_nsec += (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec >= 1000000000) { \ - (vvp)->tv_sec++; \ - (vvp)->tv_nsec -= 1000000000; \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ } \ } while (0) -#define timespecsub(vvp, uvp) \ +#define timespecsub(tsp, usp, vsp) \ do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ } \ } while (0) +#ifdef _KERNEL + /* Operations on timevals. */ #define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c index 43829e869d4c..fed0456b13cb 100644 --- a/sys/ufs/ffs/ffs_snapshot.c +++ b/sys/ufs/ffs/ffs_snapshot.c @@ -694,7 +694,7 @@ ffs_snapshot(mp, snapfile) vfs_write_resume(vp->v_mount, VR_START_WRITE | VR_NO_SUSPCLR); if (collectsnapstats && starttime.tv_sec > 0) { nanotime(&endtime); - timespecsub(&endtime, &starttime); + timespecsub(&endtime, &starttime, &endtime); printf("%s: suspended %ld.%03ld sec, redo %ld of %d\n", vp->v_mount->mnt_stat.f_mntonname, (long)endtime.tv_sec, endtime.tv_nsec / 1000000, redo, fs->fs_ncg); diff --git a/sys/x86/iommu/intel_dmar.h b/sys/x86/iommu/intel_dmar.h index 6d25ac3644e6..af151aa6f91f 100644 --- a/sys/x86/iommu/intel_dmar.h +++ b/sys/x86/iommu/intel_dmar.h @@ -524,8 +524,7 @@ extern struct timespec dmar_hw_timeout; } else { \ forever = false; \ nanouptime(&curr); \ - last = curr; \ - timespecadd(&last, &dmar_hw_timeout); \ + timespecadd(&curr, &dmar_hw_timeout, &last); \ } \ for (;;) { \ if (cond) { \ diff --git a/tools/regression/posixsem/posixsem.c b/tools/regression/posixsem/posixsem.c index 693a923ab5e6..9d0465682951 100644 --- a/tools/regression/posixsem/posixsem.c +++ b/tools/regression/posixsem/posixsem.c @@ -55,35 +55,6 @@ __FBSDID("$FreeBSD$"); #include "test.h" -/* Cut and pasted from kernel header, bah! */ - -/* Operations on timespecs */ -#define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) -#define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) -#define timespeccmp(tvp, uvp, cmp) \ - (((tvp)->tv_sec == (uvp)->tv_sec) ? \ - ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ - ((tvp)->tv_sec cmp (uvp)->tv_sec)) -#define timespecadd(vvp, uvp) \ - do { \ - (vvp)->tv_sec += (uvp)->tv_sec; \ - (vvp)->tv_nsec += (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec >= 1000000000) { \ - (vvp)->tv_sec++; \ - (vvp)->tv_nsec -= 1000000000; \ - } \ - } while (0) -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) - - #define TEST_PATH "/tmp/posixsem_regression_test" #define ELAPSED(elapsed, limit) (abs((elapsed) - (limit)) < 100) @@ -791,7 +762,7 @@ timedwait(semid_t id, u_int msec, u_int *delta, int error) } end.tv_sec = msec / 1000; end.tv_nsec = msec % 1000 * 1000000; - timespecadd(&end, &start); + timespecadd(&end, &start, &end); if (ksem_timedwait(id, &end) < 0) { if (errno != error) { fail_errno("ksem_timedwait"); @@ -805,7 +776,7 @@ timedwait(semid_t id, u_int msec, u_int *delta, int error) fail_errno("clock_gettime(CLOCK_REALTIME)"); return (-1); } - timespecsub(&end, &start); + timespecsub(&end, &start, &end); *delta = end.tv_nsec / 1000000; *delta += end.tv_sec * 1000; return (0); @@ -944,7 +915,7 @@ testwait(semid_t id, u_int *delta) fail_errno("clock_gettime(CLOCK_REALTIME)"); return (-1); } - timespecsub(&end, &start); + timespecsub(&end, &start, &end); *delta = end.tv_nsec / 1000000; *delta += end.tv_sec * 1000; return (0); diff --git a/tools/regression/sockets/udp_pingpong/udp_pingpong.c b/tools/regression/sockets/udp_pingpong/udp_pingpong.c index 25750b0c3c0d..fc585d275db4 100644 --- a/tools/regression/sockets/udp_pingpong/udp_pingpong.c +++ b/tools/regression/sockets/udp_pingpong/udp_pingpong.c @@ -106,31 +106,6 @@ struct rtt { #define NSEC_MAX 1000000000L #define NSEC_IN_USEC 1000L -#define timespecsub2(r, v, u) \ - do { \ - SEC(r) = SEC(v) - SEC(u); \ - NSEC(r) = NSEC(v) - NSEC(u); \ - if (NSEC(r) < 0 && (SEC(r) > 0 || NSEC(r) <= -NSEC_MAX)) { \ - SEC(r)--; \ - NSEC(r) += NSEC_MAX; \ - } \ - } while (0); - -#define timespecadd2(r, v, u) \ - do { \ - SEC(r) = SEC(v) + SEC(u); \ - NSEC(r) = NSEC(v) + NSEC(u); \ - if (NSEC(r) >= NSEC_MAX) { \ - SEC(r)++; \ - NSEC(r) -= NSEC_MAX; \ - } \ - } while (0); - -#define timespeccmp(t, c, u) \ - ((SEC(t) == SEC(u)) ? \ - (NSEC(t) c NSEC(u)) : \ - (SEC(t) c SEC(u))) - #define timeval2timespec(tv, ts) \ do { \ SEC(ts) = (tv)->tv_sec; \ @@ -536,10 +511,10 @@ static void calc_rtt(struct test_pkt *tpp, struct rtt *rttp) { - timespecsub2(&rttp->a2b, &tpp->tss[1].recvd, &tpp->tss[0].sent); - timespecsub2(&rttp->b2a, &tpp->tss[0].recvd, &tpp->tss[1].sent); - timespecadd2(&rttp->a2b_b2a, &rttp->a2b, &rttp->b2a); - timespecsub2(&rttp->e2e, &tpp->tss[0].recvd, &tpp->tss[0].sent); + timespecsub(&tpp->tss[1].recvd, &tpp->tss[0].sent, &rttp->a2b); + timespecsub(&tpp->tss[0].recvd, &tpp->tss[1].sent, &rttp->b2a); + timespecadd(&rttp->a2b, &rttp->b2a, &rttp->a2b_b2a); + timespecsub(&tpp->tss[0].recvd, &tpp->tss[0].sent, &rttp->e2e); } static void @@ -604,13 +579,13 @@ test_run(int ts_type, int use_ipv6, int use_recvmsg, const char *name) continue; } calc_rtt(&test_ctx.test_pkts[i], &rtt); - if (!timespeccmp(&rtt.e2e, >, &rtt.a2b_b2a)) + if (!timespeccmp(&rtt.e2e, &rtt.a2b_b2a, >)) errx(1, "end-to-end trip time is too small"); - if (!timespeccmp(&rtt.e2e, <, &max_ts)) + if (!timespeccmp(&rtt.e2e, &max_ts, <)) errx(1, "end-to-end trip time is too large"); - if (!timespeccmp(&rtt.a2b, >, &zero_ts)) + if (!timespeccmp(&rtt.a2b, &zero_ts, >)) errx(1, "A2B trip time is not positive"); - if (!timespeccmp(&rtt.b2a, >, &zero_ts)) + if (!timespeccmp(&rtt.b2a, &zero_ts, >)) errx(1, "B2A trip time is not positive"); } teardown_udp(&test_ctx); diff --git a/tools/regression/sockets/unix_cmsg/uc_check_time.c b/tools/regression/sockets/unix_cmsg/uc_check_time.c index 5b7dfe11bb89..682cd442077d 100644 --- a/tools/regression/sockets/unix_cmsg/uc_check_time.c +++ b/tools/regression/sockets/unix_cmsg/uc_check_time.c @@ -35,20 +35,6 @@ __FBSDID("$FreeBSD$"); static const struct timeval max_diff_tv = {.tv_sec = 1, .tv_usec = 0}; static const struct timespec max_diff_ts = {.tv_sec = 1, .tv_nsec = 0}; -#define timespeccmp(tvp, uvp, cmp) \ - (((tvp)->tv_sec == (uvp)->tv_sec) ? \ - ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ - ((tvp)->tv_sec cmp (uvp)->tv_sec)) -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) - int uc_check_bintime(const struct bintime *mt) { @@ -79,7 +65,7 @@ uc_check_timespec_real(const struct timespec *bt) if (clock_gettime(CLOCK_REALTIME, &ct) < 0) return (-1); - timespecsub(&ct, bt); + timespecsub(&ct, bt, &ct); if (!timespeccmp(&ct, &max_diff_ts, <)) return (-1); @@ -93,7 +79,7 @@ uc_check_timespec_mono(const struct timespec *bt) if (clock_gettime(CLOCK_MONOTONIC, &ct) < 0) return (-1); - timespecsub(&ct, bt); + timespecsub(&ct, bt, &ct); if (!timespeccmp(&ct, &max_diff_ts, <)) return (-1); diff --git a/tools/tools/netrate/juggle/juggle.c b/tools/tools/netrate/juggle/juggle.c index 804dfc9173e0..226f34ad301a 100644 --- a/tools/tools/netrate/juggle/juggle.c +++ b/tools/tools/netrate/juggle/juggle.c @@ -93,19 +93,6 @@ */ #define PIPELINE_MAX 4 -/* - * As in all programs, steal timespecsub() from time.h. - */ -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) - static int udp_create(int *fd1p, int *fd2p) { @@ -277,7 +264,7 @@ juggle(int fd1, int fd2, int pipeline) if (clock_gettime(CLOCK_REALTIME, &tfinish) < 0) err(-1, "juggle: clock_gettime"); - timespecsub(&tfinish, &tstart); + timespecsub(&tfinish, &tstart, &tfinish); return (tfinish); } @@ -373,7 +360,7 @@ thread_juggle(int fd1, int fd2, int pipeline) if (pthread_join(thread, NULL) != 0) err(-1, "thread_juggle: pthread_join"); - timespecsub(&tfinish, &tstart); + timespecsub(&tfinish, &tstart, &tfinish); return (tfinish); } @@ -458,7 +445,7 @@ process_juggle(int fd1, int fd2, int pipeline) if (wpid != pid) errx(-1, "process_juggle: waitpid: pid != wpid"); - timespecsub(&tfinish, &tstart); + timespecsub(&tfinish, &tstart, &tfinish); return (tfinish); } diff --git a/tools/tools/netrate/tcpp/tcpp_client.c b/tools/tools/netrate/tcpp/tcpp_client.c index 70620ce75225..e88976bedf8b 100644 --- a/tools/tools/netrate/tcpp/tcpp_client.c +++ b/tools/tools/netrate/tcpp/tcpp_client.c @@ -57,16 +57,6 @@ #define min(x, y) (x < y ? x : y) -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) - /* * Gist of each client worker: build up to mflag connections at a time, and @@ -336,7 +326,7 @@ tcpp_client(void) if (sysctlbyname(SYSCTLNAME_CPTIME, &cp_time_finish, &size, NULL, 0) < 0) err(-1, "sysctlbyname: %s", SYSCTLNAME_CPTIME); - timespecsub(&ts_finish, &ts_start); + timespecsub(&ts_finish, &ts_start, &ts_finish); if (failed) errx(-1, "Too many errors"); diff --git a/tools/tools/syscall_timing/syscall_timing.c b/tools/tools/syscall_timing/syscall_timing.c index 3a4fcd840bce..2a2caa25ac7d 100644 --- a/tools/tools/syscall_timing/syscall_timing.c +++ b/tools/tools/syscall_timing/syscall_timing.c @@ -59,16 +59,6 @@ static struct timespec ts_start, ts_end; static int alarm_timeout; static volatile int alarm_fired; -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) - #define BENCHMARK_FOREACH(I, NUM) for (I = 0; I < NUM && alarm_fired == 0; I++) static void @@ -1112,7 +1102,7 @@ main(int argc, char *argv[]) for (k = 0; k < loops; k++) { calls = the_test->t_func(iterations, the_test->t_int, path); - timespecsub(&ts_end, &ts_start); + timespecsub(&ts_end, &ts_start, &ts_end); printf("%s\t%ju\t", the_test->t_name, k); printf("%ju.%09ju\t%ju\t", (uintmax_t)ts_end.tv_sec, (uintmax_t)ts_end.tv_nsec, calls); diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c index 092188a4b60c..cc28dda61e86 100644 --- a/usr.bin/truss/setup.c +++ b/usr.bin/truss/setup.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -522,12 +523,12 @@ print_line_prefix(struct trussinfo *info) len += fprintf(info->outfile, ": "); } if (info->flags & ABSOLUTETIMESTAMPS) { - timespecsubt(&t->after, &info->start_time, &timediff); + timespecsub(&t->after, &info->start_time, &timediff); len += fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, timediff.tv_nsec); } if (info->flags & RELATIVETIMESTAMPS) { - timespecsubt(&t->after, &t->before, &timediff); + timespecsub(&t->after, &t->before, &timediff); len += fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, timediff.tv_nsec); } diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 92f6854a1ce0..1df36775abbe 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #define _WANT_FREEBSD11_STAT #include +#include #include #include #include @@ -2639,7 +2640,7 @@ print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval) t = trussinfo->curthread; sc = t->cs.sc; if (trussinfo->flags & COUNTONLY) { - timespecsubt(&t->after, &t->before, &timediff); + timespecsub(&t->after, &t->before, &timediff); timespecadd(&sc->time, &timediff, &sc->time); sc->ncalls++; if (errorp) diff --git a/usr.bin/truss/truss.h b/usr.bin/truss/truss.h index e63dbcbcb50c..4615b798e7cd 100644 --- a/usr.bin/truss/truss.h +++ b/usr.bin/truss/truss.h @@ -119,23 +119,3 @@ struct trussinfo LIST_HEAD(, procinfo) proclist; }; - -#define timespecsubt(tvp, uvp, vvp) \ - do { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_nsec = (tvp)->tv_nsec - (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) - -#define timespecadd(tvp, uvp, vvp) \ - do { \ - (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ - (vvp)->tv_nsec = (tvp)->tv_nsec + (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec > 1000000000) { \ - (vvp)->tv_sec++; \ - (vvp)->tv_nsec -= 1000000000; \ - } \ - } while (0) diff --git a/usr.sbin/camdd/camdd.c b/usr.sbin/camdd/camdd.c index 040920ad9562..1133c6c182aa 100644 --- a/usr.sbin/camdd/camdd.c +++ b/usr.sbin/camdd/camdd.c @@ -429,23 +429,6 @@ static sig_atomic_t need_status = 0; #define min(a, b) (a < b) ? a : b #endif -/* - * XXX KDM private copy of timespecsub(). This is normally defined in - * sys/time.h, but is only enabled in the kernel. If that definition is - * enabled in userland, it breaks the build of libnetbsd. - */ -#ifndef timespecsub -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) -#endif - /* Generically useful offsets into the peripheral private area */ #define ppriv_ptr0 periph_priv.entries[0].ptr @@ -3069,7 +3052,7 @@ camdd_print_status(struct camdd_dev *camdd_dev, struct camdd_dev *other_dev, return; } - timespecsub(&done_time, start_time); + timespecsub(&done_time, start_time, &done_time); total_ns = done_time.tv_nsec + (done_time.tv_sec * 1000000000); total_sec = total_ns;