From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33E10C433ED for ; Mon, 17 May 2021 06:37:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE87F606A5 for ; Mon, 17 May 2021 06:37:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE87F606A5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/WQJ1zxcicZmNOpGXNs/osVXc09sBm4Ezdv0XT5Csps=; b=git+jnT54EiJ7kO1jAZbC3WSa N9E2/JIjGqPQsYviO92wlsppQBWtoYqnxcVXxGCpEa9iU6hmmb1s72WO4WKMV/KaUcrzzjmavyZ5I kN0O4WvC2omMXOESpWU7tRc3i1LOoiNN548306vYXHyCk4U9/EI9S6zyeMHK15o45jreosjEI3e6f 5Le6u/w0/qUuY4O/6jWZ2Uf1fl5CdYjzLCOGKLEDSNqWUdlttxLPV6pAtnZ9KgtFfghhxNtdPmDGX 7DmNeNbed7Cip9f8Jlo54Qio/CtfmhfV6k9yF/OjoaLF/9js0VTSw4fPwRXGBAqMlALP0BtcUMDhS bBqCy+80Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1liWrH-00Dut9-5M; Mon, 17 May 2021 06:36:07 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liWqT-00Dukk-EG for linux-arm-kernel@desiato.infradead.org; Mon, 17 May 2021 06:35:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=x2WEl3tfdOCurmj9wRKv9v6zxNHDsRtOS/NcLJ0pHpQ=; b=o/u3+ddvbwHowIxQYpeJfNb2Ot 4RiV0Q62akne9FnEf42Gi+AWoXWje1hSYxD9vbRvaNab/HjuIr2rJ+4KKtZGwZAFK2N6ANhfffTFu rraSwsKs/d9aaj9Pom9o9RAYobrWpSoe4TGI5P3kPHAOSB+co0nuf90+r311QdlwBg3yysqULyDb0 r9cFfmtZx+2aLKPTlxrr+R8arm1Rx0zrAexb3EFR54d3QLtNuoUXS3o6gKxUEh/70o58xS+gvSPMV 0fiKbN5Fp5EpIO3jDCawFbkU+rxsOhb3pusioOfAGgAr0MBSnC93fsIfvwFZhxzvnad7xmXyW+3tZ /mo3bDOQ==; Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liWqQ-00DW4o-NN for linux-arm-kernel@lists.infradead.org; Mon, 17 May 2021 06:35:16 +0000 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1liWqC-0006gI-VM; Mon, 17 May 2021 08:35:00 +0200 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1liWqC-0000i5-BD; Mon, 17 May 2021 08:35:00 +0200 Date: Mon, 17 May 2021 08:35:00 +0200 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Billy Tsai Cc: "devicetree@vger.kernel.org" , "p.zabel@pengutronix.de" , "linux-aspeed@lists.ozlabs.org" , "linux-pwm@vger.kernel.org" , "andrew@aj.id.au" , "linux-kernel@vger.kernel.org" , "robh+dt@kernel.org" , "thierry.reding@gmail.com" , "joel@jms.id.au" , "kernel@pengutronix.de" , BMC-SW , "lee.jones@linaro.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [v5 2/2] pwm: Add Aspeed ast2600 PWM support Message-ID: <20210517063500.toxlb2wbtbqpczwl@pengutronix.de> References: <20210514024845.10531-1-billy_tsai@aspeedtech.com> <20210514024845.10531-3-billy_tsai@aspeedtech.com> <20210515151827.amiqh6j6brv44jif@pengutronix.de> <7A439233-C5FF-4BCA-8A5C-945EB847F487@aspeedtech.com> <20210517060615.3hyifoebyrddsrta@pengutronix.de> MIME-Version: 1.0 In-Reply-To: X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210516_233514_785926_0BED8395 X-CRM114-Status: GOOD ( 27.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============8216823295607164782==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============8216823295607164782== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mlq6naakv7e3kbvs" Content-Disposition: inline --mlq6naakv7e3kbvs Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 17, 2021 at 06:23:06AM +0000, Billy Tsai wrote: > Hi, > =EF=BB=BF On 2021/5/17, 2:06 PM,Uwe Kleine-K=C3=B6nigwrote: >=20 > On Mon, May 17, 2021 at 02:53:44AM +0000, Billy Tsai wrote: > > > =EF=BB=BFOn 2021/5/15, 11:57 PM,Uwe Kleine-K=C3=B6nigwrote: > > >=20 > > > > > + div_h =3D DIV_ROUND_DOWN_ULL(div_h, > > > > > + (FIELD_MAX(PWM_ASPEED_CTRL_CLK_DIV_L) + 1)); > > > > > + div_h =3D DIV_ROUND_DOWN_ULL(div_h, NSEC_PER_SEC); > > >=20 > > > > As a division is an expensive operation you can better first mult= iply > > > > NSEC_PER_SEC and FIELD_MAX(PWM_ASPEED_CTRL_CLK_DIV_L) + 1 and div= ide by > > > > the result. > > >=20 > > > When I multiply NSEC_PER_SEC and FIELD_MAX(PWM_ASPEED_CTRL_CLK_DIV_L= ) + 1 the result will overflow > > > for 32-bits and the divisor type of do_div is 32-bits so I need to d= o div twice to avoid the issue. > > > Can you give me some suggests? >=20 > > Hmm, you're right. There doesn't seem to be a div64_64, I thought there > > was one. Anyhow, while looking at the various divide functions I saw > > that dividing by a constant shouldn't be that expensive, so I think the > > sane way is to keep the two divisions and add a comment describing the > > problem. > According to our fixed value, I think that I can use bit shift to reduce = one divide function: >=20 > rate =3D clk_get_rate(priv->clk); > /* Get the smallest value for div_h */ > div_h =3D rate * state->period; > div_h >>=3D (__fls(PWM_ASPEED_FIXED_PERIOD + 1) + > __fls(FIELD_MAX(PWM_ASPEED_CTRL_CLK_DIV_L) + 1)); > div_h =3D DIV_ROUND_DOWN_ULL(div_h, NSEC_PER_SEC); Did you check how this is compiled to code? I'd expect that it doesn't result in better code than writing it as a division. Given that a division is easier to understand for a human reader, I'd stick to that. Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=C3=B6nig = | Industrial Linux Solutions | https://www.pengutronix.de/ | --mlq6naakv7e3kbvs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmCiDpEACgkQwfwUeK3K 7AmEygf/ZwamIYMTIcLZ7TTr3rtzPErb4NtB4t5kO02cBNhwBur6mRrHvDY9Roql PK3G41Kq3eUIV05NAEaOFREG8372wixvyZDsaPl3/qSaCl1d+7MnU1nTGBiuuMjR oyn8KJzXfZvdBB4SESiJfyNSxDeDTpTCYz2+ffAk2DJ6B2Ff2NQ15W6fqDgaFGUB wFDePd/xxe3/O2Ma9tRRhflwnNcqFNTjKfivgBjC9b/e3Gi+K6XfExe08ivF2fJS nZwJX/LPNFi/sZcGswuqLn+F3D/SPY7xHCxmdeAb0N+g5LCZwpeN9mA8vqbEa+eH Ay1bLknYlDUWNi7zfL2VpjXwEVkqOQ== =BBqZ -----END PGP SIGNATURE----- --mlq6naakv7e3kbvs-- --===============8216823295607164782== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============8216823295607164782==--