aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2018-07-30 15:46:40 +0000
committerAlan Somers <asomers@FreeBSD.org>2018-07-30 15:46:40 +0000
commit6040822c4e20fb46638ecaaad543fc56f6ec2b0f (patch)
tree133352663bf8c98c65abf581f6a4a8769325ca09 /tools
parent19fe43f796f3d962b3bf023a4484a82d7b2a5711 (diff)
downloadsrc-6040822c4e20fb46638ecaaad543fc56f6ec2b0f.tar.gz
src-6040822c4e20fb46638ecaaad543fc56f6ec2b0f.zip
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
Notes
Notes: svn path=/head/; revision=336914
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/posixsem/posixsem.c35
-rw-r--r--tools/regression/sockets/udp_pingpong/udp_pingpong.c41
-rw-r--r--tools/regression/sockets/unix_cmsg/uc_check_time.c18
-rw-r--r--tools/tools/netrate/juggle/juggle.c19
-rw-r--r--tools/tools/netrate/tcpp/tcpp_client.c12
-rw-r--r--tools/tools/syscall_timing/syscall_timing.c12
6 files changed, 18 insertions, 119 deletions
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);