diff --git a/deps/oblib/src/lib/allocator/ob_block_alloc_mgr.h b/deps/oblib/src/lib/allocator/ob_block_alloc_mgr.h
index 3ae4d0a72b..4ffd4ae563 100644
--- a/deps/oblib/src/lib/allocator/ob_block_alloc_mgr.h
+++ b/deps/oblib/src/lib/allocator/ob_block_alloc_mgr.h
@@ -14,6 +14,7 @@
#define OCEANBASE_ALLOCATOR_OB_BLOCK_ALLOC_MGR_H_
#include "lib/allocator/ob_malloc.h"
+#include "common/ob_clock_generator.h"
namespace oceanbase
{
diff --git a/deps/oblib/src/lib/allocator/ob_retire_station.h b/deps/oblib/src/lib/allocator/ob_retire_station.h
index 1f12c94db4..bfbd7eddbe 100644
--- a/deps/oblib/src/lib/allocator/ob_retire_station.h
+++ b/deps/oblib/src/lib/allocator/ob_retire_station.h
@@ -17,6 +17,7 @@
#include "lib/thread_local/ob_tsi_utils.h"
#include "lib/time/ob_time_utility.h"
#include "lib/oblog/ob_log.h"
+#include "common/ob_clock_generator.h"
namespace oceanbase
{
diff --git a/deps/oblib/src/lib/objectpool/ob_server_object_pool.h b/deps/oblib/src/lib/objectpool/ob_server_object_pool.h
index 9575242c63..ac0d9172af 100644
--- a/deps/oblib/src/lib/objectpool/ob_server_object_pool.h
+++ b/deps/oblib/src/lib/objectpool/ob_server_object_pool.h
@@ -201,7 +201,7 @@ public:
int64_t itid = get_itid();
int64_t aid = itid % arena_num_;
ObPoolArenaHead &arena = arena_[aid];
- int64_t cur_ts = OB_TSC_TIMESTAMP.current_time();
+ int64_t cur_ts = ObClockGenerator::getClock();
{ // Enter the critical area of the arena, the timestamp is obtained outside the lock, and minimize the length of the critical area
ObLatchWGuard lock_guard(arena.lock, ObLatchIds::SERVER_OBJECT_POOL_ARENA_LOCK);
cmeta = static_cast(arena.next);
@@ -251,7 +251,7 @@ public:
if (aid >= 0) {
x->reset();
ObPoolArenaHead &arena = arena_[aid];
- int64_t cur_ts = OB_TSC_TIMESTAMP.current_time();
+ int64_t cur_ts = ObClockGenerator::getClock();
{ // Enter the critical area of the arena, the timestamp is obtained outside the lock, and minimize the length of the critical area
ObLatchWGuard lock_guard(arena.lock, ObLatchIds::SERVER_OBJECT_POOL_ARENA_LOCK);
cmeta->next = static_cast(arena.next);
@@ -265,7 +265,7 @@ public:
x->~T();
ob_free(cmeta);
ObPoolArenaHead &arena = arena_[-(aid + 1)];
- int64_t cur_ts = OB_TSC_TIMESTAMP.current_time();
+ int64_t cur_ts = ObClockGenerator::getClock();
{ // Enter the critical area of the arena, the timestamp is obtained outside the lock, and minimize the length of the critical area
ObLatchWGuard lock_guard(arena.lock, ObLatchIds::SERVER_OBJECT_POOL_ARENA_LOCK);
arena.miss_return_cnt++;
diff --git a/deps/oblib/src/lib/time/ob_time_utility.h b/deps/oblib/src/lib/time/ob_time_utility.h
index 422b3a12a7..9f7293f392 100644
--- a/deps/oblib/src/lib/time/ob_time_utility.h
+++ b/deps/oblib/src/lib/time/ob_time_utility.h
@@ -112,28 +112,4 @@ public:
} //common
} //oceanbase
-#define TC_REACH_TIME_INTERVAL(i) \
- ({ \
- bool bret = false; \
- static thread_local int64_t last_time = 0; \
- int64_t cur_time = OB_TSC_TIMESTAMP.current_time(); \
- if (OB_UNLIKELY((i + last_time) < cur_time)) \
- { \
- last_time = cur_time; \
- bret = true; \
- } \
- bret; \
- })
-
-#define TC_REACH_COUNT_INTERVAL(i) \
- ({ \
- bool bret = false; \
- static thread_local int64_t count = 0; \
- if (0 == (++count % i)) \
- { \
- bret = true; \
- } \
- bret; \
- })
-
#endif //_OCEANBASE_COMMON_OB_TIME_UTILITY_H_
diff --git a/deps/oblib/src/lib/time/ob_tsc_timestamp.cpp b/deps/oblib/src/lib/time/ob_tsc_timestamp.cpp
index daaf7a99b2..005041240b 100644
--- a/deps/oblib/src/lib/time/ob_tsc_timestamp.cpp
+++ b/deps/oblib/src/lib/time/ob_tsc_timestamp.cpp
@@ -67,20 +67,13 @@ int ObTscTimestamp::init()
int64_t ObTscTimestamp::current_time()
{
int ret = OB_SUCCESS;
- int64_t result_time = 0;
- if (OB_UNLIKELY(!is_init_)) {
- // init failed, use system call.
- struct timeval tv;
- if (gettimeofday(&tv, NULL) < 0) {
- ret = OB_ERR_UNEXPECTED;
- LIB_LOG(WARN, "sys gettimeofday unexpected", K(ret));
- }
- result_time = (static_cast(tv.tv_sec) * static_cast(1000000) + static_cast(tv.tv_usec));
- } else {
- const uint64_t current_tsc = rdtsc();
- result_time = ((current_tsc - tsc_count_) * scale_ >> 20) + start_us_;
+ // init failed, use system call.
+ struct timeval tv;
+ if (gettimeofday(&tv, NULL) < 0) {
+ ret = OB_ERR_UNEXPECTED;
+ LIB_LOG(WARN, "sys gettimeofday unexpected", K(ret));
}
- return result_time;
+ return (static_cast(tv.tv_sec) * static_cast(1000000) + static_cast(tv.tv_usec));
}
int64_t ObTscTimestamp::current_monotonic_time()
diff --git a/deps/oblib/src/lib/utility/ob_macro_utils.h b/deps/oblib/src/lib/utility/ob_macro_utils.h
index 7fa8600be2..322354c5af 100644
--- a/deps/oblib/src/lib/utility/ob_macro_utils.h
+++ b/deps/oblib/src/lib/utility/ob_macro_utils.h
@@ -603,11 +603,36 @@ for (__typeof__((c).at(0)) *it = ((extra_condition) && (c).count() > 0 ? &(c).at
#define ob_assert(x) ob_release_assert(x)
////////////////////////////////////////////////////////////////
// interval
+
+#define TC_REACH_TIME_INTERVAL(i) \
+ ({ \
+ bool bret = false; \
+ static thread_local int64_t last_time = 0; \
+ int64_t cur_time = common::ObClockGenerator::getClock(); \
+ if (OB_UNLIKELY((i + last_time) < cur_time)) \
+ { \
+ last_time = cur_time; \
+ bret = true; \
+ } \
+ bret; \
+ })
+
+#define TC_REACH_COUNT_INTERVAL(i) \
+ ({ \
+ bool bret = false; \
+ static thread_local int64_t count = 0; \
+ if (0 == (++count % i)) \
+ { \
+ bret = true; \
+ } \
+ bret; \
+ })
+
#define REACH_TIME_INTERVAL(i) \
({ \
bool bret = false; \
static volatile int64_t last_time = 0; \
- int64_t cur_time = OB_TSC_TIMESTAMP.current_time(); \
+ int64_t cur_time = ObClockGenerator::getClock(); \
int64_t old_time = last_time; \
if (OB_UNLIKELY((i + last_time) < cur_time) \
&& old_time == ATOMIC_CAS(&last_time, old_time, cur_time)) \
@@ -639,7 +664,7 @@ for (__typeof__((c).at(0)) *it = ((extra_condition) && (c).count() > 0 ? &(c).at
types::uint128_t next; \
static const uint64_t ONE_SECOND = 1 * 1000 *1000; \
static types::uint128_t last; \
- const int64_t cur_time = OB_TSC_TIMESTAMP.current_time(); \
+ const int64_t cur_time = common::ObClockGenerator::getClock(); \
while(true) { \
LOAD128(tmp, &last); \
if (tmp.lo + ONE_SECOND > (uint64_t)cur_time) { \
@@ -662,8 +687,8 @@ for (__typeof__((c).at(0)) *it = ((extra_condition) && (c).count() > 0 ? &(c).at
#define REACH_TIME_INTERVAL_RANGE(i, j) \
({ \
bool bret = false; \
- static volatile int64_t last_time = OB_TSC_TIMESTAMP.current_time(); \
- int64_t cur_time = OB_TSC_TIMESTAMP.current_time(); \
+ static volatile int64_t last_time = common::ObClockGenerator::getClock(); \
+ int64_t cur_time = common::ObClockGenerator::getClock(); \
int64_t old_time = last_time; \
if ((j + last_time) < cur_time) \
{ \
@@ -696,7 +721,7 @@ for (__typeof__((c).at(0)) *it = ((extra_condition) && (c).count() > 0 ? &(c).at
types::uint128_t next; \
static const uint64_t ONE_SECOND = 1 * 1000 * 1000; \
static types::uint128_t last; \
- const int64_t cur_time = OB_TSC_TIMESTAMP.current_time(); \
+ const int64_t cur_time = common::ObClockGenerator::getClock(); \
while(true) { \
LOAD128(tmp, &last); \
if (tmp.lo + ONE_SECOND < (uint64_t)cur_time) { \
diff --git a/deps/oblib/src/lib/utility/ob_tracepoint.h b/deps/oblib/src/lib/utility/ob_tracepoint.h
index cdb55f129e..42d03b2cd6 100644
--- a/deps/oblib/src/lib/utility/ob_tracepoint.h
+++ b/deps/oblib/src/lib/utility/ob_tracepoint.h
@@ -26,6 +26,7 @@
#include "lib/list/ob_dlist.h"
#include "lib/coro/co_var.h"
#include "lib/time/ob_tsc_timestamp.h"
+#include "common/ob_clock_generator.h"
#include "lib/utility/ob_macro_utils.h"
#define TP_COMMA(x) ,
diff --git a/deps/oblib/src/lib/utility/utility.h b/deps/oblib/src/lib/utility/utility.h
index 30d29a42ca..4900c0dc55 100644
--- a/deps/oblib/src/lib/utility/utility.h
+++ b/deps/oblib/src/lib/utility/utility.h
@@ -25,6 +25,7 @@
#include "lib/utility/ob_backtrace.h"
#include "lib/oblog/ob_trace_log.h"
#include "lib/container/ob_iarray.h"
+#include "common/ob_clock_generator.h"
#define FALSE_IT(stmt) ({ (stmt); false; })
#define OB_FALSE_IT(stmt) ({ (stmt); false; })
diff --git a/src/logservice/common_util/ob_log_time_utils.h b/src/logservice/common_util/ob_log_time_utils.h
index 460d4d8759..fd5a5bcd3e 100644
--- a/src/logservice/common_util/ob_log_time_utils.h
+++ b/src/logservice/common_util/ob_log_time_utils.h
@@ -26,7 +26,7 @@ namespace logservice
({ \
bool bret = false; \
static thread_local volatile int64_t last_time = 0; \
- int64_t cur_time = OB_TSC_TIMESTAMP.current_time(); \
+ int64_t cur_time = common::ObClockGenerator::getClock(); \
int64_t old_time = last_time; \
if (OB_UNLIKELY((i + last_time) < cur_time) \
&& old_time == ATOMIC_CAS(&last_time, old_time, cur_time)) \
diff --git a/src/logservice/data_dictionary/ob_data_dict_service.cpp b/src/logservice/data_dictionary/ob_data_dict_service.cpp
index 6deca64df2..3e157c1200 100644
--- a/src/logservice/data_dictionary/ob_data_dict_service.cpp
+++ b/src/logservice/data_dictionary/ob_data_dict_service.cpp
@@ -173,7 +173,7 @@ void ObDataDictService::runTimerTask()
if (IS_INIT) {
refresh_config_();
bool is_leader = ATOMIC_LOAD(&is_leader_);
- const int64_t start_time = OB_TSC_TIMESTAMP.current_time();
+ const int64_t start_time = ObClockGenerator::getClock();
const bool is_reach_time_interval = (start_time >= ATOMIC_LOAD(&last_dump_succ_time_) + ATOMIC_LOAD(&dump_interval_));
const bool force_need_dump = ATOMIC_LOAD(&force_need_dump_);
@@ -192,7 +192,7 @@ void ObDataDictService::runTimerTask()
DDLOG(WARN, "dump_data_dict_ failed", KR(ret), K_(tenant_id), K(force_need_dump));
}
} else {
- const int64_t end_time = OB_TSC_TIMESTAMP.current_time();
+ const int64_t end_time = ObClockGenerator::getClock();
ATOMIC_SET(&last_dump_succ_time_, end_time);
if (force_need_dump) {
diff --git a/src/logservice/data_dictionary/ob_data_dict_utils.h b/src/logservice/data_dictionary/ob_data_dict_utils.h
index 4c189931e4..8c3d804233 100644
--- a/src/logservice/data_dictionary/ob_data_dict_utils.h
+++ b/src/logservice/data_dictionary/ob_data_dict_utils.h
@@ -18,6 +18,7 @@
#include "lib/string/ob_string.h" // ObString
#include "lib/time/ob_time_utility.h" // ObTimeUtility
+#include "common/ob_clock_generator.h"
#include "share/ob_define.h"
namespace oceanbase
@@ -33,7 +34,7 @@ namespace datadict
({ \
bool bret = false; \
static thread_local volatile int64_t last_time = 0; \
- int64_t cur_time = OB_TSC_TIMESTAMP.current_time(); \
+ int64_t cur_time = common::ObClockGenerator::getClock(); \
int64_t old_time = last_time; \
if (OB_UNLIKELY((i + last_time) < cur_time) \
&& old_time == ATOMIC_CAS(&last_time, old_time, cur_time)) \
diff --git a/src/objit/src/core/ob_jit_allocator.cpp b/src/objit/src/core/ob_jit_allocator.cpp
index 08db00694b..9888f8befb 100644
--- a/src/objit/src/core/ob_jit_allocator.cpp
+++ b/src/objit/src/core/ob_jit_allocator.cpp
@@ -13,6 +13,7 @@
#define USING_LOG_PREFIX SQL_CG
#include "core/ob_jit_allocator.h"
+#include "common/ob_clock_generator.h"
#include
using namespace oceanbase::common;
diff --git a/src/observer/ob_srv_deliver.cpp b/src/observer/ob_srv_deliver.cpp
index bcb55feb15..e6f0af8002 100644
--- a/src/observer/ob_srv_deliver.cpp
+++ b/src/observer/ob_srv_deliver.cpp
@@ -30,6 +30,7 @@
#include "observer/omt/ob_tenant.h"
#include "observer/omt/ob_multi_tenant.h"
#include "rpc/obmysql/ob_mysql_packet.h"
+#include "common/ob_clock_generator.h"
using namespace oceanbase::common;
diff --git a/src/storage/tx_storage/ob_tenant_freezer.cpp b/src/storage/tx_storage/ob_tenant_freezer.cpp
index a0c720f84d..64e096644e 100755
--- a/src/storage/tx_storage/ob_tenant_freezer.cpp
+++ b/src/storage/tx_storage/ob_tenant_freezer.cpp
@@ -871,7 +871,7 @@ int ObTenantFreezer::get_tenant_memstore_cond(
{
int ret = OB_SUCCESS;
int64_t unused = 0;
- int64_t current_time = OB_TSC_TIMESTAMP.current_time();
+ int64_t current_time = ObClockGenerator::getClock();
RLOCAL_INIT(int64_t, last_refresh_timestamp, 0);
RLOCAL(int64_t, last_active_memstore_used);
RLOCAL(int64_t, last_total_memstore_used);
@@ -1053,7 +1053,7 @@ int ObTenantFreezer::check_tenant_out_of_memstore_limit(bool &is_out_of_mem)
int ret = OB_SUCCESS;
RLOCAL(int64_t, last_check_timestamp);
RLOCAL(bool, last_result);
- int64_t current_time = OB_TSC_TIMESTAMP.current_time();
+ int64_t current_time = ObClockGenerator::getClock();
ObTenantFreezeCtx ctx;
if (!is_inited_) {
ret = OB_NOT_INIT;
diff --git a/unittest/storage/test_io_manager.cpp b/unittest/storage/test_io_manager.cpp
index c7bea48e9b..b17cbe55ed 100644
--- a/unittest/storage/test_io_manager.cpp
+++ b/unittest/storage/test_io_manager.cpp
@@ -23,6 +23,7 @@
#include "share/ob_local_device.h"
#include "lib/thread/thread_pool.h"
#include "lib/file/file_directory_utils.h"
+#include "common/ob_clock_generator.h"
#define ASSERT_SUCC(ret) ASSERT_EQ((ret), ::oceanbase::common::OB_SUCCESS)
#define ASSERT_FAIL(ret) ASSERT_NE((ret), ::oceanbase::common::OB_SUCCESS)
@@ -1737,7 +1738,7 @@ int IOPerfRunner::do_perf_rolling()
}
int64_t pos = 0;
while (!has_set_stop() && OB_SUCC(ret)) {
- if (TC_REACH_TIME_INTERVAL(1000L * 1000L)) {
+ if (REACH_TIME_INTERVAL(1000L * 1000L)) {
ATOMIC_FAA(&io_count_, local_io_count);
ATOMIC_FAA(&total_io_count_, local_io_count);
local_io_count = 0;