Re: [Algorithms] Threading by software emulation
Brought to you by:
vexxed72
From: Jon W. <hp...@mi...> - 2008-05-23 20:47:00
|
Sebastian Lucas wrote: > Each 4000 instructions I was switching them in this way: > 1) Save the current registers, pc to the current thread. > 2) Stop the current thread. > 3) Find another one. > 4) Copy the registers, pc to the cpu module. > 5) Make it the current one. > 6) Continue until we reach again the 4000 instructions executed. > I think 4000 instructions is way too often for good performance. Try switching every 100,000 or even every 500,000 instructions, in addition to explicit switching if there's a blocking call. I don't know the exact behavior of the PS/2 scheduler, though, so perhaps that won't be compatible, but I would assume you want to run until you block in most cases. Also, I would implement context switch by storing PC, registers and other state in a struct, and allocate a new struct for each thread context. Instead of copying the context around, I would just use a pointer to the current context, and set that pointer to point to another context. Given that you probably are using a pointer to the current context anyway, that should not introduce any overhead in the innards of the emulator (other than host CPU cache misses on switch). Sincerely, jw |