Index: viewer.cpp =================================================================== --- viewer.cpp (revision 56551) +++ viewer.cpp (working copy) @@ -3522,6 +3522,69 @@ // here. request_initial_instant_messages(); + +#if LL_WINDOWS + // Process affinity hack to make SL perform better on multi-core systems + static DWORD dwOriginalProcessAffinityMask = 0; + static DWORD dwCurrentAffinityMask = 0; + static U32 u32FrameAffinitySet = 0; + + if ((u32FrameAffinitySet == 0) && (!gTeleportDisplay) && (gFrameCount >= 30)) //gStartupState == STATE_FIRST) + { + // Observation from my Athlon 64 X2 4200+ and Intel Core 2 Duo E6600 based machines: + // - launch Second Life + // - connect + // - observe frame rate of n FPS + // - using task manager force SL to run on CPU core #0 + // - observe frame rate of 2*n FPS + // - using task manager force SL to run on both CPU core #0 and #1 + // - observe frame rate of 3*n FPS + // + // If you repeat the above experiment without connecting to SL first then once you + // connect to SL your framerate will still be about 1/3 of what it should be. + // + // So the goal here is to perform that task manager hack in code until we can find + // the real problem and correct it. + + HANDLE hProcess = GetCurrentProcess(); + DWORD dwSystemAffinityMask = 0; + + if (GetProcessAffinityMask(hProcess, &dwOriginalProcessAffinityMask, &dwSystemAffinityMask) != 0) + { + // Find the first available processor + for (int i = 0; i < 32; i++) + { + if ((dwOriginalProcessAffinityMask & (1 << i)) != 0) + { + dwCurrentAffinityMask = 1 << i; + break; + } + } + + // Tell SL to only run on that processor + SetProcessAffinityMask(hProcess, dwCurrentAffinityMask); + + u32FrameAffinitySet = gFrameCount; + } + + CloseHandle(hProcess); // Not required, but here for future compatibility since someday GetCurrentProcess() may not return a pseudo-handle + } + + if ((dwCurrentAffinityMask != dwOriginalProcessAffinityMask) && (u32FrameAffinitySet != 0) && (gFrameCount >= u32FrameAffinitySet + 30) && (!gTeleportDisplay)) //(dwCurrentAffinityMask != dwOriginalProcessAffinityMask) && (gStartupState == STATE_STARTED)) + { + HANDLE hProcess = GetCurrentProcess(); + + dwCurrentAffinityMask = dwOriginalProcessAffinityMask; + + // Now run on whatever processor(s) SL was running on + SetProcessAffinityMask(hProcess, dwCurrentAffinityMask); + + CloseHandle(hProcess); // Not required, but here for future compatibility since someday GetCurrentProcess() may not return a pseudo-handle + } +#endif // LL_WINDOWS + + + /////////////////////////////////// // // Special case idle if still starting up