|
|
@ -235,12 +235,26 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { |
|
|
|
multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus, |
|
|
|
cur = 0; |
|
|
|
uv_cpu_info_t* cpu_info; |
|
|
|
const char* maxcpus_key; |
|
|
|
const char* cptimes_key; |
|
|
|
char model[512]; |
|
|
|
long* cp_times; |
|
|
|
int numcpus; |
|
|
|
size_t size; |
|
|
|
int i; |
|
|
|
|
|
|
|
#if defined(__DragonFly__) |
|
|
|
/* This is not quite correct but DragonFlyBSD doesn't seem to have anything
|
|
|
|
* comparable to kern.smp.maxcpus or kern.cp_times (kern.cp_time is a total, |
|
|
|
* not per CPU). At least this stops uv_cpu_info() from failing completely. |
|
|
|
*/ |
|
|
|
maxcpus_key = "hw.ncpu"; |
|
|
|
cptimes_key = "kern.cp_time"; |
|
|
|
#else |
|
|
|
maxcpus_key = "kern.smp.maxcpus"; |
|
|
|
cptimes_key = "kern.cp_times"; |
|
|
|
#endif |
|
|
|
|
|
|
|
size = sizeof(model); |
|
|
|
if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) { |
|
|
|
return uv__new_sys_error(errno); |
|
|
@ -262,19 +276,13 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { |
|
|
|
free(*cpu_infos); |
|
|
|
return uv__new_sys_error(errno); |
|
|
|
} |
|
|
|
|
|
|
|
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of ncpu */ |
|
|
|
size = sizeof(maxcpus); |
|
|
|
#ifdef __DragonFly__ |
|
|
|
if (sysctlbyname("hw.ncpu", &maxcpus, &size, NULL, 0) < 0) { |
|
|
|
if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0) < 0) { |
|
|
|
free(*cpu_infos); |
|
|
|
return uv__new_sys_error(errno); |
|
|
|
} |
|
|
|
#else |
|
|
|
if (sysctlbyname("kern.smp.maxcpus", &maxcpus, &size, NULL, 0) < 0) { |
|
|
|
free(*cpu_infos); |
|
|
|
return uv__new_sys_error(errno); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
size = maxcpus * CPUSTATES * sizeof(long); |
|
|
|
|
|
|
@ -284,7 +292,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { |
|
|
|
return uv__new_sys_error(ENOMEM); |
|
|
|
} |
|
|
|
|
|
|
|
if (sysctlbyname("kern.cp_times", cp_times, &size, NULL, 0) < 0) { |
|
|
|
if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0) < 0) { |
|
|
|
free(cp_times); |
|
|
|
free(*cpu_infos); |
|
|
|
return uv__new_sys_error(errno); |
|
|
|