flat assembler
Message board for the users of flat assembler.

Index > Linux > Get clock time using syscall

Author
Thread Post new topic Reply to topic
emc



Joined: 20 Aug 2011
Posts: 90
Location: France
emc
Hello,

I am trying to get the clock time on Linux. I think I have to use the gettimeofday() syscall, but I don't understant very well this page: http://www.kernel.org/doc/man-pages/online/pages/man2/gettimeofday.2.html (seconds and microseconds, wtf).

I am not sure gettimeofday() is the more suitable syscall to do that I want to do. What do you think about that?

Have you any ideas, please?


Regards Wink

_________________
;; emc
Post 16 Nov 2011, 11:43
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
well its your best option for a high resolution timer, you may use RDTSC (pentium and later) if you have a stable CPU clock frequency though.
Post 16 Nov 2011, 17:15
View user's profile Send private message Visit poster's website Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
gettimeofday() returns the time in seconds and microseconds since the Epoch (1970-01-01 00:00:00 +0000 (UTC)). That's the only thing the kernel provides you. To compute some human readable format (year, month, day, etc.) is already your task. If you however like to use libc, then this is no problem. Here a C code example:
Code:
#include <stdio.h>
#include <time.h>
#include <sys/time.h>

int main(void)
{
    struct timeval tv;

    if(gettimeofday(&tv, (struct timezone*)NULL) == 0) {
        printf("%s", asctime(localtime(&tv.tv_sec)));
    }

    return 0;
}    
Post 19 Nov 2011, 21:52
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
though we're still off-topic with our C-codes on linux ;<
Post 25 Nov 2011, 01:37
View user's profile Send private message Visit poster's website Reply with quote
emc



Joined: 20 Aug 2011
Posts: 90
Location: France
emc
Thanks for replies.
We are not off-topic with our C codes, I want write my code in assembly, but thanks for the C code example, it's useful to get a better idea of the problem Wink
Post 25 Nov 2011, 16:41
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Matrix wrote:
well its your best option for a high resolution timer, you may use RDTSC (pentium and later) if you have a stable CPU clock frequency though.
Pleaase don't consider RDTSC a general-purpose high-frequency timer.

_________________
Image - carpe noctem
Post 26 Nov 2011, 16:08
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
f0dder wrote:
Matrix wrote:
well its your best option for a high resolution timer, you may use RDTSC (pentium and later) if you have a stable CPU clock frequency though.
Pleaase don't consider RDTSC a general-purpose high-frequency timer.


yeah, i have considered HRT...
Post 26 Nov 2011, 22:18
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.