From cdd34897cbf0d218b29c42800ba10ca42b873ed3 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Mon, 7 Mar 2022 16:18:13 -0800 Subject: [PATCH] Update to Libuv 1.44.0 Adds new function: `uv.available_parallelism` Full changelog at https://github.com/libuv/libuv/blob/v1.x/ChangeLog --- CMakeLists.txt | 2 +- deps/libuv | 2 +- docs.md | 12 ++++++++++++ src/luv.c | 3 +++ src/misc.c | 7 +++++++ tests/test-misc.lua | 5 +++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 813e3d1f..f1063581 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ endif() project (luv C ASM) set(LUV_VERSION_MAJOR 1) -set(LUV_VERSION_MINOR 43) +set(LUV_VERSION_MINOR 44) set(LUV_VERSION_PATCH 0) set(LUV_VERSION ${LUV_VERSION_MAJOR}.${LUV_VERSION_MINOR}.${LUV_VERSION_PATCH}) diff --git a/deps/libuv b/deps/libuv index 988f2bfc..d2bff508 160000 --- a/deps/libuv +++ b/deps/libuv @@ -1 +1 @@ -Subproject commit 988f2bfc4defb9a85a536a3e645834c161143ee0 +Subproject commit d2bff508457336d808ba7148b33088f6acbfe0a6 diff --git a/docs.md b/docs.md index 9615bc61..75d54f6b 100644 --- a/docs.md +++ b/docs.md @@ -3316,6 +3316,18 @@ Returns the resource usage. - `nvcsw` : `integer` (voluntary context switches) - `nivcsw` : `integer` (involuntary context switches) +### `uv.available_parallelism()` + +Returns an estimate of the default amount of parallelism a program should use. Always returns a non-zero value. + +On Linux, inspects the calling thread’s CPU affinity mask to determine if it has been pinned to specific CPUs. + +On Windows, the available parallelism may be underreported on systems with more than 64 logical CPUs. + +On other platforms, reports the number of CPUs that the operating system considers to be online. + +**Returns:** `integer` + ### `uv.cpu_info()` Returns information about the CPU(s) on the system as a table of tables for each diff --git a/src/luv.c b/src/luv.c index 1d23de02..6264262e 100644 --- a/src/luv.c +++ b/src/luv.c @@ -305,6 +305,9 @@ static const luaL_Reg luv_functions[] = { {"os_homedir", luv_os_homedir}, {"os_tmpdir", luv_os_tmpdir}, {"os_get_passwd", luv_os_get_passwd}, +#endif +#if LUV_UV_VERSION_GEQ(1, 44, 0) + {"available_parallelism", luv_available_parallelism}, #endif {"cpu_info", luv_cpu_info}, {"cwd", luv_cwd}, diff --git a/src/misc.c b/src/misc.c index 0bf71d5c..70020a4a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -221,6 +221,13 @@ static int luv_getrusage(lua_State* L) { return 1; } +#if LUV_UV_VERSION_GEQ(1, 44, 0) +static int luv_available_parallelism(lua_State* L) { + lua_pushinteger(L, uv_available_parallelism()); + return 1; +} +#endif + static int luv_cpu_info(lua_State* L) { uv_cpu_info_t* cpu_infos = NULL; int count = 0, i; diff --git a/tests/test-misc.lua b/tests/test-misc.lua index 17e7676b..2e6e1b1f 100644 --- a/tests/test-misc.lua +++ b/tests/test-misc.lua @@ -39,6 +39,11 @@ return require('lib/tap')(function (test) p(rusage) end) + test("uv.available_parallelism", function (print, p, expect, uv) + local available_parallelism = assert(uv.available_parallelism()) + p(available_parallelism) + end, "1.44.0") + test("uv.cpu_info", function (print, p, expect, uv) local info = assert(uv.cpu_info()) p(info)