mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-03 11:42:28 +00:00
Fix CPU count detection in FreeBSD & NetBSD
This commit is contained in:
@@ -920,7 +920,7 @@ get_page_size :: proc() -> int {
|
||||
_processor_core_count :: proc() -> int {
|
||||
count : int = 0
|
||||
count_size := size_of(count)
|
||||
if _sysctlbyname("hw.logicalcpu", &count, &count_size, nil, 0) == 0 {
|
||||
if _sysctlbyname("hw.ncpu", &count, &count_size, nil, 0) == 0 {
|
||||
if count > 0 {
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -978,7 +978,7 @@ get_page_size :: proc() -> int {
|
||||
_processor_core_count :: proc() -> int {
|
||||
count : int = 0
|
||||
count_size := size_of(count)
|
||||
if _sysctlbyname("hw.logicalcpu", &count, &count_size, nil, 0) == 0 {
|
||||
if _sysctlbyname("hw.ncpu", &count, &count_size, nil, 0) == 0 {
|
||||
if count > 0 {
|
||||
return count
|
||||
}
|
||||
|
||||
12
src/gb/gb.h
12
src/gb/gb.h
@@ -3195,11 +3195,11 @@ void gb_affinity_init(gbAffinity *a) {
|
||||
a->core_count = 1;
|
||||
a->threads_per_core = 1;
|
||||
|
||||
if (sysctlbyname("hw.logicalcpu", &count, &count_size, NULL, 0) == 0) {
|
||||
if (sysctlbyname("kern.smp.cpus", &count, &count_size, NULL, 0) == 0) {
|
||||
if (count > 0) {
|
||||
a->thread_count = count;
|
||||
// Get # of physical cores
|
||||
if (sysctlbyname("hw.physicalcpu", &count, &count_size, NULL, 0) == 0) {
|
||||
if (sysctlbyname("kern.smp.cores", &count, &count_size, NULL, 0) == 0) {
|
||||
if (count > 0) {
|
||||
a->core_count = count;
|
||||
a->threads_per_core = a->thread_count / count;
|
||||
@@ -3210,6 +3210,14 @@ void gb_affinity_init(gbAffinity *a) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (sysctlbyname("hw.ncpu", &count, &count_size, NULL, 0) == 0) {
|
||||
// SMP disabled or unavailable.
|
||||
if (count > 0) {
|
||||
a->is_accurate = true;
|
||||
a->thread_count = count;
|
||||
a->core_count = count;
|
||||
a->threads_per_core = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user