From nobody Sun Dec 24 23:39:52 2023 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 4SyyF51hYGz54nrV; Sun, 24 Dec 2023 23:39:53 +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 4SyyF46vvfz3fls; Sun, 24 Dec 2023 23:39:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703461193; 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=15o+z0nsClNVPpmicILYB9KXLuIdzMzf9UKS3zcuLRg=; b=lFUO+7tXE7TNtOLfITmBO3UBYZRqZU/CW7/R9YaIpAi+r3YwQoe8TANER62AIdesLUWR31 yq1/bgc96R//uKaPOMCrfI2E3WibMsiprsZWUXo6TeS10kC03bS8agvr53nrvUFl5F2Duo lbAkDuameooaIuwZAsj3ehyYE5+w5vz7o1ME1xh9sRtOz0599uLtiFoC/eXd/dUb0oWrZ7 nX62w9ql4Q9ynw0gW/pahD6YGboiQyQg3e7QAW5vSso3v3WGMBgqSTUD3Zg+4cWNRDR2ud HvVdK9R1h8T3t1I0dy/vuxd9BXmENxaDsJBEGDext2NKoI1XiHONKryIX3JAcQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703461193; a=rsa-sha256; cv=none; b=QcwOx1Jio+iHISM6o6ZojCifl8vPP0rQ1WwfIbCz8BipM7aog1mCpUyjeMZ1d0gRnVs4uu gMkq91HpRCu7Mq8WlpK4Ld6Vh713tuf+TwTpMUsWxe4UTbbiX76NCxLPOCPN+qpGNP2oIx 08joM8ZHdlUyW5fzCOSeA8tGh7fdt9W0bh7RVj14I60U9ixL4OtHQqiXOG9jYkyJ0l8Aou seHIP9XiAlvxtu87Tdrb2P9FUrnrCJrvKyYnEBnwj3wVzuMwiVN4jO//ZlNPhItkCPsZ1i lEL45Tc3pM1gw9PCBss2FOxlcG4m44ZN8AXrHDdW745IjfMyuU/TOq8V07Szyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703461193; 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=15o+z0nsClNVPpmicILYB9KXLuIdzMzf9UKS3zcuLRg=; b=qe/JTqK97T6Z3HIQvCv01+9JlGoP59FV9MDt9lXrJYeVRvzjDmRjlCNT0w0n1a1+DQvUxO rMWUcaylu3ruuUaIXtKe0VIA8EJxFnDSu3vPS5wPeGAnIzxKNfIdOKecrhKCrdMxqMkCba qN0AQkMOAF++qAhhb1t3ZEexTxbQQbrPyf1ZTygpy3zAlM12OBplKf3TcH7BUcs4XIuip5 EkDXT8XXoz+8WB6HS5nwL/q/Y+GFSl23M1ZzKNJGrAOO0BbgqLiKCzqcoRQIyHTlUbh7oa FON1X+RfRpJNdbZlnOFxA+gSc2K7q4N2Y4t1QzZlMTd0vTOSQoHD+Bt0kK23JA== 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 4SyyF45pfMznXC; Sun, 24 Dec 2023 23:39:52 +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 3BONdq1q012529; Sun, 24 Dec 2023 23:39:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BONdqCV012526; Sun, 24 Dec 2023 23:39:52 GMT (envelope-from git) Date: Sun, 24 Dec 2023 23:39:52 GMT Message-Id: <202312242339.3BONdqCV012526@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: 13037eaabede - main - ig4: Actively use FIFO thresholds 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: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 13037eaabede7fb7fbc25f4e84b549c73f9acb3c Auto-Submitted: auto-generated The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=13037eaabede7fb7fbc25f4e84b549c73f9acb3c commit 13037eaabede7fb7fbc25f4e84b549c73f9acb3c Author: Alexander Motin AuthorDate: 2023-12-24 23:18:11 +0000 Commit: Alexander Motin CommitDate: 2023-12-24 23:18:11 +0000 ig4: Actively use FIFO thresholds Before every wait for FIFO interrupt set how much data/space do we want to see there. Previous code was not using it for receive, as result aggregating interrupts only within processing latency. The new code needs only one interrupt per transfer per FIFO length. On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this reduces the interrupt rate per device down to 2 per sample or 16-20 per second when idle and 120-160 per second when actively touched. MFC after: 1 month --- sys/dev/ichiic/ig4_iic.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/sys/dev/ichiic/ig4_iic.c b/sys/dev/ichiic/ig4_iic.c index 4ab36ef660ed..98c160ec9fd2 100644 --- a/sys/dev/ichiic/ig4_iic.c +++ b/sys/dev/ichiic/ig4_iic.c @@ -350,6 +350,7 @@ set_slave_addr(ig4iic_softc_t *sc, uint8_t slave) /* * Wait for TXFIFO to drain before disabling the controller. */ + reg_write(sc, IG4_REG_TX_TL, 0); wait_intr(sc, IG4_INTR_TX_EMPTY); set_controller(sc, 0); @@ -437,16 +438,20 @@ ig4iic_read(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, return (0); while (received < len) { + /* Ensure we have some free space in TXFIFO */ burst = sc->cfg.txfifo_depth - (reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK); if (burst <= 0) { + reg_write(sc, IG4_REG_TX_TL, IG4_FIFO_LOWAT); error = wait_intr(sc, IG4_INTR_TX_EMPTY); if (error) break; - burst = sc->cfg.txfifo_depth; + burst = sc->cfg.txfifo_depth - + (reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK); } /* Ensure we have enough free space in RXFIFO */ - burst = MIN(burst, sc->cfg.rxfifo_depth - lowat); + burst = MIN(burst, sc->cfg.rxfifo_depth - + (requested - received)); target = MIN(requested + burst, (int)len); while (requested < target) { cmd = IG4_DATA_COMMAND_RD; @@ -463,13 +468,15 @@ ig4iic_read(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, lowat = IG4_FIFO_LOWAT; /* After TXFLR fills up, clear it by reading available data */ while (received < requested - lowat) { - burst = MIN((int)len - received, + burst = MIN(requested - received, reg_read(sc, IG4_REG_RXFLR) & IG4_FIFOLVL_MASK); if (burst > 0) { while (burst--) buf[received++] = 0xFF & reg_read(sc, IG4_REG_DATA_CMD); } else { + reg_write(sc, IG4_REG_RX_TL, + requested - received - lowat - 1); error = wait_intr(sc, IG4_INTR_RX_FULL); if (error) goto out; @@ -487,8 +494,7 @@ ig4iic_write(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, uint32_t cmd; int sent = 0; int burst, target; - int error; - bool lowat_set = false; + int error, lowat; if (len == 0) return (0); @@ -497,12 +503,7 @@ ig4iic_write(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, burst = sc->cfg.txfifo_depth - (reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK); target = MIN(sent + burst, (int)len); - /* Leave some data queued to maintain the hardware pipeline */ - if (!lowat_set && target != len) { - lowat_set = true; - reg_write(sc, IG4_REG_TX_TL, IG4_FIFO_LOWAT); - } - while(sent < target) { + while (sent < target) { cmd = buf[sent]; if (repeated_start && sent == 0) cmd |= IG4_DATA_RESTART; @@ -512,13 +513,16 @@ ig4iic_write(ig4iic_softc_t *sc, uint8_t *buf, uint16_t len, sent++; } if (sent < len) { + if (len - sent <= sc->cfg.txfifo_depth) + lowat = sc->cfg.txfifo_depth - (len - sent); + else + lowat = IG4_FIFO_LOWAT; + reg_write(sc, IG4_REG_TX_TL, lowat); error = wait_intr(sc, IG4_INTR_TX_EMPTY); if (error) break; } } - if (lowat_set) - reg_write(sc, IG4_REG_TX_TL, 0); return (error); } @@ -974,13 +978,6 @@ ig4iic_set_config(ig4iic_softc_t *sc, bool reset) (sc->cfg.bus_speed & IG4_CTL_SPEED_MASK) == IG4_CTL_SPEED_STD ? sc->cfg.ss_sda_hold : sc->cfg.fs_sda_hold); - /* - * Use a threshold of 1 so we get interrupted on each character, - * allowing us to use mtx_sleep() in our poll code. Not perfect - * but this is better than using DELAY() for receiving data. - * - * See ig4_var.h for details on interrupt handler synchronization. - */ reg_write(sc, IG4_REG_RX_TL, 0); reg_write(sc, IG4_REG_TX_TL, 0);