summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_proc.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.alfred2003-01-211-1/+1
| | | | Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.
* Remove unnecessary lock assertion.hsu2003-01-041-15/+1
|
* Fix typos, mostly s/ an / a / where appropriate and a few s/an/and/schweikh2002-12-301-1/+1
| | | | Add FreeBSD Id tag where missing.
* - Add the new sched_pctcpu() function to the sched_* api.jeff2002-11-211-1/+1
| | | | | | | | - Provide a routine in sched_4bsd to add this functionality. - Use sched_pctcpu() in kern_proc, which is the one place outside of sched_4bsd where the old pctcpu value was accessed directly. Approved by: re
* - Implement a mechanism for allowing schedulers to place scheduler dependantjeff2002-11-211-9/+3
| | | | | | | | | 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
* Move thread related code from kern_proc.c to kern_thread.c.julian2002-10-241-258/+0
| | | | | | | | | | 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
* detect idle kse correctly.davidxu2002-10-221-1/+1
|
* Add an actual implementation of kse_wakeup()julian2002-10-201-1/+41
| | | | Submitted by: Davidxu
* Use strlcpy() instead of strncpy() to copy NUL terminated stringsrobert2002-10-171-8/+8
| | | | for safety and consistency.
* - Add a new global mutex 'ppeers_lock' to protect the p_peers list ofjhb2002-10-151-0/+2
| | | | | | | | | | | | | | | | | | | processes forked with RFTHREAD. - Use a goto to a label for common code when exiting from fork1() in case of an error. - Move the RFTHREAD linkage setup code later in fork since the ppeers_lock cannot be locked while holding a proc lock. Handle the race of a task leader exiting and killing its peers while a peer is forking a new child. In that case, go ahead and let the peer process proceed normally as the parent is about to kill it. However, the task leader may have already gone to sleep to wait for the peers to die, so the new child process may not receive a SIGKILL from the task leader. Rather than try to destruct the new child process, just go ahead and send it a SIGKILL directly and add it to the p_peers list. This ensures that the task leader will wait until both the peer process doing the fork() and the new child process have received their KILL signals and exited. Discussed with: truckman (earlier versions)
* Round out the facilty for a 'bound' thread to loan out its KSEjulian2002-10-091-19/+14
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Rename the mutex thread and process states to use a more generic 'LOCK'jhb2002-10-021-6/+6
| | | | | | | | | name instead. (e.g., SLOCK instead of SMTX, TD_ON_LOCK() instead of TD_ON_MUTEX()) Eventually a turnstile abstraction will be added that will be shared with mutexes and other types of locks. SLOCK/TDI_LOCK will be used internally by the turnstile code and will not be specific to mutexes. Making the change now ensures that turnstiles can be dropped in at a later date without affecting the ABI of userland applications.
* Let kse_wakeup() take a KSE mailbox pointer argument.archie2002-10-021-0/+3
| | | | Reviewed by: julian
* Some kernel threads try to do significant work, and the default KSTACK_PAGESscottl2002-10-021-0/+9
| | | | | | | | | | | | | 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
* Back our kernel support for reliable signal queues.jmallett2002-10-011-3/+2
| | | | Requested by: rwatson, phk, and many others
* First half of implementation of ksiginfo, signal queues, and such. Thisjmallett2002-09-301-2/+3
| | | | | | | | | | | | | | | | | | | | | | gets signals operating based on a TailQ, and is good enough to run X11, GNOME, and do job control. There are some intricate parts which could be more refined to match the sigset_t versions, but those require further evaluation of directions in which our signal system can expand and contract to fit our needs. After this has been in the tree for a while, I will make in kernel API changes, most notably to trapsignal(9) and sendsig(9), to use ksiginfo more robustly, such that we can actually pass information with our (queued) signals to the userland. That will also result in using a struct ksiginfo pointer, rather than a signal number, in a lot of kern_sig.c, to refer to an individual pending signal queue member, but right now there is no defined behaviour for such. CODAFS is unfinished in this regard because the logic is unclear in some places. Sponsored by: New Gold Technology Reviewed by: bde, tjr, jake [an older version, logic similar]
* Implement basic KSE loaning. This stops a hread that is blocked in BOUND modejulian2002-09-291-1/+3
| | | | | | | | | 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
* Rewrite the kse_create() function to better aproach the semantics wejulian2002-09-281-56/+71
| | | | have specified in the design.
* Make the following name changes to KSE related functions, etc., to betterarchie2002-09-251-9/+10
| | | | | | | | | | | | | | | 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
* oops don't do dthe copy range in a new KSE. There isn't one any more.julian2002-09-231-0/+2
|
* Add code to create > 1 KSe per process.julian2002-09-231-16/+39
| | | | | | (support code not yet complete) Submitted by: davidxu
* Add kernel support needed for the KSE-aware libpthread:mini2002-09-161-5/+22
| | | | | | | | | | | | - Use ucontext_t's to store KSE thread state. - Synthesize state for the UTS upon each upcall, rather than saving and copying a trapframe. - Deliver signals to KSE-aware processes via upcall. - Rename kse mailbox structure fields to be more BSD-like. - Store the UTS's stack in struct proc in a stack_t. Reviewed by: bde, deischen, julian Approved by: -arch
* Allocate KSEs and KSEGRPs separatly and remove them from the proc structure.julian2002-09-151-40/+44
| | | | | | | | | next step is to allow > 1 to be allocated per process. This would give multi-processor threads. (when the rest of the infrastructure is in place) While doing this I noticed libkvm and sys/kern/kern_proc.c:fill_kinfo_proc are diverging more than they should.. corrective action needed soon.
* Completely redo thread states.julian2002-09-111-5/+5
| | | | Reviewed by: davidxu@freebsd.org
* Make UAREA_PAGES and KSTACK_PAGES visible to userland via sysctl, likepeter2002-09-071-0/+6
| | | | | | | | PS_STRINGS and USRSTACK is. This is necessary in order to decode a.out core dumps. kern_proc.c was already referring to both of these values but was missing the #include "opt_kstack_pages.h". Make the sysctl variables visible so that certain kld modules can see how their parent kernel was configured.
* Minor spelling tweak: assume "his" is actually "This".rwatson2002-09-061-1/+1
|
* Use UMA as a complex object allocator.julian2002-09-061-17/+31
| | | | | | | | | | | | | | | The process allocator now caches and hands out complete process structures *including substructures* . i.e. it get's the process structure with the first thread (and soon KSE) already allocated and attached, all in one hit. For the average non threaded program (non KSE that is) the allocated thread and its stack remain attached to the process, even when the process is unused and in the process cache. This saves having to allocate and attach it later, effectively bringing us (hopefully) close to the efficiency of pre-KSE systems where these were a single structure. Reviewed by: davidxu@freebsd.org, peter@freebsd.org
* Fix typos; each file has at least one s/seperat/separat/schweikh2002-08-111-5/+5
| | | | | | | | | | (I skipped those in contrib/, gnu/ and crypto/) While I was at it, fixed a lot more found by ispell that I could identify with certainty to be errors. All of these were in comments or text, not in actual code. Suggested by: bde MFC after: 3 days
* Wire the sysctl output buffer before grabbing any locks to preventtruckman2002-07-281-0/+1
| | | | | | | SYSCTL_OUT() from blocking while locks are held. This should only be done when it would be inconvenient to make a temporary copy of the data and defer calling SYSCTL_OUT() until after the locks are released.
* Thinking about it I came to the conclusion that the KSE states were incorrectlyjulian2002-07-141-2/+0
| | | | | | | | | | | | | | formulated. The correct states should be: IDLE: On the idle KSE list for that KSEG RUNQ: Linked onto the system run queue. THREAD: Attached to a thread and slaved to whatever state the thread is in. This means that most places where we were adjusting kse state can go away as it is just moving around because the thread is.. The only places we need to adjust the KSE state is in transition to and from the idle and run queues. Reviewed by: jhb@freebsd.org
* Collect all the (now equivalent) pmap_new_proc/pmap_dispose_proc/peter2002-07-071-2/+103
| | | | | | | | | | | | | pmap_swapin_proc/pmap_swapout_proc functions from the MD pmap code and use a single equivalent MI version. There are other cleanups needed still. While here, use the UMA zone hooks to keep a cache of preinitialized proc structures handy, just like the thread system does. This eliminates one dependency on 'struct proc' being persistent even after being freed. There are some comments about things that can be factored out into ctor/dtor functions if it is worth it. For now they are mostly just doing statistics to get a feel of how it is working.
* If the process is a zombie, then you must not try dereference the threadjulian2002-06-301-53/+55
| | | | | because there isn't one. Of course this code only possibly works for single threaded processes anyhow..
* Part 1 of KSE-IIIjulian2002-06-291-73/+144
| | | | | | | | | | | | | The ability to schedule multiple threads per process (one one cpu) by making ALL system calls optionally asynchronous. to come: ia64 and power-pc patches, patches for gdb, test program (in tools) Reviewed by: Almost everyone who counts (at various times, peter, jhb, matt, alfred, mini, bernd, and a cast of thousands) NOTE: this is still Beta code, and contains lots of debugging stuff. expect slight instability in signals..
* Always drop the p_args reference we held for copyout, even if we're aboutmini2002-06-221-3/+2
| | | | | | | to change it. This fixes a leak triggered by setproctitle(3). Approved by: alfred Noticed by: Peter Jeremy <peter.jeremy@alcatel.com.au>
* Properly lock accesses to p_tracep and p_traceflag. Also make a fewjhb2002-06-071-2/+12
| | | | ktrace-only things #ifdef KTRACE that were not before.
* Change p_can{debug,see,sched,signal}()'s first argument to be a threadjhb2002-05-191-3/+3
| | | | | | | pointer instead of a proc pointer and require the process pointed to by the second argument to be locked. We now use the thread ucred reference for the credential checks in p_can*() as a result. p_canfoo() should now no longer need Giant.
* Make funsetown() take a 'struct sigio **' so that the locking canalfred2002-05-061-4/+1
| | | | | | | | | | | | | | | | be done internally. Ensure that no one can fsetown() to a dying process/pgrp. We need to check the process for P_WEXIT to see if it's exiting. Process groups are already safe because there is no such thing as a pgrp zombie, therefore the proctree lock completely protects the pgrp from having sigio structures associated with it after it runs funsetownlst. Add sigio lock to witness list under proctree and allproc, but over proc and pgrp. Seigo Tanimura helped with this.
* As malloc(9) and free(9) are now Giant-free, remove the Giant locktanimura2002-05-031-5/+1
| | | | across malloc(9) and free(9) of a pgrp or a session.
* Fix the lock order reversal between the sigio lock and a process/pgrp lock intanimura2002-05-031-0/+2
| | | | funsetownlst() by locking the sigio lock across funsetownlst().
* Free(9) should be Giant-free.tanimura2002-04-241-1/+1
| | | | Suggested by: jhb
* Push down Giant for setpgid(), setsid() and aio_daemon(). Giant protects onlytanimura2002-04-201-1/+5
| | | | malloc(9) and free(9).
* - Merge the pgrpsess_lock and proctree_lock sx locks into one proctree_lockjhb2002-04-161-14/+10
| | | | | | | | | | | | sx lock. Trying to get the lock order between these locks was getting too complicated as the locking in wait1() was being fixed. - leavepgrp() now requires an exclusive lock of proctree_lock to be held when it is called. - fixjobc() no longer gets a shared lock of proctree_lock now that it requires an xlock be held by the caller. - Locking notes in sys/proc.h are adjusted to note that everything that used to be protected by the pgrpsess_lock is now protected by the proctree_lock.
* - Change fill_kinfo_proc() to require that the process is locked when itjhb2002-04-091-14/+20
| | | | | | | | | | | | | | is called. - Change sysctl_out_proc() to require that the process is locked when it is called and to drop the lock before it returns. If this proves too complex we can change sysctl_out_proc() to simply acquire the lock at the very end and have the calling code drop the lock right after it returns. - Lock the process we are going to export before the p_cansee() in the loop in sysctl_kern_proc() and hold the lock until we call sysctl_out_proc(). - Don't call p_cansee() on the process about to be exported twice in the aforementioned loop.
* Use CTASSERT rather than a runtime check to detect kinfo_proc size changes.jake2002-04-061-16/+2
| | | | Remove the ugly yuck code to busy wait for 20 seconds.
* Change callers of mtx_init() to pass in an appropriate lock type name. Injhb2002-04-041-3/+3
| | | | | | | most cases NULL is passed, but in some cases such as network driver locks (which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used. Tested on: i386, alpha, sparc64
* Stage-2 commit of the critical*() code. This re-inlines cpu_critical_enter()dillon2002-04-011-0/+1
| | | | | | | | | | | | | | | | | | | | | and cpu_critical_exit() and moves associated critical prototypes into their own header file, <arch>/<arch>/critical.h, which is only included by the three MI source files that need it. Backout and re-apply improperly comitted syntactical cleanups made to files that were still under active development. Backout improperly comitted program structure changes that moved localized declarations to the top of two procedures. Partially re-apply one of the program structure changes to move 'mask' into an intermediate block rather then in three separate sub-blocks to make the code more readable. Re-integrate bug fixes that Jake made to the sparc64 code. Note: In general, developers should not gratuitously move declarations out of sub-blocks. They are where they are for reasons of structure, grouping, readability, compiler-localizability, and to avoid developer-introduced bugs similar to several found in recent years in the VFS and VM code. Reviewed by: jake
* Close some holes with p->p_args by NULL'ing out the p->p_args pointeralfred2002-03-311-3/+10
| | | | | | | while holding the proc lock, and by holding the pargs structure when accessing it from outside of the owner. Submitted by: Jonathan Mini <mini@haikugeek.com>
* To remove nested include of sys/lock.h and sys/mutex.h from sys/proc.halfred2002-03-281-0/+44
| | | | | | make the pargs_* functions into non-inlines in kern/kern_proc.c. Requested by: bde
* Make the reference counting of 'struct pargs' SMP safe.alfred2002-03-271-7/+5
| | | | | | | | | There is still some locations where the PROC lock should be held in order to prevent inconsistent views from outside (like the proc->p_fd fix for kern/vfs_syscalls.c:checkdirs()) that can be fixed later. Submitted by: Jonathan Mini <mini@haikugeek.com>
* Add a new mtx_init option "MTX_DUPOK" which allows duplicate acquires of locksjeff2002-03-271-1/+1
| | | | | | | | | | | with this flag. Remove the dup_list and dup_ok code from subr_witness. Now we just check for the flag instead of doing string compares. Also, switch the process lock, process group lock, and uma per cpu locks over to this interface. The original mechanism did not work well for uma because per cpu lock names are unique to each zone. Approved by: jhb
OpenPOWER on IntegriCloud