Yes, hrtime_t is 64bit integer. There is no format
specifier in kernel. But in linux application we can
use %ll. So i wrote two functions to convert the
hrtime_t value to a string. These are as follows.
#include <linux/malloc.h>
/*
* ultostring converts an unsigned long integer to
string
* and lltostring converts a lon long integer number
to a
* string. Thse functions work for both user level
calls
* as well as kernel level calls. */
char *ultostring(unsigned long arg)
{
char *ret;
unsigned char *temp;
char hexchars[]="0123456789abcdef";
#ifdef __KERNEL__
ret = (char *)kmalloc(9,GFP_KERNEL);
#else
ret = (char *)malloc(9);
#endif /* __KERNEL__ */
temp = (char *)&arg;
ret[0] = hexchars[temp[3] >> 4];
ret[1] = hexchars[temp[3] % 16];
ret[2] = hexchars[temp[2] >> 4];
ret[3] = hexchars[temp[2] % 16];
ret[4] = hexchars[temp[1] >> 4];
ret[5] = hexchars[temp[1] % 16];
ret[6] = hexchars[temp[0] >> 4];
ret[7] = hexchars[temp[0] % 16];
ret[8]='\0';
return ret;
}
static char *lltostring(long long arg)
{
unsigned char *temp;
char *ret;
char hexchars[]="0123456789abcdef";
#ifdef __KERNEL__
ret = (char *)kmalloc(18,GFP_KERNEL);
#else
ret = (char *)malloc(18);
#endif /* __KERNEL__ */
temp=(char *)&arg;
ret[0] = hexchars[temp[7] >> 4];
ret[1] = hexchars[temp[7] % 16];
ret[2] = hexchars[temp[6] >> 4];
ret[3] = hexchars[temp[6] % 16];
ret[4] = hexchars[temp[5] >> 4];
ret[5] = hexchars[temp[5] % 16];
ret[6] = hexchars[temp[4] >> 4];
ret[7] = hexchars[temp[4] % 16];
ret[8] = hexchars[temp[3] >> 4];
ret[9] = hexchars[temp[3] % 16];
ret[10] = hexchars[temp[2] >> 4];
ret[11] = hexchars[temp[2] % 16];
ret[12] = hexchars[temp[1] >> 4];
ret[13] = hexchars[temp[1] % 16];
ret[14] = hexchars[temp[0] >> 4];
ret[15] = hexchars[temp[0] % 16];
ret[16] = '\0';
return ret;
}
I dont have any experience of using timer functions. I
will try findout solution. If i get i will mail u.
One more way, but may not suit for u is send date from
a linux task thro a fifo. and in handler u store it in
a global data structure. And u note down the gethrtime
return value and whenever u want again call gethrtime
and find the difference and add two ur stored data.
Regards
Venkat
--- Narendra Kumar Upadhyay
<[EMAIL PROTECTED]> wrote:
> Hi Venkat,
> Thanks for ur response for getting time and
> date, but yaar, the linux
> functions gettimeofday() and localtime() are not
> running in init_module().
> These functions can be used in main() function only,
> but i want a function
> which can be used in init_module also. Can u please
> write me a chunk of code
> in init_module(), which i could run directly.
> Also, the function gethrtime() returns value in
> hrtime_t variable, which
> a typedef of 64-bit signed integer. Do u know any
> format specifier in
> RTLinux which can print 64-bit integer value.
> actually it is only supporting
> "%d", which is printing a 4-byte value only.
>
> I am facing a lot of problem yaar. Please write me
> according to ur
> convinience.
>
> Regards,
> Narendra Kumar Upadhyay
> TATA Consultancy Services - GG2
>
> Ph. : 91- 0124- 6439120, 6439121
> Ext. : 122, 213
> ----- Original Message -----
> From: "A V" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, April 13, 2002 12:39 PM
> Subject: Re: [rtl] Current time and date in RTLinux
>
>
> >
> > one trickey way is
> >
> > U get date and time in init_module where u can
> access
> > linux system calls. and record time(nenoseconds)
> with
> > gethrtime() also there.
> > Then whereever u want date and time again read
> time
> > with gethrtime and calculate elapsed time from ur
> > program startup. Then convert these nanooseconds
> to
> > seconds and add it to time. The pseudo code look
> like
> > this. I hope it will work.
> >
> >
> > hrtime_t start_time;
> >
> > ur_real_time_thread()
> > {
> > hrtime_t current_time;
> > hrimte_t elapsed_time;
> > current_time = gethrtime();
> > elapsed_time = current_time-start_time;
> > convert elapsed time to seconds
> > add these seconds to ur actual date and time
> > recorded in init_module.
> > }
> >
> > init_module()
> > {
> > get date and time with linux syscalls;
> > start_time = gethrtime();
> > }
> >
> > --- Norm Dresner <[EMAIL PROTECTED]> wrote:
> > > Have you tried
> > > do_gettimeofday()
> > >
> > > Norm
> > > ----- Original Message -----
> > > From: Narendra Kumar Upadhyay
> > > To: [EMAIL PROTECTED]
> > > Cc: [EMAIL PROTECTED]
> > > Sent: Friday, April 12, 2002 8:07 AM
> > > Subject: [rtl] Current time and date in
> RTLinux
> > >
> > >
> > > Hi,
> > > Is there any method to calculate the current
> > > time(in hours, minutes and seconds) and date in
> the
> > > kernel module of RTLinux. Actually
> gettimeofday()
> > > and localtime() functions are giving correct
> time
> > > but we can execute these functions in linux
> only. I
> > > want to get time and date during execution of
> the
> > > real-time thread. gethrtime( ) function gives
> time
> > > from system bootup, which can not solve my
> purpose.
> > >
> > > Any idea to get the current time and date
> in
> > > kernel module???
> > >
> > >
> > > Regards,
> > > Narendra Kumar Upadhyay
> > >
> > > Ph. : 91- 0124- 6439120, 6439121
> > > Ext. : 122, 213
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Tax Center - online filing with TurboTax
> > http://taxes.yahoo.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/
> >
>
> -- [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/
>
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.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/