Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2743743rdb; Fri, 8 Dec 2023 19:19:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBRmivvbL1ztAS6d2TDp1nxAaFHkvFwAhlP/XKZn1DGaQCkznXP+1mTYAEiXg+wZQz9EFm X-Received: by 2002:a05:6870:5ba2:b0:1fb:3ef2:a1b6 with SMTP id em34-20020a0568705ba200b001fb3ef2a1b6mr1276541oab.10.1702091963517; Fri, 08 Dec 2023 19:19:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702091963; cv=none; d=google.com; s=arc-20160816; b=a/XafF3J4M+iSC5qs5ZEGCYpS0a+9XdHwSKnTypexOOKF0I9KjjxJZ5z7T1OsM5phs D5utStWDv+n0YbAGAAfKE5cf9OLXm1i5KtGcIOGUlSvWD1tTdDqMQ9urLtSaA+MxqEuw 1X7f16K5BewZwkL+MO0bJQzdShW0iiwj53ttkUX9ndOFPFUl8Cc7OBV0xAmDxpTuwSU+ BRZNh0IcgMAoQdnmroARzEPuHw5vLZe4sXB/e/roiRU/kvVSRC1lYIOO/OTncekhWzKM flTg7oXrSMD9d/XwLF2Ns1IVQTMTHy70ACEuKskwJcx1O7MavFZaN7A+dpMlgGh0Jv3K XWtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ABwILVgZ36XlXp4YPc09BFD92uZJ0VeMjHULTP2qt9c=; fh=ibtfMb9tGSrwxW4Ncn2AZJ+RHku2xeRt7sNGHCnj2Kk=; b=gLnzsiwG3MIOv7fkt61MsEYpX3dE1dtLFJCLb3D2aNie74EhGJB1k0cRYFmvu52kZ+ GEug0IFf14yAv3v51/tHp7Ba6UPvaFPcp8Pg/zaayC2BL4t+N1lmOhnxe2COgVQ3T4OA aka6EMRzTsFBu7r+HY+mHrLqOdoBkKKyhzM70T9lxJ9XXu3XzfX9iM2P3QEYw9uOdpvM ea7Nq1RmBE0CSyjD0Ovm/hB23AfsdyIONxTT/dkmFk25A+aCsJtVFsJQDnj7wIXN2qxo 2l9ZK2z33wBT+O17EpAeqagQ1pQ4Xm3XFmbFbmA0cnOfnwinZya8H2tF6yLVHi/KkWTR olSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WWGblCDC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v15-20020a63150f000000b005b91536981csi2493839pgl.11.2023.12.08.19.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 19:19:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WWGblCDC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 97F6B80A5F88; Fri, 8 Dec 2023 19:19:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbjLIDTM (ORCPT + 99 others); Fri, 8 Dec 2023 22:19:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbjLIDTL (ORCPT ); Fri, 8 Dec 2023 22:19:11 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92360ED for ; Fri, 8 Dec 2023 19:19:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96368C433C8; Sat, 9 Dec 2023 03:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702091957; bh=SLaF6IE1Yn5LfSEved29p+6U9oFQ5UxNbVEWHYgWroI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WWGblCDCoYH1Yt3S514ZcwZfMnwlKoOox75g1Hwe0D9a05eO3Ij375MDOVH00cfB7 F9GSmpPY0qsgPlVdlD+BztWy3UrErQrwLV7Sb+RamBia2AZhc5BoMS3LNzqHt2P/oj zdRy6OVi6ZQLYJ9S3OH7WBv5qbbhhkJLpH87zkVHCovy+4WW29Q1kmcr0oeSSAD8kh R0r3cCDTMx5MIjBaE/M3V39vUVWRV+ZrpCvEI+oUa32tAIt75g7dGNp7pJ+e3gIvZl YXnTMSVQhTMGzNCy5T39kX9AbHITYWHzuNle2XYqjG/zcD6+arijgJs+bJSEyf91Ho MqaSQYU20KGfQ== Date: Fri, 8 Dec 2023 19:23:51 -0800 From: Bjorn Andersson To: David Laight Cc: 'Bjorn Andersson' , Andy Gross , Konrad Dybcio , "linux-arm-msm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Randy Dunlap Subject: Re: [PATCH] soc: qcom: stats: Fix division issue on 32-bit platforms Message-ID: References: <20231205-qcom_stats-aeabi_uldivmod-fix-v1-1-f94ecec5e894@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 08 Dec 2023 19:19:21 -0800 (PST) On Wed, Dec 06, 2023 at 02:07:16PM +0000, David Laight wrote: > From: Bjorn Andersson > > Sent: 06 December 2023 00:44 > > > > commit 'e84e61bdb97c ("soc: qcom: stats: Add DDR sleep stats")' made it > > in with a mult_frac() which causes link errors on Arm and PowerPC > > builds: > > > > ERROR: modpost: "__aeabi_uldivmod" [drivers/soc/qcom/qcom_stats.ko] undefined! > > > > Expand the mult_frac() to avoid this problem. > > > > Fixes: e84e61bdb97c ("soc: qcom: stats: Add DDR sleep stats") > > Reported-by: Randy Dunlap > > Signed-off-by: Bjorn Andersson > > --- > > drivers/soc/qcom/qcom_stats.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/soc/qcom/qcom_stats.c b/drivers/soc/qcom/qcom_stats.c > > index 4763d62a8cb0..5ba61232313e 100644 > > --- a/drivers/soc/qcom/qcom_stats.c > > +++ b/drivers/soc/qcom/qcom_stats.c > > @@ -221,7 +221,8 @@ static int qcom_ddr_stats_show(struct seq_file *s, void *unused) > > > > for (i = 0; i < ddr.entry_count; i++) { > > /* Convert the period to ms */ > > - entry[i].dur = mult_frac(MSEC_PER_SEC, entry[i].dur, ARCH_TIMER_FREQ); > > + entry[i].dur *= MSEC_PER_SEC; > > + entry[i].dur = div_u64(entry[i].dur, ARCH_TIMER_FREQ); > > Is that right? > At a guess mult_frac(a, b, c) is doing a 32x32 multiply and then a 64x32 > divide to generate a 32bit result. > So I'd guess entry[i].dur is 32bit? (this code isn't in -rc4 ...). > Which means you are now discarding the high bits. > entry[i].dur is 64 bit, so this should work just fine. Arnd proposed that as ARCH_TIMER_FREQ is evenly divisible by MSEC_PER_SEC we just div_u64(dur, ARCH_TIMER_FREQ / MSEC_PER_SEC), and I picked that patch instead. > You've also added a very slow 64bit divide. Without checking the generated code, I'd expect this to be a slow 64-bit division already. But this is a debug function, so it should be fine to take that penalty. > A multiple by reciprocal calculation will be much better. > Since absolute accuracy almost certainly doesn't matter here convert: > dur * 1000 / FREQ > to > (dur * (u32)(1000ull << 32 / FREQ)) >> 32 > which will be fine provided FREQ >= 1000 > I'm quite sure you're right regarding the accuracy. I think as this isn't in a hot path, the more readable div_u64() feels like a reasonable choice. Thank you for your input and suggestion though! Regards, Bjorn > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)