mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 11:57:43 +08:00
test gettimeofday ok
This commit is contained in:
parent
0ee5867c9d
commit
a0b258eb28
@ -330,6 +330,8 @@ FIBER_API void acl_fiber_set_error(int errnum);
|
|||||||
*/
|
*/
|
||||||
FIBER_API int acl_fiber_set_fdlimit(int limit);
|
FIBER_API int acl_fiber_set_fdlimit(int limit);
|
||||||
|
|
||||||
|
FIBER_API int acl_fiber_gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include "fiber/fiber_base.h"
|
||||||
#include "pthread_patch.h"
|
#include "pthread_patch.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
#include "init.h"
|
#include "init.h"
|
||||||
@ -142,13 +143,13 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
|
|||||||
|
|
||||||
#elif defined(USE_FAST_TIME)
|
#elif defined(USE_FAST_TIME)
|
||||||
|
|
||||||
static inline uint64_t rte_rdtsc(void)
|
static inline unsigned long long rte_rdtsc(void)
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
uint64_t tsc_64;
|
uint64_t tsc_64;
|
||||||
struct {
|
struct {
|
||||||
uint32_t lo_32;
|
unsigned lo_32;
|
||||||
uint32_t hi_32;
|
unsigned hi_32;
|
||||||
};
|
};
|
||||||
} tsc;
|
} tsc;
|
||||||
|
|
||||||
@ -160,36 +161,47 @@ static inline uint64_t rte_rdtsc(void)
|
|||||||
|
|
||||||
static __thread unsigned long long __one_msec;
|
static __thread unsigned long long __one_msec;
|
||||||
static __thread unsigned long long __one_sec;
|
static __thread unsigned long long __one_sec;
|
||||||
|
static __thread unsigned long long __metric_diff;
|
||||||
|
|
||||||
static void set_time_metric(void)
|
static void set_time_metric(void)
|
||||||
{
|
{
|
||||||
uint64_t end;
|
unsigned long long now, startup, end;
|
||||||
uint64_t begin = rte_rdtsc();
|
unsigned long long begin = rte_rdtsc();
|
||||||
|
|
||||||
#define MSEC_ONE 1000
|
#define MSEC_ONE 1000
|
||||||
|
|
||||||
usleep(MSEC_ONE);
|
usleep(MSEC_ONE);
|
||||||
|
|
||||||
end = rte_rdtsc();
|
end = rte_rdtsc();
|
||||||
__one_msec = end - begin;
|
__one_msec = end - begin;
|
||||||
__one_sec = __one_msec * 1000;
|
__one_sec = __one_msec * 1000;
|
||||||
|
|
||||||
|
startup = rte_rdtsc();
|
||||||
|
now = time(NULL) * __one_sec;
|
||||||
|
if (now > startup) {
|
||||||
|
__metric_diff = now - startup;
|
||||||
|
} else {
|
||||||
|
__metric_diff = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static __thread unsigned long long __startup;
|
int acl_fiber_gettimeofday(struct timeval *tv, struct timezone *tz fiber_unused)
|
||||||
int gettimeofday(struct timeval *tv, struct timezone *tz fiber_unused)
|
|
||||||
{
|
{
|
||||||
unsigned long long diff;
|
unsigned long long now;
|
||||||
|
|
||||||
if (__one_msec == 0) {
|
if (__one_msec == 0) {
|
||||||
set_time_metric();
|
set_time_metric();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__startup == 0) {
|
now = rte_rdtsc() + __metric_diff;
|
||||||
__startup = rte_rdtsc();
|
tv->tv_sec = now / __one_sec;
|
||||||
}
|
tv->tv_usec = (1000 * (now % __one_sec) / __one_msec);
|
||||||
diff = rte_rdtsc() - __startup;
|
|
||||||
tv->tv_sec = diff / __one_sec;
|
|
||||||
tv->tv_usec = (1000 * (diff % __one_sec) / __one_msec);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
|
{
|
||||||
|
return acl_fiber_gettimeofday(tv, tz);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user