* [pthreads] performance test using fib.scm
@ 2002-12-10 18:16 Mikael Djurfeldt
2002-12-10 21:10 ` Wolfgang Jaehrling
[not found] ` <200212110202.gBB22Et27423@mule.m17n.org>
0 siblings, 2 replies; 10+ messages in thread
From: Mikael Djurfeldt @ 2002-12-10 18:16 UTC (permalink / raw)
Cc: djurfeldt
In the announcement of the pthreads support, I attached a program
fib.scm:
(define (par-fib n n-forks)
(cond ((<= n 1) 1)
((> n-forks 0)
(letpar ((f1 (par-fib (- n 1) (- n-forks 1)))
(f2 (par-fib (- n 2) (- n-forks 1))))
(+ f1 f2)))
(else
(let ((f1 (mono-fib (- n 1)))
(f2 (mono-fib (- n 2))))
(+ f1 f2)))))
(define (mono-fib n)
(let iter ((f1 1) (f2 1) (i 1))
(if (>= i n)
f2
(iter f2 (+ f1 f2) (+ 1 i)))))
When I run this with a Guile compiled with COPT threads, it invariably
takes around 12 s to run (par-fib 40000 1) on my dual CPU machine.
"Top" reports 50% of CPU capacity usage during calculation.
With the new pthreads support (which now allows for real SMP), it
takes 2.6 s and top says 91%!
Still, for large fibonnaci numbers and large branch depths (many
threads), Guile often crashes in realloc. That function should be
thread safe, shouldn't it? Maybe we're trashing up the heap somewhere
else...
Anyone keen on some debugging? :-)
Mikael
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-10 21:10 ` Wolfgang Jaehrling
@ 2002-12-10 20:10 ` Mikael Djurfeldt
2002-12-11 20:05 ` Christopher Cramer
2002-12-11 5:02 ` Maciej Stachowiak
1 sibling, 1 reply; 10+ messages in thread
From: Mikael Djurfeldt @ 2002-12-10 20:10 UTC (permalink / raw)
Cc: djurfeldt
Wolfgang Jaehrling <pro-linux@gmx.de> writes:
> malloc() in glibc is thread-save, but not reentrant. Since the
> behaviour of realloc() is unlikely to differ from malloc() in this
> respect, you most certainly have to protect calls to it with a lock.
2002-12-10 Mikael Djurfeldt <mdj@kvast.blakulla.net>
* gc-malloc.c (malloc_mutex): New mutex.
(scm_gc_init_malloc): Initialize it.
(scm_realloc): Serialize call to realloc
(scm_calloc): Same for calloc.
Thanks to Wolfgang Jaehrling!
(Now we have to make sure all calls to malloc/realloc are made
through scm_malloc.)
How about "free"?
Best regards,
Mikael D.
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-10 18:16 [pthreads] performance test using fib.scm Mikael Djurfeldt
@ 2002-12-10 21:10 ` Wolfgang Jaehrling
2002-12-10 20:10 ` Mikael Djurfeldt
2002-12-11 5:02 ` Maciej Stachowiak
[not found] ` <200212110202.gBB22Et27423@mule.m17n.org>
1 sibling, 2 replies; 10+ messages in thread
From: Wolfgang Jaehrling @ 2002-12-10 21:10 UTC (permalink / raw)
Cc: guile-devel
On Tue, Dec 10, 2002 at 07:16:04PM +0100, Mikael Djurfeldt wrote:
> Still, for large fibonnaci numbers and large branch depths (many
> threads), Guile often crashes in realloc. That function should be
> thread safe, shouldn't it?
malloc() in glibc is thread-save, but not reentrant. Since the
behaviour of realloc() is unlikely to differ from malloc() in this
respect, you most certainly have to protect calls to it with a lock.
Cheers,
GNU/Wolfgang
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-10 21:10 ` Wolfgang Jaehrling
2002-12-10 20:10 ` Mikael Djurfeldt
@ 2002-12-11 5:02 ` Maciej Stachowiak
2002-12-11 7:11 ` Mikael Djurfeldt
1 sibling, 1 reply; 10+ messages in thread
From: Maciej Stachowiak @ 2002-12-11 5:02 UTC (permalink / raw)
Cc: Mikael Djurfeldt
On 10Dec2002 10:10PM (+0100), Wolfgang Jaehrling wrote:
> On Tue, Dec 10, 2002 at 07:16:04PM +0100, Mikael Djurfeldt wrote:
> > Still, for large fibonnaci numbers and large branch depths (many
> > threads), Guile often crashes in realloc. That function should be
> > thread safe, shouldn't it?
>
> malloc() in glibc is thread-save, but not reentrant. Since the
> behaviour of realloc() is unlikely to differ from malloc() in this
> respect, you most certainly have to protect calls to it with a lock.
>
Huh? Doesn't malloc do it's own locking when modifying global data
structures?
- Maciej
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-11 5:02 ` Maciej Stachowiak
@ 2002-12-11 7:11 ` Mikael Djurfeldt
2002-12-11 13:48 ` Maciej Stachowiak
2002-12-11 16:59 ` Wolfgang Jaehrling
0 siblings, 2 replies; 10+ messages in thread
From: Mikael Djurfeldt @ 2002-12-11 7:11 UTC (permalink / raw)
Cc: guile-devel
Maciej Stachowiak <mjs@noisehavoc.org> writes:
> On 10Dec2002 10:10PM (+0100), Wolfgang Jaehrling wrote:
>> malloc() in glibc is thread-save, but not reentrant. Since the
>> behaviour of realloc() is unlikely to differ from malloc() in this
>> respect, you most certainly have to protect calls to it with a lock.
>>
>
> Huh? Doesn't malloc do it's own locking when modifying global data
> structures?
This is what I would have expected.
Can someone please verify that malloc is reentrant?
Best regards,
Mikael D.
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-11 7:11 ` Mikael Djurfeldt
@ 2002-12-11 13:48 ` Maciej Stachowiak
2002-12-11 23:43 ` Han-Wen Nienhuys
2002-12-11 16:59 ` Wolfgang Jaehrling
1 sibling, 1 reply; 10+ messages in thread
From: Maciej Stachowiak @ 2002-12-11 13:48 UTC (permalink / raw)
Cc: Maciej Stachowiak
On 11Dec2002 08:11AM (+0100), Mikael Djurfeldt wrote:
> Maciej Stachowiak <mjs@noisehavoc.org> writes:
>
> > On 10Dec2002 10:10PM (+0100), Wolfgang Jaehrling wrote:
> >> malloc() in glibc is thread-save, but not reentrant. Since the
> >> behaviour of realloc() is unlikely to differ from malloc() in this
> >> respect, you most certainly have to protect calls to it with a lock.
> >>
> >
> > Huh? Doesn't malloc do it's own locking when modifying global data
> > structures?
>
> This is what I would have expected.
>
> Can someone please verify that malloc is reentrant?
According to the best info I can find on Google, glibc's malloc can be
called safely from multiple threads but cannot necessarily safely be
called from a signal handler (another possible definition of
re-entrant). A mutex would not help with calling it from a signal
handler anyway, though. So don't bother with locking.
If you truly suspect heap corruption I suggest running with
MALLOC_CHECK_=2 set in your environment. This should detect many kinds
of heap corruption.
Regards,
Maciej
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-11 7:11 ` Mikael Djurfeldt
2002-12-11 13:48 ` Maciej Stachowiak
@ 2002-12-11 16:59 ` Wolfgang Jaehrling
1 sibling, 0 replies; 10+ messages in thread
From: Wolfgang Jaehrling @ 2002-12-11 16:59 UTC (permalink / raw)
Cc: Maciej Stachowiak
On Wed, Dec 11, 2002 at 08:11:50AM +0100, Mikael Djurfeldt wrote:
> Can someone please verify that malloc is reentrant?
<http://sources.redhat.com/ml/libc-alpha/2002-11/msg00325.html>
Cheers,
GNU/Wolfgang
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
[not found] ` <200212110202.gBB22Et27423@mule.m17n.org>
@ 2002-12-11 17:27 ` Wolfgang Jaehrling
0 siblings, 0 replies; 10+ messages in thread
From: Wolfgang Jaehrling @ 2002-12-11 17:27 UTC (permalink / raw)
Cc: guile-devel
On Wed, Dec 11, 2002 at 11:02:14AM +0900, NIIBE Yutaka wrote:
> Wolfgang Jaehrling wrote:
> > malloc() in glibc is thread-save, but not reentrant. Since the
> > behaviour of realloc() is unlikely to differ from malloc() in this
> > respect, you most certainly have to protect calls to it with a lock.
>
> I think that we need some definition of terminology to avoid
> confusion. You mean signal protection, with the word "lock", not a
> mutex, don't you?
Yes. However, that malloc() in glibc is thread-save does not imply
that this is the case for other libc:s as well, so a mutex _might_
still be necessary for some systems. If guile does not call malloc()
(or realloc()) from a signal handler, then it is supposed to not be a
problem for GNU/Linux and GNU/Hurd (and other systems using glibc).
Cheers,
GNU/Wolfgang
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-10 20:10 ` Mikael Djurfeldt
@ 2002-12-11 20:05 ` Christopher Cramer
0 siblings, 0 replies; 10+ messages in thread
From: Christopher Cramer @ 2002-12-11 20:05 UTC (permalink / raw)
Cc: guile-devel
On Tue, Dec 10, 2002 at 09:10:37PM +0100, Mikael Djurfeldt wrote:
> Wolfgang Jaehrling <pro-linux@gmx.de> writes:
>
> > malloc() in glibc is thread-save, but not reentrant. Since the
> > behaviour of realloc() is unlikely to differ from malloc() in this
> > respect, you most certainly have to protect calls to it with a lock.
>
> 2002-12-10 Mikael Djurfeldt <mdj@kvast.blakulla.net>
>
> * gc-malloc.c (malloc_mutex): New mutex.
> (scm_gc_init_malloc): Initialize it.
> (scm_realloc): Serialize call to realloc
> (scm_calloc): Same for calloc.
> Thanks to Wolfgang Jaehrling!
> (Now we have to make sure all calls to malloc/realloc are made
> through scm_malloc.)
Every pthreads implementation is required to have a thread-safe malloc,
calloc, realloc and free (along with many other functions). The fact
that malloc etc. are non-reentrant only means that you shouldn't call
them from a signal handler.
Any pthreads implementation that requires you to lock a mutex to call
malloc is broken.
--
Christopher Cramer <crayc@pyro.net> <http://www.pyro.net/~crayc/>
"Gore would have finished ahead by the barest of margins had he pursued
and gained a complete statewide recount." -- Associated Press, 9/6/2002
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pthreads] performance test using fib.scm
2002-12-11 13:48 ` Maciej Stachowiak
@ 2002-12-11 23:43 ` Han-Wen Nienhuys
0 siblings, 0 replies; 10+ messages in thread
From: Han-Wen Nienhuys @ 2002-12-11 23:43 UTC (permalink / raw)
Cc: guile-devel
mjs@noisehavoc.org writes:
> If you truly suspect heap corruption I suggest running with
> MALLOC_CHECK_=2 set in your environment. This should detect many kinds
> of heap corruption.
for that matter, valgrind is even better: it detects other kinds of
errors.
--
Han-Wen Nienhuys | hanwen@cs.uu.nl | http://www.cs.uu.nl/~hanwen
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2002-12-11 23:43 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-10 18:16 [pthreads] performance test using fib.scm Mikael Djurfeldt
2002-12-10 21:10 ` Wolfgang Jaehrling
2002-12-10 20:10 ` Mikael Djurfeldt
2002-12-11 20:05 ` Christopher Cramer
2002-12-11 5:02 ` Maciej Stachowiak
2002-12-11 7:11 ` Mikael Djurfeldt
2002-12-11 13:48 ` Maciej Stachowiak
2002-12-11 23:43 ` Han-Wen Nienhuys
2002-12-11 16:59 ` Wolfgang Jaehrling
[not found] ` <200212110202.gBB22Et27423@mule.m17n.org>
2002-12-11 17:27 ` Wolfgang Jaehrling
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).