From 096a02d14cb9d3de6d55a29ec02c4dfcb7643c7f Mon Sep 17 00:00:00 2001 From: Piotr Kubaj Date: Tue, 8 Sep 2026 16:02:48 +0000 Subject: [PATCH] freebsd: don't fail uv_cpu_info() when hw.clockrate is missing (#5266) The hw.clockrate sysctl does not exist on all FreeBSD platforms: it is absent on powerpc64/powerpc64le, where uv_cpu_info() therefore fails and e.g. node's os.cpus() returns an empty array (while uv_available_parallelism() works fine). Anything sizing a worker pool from os.cpus().length silently gets zero workers there. Instead of failing the whole call, fall back to the cpufreq(4) driver's dev.cpu.0.freq (reports the current frequency in MHz, available on powernv machines) and finally to an unknown speed of 0, matching the existing ARM behavior. --- src/unix/freebsd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/unix/freebsd.c b/src/unix/freebsd.c index d7ac94b0c23..d2e7b57cca5 100644 --- a/src/unix/freebsd.c +++ b/src/unix/freebsd.c @@ -213,8 +213,14 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { model_key = "hw.model"; size = sizeof(cpuspeed); - if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) - return -errno; + if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) { + /* hw.clockrate is not available on all platforms (e.g. it is missing + * on PowerPC). Try the cpufreq(4) driver's current frequency and fall + * back to an unknown speed like on ARM instead of failing the call. */ + size = sizeof(cpuspeed); + if (sysctlbyname("dev.cpu.0.freq", &cpuspeed, &size, NULL, 0)) + cpuspeed = 0; + } #endif size = sizeof(model);