summaryrefslogtreecommitdiffstats
path: root/lib/libthr
Commit message (Collapse)AuthorAgeFilesLines
...
* Create a common function lookup() to search a chan, this eliminatesdavidxu2012-05-101-5/+9
| | | | redundant SC_LOOKUP() calling.
* Fix mis-merged line, move SC_LOOKUP() call todavidxu2012-05-051-1/+1
| | | | upper level.
* MFp4:davidxu2012-05-033-1/+10
| | | | | | | Enqueue thread in LIFO, this can cause starvation, but it gives better performance. Use _thr_queuefifo to control the frequency of FIFO vs LIFO, you can use environment string LIBPTHREAD_QUEUE_FIFO to configure the variable.
* Set SIGCANCEL to SIGTHR as part of some cleanup of DTrace code.gnn2012-04-181-1/+1
| | | | | Reviewed by: davidxu@ MFC after: 1 week
* umtx operation UMTX_OP_MUTEX_WAKE has a side-effect that it accessesdavidxu2012-04-052-5/+18
| | | | | | | | | | | | | | | | | | | | | a mutex after a thread has unlocked it, it event writes data to the mutex memory to clear contention bit, there is a race that other threads can lock it and unlock it, then destroy it, so it should not write data to the mutex memory if there isn't any waiter. The new operation UMTX_OP_MUTEX_WAKE2 try to fix the problem. It requires thread library to clear the lock word entirely, then call the WAKE2 operation to check if there is any waiter in kernel, and try to wake up a thread, if necessary, the contention bit is set again by the operation. This also mitgates the chance that other threads find the contention bit and try to enter kernel to compete with each other to wake up sleeping thread, this is unnecessary. With this change, the mutex owner is no longer holding the mutex until it reaches a point where kernel umtx queue is locked, it releases the mutex as soon as possible. Performance is improved when the mutex is contensted heavily. On Intel i3-2310M, the runtime of a benchmark program is reduced from 26.87 seconds to 2.39 seconds, it even is better than UMTX_OP_MUTEX_WAKE which is deprecated now. http://people.freebsd.org/~davidxu/bench/mutex_perf.c
* libthr: In the atfork handlers for signals, do not skip the last signal.jilles2012-03-261-3/+3
| | | | | | | | _SIG_MAXSIG works a bit unexpectedly: signals 1 till _SIG_MAXSIG are valid, both bounds inclusive. Reviewed by: davidxu MFC after: 1 week
* Use clockid parameter instead of hard-coded CLOCK_REALTIME.davidxu2012-03-191-1/+1
| | | | Reported by: pjd
* Some software think a mutex can be destroyed after it owned it, fordavidxu2012-03-181-7/+0
| | | | | | | | | | | example, it uses a serialization point like following: pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&muetx); They think a previous lock holder should have already left the mutex and is no longer referencing it, so they destroy it. To be maximum compatible with such code, we use IA64 version to unlock the mutex in kernel, remove the two steps unlocking code.
* When destroying a barrier, waiting all threads exit the barrier,davidxu2012-03-162-4/+31
| | | | | this makes it possible a thread received PTHREAD_BARRIER_SERIAL_THREAD immediately free memory area of the barrier.
* - Switch to saving non-offseted pointer to TLS block in order too keep ↵gonzo2012-03-061-8/+4
| | | | things simple
* Follow changes made in revision 232144, pass absolute timeout to kernel,davidxu2012-02-273-30/+37
| | | | this eliminates a clock_gettime() syscall.
* In revision 231989, we pass a 16-bit clock ID into kernel, howeverdavidxu2012-02-251-17/+32
| | | | | | | | | | | | according to POSIX document, the clock ID may be dynamically allocated, it unlikely will be in 64K forever. To make it future compatible, we pack all timeout information into a new structure called _umtx_time, and use fourth argument as a size indication, a zero means it is old code using timespec as timeout value, but the new structure also includes flags and a clock ID, so the size argument is different than before, and it is non-zero. With this change, it is possible that a thread can sleep on any supported clock, though current kernel code does not have such a POSIX clock driver system.
* Use unused fourth argument of umtx_op to pass flags to kernel for operationdavidxu2012-02-221-13/+3
| | | | | | UMTX_OP_WAIT. Upper 16bits is enough to hold a clock id, and lower 16bits is used to pass flags. The change saves a clock_gettime() syscall from libthr.
* Check both seconds and nanoseconds are zero, only checking nanosecondsdavidxu2012-02-191-1/+1
| | | | is zero may trigger timeout too early. It seems a copy&paste bug.
* Add thread-local storage support for arm:gonzo2012-02-142-4/+5
| | | | | - Switch to Variant I TCB layout - Use function from rtld for TCB allocation/deallocation
* Make code more stable by checking NULL pointers.davidxu2012-02-111-2/+6
|
* Switch MIPS TLS implementation to Variant I:gonzo2012-02-102-13/+20
| | | | | Save pointer to the TLS structure taking into account TP_OFFSET and TCB structure size.
* Plug a memory leak. When a cached thread is reused, don't clear sleepdavidxu2012-02-072-12/+19
| | | | | | | queue pointers, just reuse it. PR: 164828 MFC after: 1 week
* Use getcontextx(3) internal API instead of getcontext(2) to providekib2012-01-211-4/+13
| | | | | | | | | | | | | the signal handlers with the context information in the deferrred case. Only enable the use of getcontextx(3) in the deferred signal delivery code on amd64 and i386. Sparc64 seems to have some undetermined issues with interaction of alloca(3) and signal delivery. Tested by: flo (who also provided sparc64 harware access for me), pho Discussed with: marius MFC after: 1 month
* The TCB_GET32() and TCB_GET64() macros in the i386 and amd64-specificdim2011-12-152-2/+2
| | | | | | | | | | | | | | | | | | | | | | versions of pthread_md.h have a special case of dereferencing a null pointer. Clang warns about this with: In file included from lib/libthr/arch/i386/i386/pthread_md.c:36: lib/libthr/arch/i386/include/pthread_md.h:96:10: error: indirection of non-volatile null pointer will be deleted, not trap [-Werror,-Wnull-dereference] return (TCB_GET32(tcb_self)); ^~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:73:13: note: expanded from: : "m" (*(u_int *)(__tcb_offset(name)))); \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:96:10: note: consider using __builtin_trap() or qualifying pointer with 'volatile' Since this indirection is done relative to the fs or gs segment, to retrieve thread-specific data, it is an exception to the rule. Therefore, add a volatile qualifier to tell the compiler we really want to dereference a zero address. MFC after: 1 week
* Pass CVWAIT flags to kernel, this should handledavidxu2011-11-171-3/+2
| | | | | | | | | timeout correctly for pthread_cond_timedwait when it uses kernel-based condition variable. PR: 162403 Submitted by: jilles MFC after: 3 days
* Do not set thread name to less than informative 'initial thread'.kan2011-06-191-1/+0
|
* Merge from r161730:marius2011-06-184-21/+54
| | | | | | | | | | | | | | | | | | | | o Set TP using inline assembly to avoid dead code elimination. o Eliminate _tcb. Merge from r161840: Stylize: avoid using a global register variable. Merge from r157461: Simplify _get_curthread() and _tcb_ctor because libc and rtld now already allocate thread pointer space in tls block for initial thread. Merge from r177853: Replace function _umtx_op with _umtx_op_err, the later function directly returns errno, because errno can be mucked by user's signal handler and most of pthread api heavily depends on errno to be correct, this change should improve stability of the thread library. MFC after: 1 week
* r179417 introduced a bug into pthread_once(). Previously pthread_once()rstone2011-04-201-0/+2
| | | | | | | | | | | | | | | | | used a global pthread_mutex_t for synchronization. r179417 replaced that with an implementation that directly used atomic instructions and thr_* syscalls to synchronize callers to pthread_once. However, calling pthread_mutex_lock on the global mutex implicitly ensured that _thr_check_init() had been called but with r179417 this was no longer guaranteed. This meant that if you were unlucky enough to have your first call into libthr be a call to pthread_once(), you would segfault when trying to access the pointer returned by _get_curthread(). The fix is to explicitly call _thr_check_init() from pthread_once(). Reviewed by: davidxu Approved by: emaste (mentor) MFC after: 1 week
* Introduce a non-portable function pthread_getthreadid_np(3) to retrievejkim2011-02-073-0/+51
| | | | | | | calling thread's unique integral ID, which is similar to AIX function of the same name. Bump __FreeBSD_version to note its introduction. Reviewed by: kib
* Fix a typo.davidxu2011-01-111-1/+1
| | | | Submitted by: avg
* For the process that already loaded libthr but still not initializedkib2011-01-101-0/+26
| | | | | | | threading, fall back to libc method of performing __pthread_map_stacks_exec() job. Reported and tested by: Mykola Dzham <i levsha me>
* Implement the __pthread_map_stacks_exec() for libthr.kib2011-01-095-1/+53
| | | | | | | | | | | | Stack creation code is changed to call _rtld_get_stack_prot() to get the stack protection right. There is a race where thread is created during dlopen() of dso that requires executable stacks. Then, _rtld_get_stack_prot() may return PROT_READ | PROT_WRITE, but thread is still not linked into the thread list. In this case, the callback misses the thread stack, and rechecks the required protection afterward. Reviewed by: davidxu
* Add section .note.GNU-stack for assembly files used by 386 and amd64.kib2011-01-072-0/+4
|
* Return 0 instead of garbage value.davidxu2011-01-061-2/+1
| | | | Found by: clang static analyzer
* Because sleepqueue may still being used, we should always check wchan withdavidxu2011-01-041-6/+0
| | | | queue locked.
* Always clear flag PMUTEX_FLAG_DEFERED when unlocking, as it is onlydavidxu2010-12-241-2/+2
| | | | significant for lock owner.
* Add sleep queue code.davidxu2010-12-221-0/+175
|
* MFp4:davidxu2010-12-229-191/+666
| | | | | | | | | | | | | | | - Add flags CVWAIT_ABSTIME and CVWAIT_CLOCKID for umtx kernel based condition variable, this should eliminate an extra system call to get current time. - Add sub-function UMTX_OP_NWAKE_PRIVATE to wake up N channels in single system call. Create userland sleep queue for condition variable, in most cases, thread will wait in the queue, the pthread_cond_signal will defer thread wakeup until the mutex is unlocked, it tries to avoid an extra system call and a extra context switch in time window of pthread_cond_signal and pthread_mutex_unlock. The changes are part of process-shared mutex project.
* Use sysctl kern.sched.cpusetsize to retrieve size of kernel cpuset.davidxu2010-11-021-8/+5
|
* Return previous sigaction correctly.davidxu2010-10-291-1/+4
| | | | Submitted by: avg
* Remove local variable 'first', instead check signal number in memory,davidxu2010-10-291-4/+1
| | | | | because the variable can be in register, second checking the variable may still return true, however this is unexpected.
* Check small set and reject it, this is how kernel did. Always use thedavidxu2010-10-271-37/+32
| | | | size kernel is using.
* - Revert r214409.davidxu2010-10-271-5/+6
| | | | - Use long word to figure out sizeof kernel cpuset, hope it works.
* Remove locking and unlock in pthread_mutex_destroy, becausedavidxu2010-10-271-25/+2
| | | | | it can not fix race condition in application code, as a result, the problem described in PR threads/151767 is avoided.
* Fix typo.davidxu2010-10-251-1/+1
|
* Get cpuset in pthread_attr_get_np() and free it in pthread_attr_destroy().davidxu2010-10-252-10/+31
| | | | MFC after: 7 days
* Revert revision 214007, I realized that MySQL wants to resolvedavidxu2010-10-204-52/+2
| | | | | | | a silly rwlock deadlock problem, the deadlock is caused by writer waiters, if a thread has already locked a reader lock, and wants to acquire another reader lock, it will be blocked by writer waiters, but we had already fixed it years ago.
* Set default type to PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, thisdavidxu2010-10-181-0/+1
| | | | is the type we are using.
* sort function name.davidxu2010-10-181-2/+2
|
* s/||/&&davidxu2010-10-181-2/+2
|
* Add pthread_rwlockattr_setkind_np and pthread_rwlockattr_getkind_np, thedavidxu2010-10-184-2/+50
| | | | | | | | | functions set or get pthread_rwlock type, current supported types are: PTHREAD_RWLOCK_PREFER_READER_NP, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, PTHREAD_RWLOCK_PREFER_WRITER_NP, default is PTHREAD_RWLOCK_PREFER_WRITER_NONCECURSIVE_NP, this maintains binary compatible with old code.
* Oops, don't remove -fexceptions flag.davidxu2010-10-081-0/+1
|
* unwind.h was imported, gcc directory is no longer needed.davidxu2010-10-081-1/+0
|
* change code to use unwind.h.davidxu2010-09-302-5/+6
|
OpenPOWER on IntegriCloud