From 5565366a33e57436be08b00c14470ecafdf16632 Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 22 Jun 2012 07:44:40 -0700 Subject: [PATCH] uv: Upgrade to 171e2f71b9 --- deps/uv/include/uv.h | 2 +- deps/uv/src/win/fs.c | 9 +- deps/uv/src/win/internal.h | 1 - deps/uv/src/win/util.c | 23 ----- deps/uv/test/benchmark-fs-stat.c | 164 +++++++++++++++++++++++++++++++ deps/uv/test/benchmark-list.h | 3 + deps/uv/uv.gyp | 1 + 7 files changed, 175 insertions(+), 28 deletions(-) create mode 100644 deps/uv/test/benchmark-fs-stat.c diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index 600d51233..69e0db2f8 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -49,7 +49,7 @@ extern "C" { #define UV_VERSION_MAJOR 0 -#define UV_VERSION_MINOR 6 +#define UV_VERSION_MINOR 8 #include /* int64_t */ diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c index e2a328d8a..e81299bcf 100644 --- a/deps/uv/src/win/fs.c +++ b/deps/uv/src/win/fs.c @@ -91,6 +91,9 @@ return; \ } +#define FILETIME_TO_TIME_T(filetime) \ + ((*((uint64_t*) &(filetime)) - 116444736000000000ULL) / 10000000ULL); + #define IS_SLASH(c) ((c) == L'\\' || (c) == L'/') #define IS_LETTER(c) (((c) >= L'a' && (c) <= L'z') || \ ((c) >= L'A' && (c) <= L'Z')) @@ -630,9 +633,9 @@ static void fs__stat(uv_fs_t* req, const wchar_t* path, int link) { (int64_t) info.nFileSizeLow; } - uv_filetime_to_time_t(&info.ftLastWriteTime, &(req->stat.st_mtime)); - uv_filetime_to_time_t(&info.ftLastAccessTime, &(req->stat.st_atime)); - uv_filetime_to_time_t(&info.ftCreationTime, &(req->stat.st_ctime)); + req->stat.st_mtime = FILETIME_TO_TIME_T(info.ftLastWriteTime); + req->stat.st_atime = FILETIME_TO_TIME_T(info.ftLastAccessTime); + req->stat.st_ctime = FILETIME_TO_TIME_T(info.ftCreationTime); req->stat.st_nlink = (info.nNumberOfLinks <= SHRT_MAX) ? (short) info.nNumberOfLinks : SHRT_MAX; diff --git a/deps/uv/src/win/internal.h b/deps/uv/src/win/internal.h index aaae66e7a..b9f8bba75 100644 --- a/deps/uv/src/win/internal.h +++ b/deps/uv/src/win/internal.h @@ -280,7 +280,6 @@ void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle); void uv__util_init(); int uv_parent_pid(); -void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time); void uv_fatal_error(const int errorno, const char* syscall); uv_err_code uv_translate_sys_error(int sys_errno); diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c index 4ceae0403..49a3adc70 100644 --- a/deps/uv/src/win/util.c +++ b/deps/uv/src/win/util.c @@ -862,26 +862,3 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses, free(addresses); } - - -void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time) { - FILETIME local_time; - SYSTEMTIME system_time; - struct tm time; - - if ((file_time->dwLowDateTime || file_time->dwHighDateTime) && - FileTimeToLocalFileTime(file_time, &local_time) && - FileTimeToSystemTime(&local_time, &system_time)) { - time.tm_year = system_time.wYear - 1900; - time.tm_mon = system_time.wMonth - 1; - time.tm_mday = system_time.wDay; - time.tm_hour = system_time.wHour; - time.tm_min = system_time.wMinute; - time.tm_sec = system_time.wSecond; - time.tm_isdst = -1; - - *stat_time = mktime(&time); - } else { - *stat_time = 0; - } -} diff --git a/deps/uv/test/benchmark-fs-stat.c b/deps/uv/test/benchmark-fs-stat.c new file mode 100644 index 000000000..53aa60b14 --- /dev/null +++ b/deps/uv/test/benchmark-fs-stat.c @@ -0,0 +1,164 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "task.h" +#include "uv.h" + +#include +#include + +#define NUM_SYNC_REQS (10 * 1e5) +#define NUM_ASYNC_REQS (1 * 1e5) +#define MAX_CONCURRENT_REQS 32 + +#define sync_stat(req, path) \ + do { \ + uv_fs_stat(uv_default_loop(), (req), (path), NULL); \ + uv_fs_req_cleanup((req)); \ + } \ + while (0) + +struct async_req { + const char* path; + uv_fs_t fs_req; + int* count; +}; + + +static const char* fmt(double d) { + uint64_t v; + char* p; + + p = (char *) calloc(1, 32) + 31; /* leaks memory */ + v = d; + +#if 0 /* works but we don't care about fractional precision */ + if (d - v >= 0.01) { + *--p = '0' + (uint64_t) (d * 100) % 10; + *--p = '0' + (uint64_t) (d * 10) % 10; + *--p = '.'; + } +#endif + + if (v == 0) + *--p = '0'; + + while (v) { + if (v) *--p = '0' + (v % 10), v /= 10; + if (v) *--p = '0' + (v % 10), v /= 10; + if (v) *--p = '0' + (v % 10), v /= 10; + if (v) *--p = ','; + } + + return p; +} + + +static void warmup(const char* path) { + uv_fs_t reqs[MAX_CONCURRENT_REQS]; + int i; + + /* warm up the thread pool */ + for (i = 0; i < ARRAY_SIZE(reqs); i++) + uv_fs_stat(uv_default_loop(), reqs + i, path, uv_fs_req_cleanup); + + uv_run(uv_default_loop()); + + /* warm up the OS dirent cache */ + for (i = 0; i < 16; i++) + sync_stat(reqs + 0, path); +} + + +static void sync_bench(const char* path) { + uint64_t before; + uint64_t after; + uv_fs_t req; + int i; + + /* do the sync benchmark */ + before = uv_hrtime(); + + for (i = 0; i < NUM_SYNC_REQS; i++) + sync_stat(&req, path); + + after = uv_hrtime(); + + printf("%s stats (sync): %.2fs (%s/s)\n", + fmt(1.0 * NUM_SYNC_REQS), + (after - before) / 1e9, + fmt((1.0 * NUM_SYNC_REQS) / ((after - before) / 1e9))); + fflush(stdout); +} + + +static void stat_cb(uv_fs_t* fs_req) { + struct async_req* req = container_of(fs_req, struct async_req, fs_req); + uv_fs_req_cleanup(&req->fs_req); + if (*req->count == 0) return; + uv_fs_stat(uv_default_loop(), &req->fs_req, req->path, stat_cb); + (*req->count)--; +} + + +static void async_bench(const char* path) { + struct async_req reqs[MAX_CONCURRENT_REQS]; + struct async_req* req; + uint64_t before; + uint64_t after; + int count; + int i; + + for (i = 1; i <= MAX_CONCURRENT_REQS; i++) { + count = NUM_ASYNC_REQS; + + for (req = reqs; req < reqs + i; req++) { + req->path = path; + req->count = &count; + uv_fs_stat(uv_default_loop(), &req->fs_req, req->path, stat_cb); + } + + before = uv_hrtime(); + uv_run(uv_default_loop()); + after = uv_hrtime(); + + printf("%s stats (%d concurrent): %.2fs (%s/s)\n", + fmt(1.0 * NUM_ASYNC_REQS), + i, + (after - before) / 1e9, + fmt((1.0 * NUM_ASYNC_REQS) / ((after - before) / 1e9))); + fflush(stdout); + } +} + + +/* This benchmark aims to measure the overhead of doing I/O syscalls from + * the thread pool. The stat() syscall was chosen because its results are + * easy for the operating system to cache, taking the actual I/O overhead + * out of the equation. + */ +BENCHMARK_IMPL(fs_stat) { + const char path[] = "."; + warmup(path); + sync_bench(path); + async_bench(path); + return 0; +} diff --git a/deps/uv/test/benchmark-list.h b/deps/uv/test/benchmark-list.h index 32cd1ba1c..2e24682f6 100644 --- a/deps/uv/test/benchmark-list.h +++ b/deps/uv/test/benchmark-list.h @@ -44,6 +44,7 @@ BENCHMARK_DECLARE (udp_packet_storm_100v1000) BENCHMARK_DECLARE (udp_packet_storm_1000v1000) BENCHMARK_DECLARE (gethostbyname) BENCHMARK_DECLARE (getaddrinfo) +BENCHMARK_DECLARE (fs_stat) BENCHMARK_DECLARE (spawn) BENCHMARK_DECLARE (thread_create) BENCHMARK_DECLARE (million_timers) @@ -105,6 +106,8 @@ TASK_LIST_START BENCHMARK_ENTRY (getaddrinfo) + BENCHMARK_ENTRY (fs_stat) + BENCHMARK_ENTRY (spawn) BENCHMARK_ENTRY (thread_create) BENCHMARK_ENTRY (million_timers) diff --git a/deps/uv/uv.gyp b/deps/uv/uv.gyp index 63f3ec0e5..5b9273abb 100644 --- a/deps/uv/uv.gyp +++ b/deps/uv/uv.gyp @@ -404,6 +404,7 @@ 'dependencies': [ 'uv' ], 'sources': [ 'test/benchmark-ares.c', + 'test/benchmark-fs-stat.c', 'test/benchmark-getaddrinfo.c', 'test/benchmark-list.h', 'test/benchmark-loop-count.c', -- 2.34.1