Re: pthread_getspecific is too slow

2013-11-02 Thread Ted Unangst
On Mon, Sep 30, 2013 at 10:38, John Carr wrote: Here is a diff relative of OpenBSD 5.3 to avoid taking a lock in pthread_getspecific in the common case where storage for the key is already allocated. I have only tested this patch for my use case where a single key is created once and used

Re: pthread_getspecific is too slow

2013-09-30 Thread John Carr
Here is a diff relative of OpenBSD 5.3 to avoid taking a lock in pthread_getspecific in the common case where storage for the key is already allocated. I have only tested this patch for my use case where a single key is created once and used many times. In that case, the bottleneck I observed is

Re: pthread_getspecific is too slow

2013-09-30 Thread John Carr
I got an email saying unified diff is preferred, so here's a resend in that format. Index: rthread_tls.c === RCS file: /cvs/src/lib/librthread/rthread_tls.c,v retrieving revision 1.13 diff -u -r1.13 rthread_tls.c --- rthread_tls.c 6

Re: pthread_getspecific is too slow

2013-09-26 Thread John Carr
I attached a program showing the slowdown. It spawns threads that call pthread_getspecific in a tight loop. On Linux the wall clock time is essentially constant for number of threads up to number of processors. On OpenBSD 5.3 wall clock time increases approximately linearly with number of

Re: pthread_getspecific is too slow

2013-09-26 Thread John Carr
I think _spinlock is suboptimal, although that's not the real problem as far as my code is concerned. Spinlock is a loop: while (_atomic_lock(lock-ticket)) _sched_yield(); This causes a system call every time the lock is held by another thread. In many cases the spinlock protects a simple

Re: pthread_getspecific is too slow

2013-09-25 Thread Ted Unangst
We haven't done a lot of work to optimize performance except in response to specific issues. Sounds like you found one. Would you mind providing a test case? I just want to make sure we fix the right thing. On Wed, Sep 25, 2013 at 13:12, John Carr wrote: Problem in a nutshell: