Page 1 of 1

Multithreading performance concern

Posted: Fri Nov 04, 2016 8:01 am
by Ycep
Before I write this in assembly, would this take less than a milisecond on 300mhz CPU?

(If MOV takes 1 cycle and CMP & JMP 2 cycles)

Code: Select all

void Scheduler()
{
	if(TickLeft)return;
	curThread.type=READY_THREAD;
	Thread thr=Pop();
	if(thr.type==READY_THREAD)
	{
		thr.type=EXECUTING_THREAD;
		if(ThreadAmount<14)TickLeft=Optimizer[ThreadAmount];
		else TickLeft=1000/ThreadAmount;
		curThread=thr;
	}
}
The best answer I could hear is less than 300ns on 300mhz.

Re: Multithreading performance concern

Posted: Fri Nov 04, 2016 8:26 am
by mallard
Which "300Mhz" CPU?

A 300Mhz ARM is going to be a lot slower than a 300Mhz Pentium II or AMD K7 (and even those will have different performance). There's also going to be the factor or RAM(/cache) performance, since even if the rest of the variables fit into registers "Optimizer[ThreadAmount]" will almost certainly use RAM.

It seems that this pseudo-C code amounts to less than 20 x86 instructions with 2 probable RAM fetches. None of those simple instructions will take more than 5 cycles on a Pentium II and there's nothing likely to trip up instruction prefetch. That seems to be congruent with your 300ns estimate; assuming both RAM fetches are cache-misses and you have PC100 SDRAM, that's another ~20ns. So, yes, well under 1ms on a typical x86 CPU of 300Mhz.

Re: Multithreading performance concern

Posted: Fri Nov 04, 2016 8:36 am
by Ycep
@mallard : Hell yeah!
That is actually good since there needs to be space for priority based tasks (group of threads).
Is 200hZ for this scheduler realiable enough?