Commit Graph

177 Commits

Author SHA1 Message Date
dsl 1844147fa9 Split sys_wait4() so that compat code can fiddle with the returned 'status'
and 'rusage' without having to copy data to/from stackgap buffers.
The old split (find_stopped_child) could be removed.
amd64 seems to run netbsd32, linux and linux32 emulations. sparc64 compiles.
2007-05-07 16:53:17 +00:00
dsl 832ca390e2 Add child rusage values to exiting process in 'find_stopped_child'
so that it is (correctlly) available to the caller of wait4().
The self and child rusage values remain split for zombies.
2007-05-07 09:30:14 +00:00
dsl e6918d8f47 Remove proc->p_ru and the 'rusage' pool.
I think it existed to cache the numbers in kernel memory of a zombie when
proc->p_stats was part of the 'u' area - so got freed earlier and wouldn't
(easily) be accessible from a separate process.  However since both the
p_ru and p_stats fields are freed at the same time it is no longer needed.
Ride the recent 4.99.19 version change.
2007-04-30 20:11:41 +00:00
rmind 67d703cf25 Import of POSIX Asynchronous I/O.
Seems to be quite stable. Some work still left to do.

Please note, that syscalls are not yet MP-safe, because
of the file and vnode subsystems.

Reviewed by: <tech-kern>, <ad>
2007-04-30 14:44:28 +00:00
ad 4911263df8 cv_wakeup -> cv_signal 2007-03-29 17:35:17 +00:00
ad fed1793605 Improvements to lwp_wait1(), for PR kern/35932:
- Better detect simple cycles of threads calling _lwp_wait and return
  EDEADLK. Does not handle deeper cycles like t1 -> t2 -> t3 -> t1.
- If there are multiple threads in _lwp_wait, then make sure that
  targeted waits take precedence over waits for any LWP to exit.
- When checking for deadlock, also count the number of zombies currently
  in the process as potentially reapable. Whenever a zombie is murdered,
  kick all waiters to make them check again for deadlock.
- Add more comments.

Also, while here:

- LOCK_ASSERT -> KASSERT in some places
- lwp_free: change boolean arguments to type 'bool'.
- proc_free: let lwp_free spin waiting for the last LWP to exit, there's
  no reason to do it here.
2007-03-21 18:25:59 +00:00
ad a3128f66df Adjust previous: move the release of specificdata after the very last
file system operation.
2007-03-11 23:40:58 +00:00
ad 1bf149ba4c exit1: destroy the proc/lwp specificdata after calling uvm_proc_exit, as
file systems can still be using it.
2007-03-11 23:19:49 +00:00
ad c147748d84 - Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.
2007-03-09 14:11:22 +00:00
thorpej 4f3d5a9cc0 TRUE -> true, FALSE -> false 2007-02-22 06:34:42 +00:00
pavel 934634a18c Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
2007-02-17 22:31:36 +00:00
ad 57aa4fbf3b proc_free() was returning a NULL rusage pointer to wait() when a traced
process was reparented. Change proc_free() to copy the rusage to a buffer
on the stack if required, so it can be passed both to the debugger and
to the real parent process.

Fixes kern/35582 (kernel panics with gdb).
2007-02-16 00:39:16 +00:00
ad b07ec3fc38 Merge newlock2 to head. 2007-02-09 21:55:00 +00:00
ad 0ff4104d82 lwp::l_acflag is no longer useful. 2006-12-22 08:04:01 +00:00
yamt a575dafacc use KSI_INIT rather than memset. no functional changes. 2006-12-06 10:02:22 +00:00
yamt 1a7bc55dcc remove some __unused from function parameters. 2006-11-01 10:17:58 +00:00
christos 4d595fd7b1 - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
2006-10-12 01:30:41 +00:00
thorpej 12e8bb915e Don't free specificdata in lwp_exit2(); it's not safe to block there.
Instead, free an LWP's specificdata from lwp_exit() (if it is not the
last LWP) or exit1() (if it is the last LWP).  For consistency, free the
proc's specificdata from exit1() as well.  Add lwp_finispecific() and
proc_finispecific() functions to make this more convenient.
2006-10-11 04:51:06 +00:00
xtraeme 75d2d9715c Remove duplicated includes, from Jeff Ito -> PR kern/26113. Thanks. 2006-09-23 15:36:12 +00:00
manu 81c909dd45 1) Complete Linux exit_group() emulation
Members of the thread group must die without reporting to the parent and
without going to zombie stage. We do that by reparenting to init before
catching a SIGKILL. The parent will not see the child death.

