From nobody Fri Jan 19 17:09:50 2024 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 4TGmM32Dd2z56wlM; Fri, 19 Jan 2024 17:09:51 +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 4TGmM26xz4z4JvW; Fri, 19 Jan 2024 17:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xBXCrM7EwonIPUeNOjiJkr7mS5HyZUErK5Y0o+JeiuQ=; b=c3r8t1Hs0wDz4IglYehT5P1l9N8bzmMbWV50TuYBkOxtIvFHkHphin78nMobKlc9gLTk8h Fv0vtkJ3vLfOZp74e/B3DF4jdR/tt5SdLdBcAWEecwx117k2lraA/ixucjTI16qscnG12D edKmQ9kap4nKXPDTJE0i+yG2AUTppKumt+LW9GbQvzYMdyg6LgK3mjzXtwx3Aw+X60fx31 mMupJWttsji/fjjzhWY5tGAQrw6oRebJbCpMybc0gTBHF957R14yTHYmEIBHSnNcEa38HG huh673wHJ7+NMrXWMYbic1u/Teaz8zJ8SQX9xTm7Sr5Ex2RJBHi8dvHyyvZfvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xBXCrM7EwonIPUeNOjiJkr7mS5HyZUErK5Y0o+JeiuQ=; b=wz+J/5msgWNOm/jfS8xniNnXXZVT+sQSHBpdETSAFiJrDgh41NQwAp4A/tXCdqYYpMqLoE odJAAU++0JUlocYlgbIT4DxKtHTEEE+xRTY2mXFiSvKezIGMP8KWLCYxYF8NGS5VVdxBDl 8ImfK6Ri5TEXAWLORiO/u0OCZFMeBR9cnyt7TRqdUZwOY+K++BLLkDsqOk+K1HcYWGJHHu 3RfabQAaRDlOL0HSWXDdoM9/MlMVLD6i5jzUM75UO7MkpXw0XUDprtPE6tbKtnxrxJgPHC H7/LZSfgnI8kVzFsKUGK8u+rcYzV1tcwrms7Ae12rjNXeFHSyVroK1L3Ucr0SA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705684191; a=rsa-sha256; cv=none; b=pbx4/Xm//wHbppAGa9zidDLDTq3/OeFdGYZSvSvaeysUKVnJZ0/h0XNnpqzfucVvui+83l 2XRxtaxUwiDzP+Wu+/uY9DOtQpUSfcHU7MhKX379jPsrAUW/9kDnSa5CDUSn9xNjbMQTuX uvLdvD8n6AmM//ak/XYLv6Zey9eLZ917OWfoJ1Z0EHoDXEDLbKRWz0gyzIZ0fHpe6gDl6h eUwXqbAm59qOTDxlkqMcsJEtgSld1HganHY6kLP3acNb490/smtbV/9VMTUIlc0DO4I1Dd CbWrT/pRYbwTyfJZUd3AbE2YXyeXaq/lifxv1qmYOr2IP67nr1iUqiensWOgBg== 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 4TGmM25tpGz10QD; Fri, 19 Jan 2024 17:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40JH9oak079582; Fri, 19 Jan 2024 17:09:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40JH9oMH079579; Fri, 19 Jan 2024 17:09:50 GMT (envelope-from git) Date: Fri, 19 Jan 2024 17:09:50 GMT Message-Id: <202401191709.40JH9oMH079579@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 9f558e9f7dee - stable/13 - iichid(4): Improve idle sampling hysteresis 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: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9f558e9f7deed5b4fd804bd111e20eca337e18dd Auto-Submitted: auto-generated The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=9f558e9f7deed5b4fd804bd111e20eca337e18dd commit 9f558e9f7deed5b4fd804bd111e20eca337e18dd Author: Alexander Motin AuthorDate: 2023-12-23 03:50:52 +0000 Commit: Alexander Motin CommitDate: 2024-01-19 17:08:13 +0000 iichid(4): Improve idle sampling hysteresis In sampling mode some devices return same data indefinitely even if there is nothing to report. Previous idle hysteresis implementation activated only when device returned no data, so some devices ended up polled at fast rate all the time. This new implementation compares each new report with the previous, and, if they are identical, after reaching threshold also drop sampling rate to slow. On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this reduces idle power consumption by ~0.5W by reducing number of context switches in the driver from ~4000 to ~700 per second when not touched. MFC after: 1 month (cherry picked from commit 8c86b981240324c1daaa387d4d3f8e3e53db3d2e) --- sys/dev/iicbus/iichid.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c index 0c0e3ec84a60..d2359fdf5b20 100644 --- a/sys/dev/iicbus/iichid.c +++ b/sys/dev/iicbus/iichid.c @@ -108,7 +108,7 @@ enum { */ #define IICHID_SAMPLING_RATE_FAST 60 #define IICHID_SAMPLING_RATE_SLOW 10 -#define IICHID_SAMPLING_HYSTERESIS 1 +#define IICHID_SAMPLING_HYSTERESIS 12 /* ~ 2x fast / slow */ /* 5.1.1 - HID Descriptor Format */ struct i2c_hid_desc { @@ -177,9 +177,12 @@ struct iichid_softc { int sampling_rate_fast; int sampling_hysteresis; int missing_samples; /* iicbus lock */ - struct timeout_task periodic_task; /* iicbus lock */ + int dup_samples; /* iicbus lock */ + iichid_size_t dup_size; /* iicbus lock */ bool callout_setup; /* iicbus lock */ + uint8_t *dup_buf; struct taskqueue *taskqueue; + struct timeout_task periodic_task; /* iicbus lock */ struct task event_task; #endif @@ -523,7 +526,7 @@ iichid_event_task(void *context, int pending) device_t parent; iichid_size_t actual; bool bus_requested; - int error; + int error, rate; sc = context; parent = device_get_parent(sc->dev); @@ -541,18 +544,30 @@ iichid_event_task(void *context, int pending) if (actual > 0) { sc->intr_handler(sc->intr_ctx, sc->intr_buf, actual); sc->missing_samples = 0; - } else - ++sc->missing_samples; + if (sc->dup_size != actual || + memcmp(sc->dup_buf, sc->intr_buf, actual) != 0) { + sc->dup_size = actual; + memcpy(sc->dup_buf, sc->intr_buf, actual); + sc->dup_samples = 0; + } else + ++sc->dup_samples; + } else { + if (++sc->missing_samples == 1) + sc->intr_handler(sc->intr_ctx, sc->intr_buf, 0); + sc->dup_samples = 0; + } } else DPRINTF(sc, "read error occurred: %d\n", error); rearm: if (sc->callout_setup && sc->sampling_rate_slow > 0) { - if (sc->missing_samples == sc->sampling_hysteresis) - sc->intr_handler(sc->intr_ctx, sc->intr_buf, 0); - taskqueue_enqueue_timeout(sc->taskqueue, &sc->periodic_task, - hz / MAX(sc->missing_samples >= sc->sampling_hysteresis ? - sc->sampling_rate_slow : sc->sampling_rate_fast, 1)); + if (sc->missing_samples >= sc->sampling_hysteresis || + sc->dup_samples >= sc->sampling_hysteresis) + rate = sc->sampling_rate_slow; + else + rate = sc->sampling_rate_fast; + taskqueue_enqueue_timeout_sbt(sc->taskqueue, &sc->periodic_task, + SBT_1S / MAX(rate, 1), 0, C_PREL(1)); } out: if (bus_requested) @@ -725,6 +740,8 @@ iichid_reset_callout(struct iichid_softc *sc) /* Start with slow sampling. */ sc->missing_samples = sc->sampling_hysteresis; + sc->dup_samples = 0; + sc->dup_size = 0; taskqueue_enqueue(sc->taskqueue, &sc->event_task); return (0); @@ -812,6 +829,7 @@ iichid_intr_setup(device_t dev, hid_intr_t intr, void *context, sc->intr_buf = malloc(rdesc->rdsize, M_DEVBUF, M_WAITOK | M_ZERO); sc->intr_bufsize = rdesc->rdsize; #ifdef IICHID_SAMPLING + sc->dup_buf = malloc(rdesc->rdsize, M_DEVBUF, M_WAITOK | M_ZERO); taskqueue_start_threads(&sc->taskqueue, 1, PI_TTY, "%s taskq", device_get_nameunit(sc->dev)); #endif @@ -825,6 +843,7 @@ iichid_intr_unsetup(device_t dev) sc = device_get_softc(dev); #ifdef IICHID_SAMPLING taskqueue_drain_all(sc->taskqueue); + free(sc->dup_buf, M_DEVBUF); #endif free(sc->intr_buf, M_DEVBUF); }