From nobody Sat Nov 06 17:41:34 2021 X-Original-To: dev-commits-src-main@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 AD525184F489; Sat, 6 Nov 2021 17:41:34 +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 4Hml6k4Zh1z3vM9; Sat, 6 Nov 2021 17:41:34 +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 7E020775B; Sat, 6 Nov 2021 17:41:34 +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 1A6HfYS9017301; Sat, 6 Nov 2021 17:41:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A6HfYMn017300; Sat, 6 Nov 2021 17:41:34 GMT (envelope-from git) Date: Sat, 6 Nov 2021 17:41:34 GMT Message-Id: <202111061741.1A6HfYMn017300@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: 43b031a371eb - main - htu21: don't needlessly bother hardware when measurements are not needed List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 43b031a371eb90c15c390c26202f5f58d09300ef Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=43b031a371eb90c15c390c26202f5f58d09300ef commit 43b031a371eb90c15c390c26202f5f58d09300ef Author: Andriy Gapon AuthorDate: 2021-11-06 16:47:32 +0000 Commit: Andriy Gapon CommitDate: 2021-11-06 17:39:52 +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. MFC after: 1 week --- 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 aa8507bf7437..6b834354d73f 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); }