summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormglocker <mglocker@openbsd.org>2020-12-12 09:44:27 +0000
committermglocker <mglocker@openbsd.org>2020-12-12 09:44:27 +0000
commit2dbff3f47899dd079917592ea412b91ff5e3478a (patch)
treed236f6f32c15dc1391482be22e9b497c1c035b08 /sys
parentReplace list faked with a literal display with a real list. (diff)
downloadwireguard-openbsd-2dbff3f47899dd079917592ea412b91ff5e3478a.tar.xz
wireguard-openbsd-2dbff3f47899dd079917592ea412b91ff5e3478a.zip
The asmc sensor update task currently consumes ~50ms on each refresh cycle
because the asmc read/write functions are timing out regularly on each cycle. Since the sensor task is executed during kernel lock, this can have a negative impact on time sensitive code, as seen with USB isoc transfers. Rewriting the asmc read/write functions to a similar execution pattern as the Linux driver does, entirely removes the timeouts, and hence reduces the asmc sensor update code to be executed within ~3ms. ok mpi@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/acpi/asmc.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/sys/dev/acpi/asmc.c b/sys/dev/acpi/asmc.c
index 23e396668f5..cb9556f456c 100644
--- a/sys/dev/acpi/asmc.c
+++ b/sys/dev/acpi/asmc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asmc.c,v 1.2 2020/09/13 14:11:28 mglocker Exp $ */
+/* $OpenBSD: asmc.c,v 1.3 2020/12/12 09:44:27 mglocker Exp $ */
/*
* Copyright (c) 2015 Joerg Jung <jung@openbsd.org>
*
@@ -58,6 +58,8 @@
#define ASMC_MAXLIGHT 2 /* left and right light sensor */
#define ASMC_MAXMOTION 3 /* x y z axis motion sensors */
+#define ASMC_DELAY_LOOP 200 /* ASMC_DELAY_LOOP * 10us = 2ms */
+
struct asmc_prod {
const char *pr_name;
uint8_t pr_light;
@@ -434,36 +436,41 @@ asmc_status(struct asmc_softc *sc)
}
static int
-asmc_wait(struct asmc_softc *sc, uint8_t mask, uint8_t val)
+asmc_write(struct asmc_softc *sc, uint8_t off, uint8_t val)
{
int i;
+ uint8_t status;
- for (i = 0; i < 500; i++) { /* wait up to 5 ms */
- if ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASMC_COMMAND) &
- mask) == val)
+ bus_space_write_1(sc->sc_iot, sc->sc_ioh, off, val);
+ for (i = 0; i < ASMC_DELAY_LOOP; i++) {
+ status = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASMC_COMMAND);
+ if (status & ASMC_IBF)
+ continue;
+ if (status & ASMC_ACCEPT)
return 0;
delay(10);
+ bus_space_write_1(sc->sc_iot, sc->sc_ioh, off, val);
}
- return ETIMEDOUT;
-}
-static int
-asmc_write(struct asmc_softc *sc, uint8_t off, uint8_t val)
-{
- if (asmc_wait(sc, ASMC_IBF, 0))
- return 1;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, off, val);
- if (asmc_wait(sc, ASMC_ACCEPT, ASMC_ACCEPT))
- return 1;
- return 0;
+ return ETIMEDOUT;
}
static int
asmc_read(struct asmc_softc *sc, uint8_t off, uint8_t *buf)
{
- if (asmc_wait(sc, ASMC_OBF, ASMC_OBF))
- return 1;
+ int i;
+ uint8_t status;
+
+ for (i = 0; i < ASMC_DELAY_LOOP; i++) {
+ status = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASMC_COMMAND);
+ if (status & ASMC_OBF)
+ break;
+ delay(10);
+ }
+ if (i == ASMC_DELAY_LOOP)
+ return ETIMEDOUT;
*buf = bus_space_read_1(sc->sc_iot, sc->sc_ioh, off);
+
return 0;
}