complete, tick-resolution gettimeofday() implementation

This commit is contained in:
Ben Gras 2005-07-06 07:08:36 +00:00
parent 493ab97a8d
commit f0817fbd4c
7 changed files with 54 additions and 8 deletions

View file

@ -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 */

View file

@ -3,16 +3,19 @@ gettimeofday.c
*/
#include <sys/time.h>
#include <lib.h>
#include <time.h>
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;
}

22
man/man2/gettimeofday.2 Normal file
View file

@ -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 <sys/time.h>
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).

View file

@ -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];

View file

@ -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) );

View file

@ -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];

View file

@ -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);
}