From: Ben Gras Date: Wed, 6 Jul 2005 07:08:36 +0000 (+0000) Subject: complete, tick-resolution gettimeofday() implementation X-Git-Tag: v3.1.0~645 X-Git-Url: http://zhaoyanbai.com/repos/doc/tz-art.htm?a=commitdiff_plain;h=f0817fbd4cccf30d43d63ab28c43f96a42d97dd6;p=minix.git complete, tick-resolution gettimeofday() implementation --- diff --git a/include/minix/callnr.h b/include/minix/callnr.h index bd75731d7..e3b10669a 100755 --- a/include/minix/callnr.h +++ b/include/minix/callnr.h @@ -1,4 +1,4 @@ -#define NCALLS 90 /* number of system calls allowed */ +#define NCALLS 91 /* number of system calls allowed */ #define EXIT 1 #define FORK 2 @@ -78,3 +78,4 @@ #define FSYNC 87 /* to FS */ #define GETPRIORITY 88 /* to PM */ #define SETPRIORITY 89 /* to PM */ +#define GETTIMEOFDAY 90 /* to PM */ diff --git a/lib/posix/gettimeofday.c b/lib/posix/gettimeofday.c index 6ec563604..f05ab5c86 100644 --- a/lib/posix/gettimeofday.c +++ b/lib/posix/gettimeofday.c @@ -3,16 +3,19 @@ gettimeofday.c */ #include +#include #include int gettimeofday(struct timeval *_RESTRICT tp, void *_RESTRICT tzp) { - if (time(&tp->tv_sec) == (time_t)-1) - return -1; - tp->tv_usec= 0; + message m; - /* tzp has to be a nul pointer according to the standard. Otherwise - * behavior is undefined. We can just ignore tzp. - */ - return 0; + if (_syscall(MM, GETTIMEOFDAY, &m) < 0) + return -1; + + tp->tv_sec = m.m2_l1; + tp->tv_usec = m.m2_l2; + + return 0; } + diff --git a/man/man2/gettimeofday.2 b/man/man2/gettimeofday.2 new file mode 100644 index 000000000..0100fb80b --- /dev/null +++ b/man/man2/gettimeofday.2 @@ -0,0 +1,22 @@ +.TH GETTIMEOFDAY 2 "July 6, 2005" +.UC 4 +.SH NAME +gettimeofday \- get date and time +.SH SYNOPSIS +.ft B +.nf +#include + +int gettimeofday(struct timeval *tp, struct timezone *tzp) +.fi +.ft R +.SH DESCRIPTION +.B Gettimeofday +returns the time in seconds and microseconds since epoch in GMT +(midnight, january 1st, 1970). The timezone argument tzp is expected +to be NULL. +.SH RETURNS +0 on success, -1 on error. If -1 is returned, errno is set to indicate +the error. +.SH "SEE ALSO +.BR ctime (3). diff --git a/servers/fs/table.c b/servers/fs/table.c index cc8bbbf4e..0a2909f4f 100644 --- a/servers/fs/table.c +++ b/servers/fs/table.c @@ -107,6 +107,7 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = { do_fsync, /* 87 = fsync */ no_sys, /* 88 = getpriority */ no_sys, /* 89 = setpriority */ + no_sys, /* 90 = gettimeofday */ }; /* This should not fail with "array size is negative": */ extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; diff --git a/servers/pm/proto.h b/servers/pm/proto.h index 108992b43..949a01828 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -86,6 +86,7 @@ _PROTOTYPE( void check_pending, (struct mproc *rmp) ); _PROTOTYPE( int do_stime, (void) ); _PROTOTYPE( int do_time, (void) ); _PROTOTYPE( int do_times, (void) ); +_PROTOTYPE( int do_gettimeofday, (void) ); /* trace.c */ _PROTOTYPE( int do_trace, (void) ); diff --git a/servers/pm/table.c b/servers/pm/table.c index 1768dd414..4f0ee23ef 100644 --- a/servers/pm/table.c +++ b/servers/pm/table.c @@ -106,6 +106,7 @@ _PROTOTYPE (int (*call_vec[NCALLS]), (void) ) = { no_sys, /* 87 = fsync */ do_getsetpriority, /* 88 = getpriority */ do_getsetpriority, /* 89 = setpriority */ + do_gettimeofday, /* 90 = gettimeofday */ }; /* This should not fail with "array size is negative": */ extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; diff --git a/servers/pm/time.c b/servers/pm/time.c index 9427de0f9..ae35c9dbb 100644 --- a/servers/pm/time.c +++ b/servers/pm/time.c @@ -84,3 +84,20 @@ PUBLIC int do_times() return(OK); } +/*===========================================================================* + * do_gettimeofday * + *===========================================================================*/ +PUBLIC int do_gettimeofday(void) +{ + clock_t uptime; + int s; + + if ( (s=sys_getuptime(&uptime)) != OK) + panic(__FILE__,"do_gettimeofday couldn't get uptime", s); + + mp->mp_reply.m2_l1 = boottime + uptime/HZ; + mp->mp_reply.m2_l2 = (uptime%HZ)*1000000/HZ; + + return(OK); +} +