[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: precision timer?



> Kevin Wooley <kwooley@xxxxxxx.com> writes:
>
> > BTW, I'm looking for 1-10uS precision at best, 1mS precision at the
> > worst. Pretty big range, but I'll take what I can get with minimal
> > effort.
>
> > > My suspicion is that I should somehow use either the Real Time Clock
> > > on the devboard or one of the built in hardware timers.  I'd rather
> > > do this in user space than driver/kernel space.  I don't need to
> > > trigger other events, just measure the time between two function
> > > calls.
>
> Just use the normal gettimeofday system call, it has usec precision and is
probably fairly accurate too.  If the accuracy isn't good enough for your
needs, it's always possible to improve the kernel code that supplies the
time to the gettimeofday call.
>
>   /Christer
>
From: "Mikael Starvik" <starvik@xxxxxxx.com>

> gettimeofday has 40 us precision on ETRAX 100 LX using a fairly new
kernel.
> Note that meassuring time from userspace gives unpredictable results since
> the kernel may choose to run other processes between your calls to
gettimeofday.

Actually gettimeofday has 1 us resolution nowadays, but the time to
make that syscall is typically 6-7 us.

Below is the result of a small testprogram I have, it simply checks the
time between calls to gettimeofday().
As you see it's normally 6-7 us but occasioanlly a lot more.
(Priorities not changed during this test)

Best regards
/Johan


# timetest
   6 us 5784
#################################################################
   7 us 1325 ##############
   8 us  605 ######
   9 us  259 ##
  10 us  117 #
  11 us   38
  12 us   18
  13 us   20
  15 us    2
  16 us    1
  18 us    1
  19 us    7
 147 us    1
 155 us    1
 156 us    1
 167 us    1
 169 us    1
 290 us    1
 442 us    1
 457 us    1
 461 us    1
 465 us    1
 485 us    1
 487 us    2
 488 us    1
zero_diff_count: 0
min_diff: 6 us
max_diff: 488 us
mean_diff: 58267/8192 = 7 us
Clock going backwords: 0
#