Skip to content

Commit ae8c90e

Browse files
committed
deps: prefer cpuinfo_cur_freq over scaling_cur_freq in uv_cpu_info()
On Linux, uv_cpu_info() reads the current CPU frequency for each core from /sys/devices/system/cpu/cpuN/cpufreq/scaling_cur_freq. On some modern AMD CPUs (EPYC, Ryzen 9000 series) running inside containers, reading scaling_cur_freq triggers an ACPI/SMM round-trip that can take ~20ms per core, making os.cpus() take 500-600ms on a 32-core system. The file cpuinfo_cur_freq exposes the same current frequency information but reads from a hardware-cached register, avoiding the costly ACPI round-trip. Prefer it when available and fall back to scaling_cur_freq for systems that do not expose cpuinfo_cur_freq. Fixes: #61998
1 parent 9145cc6 commit ae8c90e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

deps/uv/src/unix/linux.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,10 +1886,19 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
18861886
continue;
18871887

18881888
n++;
1889+
/* Prefer cpuinfo_cur_freq: it reads a hardware-cached value and avoids
1890+
* slow ACPI/SMM round-trips that scaling_cur_freq triggers on some AMD
1891+
* CPUs (especially inside containers), which can take ~20ms per core.
1892+
* Fall back to scaling_cur_freq when cpuinfo_cur_freq is not available.
1893+
*/
18891894
snprintf(buf, sizeof(buf),
1890-
"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq", cpu);
1891-
1895+
"/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_cur_freq", cpu);
18921896
fp = uv__open_file(buf);
1897+
if (fp == NULL) {
1898+
snprintf(buf, sizeof(buf),
1899+
"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq", cpu);
1900+
fp = uv__open_file(buf);
1901+
}
18931902
if (fp == NULL)
18941903
continue;
18951904

0 commit comments

Comments
 (0)