summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_thread.c
Commit message (Collapse)AuthorAgeFilesLines
* Reversion of commit by Davidxu plus fixes since applied.julian2003-02-011-648/+515
| | | | | | | | I'm not convinced there is anything major wrong with the patch but them's the rules.. I am using my "David's mentor" hat to revert this as he's offline for a while.
* Only add one tick per tick to the thread stats, instead of some random number.julian2003-01-311-2/+2
|
* Use kg_numupcalls to see if we are closing a thread group,davidxu2003-01-261-2/+2
| | | | not kg_kses which is not changed when a group is still working.
* Move UPCALL related data structure out of kse, introduce a newdavidxu2003-01-261-513/+646
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | data structure called kse_upcall to manage UPCALL. All KSE binding and loaning code are gone. A thread owns an upcall can collect all completed syscall contexts in its ksegrp, turn itself into UPCALL mode, and takes those contexts back to userland. Any thread without upcall structure has to export their contexts and exit at user boundary. Any thread running in user mode owns an upcall structure, when it enters kernel, if the kse mailbox's current thread pointer is not NULL, then when the thread is blocked in kernel, a new UPCALL thread is created and the upcall structure is transfered to the new UPCALL thread. if the kse mailbox's current thread pointer is NULL, then when a thread is blocked in kernel, no UPCALL thread will be created. Each upcall always has an owner thread. Userland can remove an upcall by calling kse_exit, when all upcalls in ksegrp are removed, the group is atomatically shutdown. An upcall owner thread also exits when process is in exiting state. when an owner thread exits, the upcall it owns is also removed. KSE is a pure scheduler entity. it represents a virtual cpu. when a thread is running, it always has a KSE associated with it. scheduler is free to assign a KSE to thread according thread priority, if thread priority is changed, KSE can be moved from one thread to another. When a ksegrp is created, there is always N KSEs created in the group. the N is the number of physical cpu in the current system. This makes it is possible that even an userland UTS is single CPU safe, threads in kernel still can execute on different cpu in parallel. Userland calls kse_create to add more upcall structures into ksegrp to increase concurrent in userland itself, kernel is not restricted by number of upcalls userland provides. The code hasn't been tested under SMP by author due to lack of hardware. Reviewed by: julian
* Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.alfred2003-01-211-3/+3
| | | | Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.
* Remove a KASSERT that can now happen and add a missing setrunnable.julian2003-01-201-0/+2
|
* Check signals for idled threads.davidxu2003-01-071-2/+1
|
* Set kse mailbox pointer to NULL when P_KSES is turned off.davidxu2003-01-041-3/+6
|
* White space fixesjulian2003-01-031-10/+10
|
* Make an explicit flag to indicate that a KSE has a reason to upcall,julian2003-01-031-19/+22
| | | | | | | and use that flag when there is a kse_wakeup() call. It will probably be used with signal delivery as well eventually. Submitted by: davidxu@
* Don't need to set retvals to 0 in the non error case. Theyjulian2003-01-031-9/+0
| | | | | | are set to a good default anyhow. Submitted by: davidxu@
* Adjust code for Julian's last commit. use td_mailbox to detect ifdavidxu2003-01-021-10/+8
| | | | a syscall is from UTS kernel.
* Add code to ddb to allow backtracing an arbitrary thread.julian2002-12-281-241/+273
| | | | | | | | | | | | | | | | | | | | | | | | (show thread {address}) Remove the IDLE kse state and replace it with a change in the way threads sahre KSEs. Every KSE now has a thread, which is considered its "owner" however a KSE may also be lent to other threads in the same group to allow completion of in-kernel work. n this case the owner remains the same and the KSE will revert to the owner when the other work has been completed. All creations of upcalls etc. is now done from kse_reassign() which in turn is called from mi_switch or thread_exit(). This means that special code can be removed from msleep() and cv_wait(). kse_release() does not leave a KSE with no thread any more but converts the existing thread into teh KSE's owner, and sets it up for doing an upcall. It is just inhibitted from being scheduled until there is some reason to do an upcall. Remove all trace of the kse_idle queue since it is no-longer needed. "Idle" KSEs are now on the loanable queue.
* Unbreak the KSE code. Keep track of zobie threads using the Per-CPU storagejulian2002-12-101-123/+72
| | | | | | | | during the context switch. Rearrange thread cleanups to avoid problems with Giant. Clean threads when freed or when recycled. Approved by: re (jhb)
* Under certain circumstances, we were calling kmem_free() frommux2002-11-221-0/+3
| | | | | | | | | | i386 cpu_thread_exit(). This resulted in a panic with WITNESS since we need to hold Giant to call kmem_free(), and we weren't helding it anymore in cpu_thread_exit(). We now do this from a new MD function, cpu_thread_dtor(), called by thread_dtor(). Approved by: re@ Suggested by: jhb
* - Implement a mechanism for allowing schedulers to place scheduler dependantjeff2002-11-211-19/+31
| | | | | | | | | data in the scheduler independant structures (proc, ksegrp, kse, thread). - Implement unused stubs for this mechanism in sched_4bsd. Approved by: re Reviewed by: luigi, trb Tested on: x86, alpha
* Make sure only update wall clock at upcall time, slightly reformatdavidxu2002-11-181-13/+13
| | | | code in kse_relase().
* 1. Support versioning and wall clock in kse mailbox,davidxu2002-11-181-9/+108
| | | | | | | | also add rusage time in thread mailbox. 2. Minor change for thread limit code in thread_user_enter(), fix typo in kse_release() last I committed. Reviewed by: deischen, mini
* include smp.h.julian2002-11-171-0/+1
| | | | | it is required by some code that was commented out until david's last commit.
* 1.Add sysctls to control KSE resource allocation.davidxu2002-11-171-8/+30
| | | | | | | | | | | | | | | | kern.threads.max_threads_per_proc kern.threads.max_groups_per_proc 2.Temporary disable borrower thread stash itself as owner thread's spare thread in thread_exit(). there is a race between owner thread and borrow thread: an owner thread may allocate a spare thread as this: if (td->td_standin == NULL) td->standin = thread_alloc(); but thread_alloc() can block the thread, then a borrower thread would possible stash it self as owner's spare thread in thread_exit(), after owner is resumed, result is a thread leak in kernel, double check in owner can avoid the race, but it may be ugly and not worth to do.
* Rework last exiting thread in kse_release(), wait a signal and thendavidxu2002-11-171-2/+11
| | | | schedule an upcall and call thread_exit().
* Return EWOULDBLOCK for last thread in kse_release().davidxu2002-11-151-0/+1
| | | | Requested by: archie
* In kse_release(), check if current thread is bounddavidxu2002-11-141-4/+16
| | | | | | and current kse mailbox was already initialized, also prevent last thread from exiting unless we figure out how to safely support null thread proc.
* KSE-enabled processes only.davidxu2002-10-311-1/+4
|
* Check NULL thread mailbox pointer.davidxu2002-10-301-0/+2
|
* Style fixes.davidxu2002-10-301-10/+10
|
* Don't forget to set syscall result.davidxu2002-10-301-0/+2
|
* Add an actual implementation of kse_thr_interrupt()davidxu2002-10-301-1/+21
|
* Close a race window in kse_create(): signal delivered after SIGPENDING calldavidxu2002-10-281-4/+2
| | | | but before we call kse_link().
* iBack out david's last commit. the suspension code needs to be calledjulian2002-10-261-12/+0
| | | | for non KSE processes too.
* Move suspension checking code from userret() into thread_userret().davidxu2002-10-261-0/+12
|
* Backout revision 1.48.davidxu2002-10-261-2/+1
|
* suspend thread only when it can be interrupted.davidxu2002-10-251-1/+2
|
* let thread_schedule_upcall() handle idle kse.davidxu2002-10-251-2/+8
|
* fix style-ojulian2002-10-251-1/+1
|
* More work on the interaction between suspending and sleeping threads.julian2002-10-251-12/+26
| | | | | | Also clean up some code used with 'single-threading'. Reviewed by: davidxu
* fix typo.davidxu2002-10-251-1/+2
|
* Extract out KSE specific code from machine specific codejulian2002-10-241-0/+47
| | | | | | | | so that there is ony one copy of it. Fix that one copy so that KSEs with no mailbox in a KSE program are not a cause of page faults (this can legitmatly happen). Submitted by: (parts) davidxu
* respect TDF_SINTR, also for SINGLE_NO_EXIT threading mode, if a threaddavidxu2002-10-241-6/+6
| | | | was already suspended, do nothing.
* don't forget to remove kse from idle queue.davidxu2002-10-241-0/+2
|
* Move thread related code from kern_proc.c to kern_thread.c.julian2002-10-241-28/+500
| | | | | | | | | | Add code to free KSEs and KSEGRPs on exit. Sort KSE prototypes in proc.h. Add the missing kse_exit() syscall. ksetest now does not leak KSEs and KSEGRPS. Submitted by: (parts) davidxu
* Round out the facilty for a 'bound' thread to loan out its KSEjulian2002-10-091-169/+264
| | | | | | | | | | | | | | | | | | | | | | | | in specific situations. The owner thread must be blocked, and the borrower can not proceed back to user space with the borrowed KSE. The borrower will return the KSE on the next context switch where teh owner wants it back. This removes a lot of possible race conditions and deadlocks. It is consceivable that the borrower should inherit the priority of the owner too. that's another discussion and would be simple to do. Also, as part of this, the "preallocatd spare thread" is attached to the thread doing a syscall rather than the KSE. This removes the need to lock the scheduler when we want to access it, as it's now "at hand". DDB now shows a lot mor info for threaded proceses though it may need some optimisation to squeeze it all back into 80 chars again. (possible JKH project) Upcalls are now "bound" threads, but "KSE Lending" now means that other completing syscalls can be completed using that KSE before the upcall finally makes it back to the UTS. (getting threads OUT OF THE KERNEL is one of the highest priorities in the KSE system.) The upcall when it happens will present all the completed syscalls to the KSE for selection.
* Put an easy-to-miss assignment into the proper place. It was stray in thejmallett2002-10-051-2/+4
| | | | | middle of a block of code, with no clear assignment. While here, move one nearby assignment out of declaration.
* Remove bogus duplicate assignment of local variables.jmallett2002-10-051-2/+2
|
* Add some unspeakable hackery to the tree under #ifdef __ia64__ to workpeter2002-10-041-0/+14
| | | | | | | | around limitations in the ia64 kernel stack handling code. Basically preallocate a bunch of threads (and hence kstacks) while contigmalloc() still works, and never free them back to the general memory pool. After the system has been running for a while, contigmalloc() eventually fails at a critical momemt and panics the system.
* Some kernel threads try to do significant work, and the default KSTACK_PAGESscottl2002-10-021-1/+1
| | | | | | | | | | | | | doesn't give them enough stack to do much before blowing away the pcb. This adds MI and MD code to allow the allocation of an alternate kstack who's size can be speficied when calling kthread_create. Passing the value 0 prevents the alternate kstack from being created. Note that the ia64 MD code is missing for now, and PowerPC was only partially written due to the pmap.c being incomplete there. Though this patch does not modify anything to make use of the alternate kstack, acpi and usb are good candidates. Reviewed by: jake, peter, jhb
* Implement basic KSE loaning. This stops a hread that is blocked in BOUND modejulian2002-09-291-0/+9
| | | | | | | | | from stopping another thread from completing a syscall, and this allows it to release its resources etc. Probably more related commits to follow (at least one I know of) Initial concept by: julian, dillon Submitted by: davidxu
* lock proc while calling psignaljulian2002-09-291-9/+17
| | | | | | (plus related cleanups) Submitted by: davidxu
* Redo how completing threads pass their state to userlandjulian2002-09-271-81/+121
| | | | | | | if they are not going to cross over themselves. Also change how the list of completed user threads is tracked and passed to the KSE. This is not a change in design but rather the implementation of what was originally envisionned.
* Make the following name changes to KSE related functions, etc., to betterarchie2002-09-251-3/+3
| | | | | | | | | | | | | | | represent their purpose and minimize namespace conflicts: kse_fn_t -> kse_func_t struct thread_mailbox -> struct kse_thr_mailbox thread_interrupt() -> kse_thr_interrupt() kse_yield() -> kse_release() kse_new() -> kse_create() Add missing declaration of kse_thr_interrupt() to <sys/kse.h>. Regenerate the various generated syscall files. Minor style fixes. Reviewed by: julian
OpenPOWER on IntegriCloud