Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp508999rdb; Sat, 17 Feb 2024 21:26:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXSFPqdI+adpv01FH6tftSt51Fxvcxt69pazotw9o57hNvahdiWa1AJVcnFVgnw0m8YtjCo4fuPsxF5px4JAhMyUegQjjuuFZBWCcGCCQ== X-Google-Smtp-Source: AGHT+IHM5zZits1nC1SIpcnIJuLHXvObMugt9Xr4PDqF9Vm5Vikl2Uc3MTz6Qmh8ce9NUdQLU6Wj X-Received: by 2002:a05:6a00:139d:b0:6e0:f752:b442 with SMTP id t29-20020a056a00139d00b006e0f752b442mr11679529pfg.7.1708234009773; Sat, 17 Feb 2024 21:26:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708234009; cv=pass; d=google.com; s=arc-20160816; b=PYVn7t13Zjyb8WnaCvsyDDQoI7iQ8nTP0P6vX9PuuhWr/TIcuQ/AKlc/Wx8meVoVAi qk07bo+TALkOvhPmkiOhI4CHdj9sDYN1kZSEhTKt1pH4DYisPvKkeUZJuVTmpWxDspwt 3jXdEVnfYGRGToI5fMperQm3F63AdvhISWTTMgg7OP9G/5s95aSJ+Qjlnr5FL9O1ylDz 3IZ/zIceYF2ZnVmI7xdYFwPk8cRCKSe61s6ufF2OzxSRwakherkNISTluYntmTxmFAbM rquP1HKx3HSfBCUyO30gFu6qIwRsqdQAEcaCgrKTwpMc9HQjgLp/jFm8Z1heqeXcqPF4 TOoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=jQeF0EtWGS9tgKqxNFCbPNoiWJT3We61+76i+eNuJQE=; fh=Gvn6BK2vcdDowid86l8g2yMA+zv0MkXDm7dzPVx3+W4=; b=VDGeKoIod/RYioT5ezvveig0yoO3zH7ar6MpkasCaU7UYBMKaiRkSO7F+yPCaUWQ+I vORyo8pClSNnpzlcliA1d4uAj5LPp4DKuPDSl6ggpawXFxidRhJ7Dc70hz68TfwrIKq7 7K8/nfLDqBKGl03EDT+c6gP8RzjL4fGXv8wV090HvuizgYuDnup157ckXddd+T0IhiOr VFCDjfwTsig8GuIDYcCAkEDQ/IvjRTZfMyOq9X1xP/tyg9i9/ds4DHTTDldFhf9AbUBF 33C6AQEXL/X1vG4mdE8msJI73hDi+xhr7UuVXfr7QSng+d2E8wlM//CDP3A4rJ9DZEfD 7DDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tweaklogic.com header.s=google header.b="NxEqw/4h"; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-70205-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70205-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y30-20020aa793de000000b006e34628b42asi1627849pff.197.2024.02.17.21.26.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 21:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70205-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@tweaklogic.com header.s=google header.b="NxEqw/4h"; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-70205-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70205-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4B27EB21B8E for ; Sun, 18 Feb 2024 05:26:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DF474C61; Sun, 18 Feb 2024 05:26:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tweaklogic.com header.i=@tweaklogic.com header.b="NxEqw/4h" Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 093064C6F for ; Sun, 18 Feb 2024 05:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708233996; cv=none; b=ArM/5EFoH2bPIAi09Ykyu8nv1rJIXUYx7HEGkGIRnRB0SNB1M6+dm/3HLBArGZ+b1j8ALnTKDPZTUz++RnMP1iuF786QNBjyNR0RtgbTrpU7YNQHfConM0VH36hHlB1zF/Nm5v44TfjGxCaU4JRdhQ/ILmcqivmxF3t9VmHlw5I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708233996; c=relaxed/simple; bh=hIx6IJ5pL8itiTPrvVrZD5A6HOd06/aoGUHVby7uyP4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QW9L4cLDyTYqMffTePqY+qerEJd6A/S52/sYruC9JVHBcZQbIGFmqo8DQoyp1abMu6tnJ5dKfZieF+gqkvwA1yc80NkasnNgnwToaMP7XxthPGPrd/fFkiGAXnqpaIH3nAXbOPtmLvclaqQppmWsOohr6tHmCboCqY1RvEqZxd4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tweaklogic.com; spf=pass smtp.mailfrom=tweaklogic.com; dkim=pass (2048-bit key) header.d=tweaklogic.com header.i=@tweaklogic.com header.b=NxEqw/4h; arc=none smtp.client-ip=209.85.166.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tweaklogic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tweaklogic.com Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-7c457b8ef7cso126023139f.2 for ; Sat, 17 Feb 2024 21:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tweaklogic.com; s=google; t=1708233994; x=1708838794; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jQeF0EtWGS9tgKqxNFCbPNoiWJT3We61+76i+eNuJQE=; b=NxEqw/4hEulKtgleQNcBO9J9PGfa8EQRG3dtaE2mEESLDjOXoF+5vJue8jdV5OUoC6 Xh5t3alwfFE0T5v+ES3peTfFpKqFWAh4n+CMJeALI++MLSOESUb72Lmhdbesvsm/bHV5 ybI9YXtt04B+fBQnhFDnBb4flHhpd3yuUM13ZXjsguG5RStoSMnUeVU7nV4FXecnZheo amoXI/gN5SgxiOQhsfVexyRgvcqmZnLC73dltQC49IMINedcxEwY5VIktPaEj0tfKgHp hPDCTy7IUzpKNjiS7ZBQuSfEMsS1fzhGXswJQxxY91taHJtqDidm0DUavq9LtAwRR9HD K0MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708233994; x=1708838794; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jQeF0EtWGS9tgKqxNFCbPNoiWJT3We61+76i+eNuJQE=; b=C+X1JOWlfPgDjDnamQvu1iUXYXiBtp09bwqtuCj91PZouKXiKqdqbpsV9UcCb1VYMG RYCLTOTp+RCLPfypwpQv3LGXe6m8XP6WNLsDitLPjj6+sdGuZQ282n7HhJYxQlb4II4p +a/0ZLlAga8RMjpAXG+/yZFEZAShCxUTTzvUjI/B7pyc0Loyp6VGsl0kx8sTgtpAgPzR iSkY1DIx//XxiKTYg1fjQNR9BCFw1vc4W1wSsCPQ9H022RcG3dBQo5k6p55rP6umCzSQ WpzZVPccbMnl4bwOSzFMVL0/UD2+2WYNSyTuQGUJaC8p3L7T9487c+NXN8ZvIdFKsfyV w1iQ== X-Forwarded-Encrypted: i=1; AJvYcCVc8bjHgvcLMbXMQeyyAz44QibQJuFRMS1AYrU13R+FMTpD3K0+db9fu85bB/Ioiv56Kxwwi+o5uWuGOyIP1xniYFTXNNIqCPK44GZG X-Gm-Message-State: AOJu0YzckNIDxXlUZqkFjFqftUdTtmC3wupWh3p/LdqttQzc6CG95W5w sUbJ+ar3tT2bhrTFSZo4MK0BCTuK0OPLudOY9yBVSby90WyEnaswDUEIF3I1pjo= X-Received: by 2002:a6b:4a01:0:b0:7c4:95e1:7c6f with SMTP id w1-20020a6b4a01000000b007c495e17c6fmr10943315iob.2.1708233993945; Sat, 17 Feb 2024 21:26:33 -0800 (PST) Received: from [192.168.20.11] ([180.150.113.62]) by smtp.gmail.com with ESMTPSA id l1-20020a170902d04100b001dbb14e6feesm2173492pll.189.2024.02.17.21.26.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 21:26:33 -0800 (PST) Message-ID: <65582213-1091-4877-ae83-c9450a3610fa@tweaklogic.com> Date: Sun, 18 Feb 2024 15:56:12 +1030 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RESEND PATCH v2] iio: gts-helper: Fix division loop To: Jonathan Cameron Cc: Matti Vaittinen , Matti Vaittinen , Lars-Peter Clausen , linux-kernel@vger.kernel.org, David Laight , linux-iio@vger.kernel.org References: <20240216135812.07c9b769@jic23-huawei> <20240217162724.767f2ab6@jic23-huawei> Content-Language: en-US From: Subhajit Ghosh In-Reply-To: <20240217162724.767f2ab6@jic23-huawei> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 18/2/24 02:57, Jonathan Cameron wrote: > 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 >>> >> > 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 Regards, Subhajit Ghosh