[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Timer resolution
Hi,
I use RTL V2.0 with Linux kernel 2.2.13. I'm trying to get the time in
milliseconds from the start of my module. But where I expect to have time in
ms, it seams I have time in seconds !
I just make a little example.
In init-module, I initialize the time like this:
static int start_time; /* Time in milli */
...
int init_module(void)
{
struct timespec tspec;
tspec = timespec_from_ns(gethrtime());
start_time = tspec.tv_sec*1000+tspec.tv_nsec/1000000;
/* starts the thread */
...
}
And I use one periodic thread with a period of one second. Here is the code
of my thread (I just print the time in millisecond):
void thread_code(void *t)
{
int i;
struct timespec tspec;
while(1)
{
tspec = timespec_from_ns(gethrtime());
i = tspec.tv_sec*1000+tspec.tv_nsec/1000000;
i = i-start_time;
rtl_printf("Time= %d ms\n", (int)i);
pthread_wait_np();
}
}
As result, I have every second the time increased by one (sometimes by two)
instead of increased by 1000 as I expect !
What's wrong ?
Thanks.
Nioclas.
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com