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
This commit is contained in:
parent
f7cf297602
commit
57476292b0
5 changed files with 11 additions and 26 deletions
|
@ -36,12 +36,8 @@ char *argv[];
|
||||||
int cycles = 0;
|
int cycles = 0;
|
||||||
struct tms pre_buf, post_buf;
|
struct tms pre_buf, post_buf;
|
||||||
int status, pid;
|
int status, pid;
|
||||||
#if _VMD_EXT
|
|
||||||
struct timeval start_time, end_time;
|
|
||||||
#else
|
|
||||||
struct tms dummy;
|
struct tms dummy;
|
||||||
int start_time, end_time;
|
int start_time, end_time;
|
||||||
#endif
|
|
||||||
u64_t start_tsc, end_tsc, spent_tsc;
|
u64_t start_tsc, end_tsc, spent_tsc;
|
||||||
clock_t real_time;
|
clock_t real_time;
|
||||||
int c;
|
int c;
|
||||||
|
@ -66,11 +62,7 @@ char *argv[];
|
||||||
name = argv[0];
|
name = argv[0];
|
||||||
|
|
||||||
/* Get real time at start of run. */
|
/* Get real time at start of run. */
|
||||||
#if _VMD_EXT
|
|
||||||
(void) sysutime(UTIME_TIMEOFDAY, &start_time);
|
|
||||||
#else
|
|
||||||
start_time = times(&dummy);
|
start_time = times(&dummy);
|
||||||
#endif
|
|
||||||
read_tsc_64(&start_tsc);
|
read_tsc_64(&start_tsc);
|
||||||
|
|
||||||
/* Fork off child. */
|
/* Fork off child. */
|
||||||
|
@ -89,14 +81,8 @@ char *argv[];
|
||||||
} while (wait(&status) != pid);
|
} while (wait(&status) != pid);
|
||||||
read_tsc_64(&end_tsc);
|
read_tsc_64(&end_tsc);
|
||||||
spent_tsc = end_tsc - start_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);
|
end_time = times(&dummy);
|
||||||
real_time = (end_time - start_time);
|
real_time = (end_time - start_time);
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((status & 0377) != 0) std_err("Command terminated abnormally.\n");
|
if ((status & 0377) != 0) std_err("Command terminated abnormally.\n");
|
||||||
times(&post_buf);
|
times(&post_buf);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* - synchronizing to the host system time;
|
* - synchronizing to the host system time;
|
||||||
* - providing an interface for HGCM communication with the host system.
|
* - providing an interface for HGCM communication with the host system.
|
||||||
*/
|
*/
|
||||||
|
#include <minix/sysutil.h>
|
||||||
#include <minix/drivers.h>
|
#include <minix/drivers.h>
|
||||||
#include <minix/driver.h>
|
#include <minix/driver.h>
|
||||||
#include <minix/optset.h>
|
#include <minix/optset.h>
|
||||||
|
|
|
@ -73,6 +73,8 @@ void ser_putc(char c);
|
||||||
void get_randomness(struct k_randomness *, int);
|
void get_randomness(struct k_randomness *, int);
|
||||||
u32_t sqrt_approx(u32_t);
|
u32_t sqrt_approx(u32_t);
|
||||||
|
|
||||||
|
int stime(time_t *_top);
|
||||||
|
|
||||||
#define asynsend(ep, msg) asynsend3(ep, msg, 0)
|
#define asynsend(ep, msg) asynsend3(ep, msg, 0)
|
||||||
int asynsend3(endpoint_t ep, message *msg, int flags);
|
int asynsend3(endpoint_t ep, message *msg, int flags);
|
||||||
int asyn_geterror(endpoint_t *dst, message *msg, int *err);
|
int asyn_geterror(endpoint_t *dst, message *msg, int *err);
|
||||||
|
|
|
@ -70,11 +70,7 @@ typedef _BSD_TIMER_T_ timer_t;
|
||||||
#undef _BSD_TIMER_T_
|
#undef _BSD_TIMER_T_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __minix
|
|
||||||
#define CLOCKS_PER_SEC 60
|
|
||||||
#else
|
|
||||||
#define CLOCKS_PER_SEC 100
|
#define CLOCKS_PER_SEC 100
|
||||||
#endif
|
|
||||||
|
|
||||||
struct tm {
|
struct tm {
|
||||||
int tm_sec; /* seconds after the minute [0-61] */
|
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 */
|
#endif /* _NETBSD_SOURCE */
|
||||||
|
|
||||||
#ifdef __minix
|
|
||||||
int stime(time_t *_top);
|
|
||||||
#endif /* __minix */
|
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif /* !_TIME_H_ */
|
#endif /* !_TIME_H_ */
|
||||||
|
|
12
test/t40f.c
12
test/t40f.c
|
@ -26,12 +26,14 @@
|
||||||
#define DO_TIMEOUT 7
|
#define DO_TIMEOUT 7
|
||||||
#define DO_DELTA 0.5
|
#define DO_DELTA 0.5
|
||||||
#define MAX_ERROR 5
|
#define MAX_ERROR 5
|
||||||
#define DELTA(x,y) (x.tv_sec - y.tv_sec) * CLOCKS_PER_SEC \
|
#define DELTA(x,y) (x.tv_sec - y.tv_sec) * system_hz \
|
||||||
+ (x.tv_usec - y.tv_usec) * CLOCKS_PER_SEC / 1000000
|
+ (x.tv_usec - y.tv_usec) * system_hz / 1000000
|
||||||
|
|
||||||
int got_signal = 0;
|
int got_signal = 0;
|
||||||
int fd_ap[2];
|
int fd_ap[2];
|
||||||
|
|
||||||
|
int system_hz;
|
||||||
|
|
||||||
static void catch_signal(int sig_no) {
|
static void catch_signal(int sig_no) {
|
||||||
got_signal = 1;
|
got_signal = 1;
|
||||||
}
|
}
|
||||||
|
@ -43,8 +45,8 @@ static float compute_diff(struct timeval start, struct timeval end, float compar
|
||||||
float diff;
|
float diff;
|
||||||
|
|
||||||
delta = DELTA(end, start); /* delta is in ticks */
|
delta = DELTA(end, start); /* delta is in ticks */
|
||||||
seconds = (int) (delta / CLOCKS_PER_SEC);
|
seconds = (int) (delta / system_hz);
|
||||||
hundreths = (int) (delta * 100 / CLOCKS_PER_SEC) - (seconds * 100);
|
hundreths = (int) (delta * 100 / system_hz) - (seconds * 100);
|
||||||
|
|
||||||
diff = seconds + (hundreths / 100.0);
|
diff = seconds + (hundreths / 100.0);
|
||||||
diff -= compare;
|
diff -= compare;
|
||||||
|
@ -149,6 +151,8 @@ static void do_parent(int child) {
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int forkres;
|
int forkres;
|
||||||
|
|
||||||
|
/* Retrieve actual system frequency. */
|
||||||
|
system_hz = sysconf(_SC_CLK_TCK);
|
||||||
/* Get subtest number */
|
/* Get subtest number */
|
||||||
if(argc != 2) {
|
if(argc != 2) {
|
||||||
printf("Usage: %s subtest_no\n", argv[0]);
|
printf("Usage: %s subtest_no\n", argv[0]);
|
||||||
|
|
Loading…
Reference in a new issue