summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-12-06 19:23:11 +0000
committercheloha <cheloha@openbsd.org>2020-12-06 19:23:11 +0000
commit950f295da4c4cabf72279ceed886bcb21b302149 (patch)
treee9552f7ad183743d82d8d08f122d1b8f65f78246
parentsrp_finalize(9): tsleep(9) -> tsleep_nsec(9) (diff)
downloadwireguard-openbsd-950f295da4c4cabf72279ceed886bcb21b302149.tar.xz
wireguard-openbsd-950f295da4c4cabf72279ceed886bcb21b302149.zip
mbg(4): more tsleep(9) -> tsleep_nsec(9)
The mbg(4) driver sometimes needs to spin until the MBG_BUSY flag goes away. If the kernel is cold it calls delay(9) for 20us an iteration for up to 50 iterations. If the kernel is not cold it sleeps for up 1 tick per iteration for up to hz/10 iterations. To switch from tsleep(9) to tsleep_nsec(9) claudio@ suggests blocking for at least 1ms per iteration for up to 10 iterations. He reasons that the flag change is expected to take ~70us, so 10 x 1ms (or more) is more than enough. Discussed with mpi@. ok claudio@
-rw-r--r--sys/dev/pci/mbg.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/sys/dev/pci/mbg.c b/sys/dev/pci/mbg.c
index 248e17154b3..c6717a6e3e2 100644
--- a/sys/dev/pci/mbg.c
+++ b/sys/dev/pci/mbg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbg.c,v 1.31 2020/11/29 03:17:27 kevlo Exp $ */
+/* $OpenBSD: mbg.c,v 1.32 2020/12/06 19:23:11 cheloha Exp $ */
/*
* Copyright (c) 2006, 2007 Marc Balmer <mbalmer@openbsd.org>
@@ -417,12 +417,12 @@ mbg_read_amcc_s5920(struct mbg_softc *sc, int cmd, char *buf, size_t len,
/* wait for the BUSY flag to go low (approx 70 us on i386) */
timer = 0;
- tmax = cold ? 50 : hz / 10;
+ tmax = cold ? 50 : 10;
do {
if (cold)
delay(20);
else
- tsleep(tstamp, 0, "mbg", 1);
+ tsleep_nsec(tstamp, 0, "mbg", MSEC_TO_NSEC(1));
status = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
AMCC_IMB4 + 3);
} while ((status & MBG_BUSY) && timer++ < tmax);
@@ -473,12 +473,12 @@ mbg_read_amcc_s5933(struct mbg_softc *sc, int cmd, char *buf, size_t len,
/* wait for the BUSY flag to go low (approx 70 us on i386) */
timer = 0;
- tmax = cold ? 50 : hz / 10;
+ tmax = cold ? 50 : 10;
do {
if (cold)
delay(20);
else
- tsleep(tstamp, 0, "mbg", 1);
+ tsleep_nsec(tstamp, 0, "mbg", MSEC_TO_NSEC(1));
status = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
AMCC_IMB4 + 3);
} while ((status & MBG_BUSY) && timer++ < tmax);
@@ -525,12 +525,12 @@ mbg_read_asic(struct mbg_softc *sc, int cmd, char *buf, size_t len,
/* wait for the BUSY flag to go low */
timer = 0;
- tmax = cold ? 50 : hz / 10;
+ tmax = cold ? 50 : 10;
do {
if (cold)
delay(20);
else
- tsleep(tstamp, 0, "mbg", 1);
+ tsleep_nsec(tstamp, 0, "mbg", MSEC_TO_NSEC(1));
status = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASIC_STATUS);
} while ((status & MBG_BUSY) && timer++ < tmax);