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/pf_table.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/pf_table.c')
-rw-r--r-- | sys/net/pf_table.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/sys/net/pf_table.c b/sys/net/pf_table.c index 487207dcd0e..07ec189a12f 100644 --- a/sys/net/pf_table.c +++ b/sys/net/pf_table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_table.c,v 1.132 2020/06/04 04:27:51 yasuoka Exp $ */ +/* $OpenBSD: pf_table.c,v 1.133 2020/06/24 22:03:43 cheloha Exp $ */ /* * Copyright (c) 2002 Cedric Berger @@ -271,7 +271,7 @@ pfr_add_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size, struct pfr_kentry *p, *q; struct pfr_addr ad; int i, rv, xadd = 0; - time_t tzero = time_second; + time_t tzero = gettime(); ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY | PFR_FLAG_FEEDBACK); if (pfr_validate_table(tbl, 0, flags & PFR_FLAG_USERIOCTL)) @@ -438,7 +438,7 @@ pfr_set_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size, struct pfr_kentry *p, *q; struct pfr_addr ad; int i, rv, xadd = 0, xdel = 0, xchange = 0; - time_t tzero = time_second; + time_t tzero = gettime(); ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY | PFR_FLAG_FEEDBACK); if (pfr_validate_table(tbl, ignore_pfrt_flags, flags & @@ -630,7 +630,7 @@ pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size, struct pfr_walktree w; struct pfr_kentryworkq workq; int rv; - time_t tzero = time_second; + time_t tzero = gettime(); if (pfr_validate_table(tbl, 0, 0)) return (EINVAL); @@ -703,7 +703,7 @@ pfr_clr_astats(struct pfr_table *tbl, struct pfr_addr *addr, int size, } if (!(flags & PFR_FLAG_DUMMY)) { - pfr_clstats_kentries(&workq, time_second, 0); + pfr_clstats_kentries(&workq, gettime(), 0); } if (nzero != NULL) *nzero = xzero; @@ -1285,7 +1285,7 @@ pfr_add_tables(struct pfr_table *tbl, int size, int *nadd, int flags) struct pfr_ktableworkq addq, changeq; struct pfr_ktable *p, *q, *r, key; int i, rv, xadd = 0; - time_t tzero = time_second; + time_t tzero = gettime(); ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY); SLIST_INIT(&addq); @@ -1438,7 +1438,7 @@ pfr_get_tstats(struct pfr_table *filter, struct pfr_tstats *tbl, int *size, struct pfr_ktable *p; struct pfr_ktableworkq workq; int n, nn; - time_t tzero = time_second; + time_t tzero = gettime(); /* XXX PFR_FLAG_CLSTATS disabled */ ACCEPT_FLAGS(flags, PFR_FLAG_ALLRSETS); @@ -1479,7 +1479,7 @@ pfr_clr_tstats(struct pfr_table *tbl, int size, int *nzero, int flags) struct pfr_ktableworkq workq; struct pfr_ktable *p, key; int i, xzero = 0; - time_t tzero = time_second; + time_t tzero = gettime(); ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY | PFR_FLAG_ADDRSTOO); SLIST_INIT(&workq); @@ -1732,7 +1732,7 @@ pfr_ina_commit(struct pfr_table *trs, u_int32_t ticket, int *nadd, struct pfr_ktableworkq workq; struct pf_ruleset *rs; int xadd = 0, xchange = 0; - time_t tzero = time_second; + time_t tzero = gettime(); ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY); rs = pf_find_ruleset(trs->pfrt_anchor); @@ -2226,7 +2226,7 @@ pfr_attach_table(struct pf_ruleset *rs, char *name, int intr) strlcpy(tbl.pfrt_anchor, ac->path, sizeof(tbl.pfrt_anchor)); kt = pfr_lookup_table(&tbl); if (kt == NULL) { - kt = pfr_create_ktable(&tbl, time_second, 1, intr); + kt = pfr_create_ktable(&tbl, gettime(), 1, intr); if (kt == NULL) return (NULL); if (ac != NULL) { |