diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2020-06-24 22:03:46 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2020-06-24 22:03:46 +0000 |
commit | ca98724d303a2d2852e5afc6ca4f8df91ce7c4f1 (patch) | |
tree | 78c03b913ca4a13ca82e30fea2eea3633977a5a0 /sys/net/if_pflow.c | |
parent | d5d00fdfec2707a72d8f409ed3069c27bc916b04 (diff) |
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_pflow.c')
-rw-r--r-- | sys/net/if_pflow.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c index e78eeb9090d..1d482865013 100644 --- a/sys/net/if_pflow.c +++ b/sys/net/if_pflow.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pflow.c,v 1.90 2018/07/30 12:22:14 mpi Exp $ */ +/* $OpenBSD: if_pflow.c,v 1.91 2020/06/24 22:03:42 cheloha Exp $ */ /* * Copyright (c) 2011 Florian Obser <florian@narrans.de> @@ -734,13 +734,13 @@ copy_flow_ipfix_4_data(struct pflow_ipfix_flow4 *flow1, * is in the future of the last time a package was seen due to pfsync. */ if (st->creation > st->expire) - flow1->flow_start = flow2->flow_start = htobe64((time_second - - time_uptime)*1000); + flow1->flow_start = flow2->flow_start = htobe64((gettime() - + getuptime())*1000); else - flow1->flow_start = flow2->flow_start = htobe64((time_second - - (time_uptime - st->creation))*1000); - flow1->flow_finish = flow2->flow_finish = htobe64((time_second - - (time_uptime - st->expire))*1000); + flow1->flow_start = flow2->flow_start = htobe64((gettime() - + (getuptime() - st->creation))*1000); + flow1->flow_finish = flow2->flow_finish = htobe64((gettime() - + (getuptime() - st->expire))*1000); flow1->protocol = flow2->protocol = sk->proto; flow1->tos = flow2->tos = st->rule.ptr->tos; @@ -773,13 +773,13 @@ copy_flow_ipfix_6_data(struct pflow_ipfix_flow6 *flow1, * is in the future of the last time a package was seen due to pfsync. */ if (st->creation > st->expire) - flow1->flow_start = flow2->flow_start = htobe64((time_second - - time_uptime)*1000); + flow1->flow_start = flow2->flow_start = htobe64((gettime() - + getuptime())*1000); else - flow1->flow_start = flow2->flow_start = htobe64((time_second - - (time_uptime - st->creation))*1000); - flow1->flow_finish = flow2->flow_finish = htobe64((time_second - - (time_uptime - st->expire))*1000); + flow1->flow_start = flow2->flow_start = htobe64((gettime() - + (getuptime() - st->creation))*1000); + flow1->flow_finish = flow2->flow_finish = htobe64((gettime() - + (getuptime() - st->expire))*1000); flow1->protocol = flow2->protocol = sk->proto; flow1->tos = flow2->tos = st->rule.ptr->tos; @@ -1082,7 +1082,7 @@ pflow_sendout_v5(struct pflow_softc *sc) h->count = htons(sc->sc_count); /* populate pflow_header */ - h->uptime_ms = htonl(time_uptime * 1000); + h->uptime_ms = htonl(getuptime() * 1000); getnanotime(&tv); h->time_sec = htonl(tv.tv_sec); /* XXX 2038 */ @@ -1145,7 +1145,7 @@ pflow_sendout_ipfix(struct pflow_softc *sc, sa_family_t af) h10 = mtod(m, struct pflow_v10_header *); h10->version = htons(PFLOW_PROTO_10); h10->length = htons(PFLOW_IPFIX_HDRLEN + set_length); - h10->time_sec = htonl(time_second); /* XXX 2038 */ + h10->time_sec = htonl(gettime()); /* XXX 2038 */ h10->flow_sequence = htonl(sc->sc_sequence); sc->sc_sequence += count; h10->observation_dom = htonl(PFLOW_ENGINE_TYPE); @@ -1186,7 +1186,7 @@ pflow_sendout_ipfix_tmpl(struct pflow_softc *sc) h10->version = htons(PFLOW_PROTO_10); h10->length = htons(PFLOW_IPFIX_HDRLEN + sizeof(struct pflow_ipfix_tmpl)); - h10->time_sec = htonl(time_second); /* XXX 2038 */ + h10->time_sec = htonl(gettime()); /* XXX 2038 */ h10->flow_sequence = htonl(sc->sc_sequence); h10->observation_dom = htonl(PFLOW_ENGINE_TYPE); |