Skip to contentSkip to conversation

do_gettimeofday( ) precision?

DISCUSSION abhijit 2 participants 4 messages Jun 23, 2004 – Jun 24, 2004

lore
Share & tools
lore

abhijit

author
#0 lore raw

hello,

the comment on top of do_gettimeofday( ) [arch/i386/kernel/time.c] says:

/*
* This version of gettimeofday has microsecond resolution
* and better than microsecond precision on fast x86 machines with TSC. */
void do_gettimeofday(struct timeval *tv)
{
...

but the code below limits usec to <= 1000000. so isn't the resolution not limited to microsec even on TSC capable boxes?

if one wants higher resolution (for timestamping etc.) whats the preferred way?

thanks
abhijit

#1 lore raw
Quoted 12 lines · abhijit

hello,

the comment on top of do_gettimeofday( ) [arch/i386/kernel/time.c] says:

/*
* This version of gettimeofday has microsecond resolution
* and better than microsecond precision on fast x86 machines with TSC. */
void do_gettimeofday(struct timeval *tv)
{
...

Quoted 8 lines

but the code below limits usec to <= 1000000. so isn't the resolution not limited to microsec even on TSC capable boxes?

if one wants higher resolution (for timestamping etc.) whats the preferred way?

thanks
abhijit

	Hi!

I think you are right that do_gettimeofday() is limited to microsec even
on boxes with TSC register. This function returns only seconds and microseconds so you won't get better resolution with it. I don't know the way how to do it, but I wonder about precision of such mechanism (if any exists).
Regards,

Lukasz

author
#2 lore raw
Quoted 2 lines · Lukasz Michal Rak

I don't know the way how to do it, but I wonder about precision of such mechanism (if any exists).

basically i want some counter w/ microsend resolution that fits into 32 bits. couple of possible solutions come to my mind:

[1] use TSC and convert it to microsec
[2] use get_timeofday( ) and convert to microsec
[3] use xtime variable directly and convert to microsec (any other ways?)

conversion in [1] will be costly (a div involved). conversion in [2]/[3] can be done using bit operators. (usec|sec << 20) but [2] will incur function call overhead which i'd like to avoid.

so is using xtime directly ok and reliable?

thanks
abhijit

author
#3 lore raw
Quoted 9 lines · abhijit

basically i want some counter w/ microsend resolution that fits into 32 bits. couple of possible solutions come to my mind:

[1] use TSC and convert it to microsec
[2] use get_timeofday( ) and convert to microsec
[3] use xtime variable directly and convert to microsec (any other ways?)

Quoted 5 lines

conversion in [1] will be costly (a div involved). conversion in [2]/[3] can be done using bit operators. (usec|sec << 20) but [2] will incur function call overhead which i'd like to avoid.

so is using xtime directly ok and reliable?

ok. after reading up the source, i think xtime isn;t updated frequently and will not have the required resolution :( so calling do_gettimeofday() seems the only way out (unless somebody has any other idea).

btw why isn't do_gettimeofday( ) declared as "inline". so its bit cheaper to call
especially where you are timestamping (say packets) often.

thanks
abhijit