зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1234126
- Add Chaos Mode support for setting thread affinity on OS X and Windows. r=froydnj
This commit is contained in:
Родитель
20b0a294c6
Коммит
72a9d3bf1f
|
@ -62,6 +62,11 @@
|
|||
#define HAVE_SCHED_SETAFFINITY
|
||||
#endif
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
#include <mach/mach.h>
|
||||
#include <mach/thread_policy.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_CANARY
|
||||
# include <unistd.h>
|
||||
# include <execinfo.h>
|
||||
|
@ -294,6 +299,31 @@ private:
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
SetThreadAffinity(unsigned int cpu)
|
||||
{
|
||||
#ifdef HAVE_SCHED_SETAFFINITY
|
||||
cpu_set_t cpus;
|
||||
CPU_ZERO(&cpus);
|
||||
CPU_SET(cpu, &cpus);
|
||||
sched_setaffinity(0, sizeof(cpus), &cpus);
|
||||
// Don't assert sched_setaffinity's return value because it intermittently (?)
|
||||
// fails with EINVAL on Linux x64 try runs.
|
||||
#elif defined(XP_MACOSX)
|
||||
// OS X does not provide APIs to pin threads to specific processors, but you
|
||||
// can tag threads as belonging to the same "affinity set" and the OS will try
|
||||
// to run them on the same processor. To run threads on different processors,
|
||||
// tag them as belonging to different affinity sets. Tag 0, the default, means
|
||||
// "no affinity" so let's pretend each CPU has its own tag `cpu+1`.
|
||||
thread_affinity_policy_data_t policy;
|
||||
policy.affinity_tag = cpu + 1;
|
||||
MOZ_ALWAYS_TRUE(thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY,
|
||||
&policy.affinity_tag, 1) == KERN_SUCCESS);
|
||||
#elif defined(XP_WIN)
|
||||
MOZ_ALWAYS_TRUE(SetThreadIdealProcessor(GetCurrentThread(), cpu) != -1);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
SetupCurrentThreadForChaosMode()
|
||||
{
|
||||
|
@ -321,15 +351,10 @@ SetupCurrentThreadForChaosMode()
|
|||
PR_SetThreadPriority(PR_GetCurrentThread(), PRThreadPriority(priority));
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SCHED_SETAFFINITY
|
||||
// Force half the threads to CPU 0 so they compete for CPU
|
||||
if (ChaosMode::randomUint32LessThan(2)) {
|
||||
cpu_set_t cpus;
|
||||
CPU_ZERO(&cpus);
|
||||
CPU_SET(0, &cpus);
|
||||
sched_setaffinity(0, sizeof(cpus), &cpus);
|
||||
SetThreadAffinity(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
|
|
Загрузка…
Ссылка в новой задаче