From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,ad26e6e70c712fe9 X-Google-Attributes: gidfee84,public From: Dave Butenhof Subject: Re: Kernel multithreading. Date: 1997/03/18 Message-ID: <332EB6D5.794B@zko.dec.com>#1/1 X-Deja-AN: 226454441 References: <5gju7p$i2e@news.ox.ac.uk> Organization: Digital Equipment Corporation Newsgroups: comp.unix.osf.osf1 Rick Heylen wrote: > > I'm writing a multithreaded program on a 4 CPU Digital UNIX 4.0 system. > When I view the running process using ps -m I see that two extra threads > are created by any process compiled with cc -pthread. I presume that they > babysit any threads the user creates explicitly. I can bind the threads to > cpus and they do appear to be bound when viewing with ps -m -Opsr but the > percentage cpu usage is never above 100%. In other words, the > multithreading is not taking advantage of the multiprocessor nature of my > machine and runs very slowly. > Can somebody please explain how the threading is implemented please? There are a lot of possible explanations. One is that the application isn't "compute-bound" enough to get the usage over 100%, even though it maybe getting time on several processors. Another is that your application is hitting a few relatively obscure bugs in 4.0, of that annoying class that never happens during testing but that an astonishing number of actual users hit. In particular, there were cases where a newly runnable thread might not be scheduled onto an idle "virtual processor". If you're really running 4.0, you should update to 4.0B, or 4.0A, or at least install all the 4.0 patches. > One of the sysadmins mentioned something about a change in the > implementation of multithreading with the new POSIX or something so I > accepted that real multiprocessor multithreading might be impossible. > I see however that dxmandel found in /usr/bin/X11/demos/dxmandel does > multithread properly. As I said, your application may have just gotten "unlucky". > erm0>ps -mp 8376 -Opcpu > PID %CPU S TTY TIME COMMAND > 8376 216.1 R N ?? 15:03:04 dxmandel > 0.0 I N 0:00.15 > 0.0 I N 0:00.00 > 44.2 R N 03:44:58 > 0.0 I N 0:00.16 > 49.1 R N 03:46:17 > 48.1 R N 03:46:45 > 74.7 R N 03:45:02 This information doesn't mean the same thing it would have meant prior to 4.0. In earlier versions, threads were mapped 1-to-1 on kernel threads, so ps showed all the threads in the application. That's no longer true, because your threads are mapped onto kernel threads temporarily, only when they can do work. Threads that block in user mode, or that are waiting for access to a kernel thread, don't show in ps at all. Threads that block in the kernel, however, do show in ps until the blocking condition completes (e.g., an I/O). A thread that blocks in the kernel is replaced by a new kernel thread, so that we can schedule a new user thread on the (presumably) vacated CPU. Our integration between user and kernel schedulers still isn't perfect, but, even in 4.0, it worked well for most applications. > I would like to know how to make my multithreaded programs run properly > over multiple processors. Can anybody help? > > Rick /---[ Dave Butenhof ]-----------------------[ butenhof@zko.dec.com ]---\ | Digital Equipment Corporation 110 Spit Brook Rd ZKO2-3/Q18 | | 603.881.2218, FAX 603.881.0120 Nashua NH 03062-2698 | \-----------------[ Better Living Through Concurrency ]----------------/