From: Vineet Gupta <Vineet.Gupta1@synopsys.com>
To: Mischa Jonker <Mischa.Jonker@synopsys.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Joern Rennecke" <joern.rennecke@embecosm.com>,
joe perches <joe@perches.com>
Subject: Re: [PATCH] ARC: Fix __udelay parentheses
Date: Thu, 29 Aug 2013 05:55:11 +0000 [thread overview]
Message-ID: <C2D7FE5348E1B147BCA15975FBA23075140F26@IN01WEMBXA.internal.synopsys.com> (raw)
In-Reply-To: <1377714588-2144-1-git-send-email-mjonker@synopsys.com>
On 08/29/2013 12:00 AM, Mischa Jonker wrote:
> Make sure that usecs is casted to long long, to ensure that the
> (usecs * 4295 * HZ) multiplication is 64 bit.
>
> Initially, the (usecs * 4295 * HZ) part was done as a 32 bit
> multiplication, with the result casted to 64 bit. This led to some bits
> falling off.
>
> Signed-off-by: Mischa Jonker <mjonker@synopsys.com>
> ---
> arch/arc/include/asm/delay.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arc/include/asm/delay.h b/arch/arc/include/asm/delay.h
> index 442ce5d..8d35fe1 100644
> --- a/arch/arc/include/asm/delay.h
> +++ b/arch/arc/include/asm/delay.h
> @@ -56,8 +56,8 @@ static inline void __udelay(unsigned long usecs)
> /* (long long) cast ensures 64 bit MPY - real or emulated
> * HZ * 4295 is pre-evaluated by gcc - hence only 2 mpy ops
> */
> - loops = ((long long)(usecs * 4295 * HZ) *
> - (long long)(loops_per_jiffy)) >> 32;
> + loops = (((long long) usecs) * 4295 * HZ *
> + (long long) loops_per_jiffy) >> 32;
>
> __delay(loops);
> }
The intent of writing orig code was to generate only 1 MPYHU insn (32*32 =
high-part-64) for the whole math, at any optimization level whatsoever. If the
first MPY is overflowing, u r likely spinning for > 10,000 usec (10ms) which is 1
scheduling tick on ARC - not good - presumably for hardware debug. It would be
better to use a tight loop there and throw it out later.
The API abuse would only be caught for const @usecs case. Maybe we need to add a
WARN_ON() there.
OTOH, if we really want to fix this, it would be cleaner to rewrite this as
loops = ((u64)usecs * 4295 * HZ * loops_per_jiffy) >> 32;
Since one factor is upcasted, all are promoted to 64 bit. And we leave the
optimizations to whims of gcc.
@Joern, I would assume that long long vs u64 (or unsigned long long) doesn't
matter in this particular case.
-Vineet
next prev parent reply other threads:[~2013-08-29 5:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-28 18:29 Mischa Jonker
2013-08-28 18:45 ` Joe Perches
2013-08-28 18:53 ` Mischa Jonker
2013-08-28 19:01 ` Joe Perches
2013-08-28 19:12 ` Mischa Jonker
2013-08-29 1:43 ` Joe Perches
2013-08-29 5:55 ` Vineet Gupta [this message]
2013-08-29 6:01 ` Joe Perches
2013-08-29 6:24 ` Vineet Gupta
2013-08-29 6:37 ` Joe Perches
2013-08-29 6:49 ` Vineet Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C2D7FE5348E1B147BCA15975FBA23075140F26@IN01WEMBXA.internal.synopsys.com \
--to=vineet.gupta1@synopsys.com \
--cc=Mischa.Jonker@synopsys.com \
--cc=joe@perches.com \
--cc=joern.rennecke@embecosm.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®