From nobody Sat Nov 13 09:05:00 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E325A18555E4; Sat, 13 Nov 2021 09:05:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HrqKS65zgz3rjY; Sat, 13 Nov 2021 09:05:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B32DD108DD; Sat, 13 Nov 2021 09:05:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AD950vi064673; Sat, 13 Nov 2021 09:05:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AD950Tk064672; Sat, 13 Nov 2021 09:05:00 GMT (envelope-from git) Date: Sat, 13 Nov 2021 09:05:00 GMT Message-Id: <202111130905.1AD950Tk064672@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: c9882d7600f9 - stable/13 - htu21: don't needlessly bother hardware when measurements are not needed List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c9882d7600f95d5aa9dfb369548900148a47a950 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=c9882d7600f95d5aa9dfb369548900148a47a950 commit c9882d7600f95d5aa9dfb369548900148a47a950 Author: Andriy Gapon AuthorDate: 2021-11-06 16:47:32 +0000 Commit: Andriy Gapon CommitDate: 2021-11-13 08:59:33 +0000 htu21: don't needlessly bother hardware when measurements are not needed sysctl(8) first queries a sysctl to get a size of its value even if the sysctl is of a fixed size, e.g. it has an integer type. Only after that sysctl(8) queries an actual value of the sysctl. Previosuly the driver would needlessly read a sensor in the first step. (cherry picked from commit 43b031a371eb90c15c390c26202f5f58d09300ef) --- sys/dev/iicbus/htu21.c | 88 +++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/sys/dev/iicbus/htu21.c b/sys/dev/iicbus/htu21.c index 5c59ebe8f54a..24f868eb5165 100644 --- a/sys/dev/iicbus/htu21.c +++ b/sys/dev/iicbus/htu21.c @@ -192,21 +192,24 @@ htu21_temp_sysctl(SYSCTL_HANDLER_ARGS) dev = arg1; sc = device_get_softc(dev); - if (sc->sc_hold) - error = htu21_get_measurement(dev, HTU21_GET_TEMP, - raw_data, nitems(raw_data)); - else - error = htu21_get_measurement_nohold(dev, HTU21_GET_TEMP_NH, - raw_data, nitems(raw_data)); - - if (error != 0) { - return (EIO); - } else if (!check_crc_16(raw_data, raw_data[2])) { - temp = -1; - sc->sc_errcount++; - } else { - temp = (((uint16_t)raw_data[0]) << 8) | (raw_data[1] & 0xfc); - temp = ((temp * 17572) >> 16 ) + 27315 - 4685; + if (req->oldptr != NULL) { + if (sc->sc_hold) + error = htu21_get_measurement(dev, HTU21_GET_TEMP, + raw_data, nitems(raw_data)); + else + error = htu21_get_measurement_nohold(dev, + HTU21_GET_TEMP_NH, raw_data, nitems(raw_data)); + + if (error != 0) { + return (EIO); + } else if (!check_crc_16(raw_data, raw_data[2])) { + temp = -1; + sc->sc_errcount++; + } else { + temp = (((uint16_t)raw_data[0]) << 8) | + (raw_data[1] & 0xfc); + temp = ((temp * 17572) >> 16 ) + 27315 - 4685; + } } error = sysctl_handle_int(oidp, &temp, 0, req); @@ -224,21 +227,24 @@ htu21_rh_sysctl(SYSCTL_HANDLER_ARGS) dev = arg1; sc = device_get_softc(dev); - if (sc->sc_hold) - error = htu21_get_measurement(dev, HTU21_GET_HUM, - raw_data, nitems(raw_data)); - else - error = htu21_get_measurement_nohold(dev, HTU21_GET_HUM_NH, - raw_data, nitems(raw_data)); - - if (error != 0) { - return (EIO); - } else if (!check_crc_16(raw_data, raw_data[2])) { - rh = -1; - sc->sc_errcount++; - } else { - rh = (((uint16_t)raw_data[0]) << 8) | (raw_data[1] & 0xfc); - rh = ((rh * 12500) >> 16 ) - 600; + if (req->oldptr != NULL) { + if (sc->sc_hold) + error = htu21_get_measurement(dev, HTU21_GET_HUM, + raw_data, nitems(raw_data)); + else + error = htu21_get_measurement_nohold(dev, + HTU21_GET_HUM_NH, raw_data, nitems(raw_data)); + + if (error != 0) { + return (EIO); + } else if (!check_crc_16(raw_data, raw_data[2])) { + rh = -1; + sc->sc_errcount++; + } else { + rh = (((uint16_t)raw_data[0]) << 8) | + (raw_data[1] & 0xfc); + rh = ((rh * 12500) >> 16 ) - 600; + } } error = sysctl_handle_int(oidp, &rh, 0, req); @@ -302,11 +308,12 @@ htu21_heater_sysctl(SYSCTL_HANDLER_ARGS) dev = arg1; sc = device_get_softc(dev); - error = htu21_get_cfg(dev, &cfg); - if (error != 0) - return (EIO); - - heater = (cfg & 0x04) != 0; + if (req->oldptr != NULL) { + error = htu21_get_cfg(dev, &cfg); + if (error != 0) + return (EIO); + heater = (cfg & 0x04) != 0; + } error = sysctl_handle_int(oidp, &heater, 0, req); if (error != 0 || req->newptr == NULL) return (error); @@ -328,11 +335,12 @@ htu21_power_sysctl(SYSCTL_HANDLER_ARGS) dev = arg1; sc = device_get_softc(dev); - error = htu21_get_cfg(dev, &cfg); - if (error != 0) - return (EIO); - - power = (cfg & 0x40) == 0; + if (req->oldptr != NULL) { + error = htu21_get_cfg(dev, &cfg); + if (error != 0) + return (EIO); + power = (cfg & 0x40) == 0; + } error = sysctl_handle_int(oidp, &power, 0, req); return (error); }