summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-07-24 20:02:07 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2019-07-24 21:59:26 +0300
commit10ee1b95b80ef1dc2fd3142e04f6031cc8be9e9d (patch)
treebe046f8641f09bbf7ac413c8184883ff969a3d28
parente764d5bc012beacc1ed26c9022829423829b621d (diff)
downloadmariadb-git-10ee1b95b80ef1dc2fd3142e04f6031cc8be9e9d.tar.gz
Remove ut_usectime(), ut_gettimeofday()
Replace ut_usectime() with my_interval_timer(), which is equivalent, but monotonically counting nanoseconds instead of counting the microseconds of real time. os_event_wait_time_low(): Use my_hrtime() instead of ut_usectime(). FIXME: Set a clock attribute on the condition variable that allows a monotonic clock to be chosen as the time base, so that the wait is immune to adjustments of the system clock.
-rw-r--r--storage/innobase/include/ut0ut.h13
-rw-r--r--storage/innobase/lock/lock0wait.cc46
-rw-r--r--storage/innobase/os/os0sync.cc26
-rw-r--r--storage/innobase/ut/ut0ut.cc96
-rw-r--r--storage/xtradb/buf/buf0buf.cc51
-rw-r--r--storage/xtradb/handler/ha_innodb.cc8
-rw-r--r--storage/xtradb/include/trx0trx.h2
-rw-r--r--storage/xtradb/include/ut0ut.h22
-rw-r--r--storage/xtradb/lock/lock0lock.cc10
-rw-r--r--storage/xtradb/lock/lock0wait.cc46
-rw-r--r--storage/xtradb/os/os0file.cc26
-rw-r--r--storage/xtradb/os/os0sync.cc26
-rw-r--r--storage/xtradb/que/que0que.cc10
-rw-r--r--storage/xtradb/srv/srv0conc.cc16
-rw-r--r--storage/xtradb/trx/trx0trx.cc14
-rw-r--r--storage/xtradb/ut/ut0ut.cc119
16 files changed, 74 insertions, 457 deletions
diff --git a/storage/innobase/include/ut0ut.h b/storage/innobase/include/ut0ut.h
index 42b70ae53f2..675cca9afd2 100644
--- a/storage/innobase/include/ut0ut.h
+++ b/storage/innobase/include/ut0ut.h
@@ -245,19 +245,6 @@ ut_time(void);
/*=========*/
#ifndef UNIV_HOTBACKUP
/**********************************************************//**
-Returns system time.
-Upon successful completion, the value 0 is returned; otherwise the
-value -1 is returned and the global variable errno is set to indicate the
-error.
-@return 0 on success, -1 otherwise */
-UNIV_INTERN
-int
-ut_usectime(
-/*========*/
- ulint* sec, /*!< out: seconds since the Epoch */
- ulint* ms); /*!< out: microseconds since the Epoch+*sec */
-
-/**********************************************************//**
Returns the number of milliseconds since some epoch. The
value may wrap around. It should only be used for heuristic
purposes.
diff --git a/storage/innobase/lock/lock0wait.cc b/storage/innobase/lock/lock0wait.cc
index 218c27ed121..5d6db2f171a 100644
--- a/storage/innobase/lock/lock0wait.cc
+++ b/storage/innobase/lock/lock0wait.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2014, 2017, MariaDB Corporation.
+Copyright (c) 2014, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -230,10 +230,6 @@ lock_wait_suspend_thread(
trx_t* trx;
ulint had_dict_lock;
ibool was_declared_inside_innodb;
- ib_int64_t start_time = 0;
- ib_int64_t finish_time;
- ulint sec;
- ulint ms;
ulong lock_wait_timeout;
trx = thr_get_trx(thr);
@@ -279,15 +275,12 @@ lock_wait_suspend_thread(
lock_wait_mutex_exit();
trx_mutex_exit(trx);
+ ulonglong start_time = 0;
+
if (thr->lock_state == QUE_THR_LOCK_ROW) {
srv_stats.n_lock_wait_count.inc();
srv_stats.n_lock_wait_current_count.inc();
-
- if (ut_usectime(&sec, &ms) == -1) {
- start_time = -1;
- } else {
- start_time = (ib_int64_t) sec * 1000000 + ms;
- }
+ start_time = my_interval_timer();
}
ulint lock_type = ULINT_UNDEFINED;
@@ -374,32 +367,25 @@ lock_wait_suspend_thread(
lock_wait_table_release_slot(slot);
if (thr->lock_state == QUE_THR_LOCK_ROW) {
- ulint diff_time;
-
- if (ut_usectime(&sec, &ms) == -1) {
- finish_time = -1;
- } else {
- finish_time = (ib_int64_t) sec * 1000000 + ms;
- }
-
- diff_time = (finish_time > start_time) ?
- (ulint) (finish_time - start_time) : 0;
-
srv_stats.n_lock_wait_current_count.dec();
- srv_stats.n_lock_wait_time.add(diff_time);
- /* Only update the variable if we successfully
- retrieved the start and finish times. See Bug#36819. */
- if (diff_time > lock_sys->n_lock_max_wait_time
- && start_time != -1
- && finish_time != -1) {
+ const ulonglong finish_time = my_interval_timer();
+ ulint diff_time;
- lock_sys->n_lock_max_wait_time = diff_time;
+ if (finish_time < start_time) {
+ diff_time = 0;
+ } else {
+ diff_time = ulint((finish_time - start_time) / 1000);
+ srv_stats.n_lock_wait_time.add(diff_time);
+ /* Only update the variable if we successfully
+ retrieved the start and finish times. See Bug#36819. */
+ if (diff_time > lock_sys->n_lock_max_wait_time) {
+ lock_sys->n_lock_max_wait_time = diff_time;
+ }
}
/* Record the lock wait time for this thread */
thd_set_lock_wait_time(trx->mysql_thd, diff_time);
-
}
if (lock_wait_timeout < 100000000
diff --git a/storage/innobase/os/os0sync.cc b/storage/innobase/os/os0sync.cc
index 0fd2935a2ae..fadc9e877ba 100644
--- a/storage/innobase/os/os0sync.cc
+++ b/storage/innobase/os/os0sync.cc
@@ -72,9 +72,6 @@ UNIV_INTERN ulint os_event_count = 0;
UNIV_INTERN ulint os_mutex_count = 0;
UNIV_INTERN ulint os_fast_mutex_count = 0;
-/* The number of microsecnds in a second. */
-static const ulint MICROSECS_IN_A_SECOND = 1000000;
-
#ifdef UNIV_PFS_MUTEX
UNIV_INTERN mysql_pfs_key_t event_os_mutex_key;
UNIV_INTERN mysql_pfs_key_t os_mutex_key;
@@ -654,26 +651,9 @@ os_event_wait_time_low(
struct timespec abstime;
if (time_in_usec != OS_SYNC_INFINITE_TIME) {
- struct timeval tv;
- int ret;
- ulint sec;
- ulint usec;
-
- ret = ut_usectime(&sec, &usec);
- ut_a(ret == 0);
-
- tv.tv_sec = sec;
- tv.tv_usec = usec;
-
- tv.tv_usec += time_in_usec;
-
- if ((ulint) tv.tv_usec >= MICROSECS_IN_A_SECOND) {
- tv.tv_sec += tv.tv_usec / MICROSECS_IN_A_SECOND;
- tv.tv_usec %= MICROSECS_IN_A_SECOND;
- }
-
- abstime.tv_sec = tv.tv_sec;
- abstime.tv_nsec = tv.tv_usec * 1000;
+ ulonglong usec = ulonglong(time_in_usec) + my_hrtime().val;
+ abstime.tv_sec = usec / 1000000;
+ abstime.tv_nsec = (usec % 1000000) * 1000;
} else {
abstime.tv_nsec = 999999999;
abstime.tv_sec = (time_t) ULINT_MAX;
diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc
index 775d79de6ac..95a7957579e 100644
--- a/storage/innobase/ut/ut0ut.cc
+++ b/storage/innobase/ut/ut0ut.cc
@@ -46,60 +46,6 @@ Created 5/11/1994 Heikki Tuuri
# include <string>
#endif /* UNIV_HOTBACKUP */
-#ifdef __WIN__
-typedef VOID(WINAPI *time_fn)(LPFILETIME);
-static time_fn ut_get_system_time_as_file_time = GetSystemTimeAsFileTime;
-
-/*****************************************************************//**
-NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix
-epoch starts from 1970/1/1. For selection of constant see:
-http://support.microsoft.com/kb/167296/ */
-#define WIN_TO_UNIX_DELTA_USEC ((ib_int64_t) 11644473600000000ULL)
-
-
-/*****************************************************************//**
-This is the Windows version of gettimeofday(2).
-@return 0 if all OK else -1 */
-static
-int
-ut_gettimeofday(
-/*============*/
- struct timeval* tv, /*!< out: Values are relative to Unix epoch */
- void* tz) /*!< in: not used */
-{
- FILETIME ft;
- ib_int64_t tm;
-
- if (!tv) {
- errno = EINVAL;
- return(-1);
- }
-
- ut_get_system_time_as_file_time(&ft);
-
- tm = (ib_int64_t) ft.dwHighDateTime << 32;
- tm |= ft.dwLowDateTime;
-
- ut_a(tm >= 0); /* If tm wraps over to negative, the quotient / 10
- does not work */
-
- tm /= 10; /* Convert from 100 nsec periods to usec */
-
- /* If we don't convert to the Unix epoch the value for
- struct timeval::tv_sec will overflow.*/
- tm -= WIN_TO_UNIX_DELTA_USEC;
-
- tv->tv_sec = (long) (tm / 1000000L);
- tv->tv_usec = (long) (tm % 1000000L);
-
- return(0);
-}
-#else
-/** An alias for gettimeofday(2). On Microsoft Windows, we have to
-reimplement this function. */
-#define ut_gettimeofday gettimeofday
-#endif
-
/**********************************************************//**
Returns system time. We do not specify the format of the time returned:
the only way to manipulate it is to use the function ut_difftime.
@@ -114,48 +60,6 @@ ut_time(void)
#ifndef UNIV_HOTBACKUP
/**********************************************************//**
-Returns system time.
-Upon successful completion, the value 0 is returned; otherwise the
-value -1 is returned and the global variable errno is set to indicate the
-error.
-@return 0 on success, -1 otherwise */
-UNIV_INTERN
-int
-ut_usectime(
-/*========*/
- ulint* sec, /*!< out: seconds since the Epoch */
- ulint* ms) /*!< out: microseconds since the Epoch+*sec */
-{
- struct timeval tv;
- int ret;
- int errno_gettimeofday;
- int i;
-
- for (i = 0; i < 10; i++) {
-
- ret = ut_gettimeofday(&tv, NULL);
-
- if (ret == -1) {
- errno_gettimeofday = errno;
- ut_print_timestamp(stderr);
- fprintf(stderr, " InnoDB: gettimeofday(): %s\n",
- strerror(errno_gettimeofday));
- os_thread_sleep(100000); /* 0.1 sec */
- errno = errno_gettimeofday;
- } else {
- break;
- }
- }
-
- if (ret != -1) {
- *sec = (ulint) tv.tv_sec;
- *ms = (ulint) tv.tv_usec;
- }
-
- return(ret);
-}
-
-/**********************************************************//**
Returns the number of milliseconds since some epoch. The
value may wrap around. It should only be used for heuristic
purposes.
diff --git a/storage/xtradb/buf/buf0buf.cc b/storage/xtradb/buf/buf0buf.cc
index 3326f734e45..0f83e7ce011 100644
--- a/storage/xtradb/buf/buf0buf.cc
+++ b/storage/xtradb/buf/buf0buf.cc
@@ -2485,10 +2485,6 @@ buf_page_get_zip(
ibool discard_attempted = FALSE;
ibool must_read;
trx_t* trx = NULL;
- ulint sec;
- ulint ms;
- ib_uint64_t start_time;
- ib_uint64_t finish_time;
buf_pool_t* buf_pool = buf_pool_get(space, offset);
if (UNIV_UNLIKELY(innobase_get_slow_log())) {
@@ -2607,14 +2603,10 @@ got_block:
if (must_read) {
/* Let us wait until the read operation
completes */
-
- if (UNIV_UNLIKELY(trx && trx->take_stats))
- {
- ut_usectime(&sec, &ms);
- start_time = (ib_uint64_t)sec * 1000000 + ms;
- } else {
- start_time = 0;
- }
+ const ulonglong start_time = UNIV_UNLIKELY(trx
+ && trx->take_stats)
+ ? my_interval_timer()
+ : 0;
for (;;) {
enum buf_io_fix io_fix;
@@ -2629,11 +2621,9 @@ got_block:
break;
}
}
- if (UNIV_UNLIKELY(start_time != 0))
- {
- ut_usectime(&sec, &ms);
- finish_time = (ib_uint64_t)sec * 1000000 + ms;
- trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
+ if (UNIV_UNLIKELY(start_time != 0)) {
+ trx->io_reads_wait_timer += ulint(
+ (my_interval_timer() - start_time) / 1000);
}
}
@@ -3013,21 +3003,13 @@ buf_wait_for_read(buf_block_t* block, trx_t* trx)
if (buf_block_get_io_fix_unlocked(block) == BUF_IO_READ) {
- ib_uint64_t start_time;
- ulint sec;
- ulint ms;
-
/* Wait until the read operation completes */
ib_mutex_t* mutex = buf_page_get_mutex(&block->page);
-
- if (UNIV_UNLIKELY(trx && trx->take_stats))
- {
- ut_usectime(&sec, &ms);
- start_time = (ib_uint64_t)sec * 1000000 + ms;
- } else {
- start_time = 0;
- }
+ const ulonglong start_time = UNIV_UNLIKELY(trx
+ && trx->take_stats)
+ ? my_interval_timer()
+ : 0;
for (;;) {
buf_io_fix io_fix;
@@ -3047,15 +3029,10 @@ buf_wait_for_read(buf_block_t* block, trx_t* trx)
}
}
- if (UNIV_UNLIKELY(start_time != 0))
- {
- ut_usectime(&sec, &ms);
- ib_uint64_t finish_time
- = (ib_uint64_t)sec * 1000000 + ms;
- trx->io_reads_wait_timer
- += (ulint)(finish_time - start_time);
+ if (UNIV_UNLIKELY(start_time != 0)) {
+ trx->io_reads_wait_timer += ulint(
+ (my_interval_timer() - start_time) / 1000);
}
-
}
}
diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc
index 2a0f1d5535b..4a39a0a9c4d 100644
--- a/storage/xtradb/handler/ha_innodb.cc
+++ b/storage/xtradb/handler/ha_innodb.cc
@@ -4577,14 +4577,6 @@ innobase_change_buffering_inited_ok:
/* Turn on monitor counters that are default on */
srv_mon_default_on();
-#ifndef UNIV_HOTBACKUP
-#ifdef _WIN32
- if (ut_win_init_time()) {
- goto mem_free_and_error;
- }
-#endif /* _WIN32 */
-#endif /* !UNIV_HOTBACKUP */
-
DBUG_RETURN(FALSE);
error:
DBUG_RETURN(TRUE);
diff --git a/storage/xtradb/include/trx0trx.h b/storage/xtradb/include/trx0trx.h
index 4b9662ada1e..f355ef4fcf4 100644
--- a/storage/xtradb/include/trx0trx.h
+++ b/storage/xtradb/include/trx0trx.h
@@ -1102,7 +1102,7 @@ struct trx_t{
ulint io_reads;
ib_uint64_t io_read;
ulint io_reads_wait_timer;
- ib_uint64_t lock_que_wait_ustarted;
+ ulonglong lock_que_wait_nstarted;
ulint lock_que_wait_timer;
ulint innodb_que_wait_timer;
ulint distinct_page_access;
diff --git a/storage/xtradb/include/ut0ut.h b/storage/xtradb/include/ut0ut.h
index c5168acf3b2..db05fd7ce13 100644
--- a/storage/xtradb/include/ut0ut.h
+++ b/storage/xtradb/include/ut0ut.h
@@ -237,19 +237,6 @@ ut_time(void);
/*=========*/
#ifndef UNIV_HOTBACKUP
/**********************************************************//**
-Returns system time.
-Upon successful completion, the value 0 is returned; otherwise the
-value -1 is returned and the global variable errno is set to indicate the
-error.
-@return 0 on success, -1 otherwise */
-UNIV_INTERN
-int
-ut_usectime(
-/*========*/
- ulint* sec, /*!< out: seconds since the Epoch */
- ulint* ms); /*!< out: microseconds since the Epoch+*sec */
-
-/**********************************************************//**
Returns the number of milliseconds since some epoch. The
value may wrap around. It should only be used for heuristic
purposes.
@@ -258,15 +245,6 @@ UNIV_INTERN
ulint
ut_time_ms(void);
/*============*/
-#ifdef _WIN32
-/**********************************************************//**
-Initialise highest available time resolution API on Windows
-@return 0 if all OK else -1 */
-int
-ut_win_init_time();
-
-#endif /* _WIN32 */
-
#endif /* !UNIV_HOTBACKUP */
/**********************************************************//**
diff --git a/storage/xtradb/lock/lock0lock.cc b/storage/xtradb/lock/lock0lock.cc
index 41fda2df0d8..27a857b26a8 100644
--- a/storage/xtradb/lock/lock0lock.cc
+++ b/storage/xtradb/lock/lock0lock.cc
@@ -2448,8 +2448,6 @@ lock_rec_enqueue_waiting(
trx_t* trx;
lock_t* lock;
trx_id_t victim_trx_id;
- ulint sec;
- ulint ms;
ulint space;
ulint page_no;
dberr_t err;
@@ -2535,8 +2533,7 @@ lock_rec_enqueue_waiting(
trx->lock.wait_started = ut_time();
if (UNIV_UNLIKELY(trx->take_stats)) {
- ut_usectime(&sec, &ms);
- trx->lock_que_wait_ustarted = (ib_uint64_t)sec * 1000000 + ms;
+ trx->lock_que_wait_nstarted = my_interval_timer();
}
ut_a(que_thr_stop(thr));
@@ -5205,8 +5202,6 @@ lock_table_enqueue_waiting(
trx_t* trx;
lock_t* lock;
trx_id_t victim_trx_id;
- ulint sec;
- ulint ms;
ut_ad(lock_mutex_own());
ut_ad(!srv_read_only_mode);
@@ -5290,8 +5285,7 @@ lock_table_enqueue_waiting(
trx->n_table_lock_waits++;
if (UNIV_UNLIKELY(trx->take_stats)) {
- ut_usectime(&sec, &ms);
- trx->lock_que_wait_ustarted = (ib_uint64_t)sec * 1000000 + ms;
+ trx->lock_que_wait_nstarted = my_interval_timer();
}
ut_a(que_thr_stop(thr));
diff --git a/storage/xtradb/lock/lock0wait.cc b/storage/xtradb/lock/lock0wait.cc
index c65b127f339..e9ef6d9d605 100644
--- a/storage/xtradb/lock/lock0wait.cc
+++ b/storage/xtradb/lock/lock0wait.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2014, 2017, MariaDB Corporation.
+Copyright (c) 2014, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -284,10 +284,6 @@ lock_wait_suspend_thread(
trx_t* trx;
ulint had_dict_lock;
ibool was_declared_inside_innodb;
- ib_int64_t start_time = 0;
- ib_int64_t finish_time;
- ulint sec;
- ulint ms;
ulong lock_wait_timeout;
blocking_trx_info blocking[MAX_BLOCKING_TRX_IN_REPORT];
size_t blocking_count = 0;
@@ -335,15 +331,12 @@ lock_wait_suspend_thread(
lock_wait_mutex_exit();
trx_mutex_exit(trx);
+ ulonglong start_time = 0;
+
if (thr->lock_state == QUE_THR_LOCK_ROW) {
srv_stats.n_lock_wait_count.inc();
srv_stats.n_lock_wait_current_count.inc();
-
- if (ut_usectime(&sec, &ms) == -1) {
- start_time = -1;
- } else {
- start_time = (ib_int64_t) sec * 1000000 + ms;
- }
+ start_time = my_interval_timer();
}
ulint lock_type = ULINT_UNDEFINED;
@@ -430,32 +423,25 @@ lock_wait_suspend_thread(
lock_wait_table_release_slot(slot);
if (thr->lock_state == QUE_THR_LOCK_ROW) {
- ulint diff_time;
-
- if (ut_usectime(&sec, &ms) == -1) {
- finish_time = -1;
- } else {
- finish_time = (ib_int64_t) sec * 1000000 + ms;
- }
-
- diff_time = (finish_time > start_time) ?
- (ulint) (finish_time - start_time) : 0;
-
srv_stats.n_lock_wait_current_count.dec();
- srv_stats.n_lock_wait_time.add(diff_time);
- /* Only update the variable if we successfully
- retrieved the start and finish times. See Bug#36819. */
- if (diff_time > lock_sys->n_lock_max_wait_time
- && start_time != -1
- && finish_time != -1) {
+ const ulonglong finish_time = my_interval_timer();
+ ulint diff_time;
- lock_sys->n_lock_max_wait_time = diff_time;
+ if (finish_time < start_time) {
+ diff_time = 0;
+ } else {
+ diff_time = ulint((finish_time - start_time) / 1000);
+ srv_stats.n_lock_wait_time.add(diff_time);
+ /* Only update the variable if we successfully
+ retrieved the start and finish times. See Bug#36819. */
+ if (diff_time > lock_sys->n_lock_max_wait_time) {
+ lock_sys->n_lock_max_wait_time = diff_time;
+ }
}
/* Record the lock wait time for this thread */
thd_set_lock_wait_time(trx->mysql_thd, diff_time);
-
}
if (lock_wait_timeout < 100000000
diff --git a/storage/xtradb/os/os0file.cc b/storage/xtradb/os/os0file.cc
index da5e8927320..0cd5aff4e94 100644
--- a/storage/xtradb/os/os0file.cc
+++ b/storage/xtradb/os/os0file.cc
@@ -2968,10 +2968,6 @@ os_file_pread(
trx_t* trx)
{
off_t offs;
- ulint sec;
- ulint ms;
- ib_uint64_t start_time;
- ib_uint64_t finish_time;
ut_ad(n);
@@ -2988,15 +2984,9 @@ os_file_pread(
os_n_file_reads++;
- if (UNIV_UNLIKELY(trx && trx->take_stats))
- {
- trx->io_reads++;
- trx->io_read += n;
- ut_usectime(&sec, &ms);
- start_time = (ib_uint64_t)sec * 1000000 + ms;
- } else {
- start_time = 0;
- }
+ const ulonglong start_time = UNIV_UNLIKELY(trx && trx->take_stats)
+ ? my_interval_timer()
+ : 0;
const bool monitor = MONITOR_IS_ON(MONITOR_OS_PENDING_READS);
#ifdef HAVE_PREAD
@@ -3022,9 +3012,8 @@ os_file_pread(
if (UNIV_UNLIKELY(start_time != 0))
{
- ut_usectime(&sec, &ms);
- finish_time = (ib_uint64_t)sec * 1000000 + ms;
- trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
+ trx->io_reads_wait_timer += ulint((my_interval_timer()
+ - start_time) / 1000);
}
return(n_bytes);
@@ -3071,9 +3060,8 @@ os_file_pread(
if (UNIV_UNLIKELY(start_time != 0)
{
- ut_usectime(&sec, &ms);
- finish_time = (ib_uint64_t)sec * 1000000 + ms;
- trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
+ trx->io_reads_wait_timer += ulint(
+ (my_interval_timer() - start_time) / 1000);
}
return(ret);
diff --git a/storage/xtradb/os/os0sync.cc b/storage/xtradb/os/os0sync.cc
index e8597554170..e409529f132 100644
--- a/storage/xtradb/os/os0sync.cc
+++ b/storage/xtradb/os/os0sync.cc
@@ -59,9 +59,6 @@ UNIV_INTERN ulint os_event_count = 0;
UNIV_INTERN ulint os_mutex_count = 0;
UNIV_INTERN ulint os_fast_mutex_count = 0;
-/* The number of microsecnds in a second. */
-static const ulint MICROSECS_IN_A_SECOND = 1000000;
-
#ifdef UNIV_PFS_MUTEX
UNIV_INTERN mysql_pfs_key_t event_os_mutex_key;
UNIV_INTERN mysql_pfs_key_t os_mutex_key;
@@ -539,26 +536,9 @@ os_event_wait_time_low(
struct timespec abstime;
if (time_in_usec != OS_SYNC_INFINITE_TIME) {
- struct timeval tv;
- int ret;
- ulint sec;
- ulint usec;
-
- ret = ut_usectime(&sec, &usec);
- ut_a(ret == 0);
-
- tv.tv_sec = sec;
- tv.tv_usec = usec;
-
- tv.tv_usec += time_in_usec;
-
- if ((ulint) tv.tv_usec >= MICROSECS_IN_A_SECOND) {
- tv.tv_sec += tv.tv_usec / MICROSECS_IN_A_SECOND;
- tv.tv_usec %= MICROSECS_IN_A_SECOND;
- }
-
- abstime.tv_sec = tv.tv_sec;
- abstime.tv_nsec = tv.tv_usec * 1000;
+ ulonglong usec = ulonglong(time_in_usec) + my_hrtime().val;
+ abstime.tv_sec = usec / 1000000;
+ abstime.tv_nsec = (usec % 1000000) * 1000;
} else {
abstime.tv_nsec = 999999999;
abstime.tv_sec = (time_t) ULINT_MAX;
diff --git a/storage/xtradb/que/que0que.cc b/storage/xtradb/que/que0que.cc
index 8cf66049088..090c5091a8d 100644
--- a/storage/xtradb/que/que0que.cc
+++ b/storage/xtradb/que/que0que.cc
@@ -204,9 +204,6 @@ que_thr_end_lock_wait(
{
que_thr_t* thr;
ibool was_active;
- ulint sec;
- ulint ms;
- ib_uint64_t now;
ut_ad(lock_mutex_own());
ut_ad(trx_mutex_own(trx));
@@ -224,10 +221,9 @@ que_thr_end_lock_wait(
que_thr_move_to_run_state(thr);
if (UNIV_UNLIKELY(trx->take_stats)) {
- ut_usectime(&sec, &ms);
- now = (ib_uint64_t)sec * 1000000 + ms;
- trx->lock_que_wait_timer
- += (ulint)(now - trx->lock_que_wait_ustarted);
+ trx->lock_que_wait_timer += static_cast<ulint>(
+ (my_interval_timer() - trx->lock_que_wait_nstarted)
+ / 1000);
}
trx->lock.que_state = TRX_QUE_RUNNING;
diff --git a/storage/xtradb/srv/srv0conc.cc b/storage/xtradb/srv/srv0conc.cc
index 3adef3a058f..3433d968eb2 100644
--- a/storage/xtradb/srv/srv0conc.cc
+++ b/storage/xtradb/srv/srv0conc.cc
@@ -401,8 +401,6 @@ srv_conc_enter_innodb_without_atomics(
ulint i;
srv_conc_slot_t* slot = NULL;
ibool has_slept = FALSE;
- ib_uint64_t start_time = 0L;
- ib_uint64_t finish_time = 0L;
ulint sec;
ulint ms;
@@ -537,12 +535,9 @@ retry:
ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
#endif /* UNIV_SYNC_DEBUG */
- if (UNIV_UNLIKELY(trx->take_stats)) {
- ut_usectime(&sec, &ms);
- start_time = (ib_uint64_t)sec * 1000000 + ms;
- } else {
- start_time = 0;
- }
+ const ulonglong start_time = UNIV_UNLIKELY(trx->take_stats)
+ ? my_interval_timer()
+ : 0;
trx->op_info = "waiting in InnoDB queue";
@@ -557,9 +552,8 @@ retry:
trx->op_info = "";
if (UNIV_UNLIKELY(start_time != 0)) {
- ut_usectime(&sec, &ms);
- finish_time = (ib_uint64_t)sec * 1000000 + ms;
- trx->innodb_que_wait_timer += (ulint)(finish_time - start_time);
+ trx->innodb_que_wait_timer += ulint((my_interval_timer()
+ - start_time) / 1000);
}
os_fast_mutex_lock(&srv_conc_mutex);
diff --git a/storage/xtradb/trx/trx0trx.cc b/storage/xtradb/trx/trx0trx.cc
index fc979a9bff8..3e0d81df8b5 100644
--- a/storage/xtradb/trx/trx0trx.cc
+++ b/storage/xtradb/trx/trx0trx.cc
@@ -1795,21 +1795,15 @@ trx_commit_or_rollback_prepare(
query thread to the suspended state */
if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) {
-
- ulint sec;
- ulint ms;
- ib_uint64_t now;
-
ut_a(trx->lock.wait_thr != NULL);
trx->lock.wait_thr->state = QUE_THR_SUSPENDED;
trx->lock.wait_thr = NULL;
if (UNIV_UNLIKELY(trx->take_stats)) {
- ut_usectime(&sec, &ms);
- now = (ib_uint64_t)sec * 1000000 + ms;
- trx->lock_que_wait_timer
- += (ulint)
- (now - trx->lock_que_wait_ustarted);
+ trx->lock_que_wait_timer += static_cast<ulint>(
+ (my_interval_timer()
+ - trx->lock_que_wait_nstarted)
+ / 1000);
}
trx->lock.que_state = TRX_QUE_RUNNING;
diff --git a/storage/xtradb/ut/ut0ut.cc b/storage/xtradb/ut/ut0ut.cc
index 0cdc618a8c4..8a339627cfb 100644
--- a/storage/xtradb/ut/ut0ut.cc
+++ b/storage/xtradb/ut/ut0ut.cc
@@ -47,83 +47,6 @@ Created 5/11/1994 Heikki Tuuri
# include <string>
#endif /* UNIV_HOTBACKUP */
-#ifdef __WIN__
-#include <innodb_priv.h> /* For sql_print_error */
-typedef VOID(WINAPI *time_fn)(LPFILETIME);
-static time_fn ut_get_system_time_as_file_time = GetSystemTimeAsFileTime;
-
-/*****************************************************************//**
-NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix
-epoch starts from 1970/1/1. For selection of constant see:
-http://support.microsoft.com/kb/167296/ */
-#define WIN_TO_UNIX_DELTA_USEC ((ib_int64_t) 11644473600000000ULL)
-
-
-/**
-Initialise highest available time resolution API on Windows
-@return 0 if all OK else -1 */
-int
-ut_win_init_time()
-{
- HMODULE h = LoadLibrary("kernel32.dll");
- if (h != NULL)
- {
- time_fn pfn = (time_fn)GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
- if (pfn != NULL)
- {
- ut_get_system_time_as_file_time = pfn;
- }
- return false;
- }
- DWORD error = GetLastError();
- sql_print_error(
- "LoadLibrary(\"kernel32.dll\") failed: GetLastError returns %lu", error);
- return(-1);
-}
-
-/*****************************************************************//**
-This is the Windows version of gettimeofday(2).
-@return 0 if all OK else -1 */
-static
-int
-ut_gettimeofday(
-/*============*/
- struct timeval* tv, /*!< out: Values are relative to Unix epoch */
- void* tz) /*!< in: not used */
-{
- FILETIME ft;
- ib_int64_t tm;
-
- if (!tv) {
- errno = EINVAL;
- return(-1);
- }
-
- ut_get_system_time_as_file_time(&ft);
-
- tm = (ib_int64_t) ft.dwHighDateTime << 32;
- tm |= ft.dwLowDateTime;
-
- ut_a(tm >= 0); /* If tm wraps over to negative, the quotient / 10
- does not work */
-
- tm /= 10; /* Convert from 100 nsec periods to usec */
-
- /* If we don't convert to the Unix epoch the value for
- struct timeval::tv_sec will overflow.*/
- tm -= WIN_TO_UNIX_DELTA_USEC;
-
- tv->tv_sec = (long) (tm / 1000000L);
- tv->tv_usec = (long) (tm % 1000000L);
-
- return(0);
-}
-#else
-/** An alias for gettimeofday(2). On Microsoft Windows, we have to
-reimplement this function. */
-#define ut_gettimeofday gettimeofday
-#endif
-
/**********************************************************//**
Returns system time. We do not specify the format of the time returned:
the only way to manipulate it is to use the function ut_difftime.
@@ -138,48 +61,6 @@ ut_time(void)
#ifndef UNIV_HOTBACKUP
/**********************************************************//**
-Returns system time.
-Upon successful completion, the value 0 is returned; otherwise the
-value -1 is returned and the global variable errno is set to indicate the
-error.
-@return 0 on success, -1 otherwise */
-UNIV_INTERN
-int
-ut_usectime(
-/*========*/
- ulint* sec, /*!< out: seconds since the Epoch */
- ulint* ms) /*!< out: microseconds since the Epoch+*sec */
-{
- struct timeval tv;
- int ret;
- int errno_gettimeofday;
- int i;
-
- for (i = 0; i < 10; i++) {
-
- ret = ut_gettimeofday(&tv, NULL);
-
- if (ret == -1) {
- errno_gettimeofday = errno;
- ut_print_timestamp(stderr);
- fprintf(stderr, " InnoDB: gettimeofday(): %s\n",
- strerror(errno_gettimeofday));
- os_thread_sleep(100000); /* 0.1 sec */
- errno = errno_gettimeofday;
- } else {
- break;
- }
- }
-
- if (ret != -1) {
- *sec = (ulint) tv.tv_sec;
- *ms = (ulint) tv.tv_usec;
- }
-
- return(ret);
-}
-
-/**********************************************************//**
Returns the number of milliseconds since some epoch. The
value may wrap around. It should only be used for heuristic
purposes.