diff --git a/src/poly/threading.h b/src/poly/threading.h index 4c8284bf5..d2208f6b1 100644 --- a/src/poly/threading.h +++ b/src/poly/threading.h @@ -23,6 +23,8 @@ namespace threading { // Gets the current high-performance tick count. uint64_t ticks(); +// TODO(benvanik): processor info API. + // Gets a stable thread-specific ID, but may not be. Use for informative // purposes only. uint32_t current_thread_id(); diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index d1b31f3f7..ed80ee3d8 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -478,8 +478,22 @@ void XThread::SetPriority(int32_t increment) { } void XThread::SetAffinity(uint32_t affinity) { - // TODO(benvanik): implement. - XELOGW("KeSetAffinityThread not implemented"); + // Affinity mask, as in SetThreadAffinityMask. + // Xbox thread IDs: + // 0 - core 0, thread 0 - user + // 1 - core 0, thread 1 - user + // 2 - core 1, thread 0 - sometimes xcontent + // 3 - core 1, thread 1 - user + // 4 - core 2, thread 0 - xaudio + // 5 - core 2, thread 1 - user + // TODO(benvanik): implement better thread distribution. + // NOTE: these are logical processors, not physical processors or cores. + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + if (system_info.dwNumberOfProcessors < 6) { + XELOGW("Too few processors - scheduling will be wonky"); + } + SetThreadAffinityMask(::GetCurrentThread(), affinity); } X_STATUS XThread::Resume(uint32_t* out_suspend_count) {