Message ID | Zcn-6e-0-nh2WcfU@drtxq0yyyyyyyyyyyyyby-3.rev.dnainternet.fi |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-61411-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2373054dyd; Mon, 12 Feb 2024 03:44:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXivS58K3ClOWfQoZAPaury6jL6hEa42OBRqZSi1RJkwR1uHdYFZE5tgkVpmICEuiPmDuFguHwACTENC0K4H5SEPVjlIQ== X-Google-Smtp-Source: AGHT+IEEIk5y2Q0Emdjch5bfoWfidk4PAVWBw5QmAQdPeCxZnYlRBjimpYBQGWmOIGOAH3KlgzfX X-Received: by 2002:a17:90b:b16:b0:296:d9c7:8727 with SMTP id bf22-20020a17090b0b1600b00296d9c78727mr3773193pjb.25.1707738249840; Mon, 12 Feb 2024 03:44:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707738249; cv=pass; d=google.com; s=arc-20160816; b=CRtqL6ihkEhyA4TvUdyUQ55r0iKgtB2SH22Lacma3EqOt//XjQmgtqYZ3VaQG64iqt e7SKHDlUvsfWZ2LLDwVpj4Di3ngnK2ZnlpHeuTH+ADfBPBOMTqTWjxSleNx1XFGvyWpU 5chCY/QAErtPauQRF7WIUlthZXhS/XS6mScOqoDuH5x5WKF6zqJbhdVfw27170ApA2Ss f0PNU7zB5uvfSSfqLNMS5OEOheXk4+eIvurH0QAkageQa965OFgiNtIGo+cT1fKmKjue PnRemFlZfjPCaxqUqK9vFjh0thzB4aQJ+5MubebryiIuqbbpLPKietpcIjXmYxGLErWX 3D/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=350dwjN8QQutWLlYzcXvkSs1h7jhGOVddH+hl5UJwAY=; fh=+9lHvcA+5Gjfl/qDiEcpzlXxAVt+0WG/fY7KRLIwJ4s=; b=C9q7k0ida4GKiFU2rT6xXSFReicBiZb3QDPZTihLSVpfebddQYhgeYXPgaTkEDJ+Fp bmGsH1/E6Ek65t3KfslXLGsuGui/U8EAzWW8MrZkbKP+yGQPC/XIPUGs5SqDQurXZR0h IAL060dQdNVBzTxMafqxD3CUnIxuMqGExp0mAwqbpzIwKFseZDW4tdsfwmapLufjfkjN LSeyuE6jFEeRA8WWEZqihUZnZoCfbRogfanM94N9bDmqM5fM/sdvwBXGVZ/78QhJr4FL ysiWUnL2klQE7YblkekjLEBOi7xiXIUWXeyIL9ULo9D4d4wb+7zv+thJhRxoP7utEiez 5Lag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=llpvAF1n; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-61411-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61411-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCX6v8x2RiVq9oxM9SxTgYPRsH9vylIJuqoGdyebBuJhDk15wgguLHQJfXuCeenR9ywjBmiMQdfl4eEsUkVkR4k628TvQQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id mf8-20020a17090b184800b00290b59aa10bsi166866pjb.120.2024.02.12.03.44.09 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 03:44:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61411-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=llpvAF1n; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-61411-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61411-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B786AB2376A for <ouuuleilei@gmail.com>; Mon, 12 Feb 2024 11:20:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 212B538FB9; Mon, 12 Feb 2024 11:20:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="llpvAF1n" Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F52D2BAE7; Mon, 12 Feb 2024 11:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707736824; cv=none; b=LKcIpPo0jnHb+wW/e/Pz+a9x9BDJGpDpCq1LgaDRBezQEwN4AEJdUhEC/rqpuTw2dSzTfcxoIO5tonFCFqIiwvD6D4X0Uglfv9rP2rR9ykY+TZLZLRVq7YjMGfxS+tTEBH5Xo5QIj0TurE/17jXbgoLN3PUgEJsQ96taxhC5wLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707736824; c=relaxed/simple; bh=NIf3m0p41QvLOoLpJZww8fr5lUh/7naMs+DwQJ35TCQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=civdbu5gKpLbm5uxFKkt8wC7iVNvngyxBMp+ndGytLji98KLtzajk+I8AYMOmZExMCSZnoO+q6TaVWhcurMJ1tS6rH2USmGHpueOcRCfwVQ4GMnOXDwrCWaECXc6AsQaGYtrQnhbNNUAOSajijkSek5t9d78ZHMcfYDogIGg3TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=llpvAF1n; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2cf3ed3b917so38614591fa.1; Mon, 12 Feb 2024 03:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707736820; x=1708341620; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=350dwjN8QQutWLlYzcXvkSs1h7jhGOVddH+hl5UJwAY=; b=llpvAF1ng31phyOQzD7fl+FdTAnXnU4Yyjr6b0NF6QRd80NZN50fBidbmG8dMA+0TG bSGpjL4AMTvnPg0fmYeb+u7r60a+AsgsBsIwPC7qGoGuKzk7T0kJQS7aQOLpFZEVEDj7 aWOSfIzNGl4PHXnk7Ly+zgCKrLvs7GfJam//ZY6ATTlww88ZLm+bdIAeYpYIHElD/tuU xsvpSy5tst0JMrqhJVx7bOlzrztDdvXkPFs+wbu1seQ11JfTKd1wmm+8QNyNtUr9XzVA DLyrEjKOfC1dF025GUznm7svN2WLix/+SV+BDDM1SPnuBxTLljjiuwuQG7NB3dof+b0M JoMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707736820; x=1708341620; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=350dwjN8QQutWLlYzcXvkSs1h7jhGOVddH+hl5UJwAY=; b=YCO+6HhLyKlKJ98GYohvSI/20oS6jTbU1HJS4O25G4QOmCedt+F/0D5LcllC6TNBn3 OJm5nhhPTvUAlHbxPuUpTlPApyzBgSnDU3esev0IEWX1dxmd2N9uG7PMS+ltSDOreVM8 dTsHASR9eeO7iJd1IZ5y7yHnXYTZBanNXKQvDUvtrJK6jqmvHGu0UOhcKHLy/rVYY5i/ lJc0O4rjd57TGh8AAwJ1+T4KGhsqosbT61EEbLjSGXqVdaLDvZp7s+RGrtszg/UwWgNu 7HBz3By5MKkPtw+o9UgGSllTFC7wzcW2n2I+H1xEFMOVpN6/tOV+O+d1YJt0qlzkfntD yXFg== X-Forwarded-Encrypted: i=1; AJvYcCUd65KSB7TI+kalHxFND8PAyDbCpHNpVHUo+7i0+uExG8dafllKmG6vXRQYZA4R4CS1XdDqGSL/M8z3/O117NET5M73+tAOATmApPlRyDZj9nJhY/XXzUtXfi+NKHPOuRNPJJBPP1n4 X-Gm-Message-State: AOJu0YzgJ7ogV6dZbLdBUMQ+S60jToLKZwZ3atGg31S1swT/01mTrUsK t8jgpmJa2sBYHrRlFFdozFSerSgWy4KfNm4mai1oWlWc7pZaETi8 X-Received: by 2002:a05:6512:138a:b0:511:8cb1:7c9d with SMTP id fc10-20020a056512138a00b005118cb17c9dmr2607187lfb.24.1707736820241; Mon, 12 Feb 2024 03:20:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUhu0kIEcrqnMooWZvnav8sYvNIRGqSw2J29k0CoLGP8C48lwyUELDMV/YA8XZhjckkhXC+zUpOnkPwvcGOdlYsrihJbwle4RA/j86jo7/gBOe20hW36i5OoZvu4htDoGF1hJnUGiof67pa/2d7PO81thT5gNY0dqt1/BacOBW7BtPH6siiVVxX+9jNzqiUk8NpOxfaB3x2H+mlEFnjWwsE2TeY5vL3qEybeu59pFPMtasR3YXLNZzHdprnOyHoTxNOH1YPSDgoMNG2 Received: from drtxq0yyyyyyyyyyyyyby-3.rev.dnainternet.fi (drtxq0yyyyyyyyyyyyyby-3.rev.dnainternet.fi. [2001:14ba:7426:df00::2]) by smtp.gmail.com with ESMTPSA id bi31-20020a0565120e9f00b005117fc3d553sm824462lfb.70.2024.02.12.03.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 03:20:19 -0800 (PST) Date: Mon, 12 Feb 2024 13:20:09 +0200 From: Matti Vaittinen <mazziesaccount@gmail.com> To: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>, Matti Vaittinen <mazziesaccount@gmail.com> Cc: Jonathan Cameron <jic23@kernel.org>, Lars-Peter Clausen <lars@metafoo.de>, Matti Vaittinen <mazziesaccount@gmail.com>, linux-kernel@vger.kernel.org, David Laight <David.Laight@aculab.com>, Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>, linux-iio@vger.kernel.org Subject: [RESEND PATCH v2] iio: gts-helper: Fix division loop Message-ID: <Zcn-6e-0-nh2WcfU@drtxq0yyyyyyyyyyyyyby-3.rev.dnainternet.fi> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="r7jqDadsvKX59wc/" Content-Disposition: inline X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790693343211111914 X-GMAIL-MSGID: 1790693343211111914 |
Series |
[RESEND,v2] iio: gts-helper: Fix division loop
|
|
Commit Message
Matti Vaittinen
Feb. 12, 2024, 11:20 a.m. UTC
The loop based 64bit division may run for a long time when dividend is a
lot bigger than the divider. Replace the division loop by the
div64_u64() which implementation may be significantly faster.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers")
---
This is a resend. Only change is the base which is now the v6.8-rc4 and
not the v6.8-rc1
This change was earlier applied and reverted as it confusingly lacked of
the removal of the overflow check (which is only needed when we do
looping "while (full > scale * (u64)tmp)". As this loop got removed, the
check got also obsolete and leaving it to the code caused some
confusion.
So, I marked this as a v2, where v1 is the reverted change discussed
here:
https://lore.kernel.org/linux-iio/ZZZ7pJBGkTdFFqiY@dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi/
Revision history:
v1 => v2:
- Drop the obsolete overflow check
- Rebased on top of the v6.8-rc4
iio: gts: loop fix fix
---
drivers/iio/industrialio-gts-helper.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de
Comments
On Mon, 12 Feb 2024 13:20:09 +0200 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > The loop based 64bit division may run for a long time when dividend is a > lot bigger than the divider. Replace the division loop by the > div64_u64() which implementation may be significantly faster. > > Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> > Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") > > --- > This is a resend. Only change is the base which is now the v6.8-rc4 and > not the v6.8-rc1 Given I'm not rushing this in, it is going via my togreg tree, so the rebase wasn't really helpful (thankfully didn't stop it applying). Would have been fine to send a ping response to the first posting of it. I was leaving some time for David or Subhajit to have time to take another look, but guess they are either happy with this or busy. Applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons. Jonathan > > This change was earlier applied and reverted as it confusingly lacked of > the removal of the overflow check (which is only needed when we do > looping "while (full > scale * (u64)tmp)". As this loop got removed, the > check got also obsolete and leaving it to the code caused some > confusion. > > So, I marked this as a v2, where v1 is the reverted change discussed > here: > https://lore.kernel.org/linux-iio/ZZZ7pJBGkTdFFqiY@dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi/ > > Revision history: > v1 => v2: > - Drop the obsolete overflow check > - Rebased on top of the v6.8-rc4 > > iio: gts: loop fix fix > --- > drivers/iio/industrialio-gts-helper.c | 15 +-------------- > 1 file changed, 1 insertion(+), 14 deletions(-) > > diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c > index 7653261d2dc2..b51eb6cb766f 100644 > --- a/drivers/iio/industrialio-gts-helper.c > +++ b/drivers/iio/industrialio-gts-helper.c > @@ -34,24 +34,11 @@ > static int iio_gts_get_gain(const u64 max, const u64 scale) > { > u64 full = max; > - int tmp = 1; > > if (scale > full || !scale) > return -EINVAL; > > - if (U64_MAX - full < scale) { > - /* Risk of overflow */ > - if (full - scale < scale) > - return 1; > - > - full -= scale; > - tmp++; > - } > - > - while (full > scale * (u64)tmp) > - tmp++; > - > - return tmp; > + return div64_u64(full, scale); > } > > /** > > base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de
On 17/2/24 00:28, Jonathan Cameron wrote: > On Mon, 12 Feb 2024 13:20:09 +0200 > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >> The loop based 64bit division may run for a long time when dividend is a >> lot bigger than the divider. Replace the division loop by the >> div64_u64() which implementation may be significantly faster. >> >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") >> >> --- >> This is a resend. Only change is the base which is now the v6.8-rc4 and >> not the v6.8-rc1 > Given I'm not rushing this in, it is going via my togreg tree, so the > rebase wasn't really helpful (thankfully didn't stop it applying). > Would have been fine to send a ping response to the first posting of it. > > I was leaving some time for David or Subhajit to have time to take > another look, but guess they are either happy with this or busy. > > Applied to the togreg branch of iio.git and pushed out as testing for > all the normal reasons. > > Jonathan > >> >> This change was earlier applied and reverted as it confusingly lacked of >> the removal of the overflow check (which is only needed when we do >> looping "while (full > scale * (u64)tmp)". As this loop got removed, the >> check got also obsolete and leaving it to the code caused some >> confusion. >> >> So, I marked this as a v2, where v1 is the reverted change discussed >> here: >> https://lore.kernel.org/linux-iio/ZZZ7pJBGkTdFFqiY@dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi/ >> >> Revision history: >> v1 => v2: >> - Drop the obsolete overflow check >> - Rebased on top of the v6.8-rc4 >> >> iio: gts: loop fix fix >> --- >> drivers/iio/industrialio-gts-helper.c | 15 +-------------- >> 1 file changed, 1 insertion(+), 14 deletions(-) >> >> diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c >> index 7653261d2dc2..b51eb6cb766f 100644 >> --- a/drivers/iio/industrialio-gts-helper.c >> +++ b/drivers/iio/industrialio-gts-helper.c >> @@ -34,24 +34,11 @@ >> static int iio_gts_get_gain(const u64 max, const u64 scale) >> { >> u64 full = max; >> - int tmp = 1; >> >> if (scale > full || !scale) >> return -EINVAL; >> >> - if (U64_MAX - full < scale) { >> - /* Risk of overflow */ >> - if (full - scale < scale) >> - return 1; >> - >> - full -= scale; >> - tmp++; >> - } >> - >> - while (full > scale * (u64)tmp) >> - tmp++; >> - >> - return tmp; >> + return div64_u64(full, scale); >> } >> >> /** Hi Matti and Jonathan, I somehow missed testing this patch earlier. The above patch works fine with apds9306 v7 driver(which work in progress!). There are no errors. My test script is simple: #!/bin/bash D=0 S=`cat /sys/bus/iio/devices/iio:device${D}/in_illuminance_scale_available` for s in $S; do echo $s echo $s > /sys/bus/iio/devices/iio:device${D}/in_illuminance_scale sleep 5 done One question - if I test a patch like this, do I put a "Tested-by" tag or just mention that I have tested it? Regards, Subhajit Ghosh >> >> base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de >
On Sun, 18 Feb 2024 01:09:33 +1030 Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote: > On 17/2/24 00:28, Jonathan Cameron wrote: > > On Mon, 12 Feb 2024 13:20:09 +0200 > > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > > > >> The loop based 64bit division may run for a long time when dividend is a > >> lot bigger than the divider. Replace the division loop by the > >> div64_u64() which implementation may be significantly faster. > >> > >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> > >> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") > >> > >> --- > >> This is a resend. Only change is the base which is now the v6.8-rc4 and > >> not the v6.8-rc1 > > Given I'm not rushing this in, it is going via my togreg tree, so the > > rebase wasn't really helpful (thankfully didn't stop it applying). > > Would have been fine to send a ping response to the first posting of it. > > > > I was leaving some time for David or Subhajit to have time to take > > another look, but guess they are either happy with this or busy. > > > > Applied to the togreg branch of iio.git and pushed out as testing for > > all the normal reasons. > > > > Jonathan > > > >> > >> This change was earlier applied and reverted as it confusingly lacked of > >> the removal of the overflow check (which is only needed when we do > >> looping "while (full > scale * (u64)tmp)". As this loop got removed, the > >> check got also obsolete and leaving it to the code caused some > >> confusion. > >> > >> So, I marked this as a v2, where v1 is the reverted change discussed > >> here: > >> https://lore.kernel.org/linux-iio/ZZZ7pJBGkTdFFqiY@dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi/ > >> > >> Revision history: > >> v1 => v2: > >> - Drop the obsolete overflow check > >> - Rebased on top of the v6.8-rc4 > >> > >> iio: gts: loop fix fix > >> --- > >> drivers/iio/industrialio-gts-helper.c | 15 +-------------- > >> 1 file changed, 1 insertion(+), 14 deletions(-) > >> > >> diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c > >> index 7653261d2dc2..b51eb6cb766f 100644 > >> --- a/drivers/iio/industrialio-gts-helper.c > >> +++ b/drivers/iio/industrialio-gts-helper.c > >> @@ -34,24 +34,11 @@ > >> static int iio_gts_get_gain(const u64 max, const u64 scale) > >> { > >> u64 full = max; > >> - int tmp = 1; > >> > >> if (scale > full || !scale) > >> return -EINVAL; > >> > >> - if (U64_MAX - full < scale) { > >> - /* Risk of overflow */ > >> - if (full - scale < scale) > >> - return 1; > >> - > >> - full -= scale; > >> - tmp++; > >> - } > >> - > >> - while (full > scale * (u64)tmp) > >> - tmp++; > >> - > >> - return tmp; > >> + return div64_u64(full, scale); > >> } > >> > >> /** > Hi Matti and Jonathan, > > I somehow missed testing this patch earlier. The above patch works fine with apds9306 v7 driver(which work in progress!). > There are no errors. > My test script is simple: > #!/bin/bash > D=0 > S=`cat /sys/bus/iio/devices/iio:device${D}/in_illuminance_scale_available` > > for s in $S; do > echo $s > echo $s > /sys/bus/iio/devices/iio:device${D}/in_illuminance_scale > sleep 5 > done > > One question - if I test a patch like this, do I put a "Tested-by" tag or just mention that I have tested it? Both are useful - so thanks for this email. Preference for a formal tag though as that goes in the git commit and we have a convenient record that both says you tested it + that we should make sure to cc you on related changes as you may well be in a position to test those as well! Thanks, Jonathan > > Regards, > Subhajit Ghosh > > >> > >> base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de > > >
On 18/2/24 02:57, Jonathan Cameron wrote: > On Sun, 18 Feb 2024 01:09:33 +1030 > Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote: > >> On 17/2/24 00:28, Jonathan Cameron wrote: >>> On Mon, 12 Feb 2024 13:20:09 +0200 >>> Matti Vaittinen <mazziesaccount@gmail.com> wrote: >>> >>>> The loop based 64bit division may run for a long time when dividend is a >>>> lot bigger than the divider. Replace the division loop by the >>>> div64_u64() which implementation may be significantly faster. >>>> >>>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >>>> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") >>>> >>>> --- >>>> This is a resend. Only change is the base which is now the v6.8-rc4 and >>>> not the v6.8-rc1 >>> Given I'm not rushing this in, it is going via my togreg tree, so the >>> rebase wasn't really helpful (thankfully didn't stop it applying). >>> Would have been fine to send a ping response to the first posting of it. >>> >>> I was leaving some time for David or Subhajit to have time to take >>> another look, but guess they are either happy with this or busy. >>> >>> Applied to the togreg branch of iio.git and pushed out as testing for >>> all the normal reasons. >>> >>> Jonathan >>> >>>> >>>> This change was earlier applied and reverted as it confusingly lacked of >>>> the removal of the overflow check (which is only needed when we do >>>> looping "while (full > scale * (u64)tmp)". As this loop got removed, the >>>> check got also obsolete and leaving it to the code caused some >>>> confusion. >>>> >>>> So, I marked this as a v2, where v1 is the reverted change discussed >>>> here: >>>> https://lore.kernel.org/linux-iio/ZZZ7pJBGkTdFFqiY@dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi/ >>>> >>>> Revision history: >>>> v1 => v2: >>>> - Drop the obsolete overflow check >>>> - Rebased on top of the v6.8-rc4 >>>> >>>> iio: gts: loop fix fix >>>> --- >>>> drivers/iio/industrialio-gts-helper.c | 15 +-------------- >>>> 1 file changed, 1 insertion(+), 14 deletions(-) >>>> >>>> diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c >>>> index 7653261d2dc2..b51eb6cb766f 100644 >>>> --- a/drivers/iio/industrialio-gts-helper.c >>>> +++ b/drivers/iio/industrialio-gts-helper.c >>>> @@ -34,24 +34,11 @@ >>>> static int iio_gts_get_gain(const u64 max, const u64 scale) >>>> { >>>> u64 full = max; >>>> - int tmp = 1; >>>> >>>> if (scale > full || !scale) >>>> return -EINVAL; >>>> >>>> - if (U64_MAX - full < scale) { >>>> - /* Risk of overflow */ >>>> - if (full - scale < scale) >>>> - return 1; >>>> - >>>> - full -= scale; >>>> - tmp++; >>>> - } >>>> - >>>> - while (full > scale * (u64)tmp) >>>> - tmp++; >>>> - >>>> - return tmp; >>>> + return div64_u64(full, scale); >>>> } >>>> >>>> /** >> Hi Matti and Jonathan, >> >> I somehow missed testing this patch earlier. The above patch works fine with apds9306 v7 driver(which work in progress!). >> There are no errors. >> My test script is simple: >> #!/bin/bash >> D=0 >> S=`cat /sys/bus/iio/devices/iio:device${D}/in_illuminance_scale_available` >> >> for s in $S; do >> echo $s >> echo $s > /sys/bus/iio/devices/iio:device${D}/in_illuminance_scale >> sleep 5 >> done >> >> One question - if I test a patch like this, do I put a "Tested-by" tag or just mention that I have tested it? > Both are useful - so thanks for this email. > > Preference for a formal tag though as that goes in the git commit and we have > a convenient record that both says you tested it + that we should make sure > to cc you on related changes as you may well be in a position to test those > as well! > > Thanks, > > Jonathan > >> >> Regards, >> Subhajit Ghosh >> >>>> >>>> base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de >>> >> > Thank you Jonathan for explaining the above. I forgot to mention that the above test is run in parallel with continuous raw reads from another script and event monitoring. As I understand that you have already applied this patch but still, Tested-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> Regards, Subhajit Ghosh
Hi Jonathan, On 2/16/24 15:58, Jonathan Cameron wrote: > On Mon, 12 Feb 2024 13:20:09 +0200 > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >> The loop based 64bit division may run for a long time when dividend is a >> lot bigger than the divider. Replace the division loop by the >> div64_u64() which implementation may be significantly faster. >> >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") >> >> --- >> This is a resend. Only change is the base which is now the v6.8-rc4 and >> not the v6.8-rc1 > Given I'm not rushing this in, it is going via my togreg tree, so the > rebase wasn't really helpful (thankfully didn't stop it applying). Oh, I didn't think about it. Just thought I'll rebase to the most recent tag. I see the point now that you mentioned it, thanks. > Would have been fine to send a ping response to the first posting of it. Ok. Some maintainers like Mark prefer getting full resend instead of a ping because they don't keep the old messages/patches around. Reacting to ping would require them to go and fetch the patch from lore - while having full resend allows them to apply patch using their normal work-flow. Or, at least I think this is how Mark told me couple of years ago. I must admit that plenty of water has flown through the Oulu-river since that, so maybe this has changed also for them. Anyways, good to know your preference, thanks! > I was leaving some time for David or Subhajit to have time to take > another look, but guess they are either happy with this or busy. Ok. This is perfectly fine. I just thought that maybe the patch fell through the cracks and decided to re-send before I forget ... :) > Applied to the togreg branch of iio.git and pushed out as testing for > all the normal reasons. Thanks! Yours, -- Matti
On 2/18/24 07:26, Subhajit Ghosh wrote: > On 18/2/24 02:57, Jonathan Cameron wrote: >> On Sun, 18 Feb 2024 01:09:33 +1030 >> Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote: >> >>> On 17/2/24 00:28, Jonathan Cameron wrote: >>>> On Mon, 12 Feb 2024 13:20:09 +0200 >>>> Matti Vaittinen <mazziesaccount@gmail.com> wrote: >>>>> The loop based 64bit division may run for a long time when dividend >>>>> is a >>>>> lot bigger than the divider. Replace the division loop by the >>>>> div64_u64() which implementation may be significantly faster. >>>>> >>>>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >>>>> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") >>>>> >>>>> --- > As I understand that you have already applied this patch but still, > > Tested-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> Thank you Subhajit! Your effort is _very much_ appreciated! :) Yours, -- Matti
On Mon, 19 Feb 2024 09:22:24 +0200 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > On 2/18/24 07:26, Subhajit Ghosh wrote: > > On 18/2/24 02:57, Jonathan Cameron wrote: > >> On Sun, 18 Feb 2024 01:09:33 +1030 > >> Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote: > >> > >>> On 17/2/24 00:28, Jonathan Cameron wrote: > >>>> On Mon, 12 Feb 2024 13:20:09 +0200 > >>>> Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >>>>> The loop based 64bit division may run for a long time when dividend > >>>>> is a > >>>>> lot bigger than the divider. Replace the division loop by the > >>>>> div64_u64() which implementation may be significantly faster. > >>>>> > >>>>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> > >>>>> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") > >>>>> > >>>>> --- > > > > As I understand that you have already applied this patch but still, > > > > Tested-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> > > Thank you Subhajit! Your effort is _very much_ appreciated! :) I had to rebase the tree anyway to squash an unrelated issue, so I added the tag whilst doing so. Thanks, Jonathan > > Yours, > -- Matti >
On 20/2/24 06:02, Jonathan Cameron wrote: > On Mon, 19 Feb 2024 09:22:24 +0200 > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >> On 2/18/24 07:26, Subhajit Ghosh wrote: >>> On 18/2/24 02:57, Jonathan Cameron wrote: >>>> On Sun, 18 Feb 2024 01:09:33 +1030 >>>> Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> wrote: >>>> >>>>> On 17/2/24 00:28, Jonathan Cameron wrote: >>>>>> On Mon, 12 Feb 2024 13:20:09 +0200 >>>>>> Matti Vaittinen <mazziesaccount@gmail.com> wrote: >>>>>>> The loop based 64bit division may run for a long time when dividend >>>>>>> is a >>>>>>> lot bigger than the divider. Replace the division loop by the >>>>>>> div64_u64() which implementation may be significantly faster. >>>>>>> >>>>>>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >>>>>>> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") >>>>>>> >>>>>>> --- >> >> >>> As I understand that you have already applied this patch but still, >>> >>> Tested-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> >> >> Thank you Subhajit! Your effort is _very much_ appreciated! :) > I had to rebase the tree anyway to squash an unrelated issue, so > I added the tag whilst doing so. > > Thanks, > > Jonathan > >> >> Yours, >> -- Matti >> > You are welcome Matti and thank you Jonathan. Regards, Subhajit Ghosh
diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c index 7653261d2dc2..b51eb6cb766f 100644 --- a/drivers/iio/industrialio-gts-helper.c +++ b/drivers/iio/industrialio-gts-helper.c @@ -34,24 +34,11 @@ static int iio_gts_get_gain(const u64 max, const u64 scale) { u64 full = max; - int tmp = 1; if (scale > full || !scale) return -EINVAL; - if (U64_MAX - full < scale) { - /* Risk of overflow */ - if (full - scale < scale) - return 1; - - full -= scale; - tmp++; - } - - while (full > scale * (u64)tmp) - tmp++; - - return tmp; + return div64_u64(full, scale); } /**