getting timestamp in kernel

64 views
Skip to first unread message

paras...@sestrasystems.com

unread,
Jun 15, 2016, 7:50:30 PM6/15/16
to BeagleBoard
I am new to kernel programing and am trying to find a way to get a timestamp into some kernel code we had custom written for us.

it looks like the normal c library time.h has a get_clocktime() function, but this does not exists in the linux/time.h lib.

Is there a way to stamp my debug/info meassges from my kernel code with a time at millisecond resolution. The timestamp on the log file is buffered and thefore off.

Thanks

Dieter Wirz

unread,
Jun 16, 2016, 11:43:08 AM6/16/16
to beagl...@googlegroups.com
Hi
I am no Kernel Programmer;), however I guess what u are looking for
is: gettimeofday()
e.g.
#include <sys/time.h>
#include <stdio.h>
void main()
{
struct timeval tv;

gettimeofday(&tv, NULL);

unsigned long long millisecondsSinceEpoch =
(unsigned long long)(tv.tv_sec) * 1000 +
(unsigned long long)(tv.tv_usec) / 1000;

printf("ms since 1/1/1970: %llu\n", millisecondsSinceEpoch);
}

Hint: if you are searching for ANSI c hints in google, add ansi or cpp
or POSIX to your question, e.g.:
"gcc unix timestamp milliseconds"
HTH
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beagleboard...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beagleboard/aeaec6ce-e16c-41c4-8866-4415bc7d6c02%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages