scsh-users
[Top] [All Lists]

Re: timing threads

To: scsh-news@zurich.ai.mit.edu
Subject: Re: timing threads
From: sgelkins@bellsouth.net (Steve Elkins)
Date: 27 Oct 2002 04:33:28 -0800
Organization: http://groups.google.com/
andreas.bernauer@gmx.de (Andreas Bernauer) wrote in message 
news:<20021025212528.B895@zxmbk34.extern.uni-tuebingen.de>...

> On my system the results look like this:
[...]
> 10000   10000   1.28    1.17    0.11
> 
> My system is a Linux 2.4.4-4GB.
> I am using the CVS version of scsh, 0.6.3.

Yes, I forgot to provide those details.  My system is OpenBSD
3.1-stable (on a 1.7GHz P4) and I'm using the 0.6.2 version of scsh.

Maybe I should raise the priority of trying the 0.6.3 version.

Anyway, looks like my test was bogus, since Stephen Ma sent me this:

--------8<--------8<--------8<--------8<--------8<--------8<--------8<--

Ugh... Like posix threads, scsh doesn't appear to have an implicit
"wait for all running threads to finish" when the main function exits,
so you're just timing the thread creation, not the context switches.

In fact, I can't see any equivalent of thread-join.... Hmmm, no
semaphores either. Ummm, try the following (corrected to run each loop
n times, rather than (n + 1) times :-):

========================================================================
#!/export/home/stephenm/exp-s/bin/scsh \
-o threads -o locks -o placeholders -e go -s
!#

;; ~/scsh/thread-fun.scm

(define (make-semaphore init)
  (let ((s (make-vector 3)))
    (vector-set! s 0 (make-lock))
    (vector-set! s 1 init)
    (vector-set! s 2 '())
    s))

(define (semaphore-add s)
  (obtain-lock (vector-ref s 0))
  (vector-set! s 1 (+ 1 (vector-ref s 1)))
  (if (and (< 0 (vector-ref s 1))
           (not (null? (vector-ref s 2))))
      (let ((p (car (vector-ref s 2))))
        (vector-set! s 2 (cdr (vector-ref s 2)))
        (placeholder-set! p #t)))
  (release-lock (vector-ref s 0)))

(define (semaphore-sub s)
  (let loop ()
    (obtain-lock (vector-ref s 0))
    (if (>= 0 (vector-ref s 1))
        (let ((p (make-placeholder)))
          (vector-set! s 2 (cons p (vector-ref s 2)))
          (release-lock (vector-ref s 0))
          (placeholder-value p)
          (loop)))
    (vector-set! s 1 (- (vector-ref s 1) 1))
    (release-lock (vector-ref s 0))))

(define (go prog+args)
  (let ((args (cdr prog+args)))
    (let* ((threads (string->number (car args)))
           (times (string->number (cadr args)))
           (s (make-semaphore (- 1 threads))))
      (let loop ((i 1))
        (spawn (lambda ()
                 (let loop ((i 1))
                   (relinquish-timeslice)
                   (if (< i times)
                       (loop (+ i 1))))
                 (semaphore-add s)
                 ))
        (if (< i threads)
            (loop (+ i 1))))
      (semaphore-sub s)
      )))
========================================================================

Results on my 500MHz P3: (only up to 1000 * 1000 [I need a faster box
:-)])

Threads Times   Real    User    System
10      10      0.23    0.19    0.03
10      100     0.31    0.24    0.03
10      1000    1.22    1.05    0.10
10      10000   9.74    9.53    0.13
100     10      0.48    0.44    0.02
100     100     2.72    2.57    0.07
100     1000    25.13   24.26   0.19
100     10000   248.49  242.14  0.15
1000    10      20.28   18.19   0.11
1000    100     173.49  172.19  0.09
1000    1000    1749.48 1707.62 0.64

--------8<--------8<--------8<--------8<--------8<--------8<--------8<--

I starting Stephen's code yesterday morning and it's still cranking
away.  Here's a little output from top...

  PID USERNAME PRI NICE  SIZE   RES STATE WAIT     TIME    CPU COMMAND
31054 sge       72    4   19M   19M run   -      360:15 98.78% scshvm

...and here is the output so far...

Threads Times   Real    User    System
10      10      0.08    0.05    0.03
10      100     0.11    0.09    0.01
10      1000    0.47    0.44    0.02
10      10000   3.75    3.63    0.06
100     10      0.16    0.14    0.02
100     100     0.97    0.90    0.05
100     1000    8.62    8.46    0.05
100     10000   84.91   84.22   0.03
1000    10      6.35    6.25    0.04
1000    100     58.99   58.33   0.05
1000    1000    587.22  581.71  0.10
1000    10000   5872.14 5809.30 0.44
10000   10      564.78  556.06  0.14
10000   100     5759.76 5691.78 0.44
10000   1000    57282.53        56623.52        3.49


The times don't interest me as much as the fact that it's still making
headway.  Scsh is impressive.

Steve

<Prev in Thread] Current Thread [Next in Thread>