Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp752683rwb; Wed, 28 Sep 2022 08:41:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6N7l009A9thtdqXf87nSo0eN+FxU+WsLM9/8yhx/tVkJ0DV1+OgdP2RHvVduGmiXpgitFr X-Received: by 2002:a17:907:31c1:b0:742:28a3:5d08 with SMTP id xf1-20020a17090731c100b0074228a35d08mr27868791ejb.112.1664379660836; Wed, 28 Sep 2022 08:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664379660; cv=none; d=google.com; s=arc-20160816; b=EU0OGqmzE9/7UytM0OKBdJKipmN7NYTA42fZ5YbjlO0eHhmzceZ2IuUAbiX1Ux6i4e zh9yaZ7MzqPhdc3O8uCUBTnuzW6HGQY77sCp2gyWLZhQxtAsspGeP6f/uZcKu4jFxUbJ mThd6ELXc+vU9T7CK0U2pHAqmWzchPTi7RY8OvjXkNsZs+hmPXL3TXw9xXHZLb9dYERL AFMNJpmPK/OJIIGo8MYDPMXuTmD+hg0KpmDY/gG7YQ+eEIetNlU7rr+4ua/MLI0MPhvy b9j3i0NWq1ZL3W62YV1kxD0hSRBdhiWtonbJm+2ycSnB+v0Myoey9GKZhFX9WehFkiM/ axpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6RVS2yHMtMgbWKW8mt4Gmc48qyDC1ei7uda2cYYmRkQ=; b=KFx7XgqKwf9Pmk2G6IhpqDzHAkZ1lYrH+KTBLffkJzQ8zz6p0EP7oOduxJySNDKhCu iY06VF8AujmFOt+6V50XRtXVJ3I9IvNEVb6Zc32+pr9eI8dnEEhhwUJGRTwGHXqUHGw3 WEQwyhsrMjzBIbeLXef7VLnnN+oGqEC8Y+7biEEBmyaL4fld8uLZ7Dn7gQz1M/0OHtCv 6Okgl5+1/bFjKsRSl32UrnlrgNxbpDaqL7squsgHx4pf0gOH9kuTcGNdgQ2P0UzzKnVr MdE2wwQjDIb+VT6qM5+aff+mgS4Z5EQjj4i1tU6drYpB6/aObX4XqZcdBwP1MvBUvV4F 1SuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PDz0FEtO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp14-20020a1709071b0e00b007879f5efba7si1217848ejc.872.2022.09.28.08.40.35; Wed, 28 Sep 2022 08:41:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PDz0FEtO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234515AbiI1Otv (ORCPT + 99 others); Wed, 28 Sep 2022 10:49:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbiI1Otl (ORCPT ); Wed, 28 Sep 2022 10:49:41 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51B23B87C; Wed, 28 Sep 2022 07:49:35 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id n40-20020a05600c3ba800b003b49aefc35fso1144080wms.5; Wed, 28 Sep 2022 07:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=6RVS2yHMtMgbWKW8mt4Gmc48qyDC1ei7uda2cYYmRkQ=; b=PDz0FEtOhXdgSMyri2zGSlMGSyFeyaZW4SIMQOA7PTFZd+wqyaeGTnCaYsPPS0MpT2 p1QoiuSRv4WLx9IFrtHTV0UwmJuMCsoaOz4rBSB3bFBKsU3ZZ7XtEbt6LUW8mMZvSG4T OSf2JzCPc9e/r3X/sfDbxZsN7BhbyU2dD7USntkdWajX99mOrPdlh09lm73aCt+FkIxc MnTlc57BneX5GYh7KMaK9bJKI4O5a9N6XrHbGkBYEYNxD0LDmMT0k1lALPkbNISrCn4C u8MKq93Mz1xquEhawmTo+4ZZ8nCdUJYdPfNI9Fb53ah1e1h6YUwWWBGo/SYJh5Juwsps D/aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=6RVS2yHMtMgbWKW8mt4Gmc48qyDC1ei7uda2cYYmRkQ=; b=bR0RqVIasdc1tNZAyLp1oT3UES01yUrTVRN8tvaYiSDbrSgEuqLyjnqnjiqQtI587l BIIGaqyV42Ti6xcXPMjjtN0pzQ7z8hLN7u+gDRIZEiqrwvvzOhTe0e6pXys9smi32glQ +BEUTTZGHPACMP4zNAkE8bbyi0XFmJ7QL932KyxtQaB/V0mqUAY2SG1eLby15Fcs/JK7 vtZknR0M62nWBObW3adsq7jRIJFp2bIPIIRmnteoC4P+pDxLHVE3zomaGzMz/wKK3O+I hPpTIG7Kk2I8LVAMqXTClB5Ja1m5ugy9WlMGHkt26xcJZmwY2cFeotHOlvkYkExY91hP lH3w== X-Gm-Message-State: ACrzQf2TiYCTYdbac6z8fag0Si7EmtwiQWhkY3TMH5+12EKxFowP0Knl 298WMuQlGj+9zH29wgkybMsKQA1/KDCduA== X-Received: by 2002:a05:600c:1589:b0:3b4:fe4a:c225 with SMTP id r9-20020a05600c158900b003b4fe4ac225mr7448623wmf.150.1664376573130; Wed, 28 Sep 2022 07:49:33 -0700 (PDT) Received: from michael-VirtualBox.xsight.ent (89-139-44-91.bb.netvision.net.il. [89.139.44.91]) by smtp.googlemail.com with ESMTPSA id m35-20020a05600c3b2300b003b47b913901sm6977446wms.1.2022.09.28.07.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 07:49:32 -0700 (PDT) From: Michael Zaidman To: jikos@kernel.org Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Michael Zaidman , Guillaume Champagne Subject: [PATCH v2 2/7] HID: ft260: improve i2c write performance Date: Wed, 28 Sep 2022 17:48:49 +0300 Message-Id: <20220928144854.5580-3-michael.zaidman@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220928144854.5580-1-michael.zaidman@gmail.com> References: <20220928144854.5580-1-michael.zaidman@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch improves i2c writing performance by about 30 percent by revising the sleep time in the ft260_hid_output_report_check_status() in the following ways: 1. Reduce the sleep time and start to poll earlier: Before: $ sudo ./i2cperf -f 2 -o 2 -s 32 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 40510 80 256 8 32 After: $ sudo ./i2cperf -f 2 -o 2 -s 32 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 52584 80 256 8 32 2. Do not sleep when the calculated sleep time is below 2 ms: Before: $ sudo ./i2cperf -f 2 -o 2 -s 16 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 26707 73 256 16 16 After: $ sudo ./i2cperf -f 2 -o 2 -s 16 -r 0-0xff 13 0x51 -S Fill block with increment via i2ctransfer by chunks ------------------------------------------------------------------- data rate(bps) efficiency(%) data size(B) total IOs IO size(B) ------------------------------------------------------------------- 37034 73 256 16 16 Link to the i2cperf - https://github.com/MichaelZaidman/i2cperf Signed-off-by: Michael Zaidman Tested-by: Guillaume Champagne --- drivers/hid/hid-ft260.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index a35201d68b15..44106cadd746 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -345,7 +345,7 @@ static int ft260_hid_output_report(struct hid_device *hdev, u8 *data, static int ft260_hid_output_report_check_status(struct ft260_device *dev, u8 *data, int len) { - int ret, usec, try = 3; + int ret, usec, try = 100; struct hid_device *hdev = dev->hdev; ret = ft260_hid_output_report(hdev, data, len); @@ -356,10 +356,14 @@ static int ft260_hid_output_report_check_status(struct ft260_device *dev, return ret; } - /* transfer time = 1 / clock(KHz) * 10 bits * bytes */ - usec = 10000 / dev->clock * len; - usleep_range(usec, usec + 100); - ft260_dbg("wait %d usec, len %d\n", usec, len); + /* transfer time = 1 / clock(KHz) * 9 bits * bytes */ + usec = len * 9000 / dev->clock; + if (usec > 2000) { + usec -= 1500; + usleep_range(usec, usec + 100); + ft260_dbg("wait %d usec, len %d\n", usec, len); + } + do { ret = ft260_xfer_status(dev); if (ret != -EAGAIN) -- 2.34.1