linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: jamie@shareable.org (Jamie Lokier)
To: linux-arm-kernel@lists.infradead.org
Subject: udelay() broken for SMP cores?
Date: Thu, 22 Apr 2010 01:14:17 +0100	[thread overview]
Message-ID: <20100422001417.GF27575@shareable.org> (raw)
In-Reply-To: <20100421205745.GI26616@n2100.arm.linux.org.uk>

Russell King - ARM Linux wrote:
> > > Consider system performance where you're driving a bus using udelay()
> > > to provide 1us timings, but udelay ends up taking 10us instead every
> > > time because of the calculation for number of loops for a 1us timing.
> > 
> > Hence nested loop.  You don't multiply.  No calculation.
> 
> Ok, since you seem to have a clear idea how to convert this into a double
> nested loop, try converting it:
> 
> 						@ 0 <= r0 <= 0x7fffff06
>                 ldr     r2, .LC0 (loops_per_jiffy)
>                 ldr     r2, [r2]                @ max = 0x01ffffff
>                 mov     r0, r0, lsr #14         @ max = 0x0001ffff
>                 mov     r2, r2, lsr #10         @ max = 0x00007fff
>                 mul     r0, r2, r0              @ max = 2^32-1
>                 movs    r0, r0, lsr #6
>                 moveq   pc, lr
> 1:              subs    r0, r0, #1
>                 bhi     1b
>                 mov     pc, lr
> 
> into two loops without losing the precision - note that the multiply
> is part of a 'dividing by multiply+shift' technique.

	ldr	r2, loops_per_jiffy
	ldr	r3, microseconds_per_jiffy
        mov     r4, r2
1:      subs    r4, r4, r3
        bhi     1b
        subs    r0, r0, #1
        add     r4, r4, r2
        bhi     1b
        mov     pc, lr

Goodnight :)
- Jamie

(Admission: I wasn't thinking of high precision when I glibly said two
loops; your challenge prompted me to work it out, and I was pleasantly
surprised to see it come out so neatly.)

  reply	other threads:[~2010-04-22  0:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-21  2:19 udelay() broken for SMP cores? Saravana Kannan
2010-04-21  4:56 ` Shilimkar, Santosh
2010-04-21  6:43   ` Saravana Kannan
2010-04-21  7:22     ` Russell King - ARM Linux
2010-04-21  9:39       ` skannan at codeaurora.org
2010-04-21  9:50         ` Russell King - ARM Linux
2010-04-21  9:58           ` Gilles Chanteperdrix
2010-04-21 10:00           ` Jamie Lokier
2010-04-21 19:29             ` Russell King - ARM Linux
2010-04-21 19:52               ` Jamie Lokier
2010-04-21 20:21                 ` Russell King - ARM Linux
2010-04-21 20:47                   ` Jamie Lokier
2010-04-21 20:57                     ` Russell King - ARM Linux
2010-04-22  0:14                       ` Jamie Lokier [this message]
2011-01-08 23:24                         ` Russell King - ARM Linux
2010-04-21 10:31           ` skannan at codeaurora.org
2010-04-21 19:33             ` Russell King - ARM Linux
2010-04-21 23:47               ` Saravana Kannan
2010-04-23  9:00           ` Pavel Machek

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=20100422001417.GF27575@shareable.org \
    --to=jamie@shareable.org \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).