Skip to content

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

Merged
merged 2 commits into from
May 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CoreFoundation/Base.subproj/CFUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
#include <pthread.h>
#endif

#if DEPLOYMENT_TARGET_LINUX && __has_include(<sched.h>)
#include <sched.h>
#endif


#if !defined(CF_HAVE_HW_CONFIG_COMMPAGE) && defined(_COMM_PAGE_LOGICAL_CPUS) && defined(_COMM_PAGE_PHYSICAL_CPUS) && defined(_COMM_PAGE_ACTIVE_CPUS) && !__has_feature(address_sanitizer)
Expand Down Expand Up @@ -451,6 +454,14 @@ CF_PRIVATE CFIndex __CFActiveProcessorCount() {
pcnt = 0;
}
#elif DEPLOYMENT_TARGET_LINUX

#ifdef _SCHED_H
Copy link
Member

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)

cpu_set_t set;
if (sched_getaffinity (getpid(), sizeof(set), &set) == 0) {
return CPU_COUNT (&set);
}
#endif

pcnt = sysconf(_SC_NPROCESSORS_ONLN);
#else
// Assume the worst
Expand Down