aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr
Commit message (Collapse)AuthorAgeFilesLines
* mdoc: order prologue macros consistently by Dd/Dt/OsUlrich Spörlein2010-04-141-1/+1
| | | | | | | | | | | Although groff_mdoc(7) gives another impression, this is the ordering most widely used and also required by mdocml/mandoc. Reviewed by: ru Approved by: philip, ed (mentors) Notes: svn path=/head/; revision=206622
* Merge r195129 from project/mips to head by hand:Warner Losh2010-01-091-2/+6
| | | | | | | | r195129 | gonzo | 2009-06-27 17:28:56 -0600 (Sat, 27 Jun 2009) | 2 lines - Use sysarch(2) in MIPS version of _tcb_set/_tcb_get Notes: svn path=/head/; revision=201864
* remove file thr_sem_new.c.David Xu2010-01-051-1/+0
| | | | Notes: svn path=/head/; revision=201565
* Remove extra new semaphore stubs, because libc already has them, andDavid Xu2010-01-052-110/+0
| | | | | | | | | ld can find the newest version which is default. Poked by: kan@ Notes: svn path=/head/; revision=201559
* Use umtx to implement process sharable semaphore, to make this work,David Xu2010-01-056-232/+172
| | | | | | | | | | | | | | | | | | | | | | | | | now type sema_t is a structure which can be put in a shared memory area, and multiple processes can operate it concurrently. User can either use mmap(MAP_SHARED) + sem_init(pshared=1) or use sem_open() to initialize a shared semaphore. Named semaphore uses file system and is located in /tmp directory, and its file name is prefixed with 'SEMD', so now it is chroot or jail friendly. In simplist cases, both for named and un-named semaphore, userland code does not have to enter kernel to reduce/increase semaphore's count. The semaphore is designed to be crash-safe, it means even if an application is crashed in the middle of operating semaphore, the semaphore state is still safely recovered by later use, there is no waiter counter maintained by userland code. The main semaphore code is in libc and libthr only has some necessary stubs, this makes it possible that a non-threaded application can use semaphore without linking to thread library. Old semaphore implementation is kept libc to maintain binary compatibility. The kernel ksem API is no longer used in the new implemenation. Discussed on: threads@ Notes: svn path=/head/; revision=201546
* Work-around a race condition on ia64 while unlocking a contested lock.Marcel Moolenaar2009-12-141-0/+3
| | | | | | | | | | | The race condition is believed to be in UMTX_OP_MUTEX_WAKE. On ia64, we simply go to the kernel to unlock. The big question is why this is only a race condition on ia64... MFC after: 3 days Notes: svn path=/head/; revision=200498
* Revert r199830 for now. Too many ports dlopen() libraries linked withKonstantin Belousov2009-11-281-1/+1
| | | | | | | libthr, but forgot to link main binary with it. Notes: svn path=/head/; revision=199878
* Libthr cannot be dynamically loaded into the running process.Konstantin Belousov2009-11-261-1/+1
| | | | | | | | | | Mark it with -z nodlopen for now. Discussed with: jhb, kan MFC after: 3 weeks Notes: svn path=/head/; revision=199830
* Current pselect(3) is implemented in usermode and thus vulnerable toKonstantin Belousov2009-10-271-1/+3
| | | | | | | | | | | | | | | | | | | | well-known race condition, which elimination was the reason for the function appearance in first place. If sigmask supplied as argument to pselect() enables a signal, the signal might be delivered before thread called select(2), causing lost wakeup. Reimplement pselect() in kernel, making change of sigmask and sleep atomic. Since signal shall be delivered to the usermode, but sigmask restored, set TDP_OLDMASK and save old mask in td_oldsigmask. The TDP_OLDMASK should be cleared by ast() in case signal was not gelivered during syscall execution. Reviewed by: davidxu Tested by: pho MFC after: 1 month Notes: svn path=/head/; revision=198508
* Implement _umtx_op_err() for ia64.Marcel Moolenaar2009-10-243-1/+38
| | | | Notes: svn path=/head/; revision=198450
* Make openat(2) a cancellation point.Jilles Tjoelker2009-10-113-0/+34
| | | | | | | | | | This is required by POSIX and matches open(2). Reviewed by: kib, jhb MFC after: 1 month Notes: svn path=/head/; revision=197968
* don't report error if key was deleted.David Xu2009-09-251-1/+11
| | | | | | | PR: threads/135462 Notes: svn path=/head/; revision=197477
* rwlock implemented from libthr need to fall through the 'hard path' andAttilio Rao2009-09-231-2/+5
| | | | | | | | | | | | | | | | | | | | | | | query umtx also if the shared waiters bit is set on a shared lock. The writer starvation avoidance technique, infact, can lead to shared waiters on a shared lock which can bring to a missed wakeup and thus to a deadlock if the right bit is not checked (a notable case is the writers counterpart to be handled through expired timeouts). Fix that by checking for the shared waiters bit also when unlocking the shared locks. That bug was causing a reported MySQL deadlock. Many thanks go to Nick Esborn and his employer DesertNet which provided time and machines to identify and fix this issue. PR: thread/135673 Reported by: Nick Esborn <nick at desert dot net> Tested by: Nick Esborn <nick at desert dot net> Reviewed by: jeff Notes: svn path=/head/; revision=197445
* In the current code, rdlock_count is not correctly handled for some cases.Attilio Rao2009-07-062-1/+4
| | | | | | | | | | | | | | | | | | The most notable is that it is not bumped in rwlock_rdlock_common() when the hard path (__thr_rwlock_rdlock()) returns successfully. This can lead to deadlocks in libthr when rwlocks recursion in read mode happens. Fix the interested parts by correctly handling rdlock_count. PR: threads/136345 Reported by: rink Tested by: rink Reviewed by: jeff Approved by: re (kib) MFC: 2 weeks Notes: svn path=/head/; revision=195403
* These are some cosmetic changes to improve the clarity of libthr's fork ↵Brian Feldman2009-05-111-9/+9
| | | | | | | implementation. Notes: svn path=/head/; revision=191993
* Now that the kernel defines CACHE_LINE_SIZE in machine/param.h, useRobert Watson2009-04-191-2/+0
| | | | | | | | | | | that definition in the custom locking code for the run-time linker rather than local definitions. Pointed out by: tinderbox MFC after: 2 weeks Notes: svn path=/head/; revision=191291
* Turn on nodelete linker flag because libthr can not be unloaded safely,David Xu2009-03-311-0/+1
| | | | | | | it does hook on to libc. Notes: svn path=/head/; revision=190585
* Forcibly unlock the malloc() locks in the child process after fork(),Konstantin Belousov2009-03-191-1/+4
| | | | | | | | | | by temporary pretending that the process is still multithreaded. Current malloc lock primitives do nothing for singlethreaded process. Reviewed by: davidxu, deischen Notes: svn path=/head/; revision=190025
* Don't ignore other fcntl functions, directly call __sys_fcntl ifDavid Xu2009-03-091-1/+1
| | | | | | | | | WITHOUT_SYSCALL_COMPAT is not defined. Reviewed by: deischen Notes: svn path=/head/; revision=189553
* Don't reference non-existent __fcntl_compat if WITHOUT_SYSCALL_COMPAT is ↵David Xu2009-03-092-0/+10
| | | | | | | | | defined. Submitted by: Pawel Worach "pawel dot worach at gmail dot com" Notes: svn path=/head/; revision=189549
* With only one threading library, simplify the logic of setting SHLIBDIR.Ruslan Ermilov2009-02-241-4/+2
| | | | Notes: svn path=/head/; revision=188997
* Fix build when WITH_SSP is set explicitly.Ruslan Ermilov2009-02-211-2/+1
| | | | | | | Submitted by: Jeremie Le Hen Notes: svn path=/head/; revision=188895
* Honor WITHOUT_INSTALLLIB in some places.Jung-uk Kim2009-02-131-0/+2
| | | | Notes: svn path=/head/; revision=188583
* When libthr and rtld start up, there are a number of magic spells castPeter Wemm2008-12-071-1/+1
| | | | | | | | | | | | | | | | | in order to get the symbol binding state "just so". This is to allow locking to be activated and not run into recursion problems later. However, one of the magic bits involves an explicit call to _umtx_op() to force symbol resolution. It does a wakeup operation on a fake, uninitialized (ie: random contents) umtx. Since libthr isn't active, this is harmless. Nothing can match the random wakeup. However, valgrind finds this and is not amused. Normally I'd just write a suppression record for it, but the idea of passing random args to syscalls (on purpose) just doesn't feel right. Notes: svn path=/head/; revision=185728
* Provide custom simple allocator for rtld locks in libthr. The allocatorKonstantin Belousov2008-12-022-24/+24
| | | | | | | | | | | | does not use any external symbols, thus avoiding possible recursion into rtld to resolve symbols, when called. Reviewed by: kan, davidxu Tested by: rink MFC after: 1 month Notes: svn path=/head/; revision=185558
* Invoke _rtld_atfork_post earlier, before we reinitialize rtld locksAlexander Kabaev2008-12-011-3/+4
| | | | | | | | | | | | | | | by switching into single-thread mode. libthr ignores broken use of lock bitmaps used by default rtld locking implementation, this in turn turns lock handoff in _rtld_thread_init into NOP. This in turn makes child processes of forked multi-threaded programs to run with _thr_signal_block still in effect, with most signals blocked. Reported by: phk, kib Notes: svn path=/head/; revision=185531
* Unlock the malloc() locks in the child process after fork(). This givesKonstantin Belousov2008-11-291-0/+1
| | | | | | | | | | | | | | | | us working malloc in the fork child of the multithreaded process. Although POSIX requires that only async-signal safe functions shall be operable after fork in multithreaded process, not having malloc lower the quality of our implementation. Tested by: rink Discussed with: kan, davidxu Reviewed by: kan MFC after: 1 month Notes: svn path=/head/; revision=185456
* Add two rtld exported symbols, _rtld_atfork_pre and _rtld_atfork_post.Konstantin Belousov2008-11-271-1/+10
| | | | | | | | | | | | | | | | | Threading library calls _pre before the fork, allowing the rtld to lock itself to ensure that other threads of the process are out of dynamic linker. _post releases the locks. This allows the rtld to have consistent state in the child. Although child may legitimately call only async-safe functions, the call may need plt relocation resolution, and this requires working rtld. Reported and debugging help by: rink Reviewed by: kan, davidxu MFC after: 1 month (anyway, not before 7.1 is out) Notes: svn path=/head/; revision=185369
* Allow psaddr_t to be widened by using thr_pread_{int,long,ptr},Marcel Moolenaar2008-09-141-2/+2
| | | | | | | | | | where critical. Some places still use ps_pread/ps_pwrite directly, but only need changed when byte-order comes into the picture. Also, change th_p in td_event_msg_t from a pointer type to psaddr_t, so that events also work when psaddr_t is widened. Notes: svn path=/head/; revision=183021
* Move call to _malloc_thread_cleanup() so that if this is the last thread,Jason Evans2008-09-091-3/+6
| | | | | | | | | | the call never happens. This is necessary because malloc may be used during exit handler processing. Submitted by: davidxu Notes: svn path=/head/; revision=182894
* Add thread-specific caching for small size classes, based on magazines.Jason Evans2008-08-271-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | This caching allows for completely lock-free allocation/deallocation in the steady state, at the expense of likely increased memory use and fragmentation. Reduce the default number of arenas to 2*ncpus, since thread-specific caching typically reduces arena contention. Modify size class spacing to include ranges of 2^n-spaced, quantum-spaced, cacheline-spaced, and subpage-spaced size classes. The advantages are: fewer size classes, reduced false cacheline sharing, and reduced internal fragmentation for allocations that are slightly over 512, 1024, etc. Increase RUN_MAX_SMALL, in order to limit fragmentation for the subpage-spaced size classes. Add a size-->bin lookup table for small sizes to simplify translating sizes to size classes. Include a hard-coded constant table that is used unless custom size class spacing is specified at run time. Add the ability to disable tiny size classes at compile time via MALLOC_TINY. Notes: svn path=/head/; revision=182225
* In function pthread_condattr_getpshared, store result correctly.David Xu2008-08-011-1/+1
| | | | | | | PR: kern/126128 Notes: svn path=/head/; revision=181099
* Enable GCC stack protection (aka Propolice) for userland:Ruslan Ermilov2008-06-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | - It is opt-out for now so as to give it maximum testing, but it may be turned opt-in for stable branches depending on the consensus. You can turn it off with WITHOUT_SSP. - WITHOUT_SSP was previously used to disable the build of GNU libssp. It is harmless to steal the knob as SSP symbols have been provided by libc for a long time, GNU libssp should not have been much used. - SSP is disabled in a few corners such as system bootstrap programs (sys/boot), process bootstrap code (rtld, csu) and SSP symbols themselves. - It should be safe to use -fstack-protector-all to build world, however libc will be automatically downgraded to -fstack-protector because it breaks rtld otherwise. - This option is unavailable on ia64. Enable GCC stack protection (aka Propolice) for kernel: - It is opt-out for now so as to give it maximum testing. - Do not compile your kernel with -fstack-protector-all, it won't work. Submitted by: Jeremie Le Hen <jeremie@le-hen.org> Notes: svn path=/head/; revision=180012
* Add two commands to _umtx_op system call to allow a simple mutex to beDavid Xu2008-06-243-54/+106
| | | | | | | | | | | | | | | | | locked and unlocked completely in userland. by locking and unlocking mutex in userland, it reduces the total time a mutex is locked by a thread, in some application code, a mutex only protects a small piece of code, the code's execution time is less than a simple system call, if a lock contention happens, however in current implemenation, the lock holder has to extend its locking time and enter kernel to unlock it, the change avoids this disadvantage, it first sets mutex to free state and then enters kernel and wake one waiter up. This improves performance dramatically in some sysbench mutex tests. Tested by: kris Sounds great: jeff Notes: svn path=/head/; revision=179970
* Make pthread_cleanup_push() and pthread_cleanup_pop() as a pair of macros,David Xu2008-06-093-22/+50
| | | | | | | | | | use stack space to keep cleanup information, this eliminates overhead of calling malloc() and free() in thread library. Discussed on: thread@ Notes: svn path=/head/; revision=179662
* Call the fcntl compatiblity wrapper from the thread library fcntl wrappersDoug Rabson2008-05-301-1/+2
| | | | | | | | | so that they get the benefit of the (limited) forward ABI compatibility. MFC after: 1 week Notes: svn path=/head/; revision=179434
* Eliminate global mutex by using pthread_once's state field asDavid Xu2008-05-301-33/+29
| | | | | | | a semaphore. Notes: svn path=/head/; revision=179417
* - Reduce function call overhead for uncontended case.David Xu2008-05-293-217/+104
| | | | | | | | - Remove unused flags MUTEX_FLAGS_* and their code. - Check validity of the timeout parameter in mutex_self_lock(). Notes: svn path=/head/; revision=179411
* Commit missing mips libthr support that I thought I'd committed earlierWarner Losh2008-05-112-0/+141
| | | | Notes: svn path=/head/; revision=178938
* Remove libc_r's remnant code.David Xu2008-05-061-16/+0
| | | | Notes: svn path=/head/; revision=178806
* Use UMTX_OP_WAIT_UINT_PRIVATE and UMTX_OP_WAKE_PRIVATE to saveDavid Xu2008-04-299-19/+20
| | | | | | | time in kernel(avoid VM lookup). Notes: svn path=/head/; revision=178647
* Increase the default MUTEX_ADAPTIVE_SPINS to 2000, after furtherKris Kennaway2008-04-261-1/+1
| | | | | | | | | | | testing it turns out 200 was too short to give good adaptive performance. Reviewed by: jeff MFC after: 1 week Notes: svn path=/head/; revision=178587
* Bring in mips threads support from perforce mips2-jnpr branch.Warner Losh2008-04-261-0/+5
| | | | Notes: svn path=/head/; revision=178581
* Avoid various shadowed variables. libthr is now almost WARNS=4 clean exceptXin LI2008-04-234-25/+25
| | | | | | | | | for some const dequalifiers that needs more careful investigation. Ok'ed by: davidxu Notes: svn path=/head/; revision=178446
* Use native rwlock.David Xu2008-04-221-54/+20
| | | | Notes: svn path=/head/; revision=178413
* _vfork is not in libthr, remove the reference.David Xu2008-04-161-1/+0
| | | | Notes: svn path=/head/; revision=178236
* don't include pthread_np.h, it is not used.David Xu2008-04-141-1/+0
| | | | Notes: svn path=/head/; revision=178194
* put THR_CRITICAL_LEAVE into do .. while statement.David Xu2008-04-031-2/+4
| | | | Notes: svn path=/head/; revision=177871
* add __hidden suffix to _umtx_op_err, this eliminates PLT.David Xu2008-04-031-1/+1
| | | | Notes: svn path=/head/; revision=177869
* Non-portable functions are in pthread_np.h, fix compiling problem.David Xu2008-04-021-1/+1
| | | | Notes: svn path=/head/; revision=177861