Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp291789rdb; Sat, 17 Feb 2024 08:28:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXkjBMz/xONoLTOYVwm0tjQhum4FF9jE5GfB+wZOD6yTMwVcEpA0LhFPfaS+w/yPIi6vqE/73XIuDSVPDfBAUdGXXKF+Je2fVKj/W8y2A== X-Google-Smtp-Source: AGHT+IGon8uZheVCuWOnMg8Px6ngQzUXYRO0REvI0MVYJfQbTEpaTjn0FjgBpCR6pDj3dHzfDV30 X-Received: by 2002:a17:906:2516:b0:a3d:1799:97ec with SMTP id i22-20020a170906251600b00a3d179997ecmr4763362ejb.30.1708187291059; Sat, 17 Feb 2024 08:28:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708187291; cv=pass; d=google.com; s=arc-20160816; b=o6Na0jPEpimiovsu6lag7E8p91bc3ipD0FREV4y88K6rSRukwhlEE3Fic2fmwSPSFy oybjtc7i72ILiI+ozt0N7HcUxxnTOlSk+vv0LkrhDEmn15o0pbKKKgHEDh4RCRd66CUz 8Jzgb5y/u10Nqe/2v+f7WenqZ9fpoYekBXCz+lR48qccne1e5obCMA8OMu4XuMOYYTs7 9jRCmzYCoBCIAN9d57sdsXlVfkPD+vd13GAxBuN6nqmgM2b3XXbJy5kJJLSWP3uiRpba m785+3xtkomvNDnkPAdpSeuTw0XY1j20p579QV/+TP27mLDCV994IGi+fDX2r3srBfDA 5rfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=pc+8sjcN1F2wRb/yFeMv+P5zsPQtyN9hYndVLiwYpnk=; fh=vs1ticOrLYT3ewZ10QaDIpSEJvJCVofwN06UPyII/Uc=; b=Hg8m0WfVuIX1EyPz7jbRcx4OTbBvJUFPo3+23FvJYsVaXZaZKuQ9ApYoek72P5BpCO XXW0qIJK1NEurQYED0JxfgGOru9jfKB8Y8wJ1RbF/uX94fiaiB0VRpNKc/b9aZYqMy+s sFHKhPNu0Vz+Trscug1VnMM7byj8nGLy7sFaOmzreVqUekGkBq+ueh5cqT9jCwaqtqO3 owHVtTJQ5HHA58AMav6EnNePBqblz1uyjjHOTiRqabQnYovckl0MJbkkZpU13BhnPIXi rYO9S/0HUokKRZZFkhcPXmg/cn8FGGi4XLAl5Y9qfR04yu0VA+i7zyd4P8u9gzSuy6MY Z/Bg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PgvXsaS1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69968-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s22-20020a170906455600b00a3e0c074489si853856ejq.699.2024.02.17.08.28.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 08:28:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69968-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PgvXsaS1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69968-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id CEE821F21C15 for ; Sat, 17 Feb 2024 16:28:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A53E47CF28; Sat, 17 Feb 2024 16:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PgvXsaS1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB5487C0A4; Sat, 17 Feb 2024 16:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708187256; cv=none; b=jnLp4roxueIUY/LPZ/5DqP9noP4WkpYcDj9EZxMXjEkajGw0OU+Igd/L4QjQRdAJ4PUR42LrurHDFQjwRwPQx3E2ePFehGnLX2jKAVwO5O3wsmjkDxy7Or2CTwsg1tNZ66THSgASVNXmuuZITPBeZYp5PdmQLJElxeMGH5l4GTo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708187256; c=relaxed/simple; bh=OxQUJIbmzj1GSzutcw5Ae7+lxbWZuacLVGzXpfA7VVw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KJmlGGPOLB2XxYZ+xUiDL+hrCt0bzaoLvTi7n4ScnAIpgLoM7ZtiNE0jKJUcAdB+AjA7XyT6GT4P9Uvqt0xcRlcj2GofdnyCOBdjArh2RnyPpnjoKSYdG8bCDNZ3ys1/jxPLBR/6Xc2Mc/i7dKdPLF0vZ4hgzbaFiHtFUUQjui4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PgvXsaS1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBD62C433C7; Sat, 17 Feb 2024 16:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708187256; bh=OxQUJIbmzj1GSzutcw5Ae7+lxbWZuacLVGzXpfA7VVw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PgvXsaS1v8qai/8BwB0Dz7/3XyllpWX4krFIKs2Ct4c0wQnk0i751CtaXMqP7+BBA DZXpfae8uBz2e9IL+CowZt3L9WuAJmd02uR0/+ge83Lb/TIwaXRM9wy8vXCDVjVp2f Qp7VuW+vyAgg1tUTR584QRjvX8In1UEuzP0nfhjO+YUZpFEF0ftwnWah9ceaNPnZ2s k1SblMCTJ3zwyjxlACWeC35Zl/92A/BU4wsnTK2h6cliFVIfGoRgTqnr7QOmJZ2Ngr VZbqBoaaNjWQxgr05bINKWXJSeeCCOCVF8c69xeYCoDPAVxsDANrh/ehDboG0Pphx2 /K6rXv5azRBLQ== Date: Sat, 17 Feb 2024 16:27:24 +0000 From: Jonathan Cameron To: Subhajit Ghosh Cc: Matti Vaittinen , Matti Vaittinen , Lars-Peter Clausen , linux-kernel@vger.kernel.org, David Laight , linux-iio@vger.kernel.org Subject: Re: [RESEND PATCH v2] iio: gts-helper: Fix division loop Message-ID: <20240217162724.767f2ab6@jic23-huawei> In-Reply-To: References: <20240216135812.07c9b769@jic23-huawei> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 18 Feb 2024 01:09:33 +1030 Subhajit Ghosh wrote: > On 17/2/24 00:28, Jonathan Cameron wrote: > > On Mon, 12 Feb 2024 13:20:09 +0200 > > Matti Vaittinen 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 > >> 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 > > >