[haiku-3rdparty-dev] Re: Multi-Threaded Code

  • From: "Andrew Hudson" <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "hudsonco1" for DMARC)
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Sun, 17 Apr 2016 21:13:02 -0400




At the moment I am developing a multi-threaded compressor on Haiku-OS.

How despise the machine being a I7 with four real CPUs and four virtual CPUs I 
don't see a real speedup once I configure to run with more than four >threads.

Between one to four threads i see a real speedup of the compression, but after 
that the speedup slows down a lot.

Since I am running the threads at NORMAL_PRIORITY I was expecting the 
slow-down to take place after I had eight threads running.

However, I am running the each thread to wait on it's command queue using a 
snooze(1LL) inside the loop.  Even then I am using a lot of CPU time >in the 
loops. Add in the cache misses because different threads are accessing 
different memory areas and I am not surprised that the threads use a >lot of 
CPU while idling.

What I wanted to asked before doing a major rewrite, does anyone know if 
resume_thread() and suspend_thread() are very fast calls?


I think what you are experiencing is what is expected. If you have 4 cores and 
4 hyperthreaded cores, you will only see additional performance benefits using 
the virtual cores if your code is not very optimized. If your code is 
well-written and makes use of Intel vector instructions, you can actually see a 
performance drop when using more than 4 cores. 


Regards,
Andrew




Other related posts: