projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
implement get_cpu_clock() for s390/s390x
[fio.git]
/
gettime.c
diff --git
a/gettime.c
b/gettime.c
index 248f14691a5b307c8ae17e4fc6b0111ae6e2c2ec..df329f66d3d5735b3225411315303f87b039c796 100644
(file)
--- a/
gettime.c
+++ b/
gettime.c
@@
-15,6
+15,7
@@
#ifdef ARCH_HAVE_CPU_CLOCK
static unsigned long cycles_per_usec;
#ifdef ARCH_HAVE_CPU_CLOCK
static unsigned long cycles_per_usec;
+static unsigned long inv_cycles_per_usec;
int tsc_reliable = 0;
#endif
int tsc_reliable = 0;
#endif
@@
-120,6
+121,15
@@
static void fio_init gtod_init(void)
#endif /* FIO_DEBUG_TIME */
#endif /* FIO_DEBUG_TIME */
+static int fill_clock_gettime(struct timespec *ts)
+{
+#ifdef FIO_HAVE_CLOCK_MONOTONIC
+ return clock_gettime(CLOCK_MONOTONIC, ts);
+#else
+ return clock_gettime(CLOCK_REALTIME, ts);
+#endif
+}
+
#ifdef FIO_DEBUG_TIME
void fio_gettime(struct timeval *tp, void *caller)
#else
#ifdef FIO_DEBUG_TIME
void fio_gettime(struct timeval *tp, void *caller)
#else
@@
-148,11
+158,7
@@
void fio_gettime(struct timeval *tp, void fio_unused *caller)
case CS_CGETTIME: {
struct timespec ts;
case CS_CGETTIME: {
struct timespec ts;
-#ifdef FIO_HAVE_CLOCK_MONOTONIC
- if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
-#else
- if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
-#endif
+ if (fill_clock_gettime(&ts) < 0) {
log_err("fio: clock_gettime fails\n");
assert(0);
}
log_err("fio: clock_gettime fails\n");
assert(0);
}
@@
-172,7
+178,7
@@
void fio_gettime(struct timeval *tp, void fio_unused *caller)
} else if (tv)
tv->last_cycles = t;
} else if (tv)
tv->last_cycles = t;
- usecs =
t / cycles_per_usec
;
+ usecs =
(t * inv_cycles_per_usec) / 16777216UL
;
tp->tv_sec = usecs / 1000000;
tp->tv_usec = usecs % 1000000;
break;
tp->tv_sec = usecs / 1000000;
tp->tv_usec = usecs % 1000000;
break;
@@
-203,15
+209,22
@@
void fio_gettime(struct timeval *tp, void fio_unused *caller)
#ifdef ARCH_HAVE_CPU_CLOCK
static unsigned long get_cycles_per_usec(void)
{
#ifdef ARCH_HAVE_CPU_CLOCK
static unsigned long get_cycles_per_usec(void)
{
+ struct timespec ts;
struct timeval s, e;
unsigned long long c_s, c_e;
struct timeval s, e;
unsigned long long c_s, c_e;
- gettimeofday(&s, NULL);
+ fill_clock_gettime(&ts);
+ s.tv_sec = ts.tv_sec;
+ s.tv_usec = ts.tv_nsec / 1000;
+
c_s = get_cpu_clock();
do {
unsigned long long elapsed;
c_s = get_cpu_clock();
do {
unsigned long long elapsed;
- gettimeofday(&e, NULL);
+ fill_clock_gettime(&ts);
+ e.tv_sec = ts.tv_sec;
+ e.tv_usec = ts.tv_nsec / 1000;
+
elapsed = utime_since(&s, &e);
if (elapsed >= 1280) {
c_e = get_cpu_clock();
elapsed = utime_since(&s, &e);
if (elapsed >= 1280) {
c_e = get_cpu_clock();
@@
-265,6
+278,8
@@
static void calibrate_cpu_clock(void)
dprint(FD_TIME, "mean=%f, S=%f\n", mean, S);
cycles_per_usec = avg;
dprint(FD_TIME, "mean=%f, S=%f\n", mean, S);
cycles_per_usec = avg;
+ inv_cycles_per_usec = 16777216UL / cycles_per_usec;
+ dprint(FD_TIME, "inv_cycles_per_usec=%lu\n", inv_cycles_per_usec);
}
#else
static void calibrate_cpu_clock(void)
}
#else
static void calibrate_cpu_clock(void)