-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
415 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
|
||
struct cpuinfo_freebsd_topology { | ||
uint32_t packages; | ||
uint32_t cores; | ||
uint32_t threads; | ||
}; | ||
|
||
|
||
struct cpuinfo_freebsd_topology cpuinfo_freebsd_detect_topology(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
|
||
#include <sys/types.h> | ||
#include <sys/sysctl.h> | ||
|
||
#include <cpuinfo/log.h> | ||
#include <freebsd/api.h> | ||
|
||
|
||
|
||
struct cpuinfo_freebsd_topology cpuinfo_freebsd_detect_topology(void) { | ||
int threads = 1; | ||
size_t sizeof_threads = sizeof(threads); | ||
if (sysctlbyname("hw.ncpu", &threads, &sizeof_threads, NULL, 0) != 0) { | ||
cpuinfo_log_error("sysctlbyname(\"hw.ncpu\") failed: %s", strerror(errno)); | ||
} else if (threads <= 0) { | ||
cpuinfo_log_error("sysctlbyname(\"hw.ncpu\") returned invalid value %d", threads); | ||
} | ||
|
||
int cores = threads / 2; | ||
int packages = 1; | ||
|
||
cpuinfo_log_debug("freebsd topology: packages = %d, cores = %d, threads = %d", packages, (int) cores, (int) threads); | ||
struct cpuinfo_freebsd_topology topology = { | ||
.packages = (uint32_t) packages, | ||
.cores = (uint32_t) cores, | ||
.threads = (uint32_t) threads | ||
}; | ||
|
||
return topology; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.