public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Nishanth Menon <nm@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] Timer implementations
Date: Tue, 26 Oct 2010 10:11:45 -0500	[thread overview]
Message-ID: <4CC6EFB1.9000701@ti.com> (raw)
In-Reply-To: <4CC68A07.6050109@emk-elektronik.de>

Reinhard Meyer had written, on 10/26/2010 02:57 AM, the following:
> Wolfgang Denk schrieb:
>> Dear Reinhard Meyer,
>>
>> In message <4CC67CA1.9090302@emk-elektronik.de> you wrote:
>>> If implemented with true 64 bits for get_ticks() that function is useable
>>> for timeout programming:
>>>
>>> 	ulong timeval = get_timer (0);
>>>
>>> 	do {
>>> 		...
>>> 	} while (get_timer (timeval) < TIMEOUT);
>>>
>>> It appears that the "base" parameter and return value is in CONFIG_SYS_HZ
>>> units, and not in native ticks. That causes 64 bit mul/div every
>>> time get_timer() is called. Won't hurt in a timeout loop, though.
>> But it will hurt in othe rplaces.
>>
>> Also, this code _is_ a bit different, as "get_timer(0)" makes sure
>> the counter starts ticking again at 0
> 
> Nope, it does not reset the counter itself. It returns the current
> counter value (recalculated into CONFIG_SYS_HZ units).
> Maybe you mean reset_timer() instead?
> 
> In arm9226ejs/omap/timer.c udelay() is implemented with reset_timer()
> and get_timer(). Since those functions are inherently not nestable,
> beware of base=get_timer(0); do { ... udelay(xx); ... } while (get_timer(base) < TIMEOUT);
> constructs!
At least the omap3+ code arch/arm/cpu/armv7/omap-common/timer.c
__udelay() does'nt seem to reset the timer
BUT,
unsigned long long get_ticks(void)
{
         return get_timer(0);
}
ulong get_timer(ulong base)
{        return get_timer_masked() - base;
}
ulong get_timer_masked(void)
{
         /* current tick value */
         ulong now = readl(&timer_base->tcrr) / (TIMER_CLOCK / 
CONFIG_SYS_HZ);

         if (now >= lastinc)     /* normal mode (non roll) */
                 /* move stamp fordward with absoulte diff ticks */
                 timestamp += (now - lastinc);
         else    /* we have rollover of incrementer */
                 timestamp += ((TIMER_LOAD_VAL / (TIMER_CLOCK / 
CONFIG_SYS_HZ))
                                 - lastinc) + now;
         lastinc = now;
         return timestamp;
}

if I am not mistaken, this is 32bit long.. but since we have as wdenk 
mentions below a 2^32 tick duration, we can safely go with an option 
such as:
/* If we fail after 1 second wait, something is really bad */
#define MAX_RETRY_US    (1 * 1000 * 1000)

uint64_t etime; /* actually this could be u32 */

etime = get_ticks() + usec2ticks(MAX_RETRY_US);
while (!(readl(&mmc_base->stat) & CC_MASK)) {
         if (get_ticks() <= etime) {
                 printf("%s: timedout waiting for cc2!\n", __func__);
                 return;
         }
}

sounds right?

> 
>> , and get_timer() is defined to
>> have millisecond resolution.
> 
> Actually CONFIG_SYS_HZ (whatever that is).
> 
>> So you have a guaranteed 2^32
>> milliseconds or 4294967 seconds or about 3.3 years available which
>> indeed should be sufficient to implement standard timeouts.
> 
> I think it is necessary to summarize all implicit or explicit documented
> "defined to have's" regarding the timer and then to verify that all
> implementations adhere to them.
> 
yes indeed.. :(

-- 
Regards,
Nishanth Menon

  parent reply	other threads:[~2010-10-26 15:11 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-26  1:02 [U-Boot] [PATCH v2] mmc: omap: timeout counter fix Nishanth Menon
2010-10-26  1:14 ` Reinhard Meyer
2010-10-26  1:18   ` Nishanth Menon
2010-10-26  5:29     ` Wolfgang Denk
2010-10-26  5:28   ` Wolfgang Denk
2010-10-26  5:34     ` Ghorai, Sukumar
2010-10-26 13:58       ` Nishanth Menon
2010-10-26  5:43     ` Reinhard Meyer
2010-10-26  5:48       ` Wolfgang Denk
2010-10-26  6:01         ` Reinhard Meyer
2010-10-26  7:00           ` [U-Boot] Timer implementations (was: Re: [PATCH v2] mmc: omap: timeout counter fix) Reinhard Meyer
2010-10-26  7:41             ` Wolfgang Denk
2010-10-26  7:57               ` [U-Boot] Timer implementations Reinhard Meyer
2010-10-26  9:33                 ` Wolfgang Denk
2010-10-26 10:18                   ` Reinhard Meyer
2010-10-26 13:05                     ` Wolfgang Denk
2010-10-26 13:33                       ` Reinhard Meyer
2010-10-26 21:19                         ` J. William Campbell
2010-10-28  6:02                           ` Reinhard Meyer
2010-11-01 13:47                             ` J. William Campbell
2010-11-01 20:01                               ` Reinhard Meyer
2010-11-01 20:15                                 ` Wolfgang Denk
2010-10-26 15:11                 ` Nishanth Menon [this message]
2010-10-26 15:17                   ` Wolfgang Denk
2010-10-26 15:22                     ` Nishanth Menon
2010-10-26 16:26                       ` Wolfgang Denk
2010-10-26 18:36                         ` Reinhard Meyer
2010-10-26  7:03           ` [U-Boot] [PATCH v2] mmc: omap: timeout counter fix J. William Campbell
2010-10-26  7:36           ` Wolfgang Denk
2010-10-26  7:48             ` Reinhard Meyer
2010-10-26  4:36 ` Wolfgang Denk
2010-10-26  5:26   ` Ghorai, Sukumar

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=4CC6EFB1.9000701@ti.com \
    --to=nm@ti.com \
    --cc=u-boot@lists.denx.de \
    /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