The thread group leader must report the exit status, even if it exits
because of another thread calling exit_group(). We do that by storing the
exit status in struct linux_emuldata_shared, and the exit hook has the
duty of setting struct proc's p_xstat for the thread group leader.

2) For exit/fork/exec hooks, move the NPTL specific code to separate functions
that are shared between COMPAT_LINUX and COMPAT_LINUX32

3) Fix LINUX_CLONE_PARENT_SETTID semantics
2006-08-23 19:49:09 +00:00
ad 2b79369c7e - Hold a reference to the process credentials in each struct lwp.
- Update the reference on syscall and user trap if p_cred has changed.
- Collect accounting flags in the LWP, and collate on LWP exit.
2006-07-19 21:11:37 +00:00
elad 215bd95ba4 integrate kauth. 2006-05-14 21:15:11 +00:00
christos a4495f4cec implement PT_SYSCALL 2006-03-05 07:21:37 +00:00
christos 95e1ffb156 merge ktrace-lwp. 2005-12-11 12:16:03 +00:00
jdolecek 05a8b02adf log when traced process is orphaned
PR: 17388 by Greg A. Woods
2005-10-01 21:07:38 +00:00
yamt f615d37667 simplify lwp exit code. 2005-10-01 06:12:44 +00:00
yamt 9020ca379a protect p_nrlwps by sched_lock. no objection on tech-kern@. PR/29652. 2005-08-28 14:57:18 +00:00
yamt 5a3ce82137 exit_lwps: fix a race with eg. sa_setwoken.
ie. "exit_lwps: lwp_wait1 failed with error 11"
PR/30689.
2005-08-10 09:44:02 +00:00
yamt 98d4a17db9 exit_lwps: fix a race which causes a panic "setrunnable: lwp %p state was %d". 2005-08-10 09:42:03 +00:00
christos efb6943313 - add const.
- remove unnecessary casts.
- add __UNCONST casts and mark them with XXXUNCONST as necessary.
2005-05-29 22:24:14 +00:00
christos 8dc75b1c08 Panic strings should not end with \n. 2005-05-08 18:44:39 +00:00
christos f9a341d1f6 PR/19837: Stephen Ma: signal(SIGCHLD, SIG_IGN) should not create zombies. 2005-03-30 17:07:50 +00:00
perry da8abec863 nuke trailing whitespace 2005-02-26 21:34:55 +00:00
dbj 208b0b3a89 clear p->p_cwdi of exiting processes and
avoid dereferencing invalid p_cwdi in checkdirs
this fixes a race condition between exiting processes and mount
see discussion on tech-kern:
 http://mail-index.netbsd.org/tech-kern/2004/10/04/0006.html
 http://mail-index.netbsd.org/tech-kern/2004/10/08/0005.html
2005-01-24 21:27:02 +00:00
yamt 0994e6acb8 introduce a function, proclist_foreach_call, to iterate all procs on
a proclist and call the specified function for each of them.
primarily to fix a procfs locking problem, but i think that it's useful for
others as well.

