Apr
06
2009
0

FYP Development: Two Hours to Submission and…

I just went to Tilmitt‘s house to check out how well YakumoDemo would work (or if it would work at all) on a non-development machine.

At first, it was just crazy slow. When adding an object to the sphere, it would lock up for about a second or two. The framerate was averaging about 1.3fps. I opened perfmon to see what was going on, and saw that CPU usage was about 24%, but that figure was for all the cores. When I opened taskmgr I saw that the first core was being totally choked. But what was even more interesting was that when it started to get choked, YakumoDemo’s screen went black, then grey, then totally locked up.

It turned out that when taskmgr was active, it would always freeze when adding a new object to the sphere! I tried changing the affinity of the process to use only two of the four cores on his system and it was performing fine, just like at home. It chugged a bit but no real problem. Then I changed it to use only one core, and it was perfectly fast!! Keep in mind that all the threading code was totally unchanged.. the thing is still using about a dozen threads, but by throwing out all the other cores, it was dramatically faster! The only explanation I can imagine is Tilmitt’s: Vista’s threading model ends up moving threads between cores a lot. If there’s a lot else going on, maybe it takes a thread off a core and lets some other process use it, then tries to find a new core for the thread, which takes time? I don’t know…

Anyway, here’s the last-minute hack I put in to fix it:

// Due to some problem with either the Vista threading model,
// Havok's multithreading, or both, everything currently runs
// faster if only one core is used.
{
	// Find the number of cores available on this system.
	SYSTEM_INFO sysinfo;
	GetSystemInfo( &sysinfo );
	int cores = sysinfo.dwNumberOfProcessors;
	// Set this process to use only the last core.
	SetThreadAffinityMask( GetCurrentThread(), cores-1 );
}
No comments »
Written by in: University |

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com