unix: fix uv_cpu_info() error on FreeBSD
This commit updates the key used in uv_cpu_info() for ARM FreeBSD. Fixes: https://github.com/nodejs/node/issues/17995 Fixes: https://github.com/libuv/libuv/issues/1694 PR-URL: https://github.com/libuv/libuv/pull/1700 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
parent
15f29dc08f
commit
9241cc2977
@ -276,6 +276,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
||||
uv_cpu_info_t* cpu_info;
|
||||
const char* maxcpus_key;
|
||||
const char* cptimes_key;
|
||||
const char* model_key;
|
||||
char model[512];
|
||||
long* cp_times;
|
||||
int numcpus;
|
||||
@ -294,8 +295,20 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
||||
cptimes_key = "kern.cp_times";
|
||||
#endif
|
||||
|
||||
#if defined(__arm__) || defined(__aarch64__)
|
||||
/* The key hw.model and hw.clockrate are not available on FreeBSD ARM. */
|
||||
model_key = "hw.machine";
|
||||
cpuspeed = 0;
|
||||
#else
|
||||
model_key = "hw.model";
|
||||
|
||||
size = sizeof(cpuspeed);
|
||||
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0))
|
||||
return -errno;
|
||||
#endif
|
||||
|
||||
size = sizeof(model);
|
||||
if (sysctlbyname("hw.model", &model, &size, NULL, 0))
|
||||
if (sysctlbyname(model_key, &model, &size, NULL, 0))
|
||||
return -errno;
|
||||
|
||||
size = sizeof(numcpus);
|
||||
@ -308,12 +321,6 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
||||
|
||||
*count = numcpus;
|
||||
|
||||
size = sizeof(cpuspeed);
|
||||
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {
|
||||
uv__free(*cpu_infos);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of
|
||||
* ncpu.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user