mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 03:47:53 +08:00
fixed one bug in hooked API gettimeofday for precision.
This commit is contained in:
parent
6c9a37e0d2
commit
42d2bd5684
@ -143,6 +143,26 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
|
||||
#elif defined(USE_FAST_TIME)
|
||||
|
||||
#include "fiber.h"
|
||||
|
||||
typedef int (*gettimeofday_fn)(struct timeval *, struct timezone *);
|
||||
static gettimeofday_fn __gettimeofday = NULL;
|
||||
|
||||
static void hook_api(void)
|
||||
{
|
||||
__gettimeofday = (gettimeofday_fn) dlsym(RTLD_NEXT, "gettimeofday");
|
||||
assert(__gettimeofday);
|
||||
}
|
||||
|
||||
static pthread_once_t __once_control = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void hook_init(void)
|
||||
{
|
||||
if (pthread_once(&__once_control, hook_api) != 0) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
static inline unsigned long long rte_rdtsc(void)
|
||||
{
|
||||
union {
|
||||
@ -168,12 +188,13 @@ static void set_time_metric(void)
|
||||
unsigned long long now, startup, end;
|
||||
unsigned long long begin = rte_rdtsc();
|
||||
|
||||
#define MSEC_ONE 1000
|
||||
#define MSEC_ONE 1000
|
||||
#define METRIC 50
|
||||
|
||||
usleep(MSEC_ONE);
|
||||
usleep(MSEC_ONE * METRIC);
|
||||
|
||||
end = rte_rdtsc();
|
||||
__one_msec = end - begin;
|
||||
__one_msec = (end - begin) / METRIC;
|
||||
__one_sec = __one_msec * 1000;
|
||||
|
||||
startup = rte_rdtsc();
|
||||
@ -201,6 +222,13 @@ int acl_fiber_gettimeofday(struct timeval *tv, struct timezone *tz fiber_unused)
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
if (!var_hook_sys_api) {
|
||||
if (__gettimeofday == NULL) {
|
||||
hook_init();
|
||||
}
|
||||
return __gettimeofday(tv, tz);
|
||||
}
|
||||
|
||||
return acl_fiber_gettimeofday(tv, tz);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef FIBER_INCLUDE_H
|
||||
#define FIBER_INCLUDE_H
|
||||
|
||||
#include "common/ring.h"
|
||||
#include "event.h"
|
||||
|
||||
#ifdef ACL_ARM_LINUX
|
||||
|
@ -222,13 +222,14 @@ static void hook_init(void)
|
||||
#ifdef SYS_UNIX
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
if (!var_hook_sys_api) {
|
||||
if (var_hook_sys_api) {
|
||||
#ifndef USE_SYSCALL
|
||||
if (__sys_sleep == NULL) {
|
||||
hook_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("use system gettimeofday\r\n");
|
||||
return __sys_sleep(seconds);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
|
||||
110) 2019.8.6
|
||||
110.1) bugfix: gettimeofday 内部在进行时间校准时休眠 50 毫秒,之前是休眠 1 毫秒造成较大误差
|
||||
|
||||
109) 2019.7.31
|
||||
109.1) performance: 因为 ring.h 中的方法被调用次数比较频繁,所以将其中代码实现
|
||||
放在头文件中,成为内联函数或宏定义
|
||||
|
Loading…
Reference in New Issue
Block a user