-
Notifications
You must be signed in to change notification settings - Fork 26
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
2 changed files
with
34 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Check if the required APIs for thread pinning are available | ||
|
||
set(THREAD_PINNING_WORKS FALSE) | ||
if(UNIX) | ||
# Check if sched_getcpu/sched_setaffinity are available | ||
check_include_files("schedx.h" HEADER_AVAILABLE LANGUAGE CXX) | ||
if(${HEADER_AVAILABLE}) | ||
# we need to actually check the available symbols | ||
include(CheckSourceCompiles) | ||
check_source_compiles(CXX | ||
"#include <sched.h> | ||
int main() { | ||
int cpu_id = sched_getcpu(); | ||
int num_cpus = 4; | ||
const size_t size = CPU_ALLOC_SIZE(num_cpus); | ||
cpu_set_t mask; | ||
CPU_ZERO(&mask); | ||
CPU_SET(cpu_id, &mask); | ||
int err = sched_setaffinity(0, size, &mask); | ||
return 0; | ||
}" | ||
EXAMPLE_COMPILES) | ||
if(${EXAMPLE_COMPILES}) | ||
set(THREAD_PINNING_WORKS TRUE) | ||
endif() | ||
endif() | ||
elseif(WIN32) | ||
set(THREAD_PINNING_WORKS TRUE) | ||
endif() |