Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp241611rdb; Sat, 17 Feb 2024 06:39:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXfgIz4DhEzKf3urgGnrhW+QKcPNs59BcQg6oPSAho/wF3xpIV8IiPEjz8teFCnfoQpfyT3fN0jjMw6fyJWEjL4liXNeeLz5pOjx4Yp/w== X-Google-Smtp-Source: AGHT+IGKCIJ4iEyYIP6HsV5AZ1xuUUrUGlB3PXaMceB2DwA+dnnBgIGPdWe6ypQe0cE4Jb8ok0Xb X-Received: by 2002:aa7:d0d6:0:b0:564:1bcd:c995 with SMTP id u22-20020aa7d0d6000000b005641bcdc995mr1201910edo.36.1708180791348; Sat, 17 Feb 2024 06:39:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708180791; cv=pass; d=google.com; s=arc-20160816; b=N8A2f8xyCUHgYheBgBaX/iloHR+/PW4JQ5Coq98ZmvlzqImLLnZZjEeltkxAfg0gA6 bOZrNhmLXXw57pNAHrMVh8RYBZhvvmxwFH82s+qvoRyERGtJJMMGfwY1GDaaPnhmj0nz xXwhPwCr57LAvwywU8hwfABTDrCornCzfLaH4AbnxQrw3sEkKr47CG4Ze4nXXt3+vPNg Fg5z5y1wNXX9djOCz3tVjxmUp38JtQ+MtYnQmo0iQweFr4/Z+fNbqCSnNDCgqquzVPb7 Xhi6T3LOS7LqTvlBXzVji+rcvUr/uQSGHT+F2Vs725ND2JQ4ED11ZtAcgZ3P5L2H0NoV YOwQ== 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=Snv5IU+ADbcqgOjycYAOmXHtXMcTl5Y5BUfYBZJWwIg=; fh=CgdS4OO1hSYpFWVn2lPYz/M4YYrDZX5rqYGTcksUa1I=; b=FjUFttmaTpvQCykgARQGuowL96+GuN1eE7PVh+zC4jNneFTynFOVD9rzmO/GK3Ek7O bQWBCK7tlPTlD7Ozm1SXkeXH1x+ek4pEfwl24+o+CsDQtu52eX/V65LhkuGVU3AB6WIQ bLf81nrK2FChXoVsszjRLYn4/x0gHZGxHXERCabF7jBCwvlAxupe/a20k9BsMKpXeQWB /ZWohS30ir31hZLo8TH4/KmhyQ7v+Bay10ARQjaIQ3KabWMqSkmmMn2tzrDETODYWcO4 usnI2+6Y6fEjWD2zYM63CCFGcNCuQr8QWpRQ7vPYi8h/eyYiewViU+IN7yiUZ2FtJHcM 9BUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tweaklogic.com header.s=google header.b=PANa8sru; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-69909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69909-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 bc5-20020a056402204500b005640a2568c7si866240edb.346.2024.02.17.06.39.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 06:39:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69909-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=PANa8sru; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-69909-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69909-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 C32061F21CE2 for ; Sat, 17 Feb 2024 14:39:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E5317C09D; Sat, 17 Feb 2024 14:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tweaklogic.com header.i=@tweaklogic.com header.b="PANa8sru" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 BA47D41C63 for ; Sat, 17 Feb 2024 14:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708180782; cv=none; b=OmSdZlXIj1luYF7nNucw3QyKSZ6u7jg1FGHkmhm5cvc+1a06vi/Msdm2zt2RnCmueohrP7vyOp4th5JeVqwNEDTGV5s5dnTXDK1egfOZOJBCs0FAukXSfz8STIZY0RgjhFwaa1CKxuF9IaxSN+MNjgnHZLKaInndWYSLKF9KZuI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708180782; c=relaxed/simple; bh=xWWAkwL0hz4hu8Jh3YaTF/1bFJqdVShaDpWcm63XY2U=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Lr6uHBTRxSI5FEskJd0LJgNSuIXpahB12XgSlj14eIXiDs2lTulngf9KO680Ckzow5b6vuxS3XdViWCr+xZTCPfthRnOLmxsJKQErpPeX0WDDEiCyWKq+EpvKUfJyIWyp9z1OMJLI5c2GcwaIenGRR6ZCXgBFMYKSRPTDXjwcqE= 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=PANa8sru; arc=none smtp.client-ip=209.85.215.182 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-pg1-f182.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so2418791a12.1 for ; Sat, 17 Feb 2024 06:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tweaklogic.com; s=google; t=1708180779; x=1708785579; 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=Snv5IU+ADbcqgOjycYAOmXHtXMcTl5Y5BUfYBZJWwIg=; b=PANa8sruRbDv1u1RX0i4Py3Kum7c4V+fkE0skrMnyP0J+rhT4d1dXfcX4j/8uSpLoS 18MjyajSDSsHbK998T2wlaGdSppt2k/eIkGrDRkVsXt0322sbiFHLDQl1KMQ0O6sTz6K CZAKqQXkhLgm0nvbzDBD99PyI6J4ApEE5b3kqOxZzcQvYSOdwFzhawGVOM+CUThNf6mI SG1Gy/c5zOXyhHJGJsXGk7OIPZB47vYh+/l0jYPs0hztlLvUjzkr0IBII49GeWbXdDTN kiBi/S1k5gx05WHo6l1CVS7i2FBDez/T6ot9Pz4O8HJKK0EJMA6m92fCQWCNdk/p0LJl hgfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708180779; x=1708785579; 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=Snv5IU+ADbcqgOjycYAOmXHtXMcTl5Y5BUfYBZJWwIg=; b=MaDiQMNRzyJGN9DSOkYwKMdP1lylUcJT59ZfAN5g9IPCkbqozm+XaVqkVIGebQW5Pt SGg74funUi+7M9rojE3NbSSmqPUGKb93NPXDZ6pa4CRgGt4z22UdNzSVR1mtAQHaBlTR l37IoPcujD9MQydclED+QSL3CbrcwAP9PJaG2+IIKz9B8DtFAIOKzlvtJvch6NEmTmTq U0dKEm/Lb7uKK1Fx6ZMKMjn/k9myGgRNVHvDX9sMNnQaFfTQndt3V8lrVntDwrGI1VSk 9xV4nU+W3s5ny7Nv35C8TofYgxR92J4ljbIDRzvSjV8urCHzNY/1Jvq0k11UpIBpJB9e X5vw== X-Forwarded-Encrypted: i=1; AJvYcCVNbQ0jtOvXi0XzljGQeLgpjvn9mTsfxHBa0FGxq/dx12oXop/LW/IyI2J9Jn8Hlf2bGFrSYglv9N44qKQZ/nqtUrT3pLIBO/JRufJG X-Gm-Message-State: AOJu0YxPzjzxwlDsvlZm9yc05bYck4EUNuHUWdYU1IGnUONcPQw8HGKB 1BB76N6IOo2Pd6Yh2BjcvpxXYw8eraMXPqJ1WrRvod5o1wE8Sr3xeyZpryJxn7w= X-Received: by 2002:a05:6a20:9e48:b0:1a0:60b2:45b with SMTP id mt8-20020a056a209e4800b001a060b2045bmr9980124pzb.6.1708180778915; Sat, 17 Feb 2024 06:39:38 -0800 (PST) Received: from [192.168.20.11] ([180.150.113.62]) by smtp.gmail.com with ESMTPSA id n14-20020a635c4e000000b005dc2ca5b667sm1454274pgm.10.2024.02.17.06.39.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 06:39:38 -0800 (PST) Message-ID: Date: Sun, 18 Feb 2024 01:09:33 +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 , Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , linux-kernel@vger.kernel.org, David Laight , linux-iio@vger.kernel.org References: <20240216135812.07c9b769@jic23-huawei> Content-Language: en-US From: Subhajit Ghosh In-Reply-To: <20240216135812.07c9b769@jic23-huawei> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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? Regards, Subhajit Ghosh >> >> base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de >