From 4b78f41ac76a6cabd33b927b0f8faedb21c7197f Mon Sep 17 00:00:00 2001 From: kn Date: Fri, 26 Mar 2021 22:54:41 +0000 Subject: [PATCH] Flag sensors as invalid on bogus reads Follow-up to the previous commit: This driver continues to report stale hw.sensors values when reading them fails, which can easily be observed on a Pinebook Pro after plugging in the AC cable, causing the hw.sensors.cwfg0.raw0 (battery remaining minutes) value to jump considerably one or two times before stalling and becoming incoherent with the rest. Flag sensors invalid upfront in apm's fashion and mark them OK iff they yield valid values; this is what other drivers such as rktemp(4) do, but the consequence/intention of SENSOR_FINVALID is sysctl(8) and systat(8) skipping such sensors (until AC gets plugged off again). OK patrick --- sys/dev/fdt/cwfg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/dev/fdt/cwfg.c b/sys/dev/fdt/cwfg.c index b08c56e26e1..7940273e1a9 100644 --- a/sys/dev/fdt/cwfg.c +++ b/sys/dev/fdt/cwfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cwfg.c,v 1.3 2021/03/25 12:18:27 kn Exp $ */ +/* $OpenBSD: cwfg.c,v 1.4 2021/03/26 22:54:41 kn Exp $ */ /* $NetBSD: cwfg.c,v 1.1 2020/01/03 18:00:05 jmcneill Exp $ */ /*- * Copyright (c) 2020 Jared McNeill @@ -348,9 +348,13 @@ cwfg_update_sensors(void *arg) uint8_t val; int error, n; -#if NAPM > 0 - /* reset previous reads so apm(4) never gets stale values + /* invalidate all previous reads to avoid stale/incoherent values * in case of transient cwfg_read() failures below */ + sc->sc_sensor[CWFG_SENSOR_VCELL].flags |= SENSOR_FINVALID; + sc->sc_sensor[CWFG_SENSOR_SOC].flags |= SENSOR_FINVALID; + sc->sc_sensor[CWFG_SENSOR_RTT].flags |= SENSOR_FINVALID; + +#if NAPM > 0 cwfg_power.battery_state = APM_BATT_UNKNOWN; cwfg_power.ac_state = APM_AC_UNKNOWN; cwfg_power.battery_life = 0; -- 2.20.1