while i'm here, introduce PROCLIST_FOREACH macro, which is similar to
LIST_FOREACH but skips marker entries which are used by proclist_foreach_call.
2004-10-01 16:30:52 +00:00
christos 251940a98f Use the P_ZOMBIE macro instead of open-coding it. No functional change. 2004-08-07 03:34:37 +00:00
pk 69211c6484 cwdfree() signature has been changed to accomodate fine-grained locking. 2004-05-31 15:33:38 +00:00
pk d190ac352d exit1: if !BIGLOCK, once the exiting process has been placed on the zombie
list and the proclist lock is released, we shouldn't touch the process
structure anymore, since it may be collected immediately by a waiting
parent.
2004-05-04 21:23:39 +00:00
cl ea5ec0212d add kernel part of concurrency support for SA on MP systems
- move per VP data into struct sadata_vp referenced from l->l_savp
  * VP id
  * lock on VP data
  * LWP on VP
  * recently blocked LWP on VP
  * queue of LWPs woken which ran on this VP before sleep
  * faultaddr
  * LWP cache for upcalls
  * upcall queue
- add current concurrency and requested concurrency variables
- make process exit run LWP on all VPs
- make signal delivery consider all VPs
- make timer events consider all VPs
- add sa_newsavp to allocate new sadata_vp structure
- add sa_increaseconcurrency to prepare new VP
- make sys_sa_setconcurrency request new VP or wakeup idle VP
- make sa_yield lower current concurrency
- set sa_cpu = VP id in upcalls
- maintain cached LWPs per VP
2004-03-14 01:08:47 +00:00
dbj f8e0478668 add some spltty() calls around TTY_LOCK() calls that didn't have them 2004-03-05 07:27:22 +00:00
yamt 471ef5f249 once exit1() releases big kernel lock, the struct proc can be freed and
re-used by another cpu immediately.  in that case, lwp_exit2() will
access freed memory.  to fix this:

- remove curlwp from p_lwps in exit1() rather than letting lwp_exit2() do so.
- add assertions to ensure freed proc has no lwps.

kern/24329 from me and kern/24574 from Havard Eidnes.
2004-03-02 09:15:26 +00:00
hannken c59d4851b8 Run pmap_deactivate() earlier in exit1(). Prevents a panic on sparc MP
where p->p_vmspace was 0xdeadbeef in pmap_deactivate().

Approved by: YAMAMOTO Takashi <yamt@netbsd.org>
2004-02-18 14:42:20 +00:00
yamt 1e18e59746 - borrow vmspace0 in uvm_proc_exit instead of uvmspace_free.
the latter is not a appropriate place to do so and it broke vfork.
- deactivate pmap before calling cpu_exit() to keep a balance of
  pmap_activate/deactivate.
2004-02-09 13:11:21 +00:00
yamt a45adbd9c7 don't deactivate pmap in exit1 because we'll touch the pmap later.
instead, borrow vmspace0 immediately before destroying the pmap
in uvmspace_free.
2004-02-07 10:05:52 +00:00
jdolecek 089abdad44 Rearrange process exit path to avoid need to free resources from different
process context ('reaper').

From within the exiting process context:
* deactivate pmap and free vmspace while we can still block
* introduce MD cpu_lwp_free() - this cleans all MD-specific context (such
  as FPU state), and is the last potentially blocking operation;
  all of cpu_wait(), and most of cpu_exit(), is now folded into cpu_lwp_free()
* process is now immediatelly marked as zombie and made available for pickup
  by parent; the remaining last lwp continues the exit as fully detached
* MI (rather than MD) code bumps uvmexp.swtch, cpu_exit() is now same
  for both 'process' and 'lwp' exit

uvm_lwp_exit() is modified to never block; the u-area memory is now
always just linked to the list of available u-areas. Introduce (blocking)
uvm_uarea_drain(), which is called to release the excessive u-area memory;
this is called by parent within wait4(), or by pagedaemon on memory shortage.
uvm_uarea_free() is now private function within uvm_glue.c.

MD process/lwp exit code now always calls lwp_exit2() immediatelly after
switching away from the exiting lwp.

