Subject: SMP and threads question
To: None <port-sparc@netbsd.org, tech-kern@netbsd.org>
From: Michael Kukat <michael@unixiron.org>
List: tech-kern
Date: 01/29/2005 11:33:20
Hello,

i just wanted to know how good the new POSIX threads implementation in NetBSD
2.0 uses SMP and i was not too happy with the results:

Test box : SparcStation 20 with 2 SM71
Test program : A little test program in Objective C using Objective C API for
threads and related things.

Problem:

If i run my test program single-threaded, it eats up one CPU. The load on both
CPUs varies from 60:40 to 95:5. So the Process (with this single thread) is
scheduled over both CPUs. Overall, it eats about 100% CPU, as expected.

If i run more threads (tested with 2 and 8 threads), it looks the same, so the
machine is 50% idle over both CPUs. As the threads i create do this:

    if(run) {
      int x, y;
      y = 0;
      for(x = 0; x < 100000000; x ++) {
        y += x;
        if(x % 1000000 == 0) printf("%d\n", x);
      }
    }

there is no problem with some locking by mutex or so between the threads. I see
no reason why the scheduler should not put 2 threads on 2 CPUs to gain the full
power of the machine.

If i start 2 processes (eg. 2 bzip2), they are put on 2 CPUs correctly, 0% idle
is the result, as expected.

Is there a known problem with the thread scheduling, or does the objc API in
the gcc version shipped use userland threads? I'll try to compile this program
on some other OS on one of my multiprocessor boxes to see a difference.

To prove top is not telling crap i did a time on my test program:

single-threaded:
   54.85s real    54.53s user     0.08s system

2 threads:
   54.89s real    54.56s user     0.06s system

In the output of the printf() i see that both threads are running concurrently.

compiled with:
gcc -s -O2 -o thr thr.m -lobjc -pthread

Any hints welcome :)

...Michael

-- 
http://www.unixiron.org/    Home Powered by: (Net|Open|Free)BSD IRIX NonStop-UX
Solaris AIX HP-UX Tru64 MUNIX Ultrix VMS SINIX Dolphin_Unix OpenStep MacOS A/UX