From: Lionel Sambuc Date: Tue, 3 Dec 2013 10:51:21 +0000 (+0100) Subject: include/time.h: merged X-Git-Tag: v3.3.0~472 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-dsfromkey.html?a=commitdiff_plain;h=57476292b079e252087adf72ae75aa1866c44032;p=minix.git include/time.h: merged - Defining CLOCKS_PER_SEC = 100, instead of 60. This define is here for legacy reasons, use sysconf(_SC_CLK_TCK) to retrieve the actual number of clock tick per second of the system in new code. - Moving stime prototype to minix/sysutil.h Change-Id: I76a73cd53ac2361845f2917f62af4125adfc615d --- diff --git a/commands/time/time.c b/commands/time/time.c index b951312bf..3fb975c22 100644 --- a/commands/time/time.c +++ b/commands/time/time.c @@ -36,12 +36,8 @@ char *argv[]; int cycles = 0; struct tms pre_buf, post_buf; int status, pid; -#if _VMD_EXT - struct timeval start_time, end_time; -#else struct tms dummy; int start_time, end_time; -#endif u64_t start_tsc, end_tsc, spent_tsc; clock_t real_time; int c; @@ -66,11 +62,7 @@ char *argv[]; name = argv[0]; /* Get real time at start of run. */ -#if _VMD_EXT - (void) sysutime(UTIME_TIMEOFDAY, &start_time); -#else start_time = times(&dummy); -#endif read_tsc_64(&start_tsc); /* Fork off child. */ @@ -89,14 +81,8 @@ char *argv[]; } while (wait(&status) != pid); read_tsc_64(&end_tsc); spent_tsc = end_tsc - start_tsc; -#if _VMD_EXT - (void) sysutime(UTIME_TIMEOFDAY, &end_time); - real_time = (end_time.tv_sec - start_time.tv_sec) * CLOCKS_PER_SEC - + (end_time.tv_usec - start_time.tv_usec) * CLOCKS_PER_SEC / 1000000; -#else end_time = times(&dummy); real_time = (end_time - start_time); -#endif if ((status & 0377) != 0) std_err("Command terminated abnormally.\n"); times(&post_buf); diff --git a/drivers/vbox/vbox.c b/drivers/vbox/vbox.c index ac199cbd8..346c96eb1 100644 --- a/drivers/vbox/vbox.c +++ b/drivers/vbox/vbox.c @@ -4,6 +4,7 @@ * - synchronizing to the host system time; * - providing an interface for HGCM communication with the host system. */ +#include #include #include #include diff --git a/include/minix/sysutil.h b/include/minix/sysutil.h index dbf8e09b9..cc9eeebd1 100644 --- a/include/minix/sysutil.h +++ b/include/minix/sysutil.h @@ -73,6 +73,8 @@ void ser_putc(char c); void get_randomness(struct k_randomness *, int); u32_t sqrt_approx(u32_t); +int stime(time_t *_top); + #define asynsend(ep, msg) asynsend3(ep, msg, 0) int asynsend3(endpoint_t ep, message *msg, int flags); int asyn_geterror(endpoint_t *dst, message *msg, int *err); diff --git a/include/time.h b/include/time.h index ddffa5269..2aa5ce738 100644 --- a/include/time.h +++ b/include/time.h @@ -70,11 +70,7 @@ typedef _BSD_TIMER_T_ timer_t; #undef _BSD_TIMER_T_ #endif -#ifdef __minix -#define CLOCKS_PER_SEC 60 -#else #define CLOCKS_PER_SEC 100 -#endif struct tm { int tm_sec; /* seconds after the minute [0-61] */ @@ -210,10 +206,6 @@ size_t strftime_z(const timezone_t, char * __restrict, size_t, #endif /* _NETBSD_SOURCE */ -#ifdef __minix -int stime(time_t *_top); -#endif /* __minix */ - __END_DECLS #endif /* !_TIME_H_ */ diff --git a/test/t40f.c b/test/t40f.c index 6521468b4..697b94f1c 100644 --- a/test/t40f.c +++ b/test/t40f.c @@ -26,12 +26,14 @@ #define DO_TIMEOUT 7 #define DO_DELTA 0.5 #define MAX_ERROR 5 -#define DELTA(x,y) (x.tv_sec - y.tv_sec) * CLOCKS_PER_SEC \ - + (x.tv_usec - y.tv_usec) * CLOCKS_PER_SEC / 1000000 +#define DELTA(x,y) (x.tv_sec - y.tv_sec) * system_hz \ + + (x.tv_usec - y.tv_usec) * system_hz / 1000000 int got_signal = 0; int fd_ap[2]; +int system_hz; + static void catch_signal(int sig_no) { got_signal = 1; } @@ -43,8 +45,8 @@ static float compute_diff(struct timeval start, struct timeval end, float compar float diff; delta = DELTA(end, start); /* delta is in ticks */ - seconds = (int) (delta / CLOCKS_PER_SEC); - hundreths = (int) (delta * 100 / CLOCKS_PER_SEC) - (seconds * 100); + seconds = (int) (delta / system_hz); + hundreths = (int) (delta * 100 / system_hz) - (seconds * 100); diff = seconds + (hundreths / 100.0); diff -= compare; @@ -149,6 +151,8 @@ static void do_parent(int child) { int main(int argc, char **argv) { int forkres; + /* Retrieve actual system frequency. */ + system_hz = sysconf(_SC_CLK_TCK); /* Get subtest number */ if(argc != 2) { printf("Usage: %s subtest_no\n", argv[0]);