summaryrefslogtreecommitdiffstats
path: root/sys/net/if_bpe.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/if_bpe.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/if_bpe.c')
-rw-r--r--sys/net/if_bpe.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/sys/net/if_bpe.c b/sys/net/if_bpe.c
index b9a88be8efa..13224499bb1 100644
--- a/sys/net/if_bpe.c
+++ b/sys/net/if_bpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bpe.c,v 1.10 2019/11/07 07:36:31 dlg Exp $ */
+/* $OpenBSD: if_bpe.c,v 1.11 2020/06/24 22:03:43 cheloha Exp $ */
/*
* Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
*
@@ -230,7 +230,7 @@ bpe_entry_valid(struct bpe_softc *sc, const struct bpe_entry *be)
if (be->be_type == BPE_ENTRY_STATIC)
return (1);
- diff = time_uptime - be->be_age;
+ diff = getuptime() - be->be_age;
if (diff < sc->sc_bridge_tmo)
return (1);
@@ -343,7 +343,7 @@ bpe_bridge_age(void *arg)
if (be->be_type != BPE_ENTRY_DYNAMIC)
continue;
- diff = time_uptime - be->be_age;
+ diff = getuptime() - be->be_age;
if (diff < sc->sc_bridge_tmo)
continue;
@@ -402,7 +402,7 @@ bpe_rtfind(struct bpe_softc *sc, struct ifbaconf *baconf)
switch (be->be_type) {
case BPE_ENTRY_DYNAMIC:
- age = time_uptime - be->be_age;
+ age = getuptime() - be->be_age;
bareq.ifba_age = MIN(age, 0xff);
bareq.ifba_flags = IFBAF_DYNAMIC;
break;
@@ -833,7 +833,7 @@ bpe_input_map(struct bpe_softc *sc, const uint8_t *ba, const uint8_t *ca)
if (be == NULL)
new = 1;
else {
- be->be_age = time_uptime; /* only a little bit racy */
+ be->be_age = getuptime(); /* only a little bit racy */
if (be->be_type != BPE_ENTRY_DYNAMIC ||
ETHER_IS_EQ(ba, &be->be_b_da))
@@ -857,7 +857,7 @@ bpe_input_map(struct bpe_softc *sc, const uint8_t *ba, const uint8_t *ca)
memcpy(&be->be_b_da, ba, sizeof(be->be_b_da));
be->be_type = BPE_ENTRY_DYNAMIC;
refcnt_init(&be->be_refs);
- be->be_age = time_uptime;
+ be->be_age = getuptime();
rw_enter_write(&sc->sc_bridge_lock);
num = sc->sc_bridge_num;