summaryrefslogtreecommitdiff
path: root/sys/kern/kern_thread.c
Commit message (Collapse)AuthorAgeFilesLines
* This commit was manufactured by cvs2svn to create tagrelease/5.4.0_cvscvs2svn2005-05-071-1/+1
| | | | | | 'RELENG_5_4_0_RELEASE'. This commit was manufactured to restore the state of the 5.4-RELEASE image.
* MFC: free the pointer pointed to the "spare" thread and not the oneJulian Elischer2005-03-251-2/+4
| | | | | | | | | | | pointed to by "us". This isnot really a problem in practice because it nearly always points to the same cred but it could have caused a problem in the future. Approved by: re (ken) Notes: svn path=/stable/5/; revision=144131
* MFC:David Schultz2005-02-051-2/+0
| | | | | | | | | 2004-11-20 23:00:59 UTC Remove local definitions of RANGEOF() and use __rangeof() instead. Also remove a few bogus casts. Notes: svn path=/stable/5/; revision=141334
* MFC: /*- and related license changesWarner Losh2005-01-311-1/+1
| | | | Notes: svn path=/stable/5/; revision=141090
* MFC rev 1.207: Respect TDF_SINTR, don't suspend uninterruptible thread.David Xu2004-11-091-4/+3
| | | | Notes: svn path=/stable/5/; revision=137453
* MFC:Julian Elischer2004-10-091-3/+3
| | | | | | | | | | | | Always start out with an initialised ksegrp structure. Revision Changes Path 1.200 +3 -3 src/sys/kern/kern_thread.c Approved by: re (scottl) Notes: svn path=/stable/5/; revision=136297
* MFC:Julian Elischer2004-10-091-14/+26
| | | | | | | | | | | | | | | Break out to a separate function, the code to revert a multithreaded process back to officially being a non-threaded program. Revision Changes Path 1.203 +1 -2 src/sys/kern/kern_kse.c 1.201 +26 -14 src/sys/kern/kern_thread.c 1.407 +1 -0 src/sys/sys/proc.h Approved by: re (scottl) Notes: svn path=/stable/5/; revision=136295
* MFC:Julian Elischer2004-10-091-24/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | 1.254 +46 -12 src/sys/kern/kern_exec.c 1.203 +60 -23 src/sys/kern/kern_thread.c 1.409 +5 -3 src/sys/sys/proc.h In original kern_execve() code, at the start of the function, it forces all other threads to suicide, problem is execve() could be failed, and a failed execve() would change threaded process to unthreaded, this side effect is unexpected. The new code introduces a new single threading mode SINGLE_BOUNDARY, in the mode, all threads should suspend themself at user boundary except the singler. we can not use SINGLE_NO_EXIT because we want to start from a clean state if execve() is successful, suspending other threads at unknown point and later resuming them from there and forcing them to exit at user boundary may cause the process to start from a dirty state. If execve() is successful, current thread upgrades to SINGLE_EXIT mode and forces other threads to suicide at user boundary, otherwise, other threads will be resumed and their interrupted syscall will be restarted. Submitted by: davidxu Approved by: re (scottl) Notes: svn path=/stable/5/; revision=136294
* MFC 1.202:Julian Elischer2004-10-091-6/+5
| | | | | | | | | | | Slight cleanup in the single threading code. needed to make the next MFC apply cleanly.. Approved by: re (scottl) Notes: svn path=/stable/5/; revision=136293
* Cumulative MFC of patches applied to -current to get preemptionJulian Elischer2004-09-181-1/+11
| | | | | | | | | | | | support to a non-instantly-crashing state. Also includes some cosmetic changes to keep the diffs to a minimum and an experimental option (followon) in sched_4bsd. (turned off but included to keep diffs to a mimimum) Approved by: re (scottl) Notes: svn path=/stable/5/; revision=135412
* MFC of:Julian Elischer2004-09-091-241/+153
| | | | | | | | | | | | Refactor a bunch of scheduler code to give basically the same behaviour but with slightly cleaned up interfaces. (2004-09-05 02:09:54 UTC) see version 1.16 of sched.h for the original commit message. Approved by: re (scottl) Notes: svn path=/stable/5/; revision=134976
* MFC: Further refine sleepqueue interface and consolidate duplicated code.John Baldwin2004-09-031-0/+19
| | | | | | | | | | This also appears to fix some select/poll races by more sanely handling TDF_SINTR. Approved by: re (scottl) Notes: svn path=/stable/5/; revision=134706
* MFC:Julian Elischer2004-09-031-1/+1
| | | | | | | | | | | | | | | | | | | > Only test return_instead if P_SINGLE_EXIT is set, otherwise a fork() > syscall can interrupt other thread's syscall in sleepq_catch_signals(). > Current, all callers know thread_suspend_check may suspend thread > itself, so we need't to check return_instead for normal suspension > flags (no P_SINGLE_EXIT set). > > Tested by: deischen > Reported by: Maarten L. Hekkelman <m.hekkelman@cmbi.kun.nl> > > Revision Changes Path > 1.195 +1 -1 src/sys/kern/kern_thread.c Approved by: re (scottl) Notes: svn path=/stable/5/; revision=134678
* Whitespace nit.Julian Elischer2004-08-141-1/+1
| | | | Notes: svn path=/head/; revision=133713
* Increase the amount of data exported by KTR in the KTR_RUNQ setting.Julian Elischer2004-08-091-3/+2
| | | | | | | | This extra data is needed to really follow what is going on in the threaded case. Notes: svn path=/head/; revision=133396
* In thread_exit(), include more information about the thread/processRobert Watson2004-08-061-1/+2
| | | | | | | | | context in the KTR trace record. In particular, include the same information as passed for mi_switch() and fork_exit() KTR trace records. Notes: svn path=/head/; revision=133234
* * Add a "how" argument to uma_zone constructors and initialization functionsBrian Feldman2004-08-021-8/+12
| | | | | | | | | | | | | | | | | | | | so that they know whether the allocation is supposed to be able to sleep or not. * Allow uma_zone constructors and initialation functions to return either success or error. Almost all of the ones in the tree currently return success unconditionally, but mbuf is a notable exception: the packet zone constructor wants to be able to fail if it cannot suballocate an mbuf cluster, and the mbuf allocators want to be able to fail in general in a MAC kernel if the MAC mbuf initializer fails. This fixes the panics people are seeing when they run out of memory for mbuf clusters. * Allow debug.nosleepwithlocks on WITNESS to be disabled, without changing the default. Both bmilekic and jeff have reviewed the changes made to make failable zone allocations work. Notes: svn path=/head/; revision=132987
* When calling scheduler entrypoints for creating new threads and processes,Julian Elischer2004-07-181-2/+2
| | | | | | | | | | | | | | specify "us" as the thread not the process/ksegrp/kse. You can always find the others from the thread but the converse is not true. Theorotically this would lead to runtime being allocated to the wrong entity in some cases though it is not clear how often this actually happenned. (would only affect threaded processes and would probably be pretty benign, but it WAS a bug..) Reviewed by: peter Notes: svn path=/head/; revision=132372
* Whitespace fix.John Baldwin2004-07-161-1/+1
| | | | Notes: svn path=/head/; revision=132265
* Add code to support debugging threaded process.David Xu2004-07-131-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Add tm_lwpid into kse_thr_mailbox to indicate which kernel thread current user thread is running on. Add tm_dflags into kse_thr_mailbox, the flags is written by debugger, it tells UTS and kernel what should be done when the process is being debugged, current, there two flags TMDF_SSTEP and TMDF_DONOTRUNUSER. TMDF_SSTEP is used to tell kernel to turn on single stepping, or turn off if it is not set. TMDF_DONOTRUNUSER is used to tell kernel to schedule upcall whenever possible, to UTS, it means do not run the user thread until debugger clears it, this behaviour is necessary because gdb wants to resume only one thread when the thread's pc is at a breakpoint, and thread needs to go forward, in order to avoid other threads sneak pass the breakpoints, it needs to remove breakpoint, only wants one thread to go. Also, add km_lwp to kse_mailbox, the lwp id is copied to kse_thr_mailbox at context switch time when process is not being debugged, so when process is attached, debugger can map kernel thread to user thread. 2. Add p_xthread to proc strcuture and td_xsig to thread structure. p_xthread is used by a thread when it wants to report event to debugger, every thread can set the pointer, especially, when it is used in ptracestop, it is the last thread reporting event will win the race. Every thread has a td_xsig to exchange signal with debugger, thread uses TDF_XSIG flag to indicate it is reporting signal to debugger, if the flag is not cleared, thread will keep retrying until it is cleared by debugger, p_xthread may be used by debugger to indicate CURRENT thread. The p_xstat is still in proc structure to keep wait() to work, in future, we may just use td_xsig. 3. Add TDF_DBSUSPEND flag, the flag is used by debugger to suspend a thread. When process stops, debugger can set the flag for thread, thread will check the flag in thread_suspend_check, enters a loop, unless it is cleared by debugger, process is detached or process is existing. The flag is also checked in ptracestop, so debugger can temporarily suspend a thread even if the thread wants to exchange signal. 4. Current, in ptrace, we always resume all threads, but if a thread has already a TDF_DBSUSPEND flag set by debugger, it won't run. Encouraged by: marcel, julian, deischen Notes: svn path=/head/; revision=132087
* - Change mi_switch() and sched_switch() to accept an optional thread toJohn Baldwin2004-07-021-2/+2
| | | | | | | | | | | | | | | | switch to. If a non-NULL thread pointer is passed in, then the CPU will switch to that thread directly rather than calling choosethread() to pick a thread to choose to. - Make sched_switch() aware of idle threads and know to do TD_SET_CAN_RUN() instead of sticking them on the run queue rather than requiring all callers of mi_switch() to know to do this if they can be called from an idlethread. - Move constants for arguments to mi_switch() and thread_single() out of the middle of the function prototypes and up above into their own section. Notes: svn path=/head/; revision=131473
* Allocate TIDs in thread_init() and deallocate them in thread_fini().Marcel Moolenaar2004-06-261-71/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | The overhead of unconditionally allocating TIDs (and likewise, unconditionally deallocating them), is amortized across multiple thread creations by the way UMA makes it possible to have type-stable storage. Previously the cost was kept down by having threads created as part of a fork operation use the process' PID as the TID. While this had some nice properties, it also introduced complexity in the way TIDs were allocated. Most importantly, by using the type-stable storage that UMA gives us this was also unnecessary. This change affects how core dumps are created and in particular how the PRSTATUS notes are dumped. Since we don't have a thread with a TID equalling the PID, we now need a different way to preserve the old and previous behavior. We do this by having the given thread (i.e. the thread passed to the core dump code in td) dump it's state first and fill in pr_pid with the actual PID. All other threads will have pr_pid contain their TIDs. The upshot of all this is that the debugger will now likely select the right LWP (=TID) as the initial thread. Credits to: julian@ for spotting how we can utilize UMA. Thanks to: all who provided julian@ with test results. Notes: svn path=/head/; revision=131149
* Mark the thread in an exiting program as inactive.Julian Elischer2004-06-211-1/+1
| | | | | | | | | | This is not really used by the process but it's confusing to some status readers to see zombie processes the "runnin" threads. Pointed out by: Don Lewis <truckman@FreeBSD.org> Notes: svn path=/head/; revision=130877
* Define __lwpid_t as an int32_t in <sys/_types.h> and define lwpid_tMarcel Moolenaar2004-06-191-4/+6
| | | | | | | | as an __lwpid_t in <sys/types.h>. Retype td_tid from an int to a lwpid_t and change related definitions accordingly. Notes: svn path=/head/; revision=130735
* If thread singler wants to terminate other threads, make sure it includesDavid Xu2004-06-181-2/+16
| | | | | | | | | all threads except itself. Obtained from: julian Notes: svn path=/head/; revision=130674
* Shuffle some code around.Julian Elischer2004-06-111-1/+42
| | | | Notes: svn path=/head/; revision=130355
* Add a comment explaining td_critnest's initial state and its life from thatJuli Mallett2004-06-091-0/+13
| | | | | | | | | | point on, as it happens relatively indirectly, and in a codepath the casual reader may not be acquainted with or find obvious. Glanced at by: jhb Notes: svn path=/head/; revision=130269
* Split kern_thread.c into 2 parts. kern_kse.c and kern_thread.cJulian Elischer2004-06-071-1209/+13
| | | | | | | | Kern_kse has already been committed. This separates out the KSE threading ABI from generic thread support. Notes: svn path=/head/; revision=130199
* Move TDF_SA from td_flags to td_pflags (and rename it accordingly)Tim J. Robbins2004-06-021-10/+10
| | | | | | | | | | so that it is no longer necessary to hold sched_lock while manipulating it. Reviewed by: davidxu Notes: svn path=/head/; revision=129989
* Clear KSE thread flags after KSE thread mode is ended. The side effectDavid Xu2004-05-211-1/+1
| | | | | | | | | | | of not clearing the flags for execv() syscall will result that a new program runs in KSE thread mode without enabling it. Submitted by: tjr Modified by: davidxu Notes: svn path=/head/; revision=129547
* Keep track of threads waiting in kse_release() to avoid a raceDaniel Eischen2004-04-281-16/+37
| | | | | | | | | | | | | | condition where kse_wakeup() doesn't yet see them in (interruptible) sleep queues. Also add an upcall check to sleepqueue_catch_signals() suggested by jhb. This commit should fix recent mysql hangs. Reviewed by: jhb, davidxu Mysql'd by: Robin P. Blanchard <robin.blanchard at gactr uga edu> Notes: svn path=/head/; revision=128721
* Assign thread IDs to kernel threads. The purpose of the thread ID (tid)Marcel Moolenaar2004-04-031-2/+98
| | | | | | | | | | | | | | | | | | | | | | | | | | is twofold: 1. When a 1:1 or M:N threaded process dumps core, we need to put the register state of each of its kernel threads in the core file. This can only be done by differentiating the pid field in the respective note. For this we need the tid. 2. When thread support is present for remote debugging the kernel with gdb(1), threads need to be identified by an integer due to limitations in the remote protocol. This requires having a tid. To minimize the impact of having thread IDs, threads that are created as part of a fork (i.e. the initial thread in a process) will inherit the process ID (i.e. tid=pid). Subsequent threads will have IDs larger than PID_MAX to avoid interference with the pid allocation algorithm. The assignment of tids is handled by thread_new_tid(). The thread ID allocation algorithm has been written with 3 assumptions in mind: 1. IDs need to be created as fast a possible, 2. Reuse of IDs may happen instantaneously, 3. Someone else will write a better algorithm. Notes: svn path=/head/; revision=127794
* Massively up the (artificial) limit on system scope threadsJulian Elischer2004-03-211-2/+2
| | | | | | | | | | in a process from 50 to 500 Also up the number of process scope threads allowed to be in the kernel at one time from 150 to 1500 (per process) Notes: svn path=/head/; revision=127264
* Push Giant down a little further:Peter Wemm2004-03-131-8/+5
| | | | | | | | | | | | | | | | | | - no longer serialize on Giant for thread_single*() and family in fork, exit and exec - thread_wait() is mpsafe, assert no Giant - reduce scope of Giant in exit to not cover thread_wait and just do vm_waitproc(). - assert that thread_single() family are not called with Giant - remove the DROP/PICKUP_GIANT macros from thread_single() family - assert that thread_suspend_check() s not called with Giant - remove manual drop_giant hack in thread_suspend_check since we know it isn't held. - remove the DROP/PICKUP_GIANT macros from thread_suspend_check() family - mark kse_create() mpsafe Notes: svn path=/head/; revision=126932
* Check for TDF_SINTR before calling sleepq_abort() as there is a narrowJohn Baldwin2004-03-011-1/+1
| | | | | | | | | | | | | | race in between sleepq_add() and sleepq_catch_signals() in that setting td_wchan and TDF_SINTR is not atomic to sched_lock but only to the sleepq lock. This band-aid will stop assertion failures, but there is perhaps a larger problem with the sleepq_add/sleepq_catch_signals race that I am not sure how to solve. For the signals case the race is harmless because we always call cursig() after setting TDF_SINTR. However, KSE doesn't do anything in sleepq_catch_signals() to check that this race was lost, so I am unsure if this race is harmful for this specific abort. Notes: svn path=/head/; revision=126469
* Switch the sleep/wakeup and condition variable implementations to use theJohn Baldwin2004-02-271-11/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sleep queue interface: - Sleep queues attempt to merge some of the benefits of both sleep queues and condition variables. Having sleep qeueus in a hash table avoids having to allocate a queue head for each wait channel. Thus, struct cv has shrunk down to just a single char * pointer now. However, the hash table does not hold threads directly, but queue heads. This means that once you have located a queue in the hash bucket, you no longer have to walk the rest of the hash chain looking for threads. Instead, you have a list of all the threads sleeping on that wait channel. - Outside of the sleepq code and the sleep/cv code the kernel no longer differentiates between cv's and sleep/wakeup. For example, calls to abortsleep() and cv_abort() are replaced with a call to sleepq_abort(). Thus, the TDF_CVWAITQ flag is removed. Also, calls to unsleep() and cv_waitq_remove() have been replaced with calls to sleepq_remove(). - The sched_sleep() function no longer accepts a priority argument as sleep's no longer inherently bump the priority. Instead, this is soley a propery of msleep() which explicitly calls sched_prio() before blocking. - The TDF_ONSLEEPQ flag has been dropped as it was never used. The associated TDF_SET_ONSLEEPQ and TDF_CLR_ON_SLEEPQ macros have also been dropped and replaced with a single explicit clearing of td_wchan. TD_SET_ONSLEEPQ() would really have only made sense if it had taken the wait channel and message as arguments anyway. Now that that only happens in one place, a macro would be overkill. Notes: svn path=/head/; revision=126326
* Use mtx_assert() rather than using a home-rolled version.John Baldwin2004-01-281-1/+1
| | | | Notes: svn path=/head/; revision=125158
* - Add a flags parameter to mi_switch. The value of flags may be SW_VOL orJeff Roberson2004-01-251-4/+2
| | | | | | | | | | | | | SW_INVOL. Assert that one of these is set in mi_switch() and propery adjust the rusage statistics. This is to simplify the large number of users of this interface which were previously all required to adjust the proper counter prior to calling mi_switch(). This also facilitates more switch and locking optimizations. - Change all callers of mi_switch() to pass the appropriate paramter and remove direct references to the process statistics. Notes: svn path=/head/; revision=124944
* Reduce gratuitous includes: don't include jail.h if it's not needed.Robert Watson2004-01-211-1/+0
| | | | | | | | | | Presumably, at some point, you had to include jail.h if you included proc.h, but that is no longer required. Result of: self injury involving adding something to struct prison Notes: svn path=/head/; revision=124802
* s/Muliple/MultipleJens Schweikhardt2004-01-101-48/+46
| | | | | | | Removed whitespace at EOL and EOF. Notes: svn path=/head/; revision=124350
* Don't use NULL (pointer) when we mean 0 (integer) for the number of ticksPeter Wemm2003-12-231-1/+1
| | | | | | | in msleep. Notes: svn path=/head/; revision=123737
* Write the thread pointer (val) in the kse mailbox (loc) before weMarcel Moolenaar2003-12-101-2/+2
| | | | | | | | set the new context in kse_switchin(2). This allows us to return an error to the calling context when the suword() fails. Notes: svn path=/head/; revision=123366
* Add kse_switchin(2). This syscall can be used by KSE implementationsMarcel Moolenaar2003-12-071-0/+24
| | | | | | | | | | | to have the kernel switch to a new thread, instead of doing it in userland. It is in fact needed on ia64 where syscall restarts do not return to userland first. It's completely handled inside the kernel. As such, any context created by the kernel as part of an upcall and caused by some syscall needs to be restored by the kernel. Notes: svn path=/head/; revision=123252
* - Giant is no longer required by vm_thread_new().Alan Cox2003-12-071-2/+0
| | | | Notes: svn path=/head/; revision=123207
* Add an implementation of turnstiles and change the sleep mutex code to useJohn Baldwin2003-11-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | turnstiles to implement blocking isntead of implementing a thread queue directly. These turnstiles are somewhat similar to those used in Solaris 7 as described in Solaris Internals but are also different. Turnstiles do not come out of a fixed-sized pool. Rather, each thread is assigned a turnstile when it is created that it frees when it is destroyed. When a thread blocks on a lock, it donates its turnstile to that lock to serve as queue of blocked threads. The queue associated with a given lock is found by a lookup in a simple hash table. The turnstile itself is protected by a lock associated with its entry in the hash table. This means that sched_lock is no longer needed to contest on a mutex. Instead, sched_lock is only used when manipulating run queues or thread priorities. Turnstiles also implement priority propagation inherently. Currently turnstiles only support mutexes. Eventually, however, turnstiles may grow two queue's to support a non-sleepable reader/writer lock implementation. For more details, see the comments in sys/turnstile.h and kern/subr_turnstile.c. The two primary advantages from the turnstile code include: 1) the size of struct mutex shrinks by four pointers as it no longer stores the thread queue linkages directly, and 2) less contention on sched_lock in SMP systems including the ability for multiple CPUs to contend on different locks simultaneously (not that this last detail is necessarily that much of a big win). Note that 1) means that this commit is a kernel ABI breaker, so don't mix old modules with a new kernel and vice versa. Tested on: i386 SMP, sparc64 SMP, alpha SMP Notes: svn path=/head/; revision=122514
* Let SA process work under ULE scheduler, originally it would panic kernel.David Xu2003-08-261-3/+16
| | | | | | | Reviewed by: jeff Notes: svn path=/head/; revision=119488
* Change instances of callout_init that specify MPSAFE behaviour toSam Leffler2003-08-191-1/+1
| | | | | | | | use CALLOUT_MPSAFE instead of "1" for the second parameter. This does not change the behaviour; it just makes the intent more clear. Notes: svn path=/head/; revision=119137
* Update powerpc to use the (old thread,new thread) calling conventionPeter Grehan2003-08-141-4/+0
| | | | | | | for cpu_throw() and cpu_switch(). Notes: svn path=/head/; revision=118893
* - Convert Alpha over to the new calling conventions for cpu_throw() andJohn Baldwin2003-08-121-1/+1
| | | | | | | | | | | cpu_switch() where both the old and new threads are passed in as arguments. Only powerpc uses the old conventions now. - Update comments in the Alpha swtch.s to reflect KSE changes. Tested by: obrien, marcel Notes: svn path=/head/; revision=118835
* Copyin the thread mailbox flags from the correct locationDaniel Eischen2003-08-081-1/+1
| | | | | | | in the mailbox. Notes: svn path=/head/; revision=118673