diff options
author | 2020-12-17 23:36:47 +0000 | |
---|---|---|
committer | 2020-12-17 23:36:47 +0000 | |
commit | c3f245a922f572cb86ab2ccf5b566f44af0470e1 (patch) | |
tree | 09264b853cc53e77b3013e266c94d03f1fc143dd | |
parent | fix possible error("%s", NULL) on error paths (diff) | |
download | wireguard-openbsd-c3f245a922f572cb86ab2ccf5b566f44af0470e1.tar.xz wireguard-openbsd-c3f245a922f572cb86ab2ccf5b566f44af0470e1.zip |
tht(4): more tsleep(9) -> tsleep_nsec(9)
The first wait-loop in tht_fw_load() can sleep for at least 10ms per
iteration instead of up to 1 tick per iteration with no ill effects.
The worst-case scenario is that we sleep a little longer than we do
now while we wait.
The second wait-loop can be simplified to sleep for at least 10ms per
iteration for up to 2000ms instead of using a timeout. This method is
less precise and less efficient but is far simpler to read and
understand than using a timeout. We can then remove all the
timeout-related stuff from if_tht.c.
Discussed with mpi@.
ok dlg@
-rw-r--r-- | sys/dev/pci/if_tht.c | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/sys/dev/pci/if_tht.c b/sys/dev/pci/if_tht.c index f37b6f4ec24..7b4b0c04d02 100644 --- a/sys/dev/pci/if_tht.c +++ b/sys/dev/pci/if_tht.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tht.c,v 1.142 2020/07/10 13:26:38 patrick Exp $ */ +/* $OpenBSD: if_tht.c,v 1.143 2020/12/17 23:36:47 cheloha Exp $ */ /* * Copyright (c) 2007 David Gwynne <dlg@openbsd.org> @@ -582,7 +582,6 @@ void tht_lladdr_read(struct tht_softc *); void tht_lladdr_write(struct tht_softc *); int tht_sw_reset(struct tht_softc *); int tht_fw_load(struct tht_softc *); -void tht_fw_tick(void *arg); void tht_link_state(struct tht_softc *); /* interface operations */ @@ -1667,11 +1666,9 @@ tht_sw_reset(struct tht_softc *sc) int tht_fw_load(struct tht_softc *sc) { - struct timeout ticker; - volatile int ok = 1; u_int8_t *fw, *buf; size_t fwlen, wrlen; - int error = 1; + int error = 1, msecs, ret; if (loadfirmware("tht", &fw, &fwlen) != 0) return (1); @@ -1682,7 +1679,9 @@ tht_fw_load(struct tht_softc *sc) buf = fw; while (fwlen > 0) { while (tht_fifo_writable(sc, &sc->sc_txt) <= THT_FIFO_GAP) { - if (tsleep(sc, PCATCH, "thtfw", 1) == EINTR) + ret = tsleep_nsec(sc, PCATCH, "thtfw", + MSEC_TO_NSEC(10)); + if (ret == EINTR) goto err; } @@ -1695,18 +1694,15 @@ tht_fw_load(struct tht_softc *sc) buf += wrlen; } - timeout_set(&ticker, tht_fw_tick, (void *)&ok); - timeout_add_sec(&ticker, 2); - while (ok) { + for (msecs = 0; msecs < 2000; msecs += 10) { if (tht_read(sc, THT_REG_INIT_STATUS) != 0) { error = 0; break; } - - if (tsleep(sc, PCATCH, "thtinit", 1) == EINTR) + ret = tsleep_nsec(sc, PCATCH, "thtinit", MSEC_TO_NSEC(10)); + if (ret == EINTR) goto err; } - timeout_del(&ticker); tht_write(sc, THT_REG_INIT_SEMAPHORE, 0x1); @@ -1716,14 +1712,6 @@ err: } void -tht_fw_tick(void *arg) -{ - volatile int *ok = arg; - - *ok = 0; -} - -void tht_link_state(struct tht_softc *sc) { static const struct timeval interval = { 0, 10000 }; |