Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp280013rdb; Mon, 22 Jan 2024 21:56:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXOtC9hfzCrv8ZHL2iUdxQ0qrqul3wII8avU7cgMqj+oNarxmFvQWv2KDpH5VelOJoUoUU X-Received: by 2002:a17:906:5ca:b0:a2d:d8f0:d987 with SMTP id t10-20020a17090605ca00b00a2dd8f0d987mr2510534ejt.33.1705989367978; Mon, 22 Jan 2024 21:56:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705989367; cv=pass; d=google.com; s=arc-20160816; b=nECFNscqLFTxELC36KIpQWCQANKVjRksi2O/QjBtxqvIZXC8zV0ehrOWJHZw0ylnyE 5Gb0JpEOe0j/KZI5xDG/wzIY6ovuUq32gz0mOnvjtMrVbMbMJ2h5ZGsfIeKqmF8IS+TG 3XRZs4OLPjIo+ol2mt1frmjNqCg5fDviubuXzCP9ubIS12678tChu9cwvxBoyyvGnkoY ZpV/61itpHtyAAtP+YFLPuU+YEhc7TY0Z9bdD4421KdBXeCF9466cfkdcjVJ2egFEy6v zE8TS6MHLc+rS+hylWWxBrrP23B1K2DUlTiMjhTCzVnvFZsco6/J5gxpdK1HazeEBSdl YjGg== 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=Ar0+/R5zg7/etbhMp1vh5sjI6Zb7oH6GKFRH8tUiMSQ=; fh=ZhfljvV0tOZZxK3YIcW9+B+KooOQd+bfuZPpoQdiVbA=; b=GpB+mJaml/d6tIQWW10vH4egvAoCmKLriwdGw82d4NyK0tPtaDwOzNSwrR9OxdkZSN xqU0F/s0Fgm7ZzOrFLvme2xnBavD2R5avMQttiCWlkIj+zk1bEyotn6CNFRs1Cj6aF2O +oYzKKlFA05XlFqzuYflPXEnV6YakUC3b9sqKXIB5hoHxuVN9p+kl+EdqGeBlLBI6AdQ K53Le28tlm7LAZJIQUQjP/qx4jhtB5qpj79GCzEB2nDYE1UFE/j/SjkCGyil+OXkA98C W2XLiqeU2H/G6xHwjZguQ1zENZrR8fvijlkIUFD8xvLf90ueoN7ozIN9KXZJPeFOdjym YvmQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tweaklogic.com header.s=google header.b=M9Ez7rlP; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-32681-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32681-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id oz26-20020a170906cd1a00b00a28cdc12db6si11061739ejb.494.2024.01.22.21.56.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 21:56:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32681-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@tweaklogic.com header.s=google header.b=M9Ez7rlP; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-32681-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32681-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D4B2A1F23600 for ; Mon, 22 Jan 2024 09:58:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2958839FD9; Mon, 22 Jan 2024 09:58:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tweaklogic.com header.i=@tweaklogic.com header.b="M9Ez7rlP" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 8B4A639FC6 for ; Mon, 22 Jan 2024 09:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705917510; cv=none; b=cbparoj1nT1zn2wZ2R6JsBpSl7KMBTj9PMgNKvG/LBwsvtfdeUqTptTI9ph76iIqvAvtNNAROGNDr9lWwxoMRvEsf7votr8fGox8IvmpP6eI9hwGN5K/s3V+TIS3w/cKwDlvQcl/gzB2y5YpFYuaenTmV0PQY24yw/OhIPVrv94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705917510; c=relaxed/simple; bh=gELjH+KX0/rA4qx7//5Nome4OCqmT9IxOo93luUA218=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=i0X3ec+xIwlEhK9e3wlbFMMbLDYifBQOZPSKYpDIudmX98UP/IDvXDxQYexPuFmIWXhVQ02DHirl+9RHr42REUsI8UE1E0SYO/750PmjJNM3PiCaOTA79P0N2R5ebZJboeSPen6hRokGCgLltNMvvI+7K2dgmAOqLBYTOEpzRKQ= 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=M9Ez7rlP; arc=none smtp.client-ip=209.85.214.180 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-pl1-f180.google.com with SMTP id d9443c01a7336-1d71e1d7c78so12908935ad.3 for ; Mon, 22 Jan 2024 01:58:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tweaklogic.com; s=google; t=1705917508; x=1706522308; 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=Ar0+/R5zg7/etbhMp1vh5sjI6Zb7oH6GKFRH8tUiMSQ=; b=M9Ez7rlPtoHYoxGO3MBzkbopA2rifgQrNPYd2MLnXEUjni/9O9okAdOgeEEXnB1HFC teEq/PGnPX7E0CyFM5yZmO4WuxKxNjyhCM5yvu84KXPzIOjJp5yU4R8fdF8smK095V29 oVQQs/v4VvH1dKcFrB8HzCvtxFTJSLxDjc2kNIMY2SwCqEtMp3QUlrFQPeWcLFcpI3t4 jvrN/A8dNXsmwQ3M6AoZ5NrOIi3Pg+e8/UY8kpRGSRj+RlEEFSBazRA1j2Zj9hRvVynD AsmrgMjrnZQSckVY8hmyAbDxQKO0R6J4mijjs8rPsh1s8VC478U8o4o71ijOAbNJJn19 ACXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705917508; x=1706522308; 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=Ar0+/R5zg7/etbhMp1vh5sjI6Zb7oH6GKFRH8tUiMSQ=; b=t6pjaXvHRy/Yf3BaWuw1g+t9XGn9jrfiy+qYp0/JizpQ2MmF9SF21oXr2NqNd3IVDe tFm3aKJOKiEfQvPoYRlk24mSpqKk1jX2S0wF8lw+Z5uEsWsL7U7KoI1RWDJ5sEnxVdeR 2Hc1QwKZxbUeQtMeDVOl9CqJeU0s77mWz5LtbIZeTHjw7py/b0CuBtyYR3A2YL9TNnSj ck98e3vqaOpVKDJBYB2KfTHYv6B0Wt2gd3RRt1TRqmXwPRAJ999lWfKn3PA7kXgj6I7H vwA+JWvqrKqCYQZj7WTGavWV5h5Dlqql+UrS4/bu3bD8+eoQMGSd10BunzeBzK6JJmGQ 5lJQ== X-Gm-Message-State: AOJu0YyIbpBV7TQPaJ7M+OQqPsiLTn3LftUk3kfbQNw3pP1p5zTXgyjv l7nyjR5fo6BGEjBSDf0/zUE4YaMm78M+oQ+rbxY1pegi3SVYiT2aytDMcuehLes= X-Received: by 2002:a17:903:2287:b0:1d7:584c:d1e9 with SMTP id b7-20020a170903228700b001d7584cd1e9mr553307plh.73.1705917507748; Mon, 22 Jan 2024 01:58:27 -0800 (PST) Received: from [192.168.20.11] ([180.150.112.156]) by smtp.gmail.com with ESMTPSA id h4-20020a170902f7c400b001d70953f166sm6591501plw.155.2024.01.22.01.58.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jan 2024 01:58:27 -0800 (PST) Message-ID: <3742308c-d063-4179-a4cb-80db021ede46@tweaklogic.com> Date: Mon, 22 Jan 2024 20:28:22 +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: [PATCH] iio: gts-helper: Fix division loop To: Matti Vaittinen , Jonathan Cameron Cc: Matti Vaittinen , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240107162253.66c1f0f1@jic23-huawei> <717b7e70-5cf8-4671-8a6b-005eefd0535e@gmail.com> Content-Language: en-US From: Subhajit Ghosh In-Reply-To: <717b7e70-5cf8-4671-8a6b-005eefd0535e@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 22/1/24 17:20, Matti Vaittinen wrote: > On 1/19/24 13:56, Subhajit Ghosh wrote: >> On 8/1/24 02:52, Jonathan Cameron wrote: >>> On Thu, 4 Jan 2024 11:34:28 +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") >>> >>> Hmm. Fix or not perf improvement?  I'm going to take the middle ground >>> and leave the fixes tag, but not rush this in. >>> >>> So applied to the togreg branch of iio.git and for now just pushed out >>> as testing for 0-day etc to take a look before I rebase that tree after >>> rc1. >>> >>> >>> >>>> --- >>>> >>>> I've implemented also a fixup series for supporting rounding of >>>> gains/scales: >>>> https://lore.kernel.org/lkml/37d3aa193e69577353d314e94463a08d488ddd8d.1701780964.git.mazziesaccount@gmail.com/ >>>> >>>> That series does also remove the offending loop. >>>> >>>> We don't currently have any in-tree users of GTS helpers which would >>>> need the rounding support so pushing the rounding is not urgent (and I >>>> haven't heard of Subjahit whose driver required the rounding). Hence, we >>>> may want to only take this loop fix in for now (?) and reconsider >>>> rounding when someone need that. >>>> >>>> Jonathan, what's your take on this? >>> Agreed - let us wait for the rounding to have a user, but makes sense >>> to tidy this corner up in the meantime. >>> >>> Thanks, >>> >>> Jonathan >>> >>>> >>>>   drivers/iio/industrialio-gts-helper.c | 5 ++--- >>>>   1 file changed, 2 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c >>>> index 7653261d2dc2..abcab2d38589 100644 >>>> --- a/drivers/iio/industrialio-gts-helper.c >>>> +++ b/drivers/iio/industrialio-gts-helper.c >>>> @@ -34,7 +34,7 @@ >>>>   static int iio_gts_get_gain(const u64 max, const u64 scale) >>>>   { >>>>       u64 full = max; >>>> -    int tmp = 1; >>>> +    int tmp = 0; >>>>       if (scale > full || !scale) >>>>           return -EINVAL; >>>> @@ -48,8 +48,7 @@ static int iio_gts_get_gain(const u64 max, const u64 scale) >>>>           tmp++; >>>>       } >>>> -    while (full > scale * (u64)tmp) >>>> -        tmp++; >>>> +    tmp += div64_u64(full, scale); >>>>       return tmp; >>>>   } >>>> >>>> base-commit: 2cc14f52aeb78ce3f29677c2de1f06c0e91471ab >>> >>> >> Hi Matti, >> >> Your fix works beautifully with the latest version of apds9306 driver which I am working on. >> All available scale values can be set without any errors. Thank you. > > Thanks for testing Subhajit! Just to ensure we have no miscommunication - did you test just this division fix, or the rounding fix here: > https://lore.kernel.org/lkml/37d3aa193e69577353d314e94463a08d488ddd8d.1701780964.git.mazziesaccount@gmail.com/ You are most welcome. I did not check the above rounding fix pointed out by the link. I will be happy to check it and let you know by the end of this month. I checked this division fix. > >> Moving to a new city with a new full time job with the assumption of getting more time >> for my list of opensource projects and contributions proved to be utterly wrong! > > Well, I can't blame you :) Being in a new work at new city sounds like you have a lot on your plate right now. Give it half a year and things will stabilize though :) Oh, and falsely assuming that "when XXX, I will have the time to do YYY" - been there done that :) > > Good luck on the new work and city! Thank you Matti. > > Yours, >     -- Matti > Regards, Subhajit Ghosh