LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* gettimeofday() in 2.6.24
@ 2008-04-17 17:31 Jack Harvard
  2008-04-17 18:13 ` Chris Friesen
  0 siblings, 1 reply; 4+ messages in thread
From: Jack Harvard @ 2008-04-17 17:31 UTC (permalink / raw)
  To: linux-kernel

Hi, I was trying to figure out how gettimeofday() measures time in
2.6.24-arm2, in which a free-running timer is added to improve the
resolution of gettimeofday() from 10ms to us, I can trace down to
do_gettimeofday() as follows:

http://lxr.linux.no/linux+v2.6.24/arch/arm/kernel/time.c#L240
 239#ifndef CONFIG_GENERIC_TIME
 240void do_gettimeofday(struct timeval *tv)
 241{
 242        unsigned long flags;
 243        unsigned long seq;
 244        unsigned long usec, sec;
 245
 246        do {
 247                seq = read_seqbegin_irqsave(&xtime_lock, flags);
 248                usec = system_timer->offset();
 249                sec = xtime.tv_sec;
 250                usec += xtime.tv_nsec / 1000;
 251        } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
 252
 253        /* usec may have gone up a lot: be safe */
 254        while (usec >= 1000000) {
 255                usec -= 1000000;
 256                sec++;
 257        }
 258
 259        tv->tv_sec = sec;
 260        tv->tv_usec = usec;
 261}
 262
 263EXPORT_SYMBOL(do_gettimeofday);

but I haven't quite figured out how gettimeofday() actually gets time
from this added timer, also how xtime is updated?

Thanks, Jack

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gettimeofday() in 2.6.24
  2008-04-17 17:31 gettimeofday() in 2.6.24 Jack Harvard
@ 2008-04-17 18:13 ` Chris Friesen
  2008-04-18  8:54   ` Jack Harvard
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Friesen @ 2008-04-17 18:13 UTC (permalink / raw)
  To: Jack Harvard; +Cc: linux-kernel

Jack Harvard wrote:

> http://lxr.linux.no/linux+v2.6.24/arch/arm/kernel/time.c#L240
>  239#ifndef CONFIG_GENERIC_TIME
>  240void do_gettimeofday(struct timeval *tv)
>  241{
>  242        unsigned long flags;
>  243        unsigned long seq;
>  244        unsigned long usec, sec;
>  245
>  246        do {
>  247                seq = read_seqbegin_irqsave(&xtime_lock, flags);
>  248                usec = system_timer->offset();
>  249                sec = xtime.tv_sec;
>  250                usec += xtime.tv_nsec / 1000;
>  251        } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));


> but I haven't quite figured out how gettimeofday() actually gets time
> from this added timer, also how xtime is updated?


system_timer->offset() uses the added timer to return the number of 
usecs since the last timer tick.  It's potentially different for each 
specific type of arm blade, and the function often has "gettimeoffset" 
in the name.

"xtime" is updated in the core kernel code.

Chris

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gettimeofday() in 2.6.24
  2008-04-17 18:13 ` Chris Friesen
@ 2008-04-18  8:54   ` Jack Harvard
  2008-04-18 14:35     ` Chris Friesen
  0 siblings, 1 reply; 4+ messages in thread
From: Jack Harvard @ 2008-04-18  8:54 UTC (permalink / raw)
  To: Chris Friesen; +Cc: linux-kernel

On Thu, Apr 17, 2008 at 7:13 PM, Chris Friesen <cfriesen@nortel.com> wrote:
> Jack Harvard wrote:
>
>
> > http://lxr.linux.no/linux+v2.6.24/arch/arm/kernel/time.c#L240
> >  239#ifndef CONFIG_GENERIC_TIME
> >  240void do_gettimeofday(struct timeval *tv)
> >  241{
> >  242        unsigned long flags;
> >  243        unsigned long seq;
> >  244        unsigned long usec, sec;
> >  245
> >  246        do {
> >  247                seq = read_seqbegin_irqsave(&xtime_lock, flags);
> >  248                usec = system_timer->offset();
> >  249                sec = xtime.tv_sec;
> >  250                usec += xtime.tv_nsec / 1000;
> >  251        } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
> >
>
>
>
> > but I haven't quite figured out how gettimeofday() actually gets time
> > from this added timer, also how xtime is updated?
> >
>
>
>  system_timer->offset() uses the added timer to return the number of usecs
> since the last timer tick.  It's potentially different for each specific
> type of arm blade, and the function often has "gettimeoffset" in the name.

>
>  "xtime" is updated in the core kernel code.

is "xtime" updated by the time tick clock timer, i.e., the timer which
generates interrupts every 1/HZ second to the kernel. Put it in
another way,
does gettimeofday get time in two parts 1) seconds from xtime.tv_sec,
updated by timer0, 2) microseconds from xtime.tv_nsec +
system_timer->offset(), updated by timer0 and timer3.

Do you mean the code here
"http://lxr.linux.no/linux+v2.6.24/kernel/time/timekeeping.c#L45"

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gettimeofday() in 2.6.24
  2008-04-18  8:54   ` Jack Harvard
@ 2008-04-18 14:35     ` Chris Friesen
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Friesen @ 2008-04-18 14:35 UTC (permalink / raw)
  To: Jack Harvard; +Cc: linux-kernel

Jack Harvard wrote:
> On Thu, Apr 17, 2008 at 7:13 PM, Chris Friesen <cfriesen@nortel.com>
> wrote:

>> system_timer->offset() uses the added timer to return the number of
>> usecs since the last timer tick.  It's potentially different for
>> each specific type of arm blade, and the function often has
>> "gettimeoffset" in the name.

>> "xtime" is updated in the core kernel code.


> is "xtime" updated by the time tick clock timer, i.e., the timer
> which generates interrupts every 1/HZ second to the kernel. Put it in
>  another way, does gettimeofday get time in two parts 1) seconds from
> xtime.tv_sec, updated by timer0, 2) microseconds from xtime.tv_nsec +
>  system_timer->offset(), updated by timer0 and timer3.

Yes, I think xtime is updated by the tick timer.

system_timer->offset() may be updated by different mechanisms, depending 
on the specific arm subarch.

> Do you mean the code here 
> "http://lxr.linux.no/linux+v2.6.24/kernel/time/timekeeping.c#L45"

No.  As I said, the function usually has "gettimeoffset" in the name and 
it's specific to arm so it would be under arch/arm.  For instance, on 
Xscale boards it's ixp2000_gettimeoffset() in arch/arm/mach-ixp2000/core.c.

For more information you might want to look at the code in arch/arm or 
else talk to the arm developers on the linux-arm-kernel mailing list.

Chris

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-04-18 14:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-17 17:31 gettimeofday() in 2.6.24 Jack Harvard
2008-04-17 18:13 ` Chris Friesen
2008-04-18  8:54   ` Jack Harvard
2008-04-18 14:35     ` Chris Friesen

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).