From Marcel Pursche, "The problem is that when OpenThreads is build with the Linux pthreads implementation all threads inherit the processor affinity from their parent thread.
This behavior is also described in the pthreads man page (http://man7.org/linux/man-pages/man3/pthread_create.3.html): > > Linux-specific details > The new thread inherits copies of the calling thread's capability > sets (see capabilities(7)) and CPU affinity mask (see > sched_setaffinity(2)). > To prevent this behaviour I wrote a patch that explicitly sets the affinity mask to all cores of the system, if no specific affinity was defined with PThread::setProcessorAffinity(unsigned int) . Thank you! "
This commit is contained in:
parent
20c0292e97
commit
64979a0c1a
@ -149,7 +149,30 @@ private:
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) || defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY) || defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
|
||||
else
|
||||
{
|
||||
// BUG-fix for linux:
|
||||
// Each thread inherits the processor affinity mask from its parent thread.
|
||||
// We need to explicitly set it to all CPUs, if no affinity was specified.
|
||||
|
||||
cpu_set_t cpumask;
|
||||
CPU_ZERO( &cpumask );
|
||||
|
||||
for (int i = 0; i < OpenThreads::GetNumberOfProcessors(); ++i)
|
||||
{
|
||||
CPU_SET( i, &cpumask );
|
||||
}
|
||||
|
||||
#if defined(HAVE_PTHREAD_SETAFFINITY_NP)
|
||||
pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);
|
||||
#elif defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
|
||||
sched_setaffinity( 0, sizeof(cpumask), &cpumask );
|
||||
#elif defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
|
||||
sched_setaffinity( 0, &cpumask );
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
ThreadCleanupStruct tcs;
|
||||
tcs.thread = thread;
|
||||
|
Loading…
Reference in New Issue
Block a user