I usually use do_gettimeofday(struct timeval *tv) to get the current time 
in kernel space. 
It returns the time in struct timeval.
so it reports the time in microseconds, but the resolution depends on jiffies.
I think it can be used enoughly to measture the time in miliseconds.

In your code,

> static int start_time; /* Time in milli */
> 
> ...
> 
> int init_module(void)
> {
>   struct timespec tspec;
    -> struct timeval tspec

>   tspec = timespec_from_ns(gethrtime());
    -> do_gettimeofday(&tspec);
>   start_time = tspec.tv_sec*1000+tspec.tv_nsec/1000000;
     -> start_time = tspec.tv_sec*1000+tspec.tv_usec/1000;
> 
> /* 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;
    -> struct timeval tspec
> 
>   while(1)
>     {
>       tspec = timespec_from_ns(gethrtime());
    -> do_gettimeofday(&tspec);

>       i = tspec.tv_sec*1000+tspec.tv_nsec/1000000;
     -> i= tspec.tv_sec*1000+tspec.tv_usec/1000;
> 
>       i = i-start_time;
>       rtl_printf("Time= %d ms\n", (int)i);
>       pthread_wait_np();
>     }
> }
> 

----- Original Message ----- 
From: "Nicolas Hoffmann" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 08, 2000 6:11 PM
Subject: [rtl] 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
> 
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
> ---
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/rtlinux/
> 
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to