unix: use uv__hrtime() internally
This commit renames the various uv_hrtime() implementations to uv__hrtime(). Libuv uses the high-res timer internally in performance-critical code paths. Calling the non-public version avoids going through the PLT when libuv is compiled as a shared object. The exported uv_hrtime() now has a single definition in src/unix/core.c that calls uv__hrtime(). A future optimization is to lift the uv__hrtime() declarations into header files so they can be inlined at the call sites. Then again, linking with -flto should accomplish the same thing.
This commit is contained in:
parent
ba83510fc0
commit
339033afc0
@ -45,7 +45,7 @@
|
||||
#include <sys/proc.h>
|
||||
#include <sys/procfs.h>
|
||||
|
||||
uint64_t uv_hrtime() {
|
||||
uint64_t uv__hrtime(void) {
|
||||
uint64_t G = 1000000000;
|
||||
timebasestruct_t t;
|
||||
read_wall_time(&t, TIMEBASE_SZ);
|
||||
|
||||
@ -66,6 +66,11 @@ static uv_loop_t default_loop_struct;
|
||||
static uv_loop_t* default_loop_ptr;
|
||||
|
||||
|
||||
uint64_t uv_hrtime(void) {
|
||||
return uv__hrtime();
|
||||
}
|
||||
|
||||
|
||||
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
|
||||
assert(!(handle->flags & (UV_CLOSING | UV_CLOSED)));
|
||||
|
||||
@ -302,7 +307,7 @@ int uv_run(uv_loop_t* loop) {
|
||||
|
||||
|
||||
void uv_update_time(uv_loop_t* loop) {
|
||||
loop->time = uv_hrtime() / 1000000;
|
||||
loop->time = uv__hrtime() / 1000000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -41,12 +41,13 @@ void uv__platform_loop_delete(uv_loop_t* loop) {
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime() {
|
||||
uint64_t uv__hrtime(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
|
||||
}
|
||||
|
||||
|
||||
void uv_loadavg(double avg[3]) {
|
||||
/* Unsupported as of cygwin 1.7.7 */
|
||||
avg[0] = avg[1] = avg[2] = 0;
|
||||
|
||||
@ -176,7 +176,7 @@ void uv__cf_loop_signal(uv_loop_t* loop, cf_loop_signal_cb cb, void* arg) {
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime(void) {
|
||||
uint64_t uv__hrtime(void) {
|
||||
mach_timebase_info_data_t info;
|
||||
|
||||
if (mach_timebase_info(&info) != KERN_SUCCESS)
|
||||
|
||||
@ -63,7 +63,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) {
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime(void) {
|
||||
uint64_t uv__hrtime(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
|
||||
|
||||
@ -174,6 +174,7 @@ void uv__work_submit(uv_loop_t* loop,
|
||||
void uv__work_done(uv_async_t* handle, int status);
|
||||
|
||||
/* platform specific */
|
||||
uint64_t uv__hrtime(void);
|
||||
int uv__kqueue_init(uv_loop_t* loop);
|
||||
int uv__platform_loop_init(uv_loop_t* loop, int default_loop);
|
||||
void uv__platform_loop_delete(uv_loop_t* loop);
|
||||
|
||||
@ -244,7 +244,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
|
||||
update_timeout:
|
||||
assert(timeout > 0);
|
||||
|
||||
diff = uv_hrtime() / 1000000;
|
||||
diff = uv__hrtime() / 1000000;
|
||||
assert(diff >= base);
|
||||
diff -= base;
|
||||
|
||||
|
||||
@ -243,7 +243,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
|
||||
update_timeout:
|
||||
assert(timeout > 0);
|
||||
|
||||
diff = uv_hrtime() / 1000000;
|
||||
diff = uv__hrtime() / 1000000;
|
||||
assert(diff >= base);
|
||||
diff -= base;
|
||||
|
||||
@ -255,7 +255,7 @@ update_timeout:
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime() {
|
||||
uint64_t uv__hrtime(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
|
||||
|
||||
@ -49,7 +49,7 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
|
||||
ngx_queue_init(&loop->watcher_queue);
|
||||
|
||||
loop->closing_handles = NULL;
|
||||
loop->time = uv_hrtime() / 1000000;
|
||||
loop->time = uv__hrtime() / 1000000;
|
||||
loop->async_pipefd[0] = -1;
|
||||
loop->async_pipefd[1] = -1;
|
||||
loop->signal_pipefd[0] = -1;
|
||||
|
||||
@ -56,7 +56,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) {
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime(void) {
|
||||
uint64_t uv__hrtime(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
|
||||
|
||||
@ -52,7 +52,7 @@ void uv__platform_loop_delete(uv_loop_t* loop) {
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime(void) {
|
||||
uint64_t uv__hrtime(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
|
||||
|
||||
@ -211,7 +211,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
|
||||
update_timeout:
|
||||
assert(timeout > 0);
|
||||
|
||||
diff = uv_hrtime() / 1000000;
|
||||
diff = uv__hrtime() / 1000000;
|
||||
assert(diff >= base);
|
||||
diff -= base;
|
||||
|
||||
@ -223,8 +223,8 @@ update_timeout:
|
||||
}
|
||||
|
||||
|
||||
uint64_t uv_hrtime() {
|
||||
return (gethrtime());
|
||||
uint64_t uv__hrtime(void) {
|
||||
return gethrtime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -354,7 +354,7 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
|
||||
struct timespec ts;
|
||||
uint64_t abstime;
|
||||
|
||||
abstime = uv_hrtime() + timeout;
|
||||
abstime = uv__hrtime() + timeout;
|
||||
ts.tv_sec = abstime / NANOSEC;
|
||||
ts.tv_nsec = abstime % NANOSEC;
|
||||
r = pthread_cond_timedwait(cond, mutex, &ts);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user