From ced16ee2648272cac259b70e7741359c9c68e723 Mon Sep 17 00:00:00 2001 From: cheloha Date: Thu, 9 May 2019 18:29:26 +0000 Subject: Measure poll interval with monotonic clock. ok jcs@ --- sys/dev/acpi/acpisbs.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'sys/dev/acpi') diff --git a/sys/dev/acpi/acpisbs.c b/sys/dev/acpi/acpisbs.c index dda591783f1..0fa031f8fc7 100644 --- a/sys/dev/acpi/acpisbs.c +++ b/sys/dev/acpi/acpisbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpisbs.c,v 1.7 2018/06/29 17:39:18 kettenis Exp $ */ +/* $OpenBSD: acpisbs.c,v 1.8 2019/05/09 18:29:25 cheloha Exp $ */ /* * Smart Battery subsystem device driver * ACPI 5.0 spec section 10 @@ -170,7 +170,7 @@ acpisbs_attach(struct device *parent, struct device *self, void *aux) memset(&sc->sc_battery, 0, sizeof(sc->sc_battery)); - getmicrotime(&sc->sc_lastpoll); + getmicrouptime(&sc->sc_lastpoll); if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "_SBS", 0, NULL, &sbs)) return; @@ -359,11 +359,11 @@ int acpisbs_notify(struct aml_node *node, int notify_type, void *arg) { struct acpisbs_softc *sc = arg; - struct timeval tv; + struct timeval diff, now; DPRINTF(("%s: %s: %d\n", sc->sc_dev.dv_xname, __func__, notify_type)); - getmicrotime(&tv); + getmicrouptime(&now); switch (notify_type) { case 0x00: @@ -373,10 +373,11 @@ acpisbs_notify(struct aml_node *node, int notify_type, void *arg) * EC SCI will come for every data point, so only run once in a * while */ - if (tv.tv_sec - sc->sc_lastpoll.tv_sec > ACPISBS_POLL_FREQ) { + timersub(&now, &sc->sc_lastpoll, &diff); + if (diff.tv_sec > ACPISBS_POLL_FREQ) { acpisbs_read(sc); acpisbs_refresh_sensors(sc); - getmicrotime(&sc->sc_lastpoll); + getmicrouptime(&sc->sc_lastpoll); } break; default: -- cgit v1.2.3