-
Notifications
You must be signed in to change notification settings - Fork 1.2k
SR-10611: ProcessInfo.activeProcessorCount too high in containerised Linux #2215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…Linux - On Linux, use sched_getaffinity() falling back to sysconf(_SC_NPROCESSORS_ONLN) as this should provide a better value for ProcessInfo.activeProcessorCount when running under cgroups (eg Docker).
cc @ianpartridge Does this seem reasonable when running under Docker? The solutions used in other languages mentioned in https://bugs.swift.org/browse/SR-10611?filter=10905 seem to use this method. |
@swift-ci test |
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring the build related things, yes, this is the right way to query the CPU information under cgroups.
@@ -451,6 +454,14 @@ CF_PRIVATE CFIndex __CFActiveProcessorCount() { | |||
pcnt = 0; | |||
} | |||
#elif DEPLOYMENT_TARGET_LINUX | |||
|
|||
#ifdef _SCHED_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use cmake for this:
include(CheckSymbolExists)
include(CheckIncludeFile)
check_include_file("sched.h" HAVE_SCHED_H)
check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
@swift-ci test |
1 similar comment
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing the additional cleanups.
CoreFoundation/CMakeLists.txt
Outdated
if(HAVE_SCHED_GETAFFINITY) | ||
target_compile_definitions(CoreFoundation | ||
PRIVATE | ||
-DHAVE_SCHED_GETAFFINITY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A level of indentation would be nice.
@swift-ci test and merge |
1 similar comment
@swift-ci test and merge |
sysconf(_SC_NPROCESSORS_ONLN) as this should provide a better
value for ProcessInfo.activeProcessorCount when running under
cgroups (eg Docker).
Not sure if this is the best solution and will need an offline test in a Docker environment.