summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_kern.c
Commit message (Collapse)AuthorAgeFilesLines
* Replace a comment with more accurated one, memory heap is now protected bydavidxu2003-12-191-3/+2
| | | | new fork() wrapper.
* Rename _thr_enter_cancellation_point to _thr_cancel_enter, renamedavidxu2003-12-091-18/+11
| | | | | | | | | | | | | | | | | | | | | _thr_leave_cancellation_point to _thr_cancel_leave, add a parameter to _thr_cancel_leave to indicate whether cancellation point should be checked, this gives us an option to not check cancallation point if a syscall successfully returns to avoid any leaks, current I have creat(), open() and fcntl(F_DUPFD) to not check cancellation point after they sucessfully returned. Replace some members in structure kse with bit flags to same some memory. Conditionally compile THR_ASSERT to nothing if _PTHREAD_INVARIANTS is not defined. Inline some small functions in thr_cancel.c. Use __predict_false in thr_kern.c for some executed only once code. Reviewd by: deischen
* 1.Macro optimizing KSE_LOCK_ACQUIRE and THR_LOCK_ACQUIRE to use static falldavidxu2003-11-291-91/+24
| | | | | | | | | | | | | | through branch predict as suggested in INTEL IA32 optimization guide. 2.Allocate siginfo arrary separately to avoid pthread to be allocated at 2K boundary, which hits L1 address alias problem and causes context switch to be slow down. 3.Simplify context switch code by removing redundant code, code size is reduced, so it is expected to run faster. Reviewed by: deischen Approved by: re (scottl)
* If a thread in critical region got a synchronous signal, according currentdavidxu2003-11-091-0/+2
| | | | | | signal handling mode, there is no chance to handle the signal, something must be wrong in the library, just call kse_thr_interrupt to dump its core. I have the code for a long time, but forgot to commit it.
* Add an implementation for pthread_atfork().deischen2003-11-041-1/+15
| | | | | | | | Aside from the POSIX requirements for pthread_atfork(), when fork()ing, take the malloc lock to keep malloc state consistent in the child. Reviewed by: davidxu
* Complete cancellation support for M:N threads, check cancelling flag whendavidxu2003-10-081-69/+156
| | | | | | | thread state is changed from RUNNING to WAIT state and do some cancellation operations for every cancellable state. Reviewed by: deischen
* When concurrency level is reduced and a kse is exiting, make sure no otherdavidxu2003-09-291-0/+13
| | | | | | threads are still referencing the kse by migrating them to initial kse. Reviewed by: deischen
* Remove unused variable.davidxu2003-09-281-2/+0
|
* Free thread name memory if there is.davidxu2003-09-231-0/+4
|
* Make KSE_STACKSIZE machine dependent by moving it from thr_kern.c tomarcel2003-09-191-2/+0
| | | | | | pthread_md.h. This commit only moves the definition; it does not change it for any of the platforms. This more easily allows 64-bit architectures (in particular) to pick a slightly larger stack size.
* Fix a typo. Also turn on PTHREAD_SCOPE_SYSTEM after fork().davidxu2003-09-161-1/+2
|
* 1. Allocating and freeing lock related resource in _thr_alloc and _thr_freedavidxu2003-09-141-73/+44
| | | | | | | | | | | to avoid potential memory leak, also fix a bug in pthread_create, contention scope should be inherited when PTHREAD_INHERIT_SCHED is set, and also check right field for PTHREAD_INHERIT_SCHED, scheduling inherit flag is in sched_inherit. 2. Execute hooks registered by atexit() on thread stack but not on scheduler stack. 3. Simplify some code in _kse_single_thread by calling xxx_destroy functions. Reviewed by: deischen
* Add code to support barrier synchronous object and implementdavidxu2003-09-041-2/+5
| | | | | | pthread_mutex_timedlock(). Reviewed by: deischen
* Allow hooks registered by atexit() to run with current thread pointer set,davidxu2003-09-041-1/+4
| | | | without this change, my atexit test dumps core.
* Move kse_wakeup_multi call to just before KSE_SCHED_UNLOCK.davidxu2003-09-031-4/+2
| | | | Tested on: SMP
* Allow the concurrency level to be reduced.deischen2003-08-301-7/+8
| | | | Reviewed by: davidxu
* Treat initial thread as scope system thread when KSE mode is not activateddavidxu2003-08-181-15/+9
| | | | | | | | | yet, so we can protect some locking code from being interrupted by signal handling. When KSE mode is turned on, reset the thread flag to scope process except we are running in 1:1 mode which we needn't turn it off. Also remove some unused member variables in structure kse. Tested by: deischen
* Keep initial kse and kse group just like we keep initial thread,davidxu2003-08-161-9/+11
| | | | | | Don't free them, so some code can still reference them. Reviewed by: deischen
* Always set tcb for bound thread, and switch tcb for M:N thread at correctdavidxu2003-08-131-7/+18
| | | | time.
* Correctly set current tcb. This fixes some IA64/KSE problems.davidxu2003-08-121-17/+11
| | | | Reviewed by: deischen, julian
* Initialize rtld lock just before turning on thread mode anddavidxu2003-08-101-19/+33
| | | | uninitialize rtld lock after thread mode shutdown.
* o Add code to GC freed KSEs and KSE groupsdavidxu2003-08-081-25/+116
| | | | | | | o Fix a bug in kse_free_unlocked(), kcb_dtor shouldn't be called because the KSE is cached and will be resued in _kse_alloc(). Reviewed by: deischen
* Don't call kse_set_curthread() when scheduling a new bounddeischen2003-08-061-2/+3
| | | | | | | thread. It should only be called by the current kse and never by a KSE on behalf of another. Submitted by: davidxu
* Rethink the MD interfaces for libpthread to account fordeischen2003-08-051-156/+160
| | | | | | | | | archs that can (or are required to) have per-thread registers. Tested on i386, amd64; marcel is testing on ia64 and will have some follow-up commits. Reviewed by: davidxu
* Move idle kse wakeup to outside of regions where locks are held.deischen2003-07-231-35/+57
| | | | | | | | This eliminates ping-ponging of locks, where the idle KSE wakes up only to find the lock it needs is being held. This gives little or no gain to M:N mode but greatly speeds up 1:1 mode. Reviewed & Tested by: davidxu
* Cleanup thread accounting. Don't reset a threads timeslicedeischen2003-07-181-36/+21
| | | | | | | | when it blocks; it only gets reset when it yields. Properly set a thread's default stack guardsize. Reviewed by: davidxu
* o Eliminate upcall for PTHREAD_SYSTEM_SCOPE thread, now itdavidxu2003-07-171-104/+217
| | | | | | | | | | | | | is system bound thread and when it is blocked, no upcall is generated. o Add ability to libkse to allow it run in pure 1:1 threading mode, defining SYSTEM_SCOPE_ONLY in Makefile can turn on this option. o Eliminate code for installing dummy signal handler for sigwait call. o Add hash table to find thread. Reviewed by: deischen
* Restore signal mask correctly after fork().davidxu2003-07-091-1/+2
|
* Save and restore thread's error code around signal handling.davidxu2003-07-091-1/+2
| | | | Reviewed by: deischen
* Check if thread is in critical region, only testing check_pendingdavidxu2003-07-031-1/+2
| | | | is not enough.
* Because there are only _SIG_MAXSIG elements in thread siginfo array,davidxu2003-06-301-1/+1
| | | | use [signal number - 1] as subscript to access the array.
* Remove surplus unlocking code I accidentally checked in. This won't bedavidxu2003-06-301-4/+0
| | | | triggered until LDT entry is exhausted.
* o Use a daemon thread to monitor signal events in kernel, if pendingdavidxu2003-06-281-96/+138
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | signals were changed in kernel, it will retrieve the pending set and try to find a thread to dispatch the signal. The dispatching process can be rolled back if the signal is no longer in kernel. o Create two functions _thr_signal_init() and _thr_signal_deinit(), all signal action settings are retrieved from kernel when threading mode is turned on, after a fork(), child process will reset them to user settings by calling _thr_signal_deinit(). when threading mode is not turned on, all signal operations are direct past to kernel. o When a thread generated a synchoronous signals and its context returned from completed list, UTS will retrieve the signal from its mailbox and try to deliver the signal to thread. o Context signal mask is now only used when delivering signals, thread's current signal mask is always the one in pthread structure. o Remove have_signals field in pthread structure, replace it with psf_valid in pthread_signal_frame. when psf_valid is true, in context switch time, thread will backout itself from some mutex/condition internal queues, then begin to process signals. when a thread is not at blocked state and running, check_pending indicates there are signals for the thread, after preempted and then resumed time, UTS will try to deliver signals to the thread. o At signal delivering time, not only pending signals in thread will be scanned, process's pending signals will be scanned too. o Change sigwait code a bit, remove field sigwait in pthread_wait_data, replace it with oldsigmask in pthread structure, when a thread calls sigwait(), its current signal mask is backuped to oldsigmask, and waitset is copied to its signal mask and when the thread gets a signal in the waitset range, its current signal mask is restored from oldsigmask, these are done in atomic fashion. o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait(). o Signal code locking is better than previous, there is fewer race conditions. o Temporary disable most of code in _kse_single_thread as it is not safe after fork().
* Untangle the inter-dependency of kse types and ksd types/functionsmarcel2003-06-231-1/+1
| | | | | | | | | | | | | | | | | | | by moving the definition of struct ksd to pthread_md.h and removing the inclusion of ksd.h from thr_private.h (which has the definition of struct kse and kse_critical_t). This allows ksd.h to have inline functions that use struct kse and kse_critical_t and generally yields a cleaner implementation at the cost of not having all ksd related types/definitions in one header. Implement the ksd functionality on ia64 by using inline functions and permanently remove ksd.c from the ia64 specific makefile. This change does not clean up the i386 specific version of ksd.h. NOTE: The ksd code on ia64 abuses the tp register in the same way as it is abused in libthr in that it is incompatible with the runtime specification. This will be address when support for TLS hits the tree.
* Change the definition of _ksd_curkse, _ksd_curthread andmarcel2003-06-231-3/+3
| | | | | | | | | _ksd_readandclear_tmbx to be function-like. That way we can define them as inline functions or create prototypes for them. This change allows the ksd interface on ia64 to be fully inlined.
* Insert threads at the end of the free thread list so thatdeischen2003-06-081-1/+1
| | | | | | | the chance of getting the same thread id when allocating a new thread is reduced. This won't work if the application creates a new thread for every time a thread exits, but we're still within the allowances of POSIX.
* KMF_DONE is now in /sys/sys/kse.h, no longer need to define it here.davidxu2003-06-041-4/+0
|
* Change low-level locking a bit so that we can tell ifdeischen2003-05-241-92/+175
| | | | | | | | | | | | | | | | | | | | | | | | | | a lock is being waitied on. Fix a races in join and cancellation. When trying to wait on a CV and the library is not yet threaded, make it threaded so that waiting actually works. When trying to nanosleep() and we're not threaded, just call the system call nanosleep instead of adding the thread to the wait queue. Clean up adding/removing new threads to the "all threads queue", assigning them unique ids, and tracking how many active threads there are. Do it all when the thread is added to the scheduling queue instead of making pthread_create() know how to do it. Fix a race where a thread could be marked for signal delivery but it could be exited before we actually add the signal to it. Other minor cleanups and bug fixes. Submitted by: davidxu Approved by: re@ (blanket for libpthread)
* Eek, staticize a couple of functions that shouldn'tdeischen2003-05-191-1/+6
| | | | | | | | | | | | be external (initialize()!). Remove cancellation points from _pthread_cond_wait and _pthread_cond_timedwait (single underscore versions are libc private functions). Point the weak reference(!) for these functions to the versions with cancellation points. Approved by: re@(blanket till 5/19) Pointed out by: kan (cancellation point bug)
* Add a method of yielding the current thread with the schedulerdeischen2003-05-161-116/+157
| | | | | | | | | | | | | | | | | | | | | | | lock held (_thr_sched_switch_unlocked()) and use this to avoid dropping the scheduler lock and having the scheduler retake the same lock again. Add a better way of detecting if a low-level lock is in use. When switching out a thread due to blocking in the UTS, don't switch to the KSE's scheduler stack only to switch back to another thread. If possible switch to the new thread directly from the old thread and avoid the overhead of the extra context switch. Check for pending signals on a thread when entering the scheduler and add them to the threads signal frame. This includes some other minor signal fixes. Most of this was a joint effor between davidxu and myself. Reviewed by: davidxu Approved by: re@ (blanket for libpthread)
* call dump_queues() only when DEBUG_THREAD_KERN is defined, save somedavidxu2003-05-051-0/+2
| | | | cpu cycles.
* Fix suspend and resume.deischen2003-05-041-16/+28
| | | | Submitted (in part) by: Kazuaki Oda <kaakun@highway.ne.jp>
* Move the mailbox to the beginning of the thread and align thedeischen2003-04-301-3/+9
| | | | thread so that the context (SSE FPU state) is also aligned.
* Call kse_wakeup_mutli() after remove current thread from RUNQ to avoiddavidxu2003-04-301-1/+1
| | | | doing unnecessary idle kse wakeup.
* Call kse_wakeup_multi() to wakeup idle KSEs when there are threads readydavidxu2003-04-301-0/+1
| | | | to run.
* o Don't add a scope system thread's KSE to the list of availabledeischen2003-04-281-40/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | KSEs when it's thread exits; allow the GC handler to do that. o Make spinlock/spinlock critical regions. The following were submitted by davidxu o Alow thr_switch() to take a null mailbox argument. o Better protect cancellation checks. o Don't set KSE specific data when creating new KSEs; rely on the first upcall of the KSE to set it. o Add the ability to set the maximum concurrency level and do this automatically. We should have a way to enable/disable this with some sort of tunable because some applications may not want this to be the default. o Hold the scheduling lock across thread switch calls. o If scheduling of a thread fails, make sure to remove it from the list of active threads. o Better protect accesses to a joining threads when the target thread is exited and detached. o Remove some macro definitions that are now provided by <sys/kse.h>. o Don't leave the library in threaded mode if creation of the initial KSE fails. o Wakeup idle KSEs when there are threads ready to run. o Maintain the number of threads active in the priority queue.
* Protect thread errno from being changed while operatingdeischen2003-04-231-0/+31
| | | | | | | | on behalf of the KSE. Add a kse_reinit function to reinitialize a reused KSE. Submitted by: davidxu
* Set the quantum for scope system threads to 0 (no quantum).deischen2003-04-221-0/+2
|
* Add a couple asserts to pthread_cond_foo to ensure the (low-level)deischen2003-04-221-19/+45
| | | | | | | | | | | | | | | lock level is 0. Thus far, the threads implementation doesn't use mutexes or condition variables so the lock level should be 0. Save the return value when trying to schedule a new thread and use this to return an error from pthread_create(). Change the max sleep time for an idle KSE to 1 minute from 2 minutes. Maintain a count of the number of KSEs within a KSEG. With these changes scope system threads seem to work, but heavy use of them crash the kernel (supposedly VM bugs).
* Add an i386-specifc hack to always set %gs. There still seemsdeischen2003-04-211-155/+231
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to be instances where the kernel doesn't properly save and/or restore it. Use noupcall and nocompleted flags in the KSE mailbox. These require kernel changes to work which will be committed sometime later. Things still work without the changes. Remove the general kse entry function and use two different functions -- one for scope system threads and one for scope process threads. The scope system function is not yet enabled and we use the same function for all threads at the moment. Keep a copy of the KSE stack for the case that a KSE runs a scope system thread and uses the same stack as the thread (no upcalls are generated, so a separate stack isn't needed). This isn't enabled yet. Use a separate field for the KSE waiting flag. It isn't correct to use the mailbox flags field. The following fixes were provided by David Xu: o Initialize condition variable locks with thread versions of the low-level locking functions instead of the kse versions. o Enable threading before creating the first thread instead of after. o Don't enter critical regions when trying to malloc/free or call functions that malloc/free. o Take the scheduling lock when inheriting thread attributes. o Check the attribute's stack pointer instead of the attributes stack size for null when allocating a thread's stack. o Add a kseg reinit function so we don't have to destroy and then recreate the same lock. o Check the return value of kse_create() and return an appropriate error if it fails. o Don't forget to destroy a thread's locks when freeing it. o Examine the correct flags word for checking to see if a thread is in a synchronization queue. Things should now work on an SMP kernel.
OpenPOWER on IntegriCloud