summaryrefslogtreecommitdiffstats
path: root/sys/net/rtsock.c
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-06-24 22:03:40 +0000
committercheloha <cheloha@openbsd.org>2020-06-24 22:03:40 +0000
commit3209772dfcc3950dd5df01bc44eebf75e637511e (patch)
tree674a3736a2e3e277e801c3c22c1430cb8a2d032f /sys/net/rtsock.c
parentFirst stab at making signal handling work. (diff)
downloadwireguard-openbsd-3209772dfcc3950dd5df01bc44eebf75e637511e.tar.xz
wireguard-openbsd-3209772dfcc3950dd5df01bc44eebf75e637511e.zip
kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)
time_second(9) and time_uptime(9) are widely used in the kernel to quickly get the system UTC or system uptime as a time_t. However, time_t is 64-bit everywhere, so it is not generally safe to use them on 32-bit platforms: you have a split-read problem if your hardware cannot perform atomic 64-bit reads. This patch replaces time_second(9) with gettime(9), a safer successor interface, throughout the kernel. Similarly, time_uptime(9) is replaced with getuptime(9). There is a performance cost on 32-bit platforms in exchange for eliminating the split-read problem: instead of two register reads you now have a lockless read loop to pull the values from the timehands. This is really not *too* bad in the grand scheme of things, but compared to what we were doing before it is several times slower. There is no performance cost on 64-bit (__LP64__) platforms. With input from visa@, dlg@, and tedu@. Several bugs squashed by visa@. ok kettenis@
Diffstat (limited to 'sys/net/rtsock.c')
-rw-r--r--sys/net/rtsock.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index e00e94997e7..9d4ccadd4e2 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.298 2020/03/24 13:50:18 tobhe Exp $ */
+/* $OpenBSD: rtsock.c,v 1.299 2020/06/24 22:03:42 cheloha Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -1325,8 +1325,8 @@ rtm_setmetrics(u_long which, const struct rt_metrics *in,
if (which & RTV_EXPIRE) {
expire = in->rmx_expire;
if (expire != 0) {
- expire -= time_second;
- expire += time_uptime;
+ expire -= gettime();
+ expire += getuptime();
}
out->rmx_expire = expire;
@@ -1340,8 +1340,8 @@ rtm_getmetrics(const struct rt_kmetrics *in, struct rt_metrics *out)
expire = in->rmx_expire;
if (expire != 0) {
- expire -= time_uptime;
- expire += time_second;
+ expire -= getuptime();
+ expire += gettime();
}
bzero(out, sizeof(*out));