g/c now unneeded routines and variables, including the reaper kernel thread
2004-01-04 11:33:29 +00:00
jdolecek 1d86b1f39f fix some comments, use NULL instead of 0 for pointer comparison 2004-01-03 19:43:55 +00:00
cl e7045955c7 kernel part of no-syscall upcall stack return: libpthread registers
an offset between ss_sp and struct sa_stackinfo_t (located in struct
__pthread_st) when calling sa_register.  The kernel increments the
sast_gen counter in struct sastack when an upcall stack is used.
libpthread increments the sasi_stackgen counter in struct
sa_stackinfo_t when an upcall stack is freed.  The kernel compares the
two counters to decide if a stack is free or in use.

- add struct sa_stackinfo_t with sasi_stackgen to count stack use in
  userland
- add sast_gen to struct sastack to count stack use in kernel
- add SA_FLAG_STACKINFO to enable the stackinfo_offset argument in the
  sa_register syscall
- add sa_stackinfo_offset to struct sadata for offset between ss_sp
  and struct sa_stackinfo_t
- add ssize_t stackinfo_offset argument to sa_register, initialize
  struct sadata's sa_stackinfo_offset from it if SA_FLAG_STACKINFO is
  set
- add sa_getstack, sa_getstack0, sa_stackused and sa_setstackfree
  functions to find/use/free upcall stacks and use these where
  appropriate
- don't record stack for upcall in sa_upcall0
- pass sau to sa_switchcall instead of l2 (l2 = curlwp in sa_switchcall)
- add sa_vp_blocker to struct sadata to pass recently blocked lwp to
  sa_switchcall
- delay finding a stack for blocked upcalls to sa_switchcall
- add sa_stacknext to struct sadata pointing to next most likely free
  upcall stack; also g/c sa_stackslist in struct sadata and sast_list
  in struct sastack
- add L_SA_WOKEN flag: LWP is on sa_woken queue
- add L_SA_RECYCLE flag: LWP should be recycled in sa_setwoken
- replace l_upcallstack with L_SA_WOKEN/L_SA_RECYCLE/L_SA_BLOCKING
  flags
- g/c now unused sast_blocker in struct sastack
- make sa_switchcall, sa_upcall0 and sa_upcall_getstate static in
  kern_sa.c
- call sa_upcall_userret only once in userret
- split sa_makeupcalls out of sa_upcall_userret and use to process
  the sa_upcalls queue
- on process exit: mark LWPs sleeping in saunblock interruptible; also
  there are no LWPs sleeping on l->l_upcallstack anymore; also clear
  sa_wokenq_head to prevent unblocked upcalls

additional changes:
- cleanup timerupcall sa_vp == curlwp check
- add check in sa_yield if we didn't block on our way here and we
  wouldn't any longer be the LWP on the VP
- invalidate sa_vp_ofaultaddr after resolving pagefault
2004-01-02 18:52:17 +00:00
atatat 44f5f6b89b The missing pieces of PROC_PID_STOPEXIT/P_STOPEXIT, a sysctl tweakable
flag that makes a process stop as it exits.
2003-12-06 04:16:33 +00:00
cl 2e11d201c2 - use list to keep track of free stacks.
- use splay tree for the pagefault check if the thread was running on
  an upcall stack.

=> removes the limitation that all upcall stacks need to be
   adjoining and that all upcall stacks have to be loaded with the
   1st sys_sa_stacks call.
=> enables keeping information associated with a stack in the kernel
   which makes it simpler to find out which LWP is using a stack.
=> allows increasing the SA_MAXNUMSTACKS without having to
   allocate an array of that size.
2003-11-17 22:52:09 +00:00
dsl 0342c9586a - Count number of zombies and stopped children and requeue them at the top
of the sibling list so that find_stopped_child can be optimised to avoid
  traversing the entire sibling list - helps when a process has a lot of
  children.
- Modify locking in pfind() and pgfind() to that the caller can rely on the
  result being valid, allow caller to request that zombies be findable.
- Rename pfind() to p_find() to ensure we break binary compatibility.
- Remove svr4_pfind since p_find willnow do the job.
- Modify some of the SMP locking of the proc lists - signals are still stuffed.

Welcome to 1.6ZF
2003-11-12 21:07:37 +00:00