Commit Graph

152 Commits

Author SHA1 Message Date
rmind 7146b2f61d Retire struct user, remove sys/user.h inclusions. Note sys/user.h header
as obsolete.  Remove USER_TO_UAREA/UAREA_TO_USER macros.

Various #include fixes and review by matt@.
2011-01-14 02:06:22 +00:00
rmind 11a35aed4d - Fix a few possible locking issues in execve1() and exit1(). Add a note
that scheduler locks are special in this regard - adaptive locks cannot
  be in the path due to turnstiles.  Randomly spotted/reported by uebayasi@.
- Remove unused lwp_relock() and replace lwp_lock_retry() by simplifying
  lwp_lock() and sleepq_enter() a little.
- Give alllwp its own cache-line and mark lwp_cache pointer as read-mostly.

OK ad@
2010-12-18 01:36:19 +00:00
chs 33fa5ccbbf many changes for COMPAT_LINUX:
- update the linux syscall table for each platform.
 - support new-style (NPTL) linux pthreads on all platforms.
   clone() with CLONE_THREAD uses 1 process with many LWPs
   instead of separate processes.
 - move the contents of sys__lwp_setprivate() into a new
   lwp_setprivate() and use that everywhere.
 - update linux_release[] and linux32_release[] to "2.6.18".
 - adjust placement of emul fork/exec/exit hooks as needed
   and adjust other emul code to match.
 - convert all struct emul definitions to use named initializers.
 - change the pid allocator to allow multiple pids to refer to the same proc.
 - remove a few fields from struct proc that are no longer needed.
 - disable the non-functional "vdso" code in linux32/amd64,
   glibc works fine without it.
 - fix a race in the futex code where we could miss a wakeup after
   a requeue operation.
 - redo futex locking to be a little more efficient.
2010-07-07 01:30:32 +00:00
rmind 3c507045e2 Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour.  Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.
2010-07-01 02:38:26 +00:00
yamt d5dec378f9 increment p_nrlwps in lwp_create rather than letting callers do so
as it's always decremented by lwp_exit.  this fixes error recovery of
eg. aio_procinit.
2010-06-13 04:13:31 +00:00
pooka 9dac69e895 Fix DIAGNOSTIC. Moral of the story: don't comment xen kernels out of the
build even if you'd like to go to sleep earlier.
2010-06-11 07:32:32 +00:00
pooka 51542301d2 lwp0 seems like an lwp instead of a process, so move bits related
to it from kern_proc.c to kern_lwp.c.  This makes kern_proc
"scheduling-clean" and more easily usable in environments with a
non-integrated scheduler (like, to take a random example, rump).
2010-06-10 20:54:53 +00:00
rmind 13f624ca0f Remove lwp_uc_pool, replace it with kmem(9), plus add some consistency.
As discussed, a while ago, with ad@.
2010-04-23 19:18:09 +00:00
pooka 2c4f731dd6 tyop 2010-04-12 23:20:18 +00:00
pooka 290fe400e0 Separate lwp specificdata data structure management from lwp cpu/vm
management.

No functional change.

(specificdata routines went from kern_lwp.c to subr_lwp_specificdata.c)
2010-04-12 22:15:31 +00:00
njoly cb925a949e Make lwp_ctl_alloc() return 0 instead of EINVAL, when lwpctl user
address already exists. This allow calling _lwp_ctl(2) more than once
on the same LWP.
2010-04-09 11:47:17 +00:00
christos ca843a73b0 PR/43128: Paul Koning: Threads support in ptrace() is insufficient for gdb to
debug threaded live apps: Add an optional lwpid in PT_STEP and PT_CONTINUE to
indicate which lwp to operate on, and implement the glue required to make it
work.
2010-04-06 13:50:22 +00:00
darran 6a9056a926 DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider.  Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-01 21:10:13 +00:00
darran 383b7f700b DTrace: Get rid of the KDTRACE_HOOKS ifdefs in the kernel. Replace the
functions with inline function that are empty when KDTRACE_HOOKS is not
defined.
2010-02-23 22:19:27 +00:00
darran 37422f86b0 Added a defflag option for KDTRACE_HOOKS and included opt_dtrace.h in the
relevant files. (Per Quentin Garnier - thanks!).
2010-02-21 07:01:57 +00:00
darran 1bc28ea1e9 Add the DTrace hooks to the kernel (KDTRACE_HOOKS config option).
DTrace adds a pointer to the lwp and proc structures which it uses to
manage its state.  These are opaque from the kernel perspective to keep
the kernel free of CDDL code. The state arenas are kmem_alloced and freed
as proccesses and threads are created and destoyed.

Also add a check for trap06 (privileged/illegal instruction) so that
DTrace can check for D scripts that may have triggered the trap so it
can clean up after them and resume normal operation.

Ok with core@.
2010-02-21 02:11:39 +00:00
rmind 1069745866 Replace few USER_TO_UAREA/UAREA_TO_USER uses, reduce sys/user.h inclusions. 2009-12-17 01:25:10 +00:00
rmind e4be2748a3 - Amend fd_hold() to take an argument and add assert (reflects two cases,
fork1() and the rest, e.g. kthread_create(), when creating from lwp0).

- lwp_create(): do not touch filedesc internals, use fd_hold().
2009-10-27 02:58:28 +00:00
rmind 33963b1448 Avoid #ifndef __NO_CPU_LWP_FREE, only ia64 is missing cpu_lwp_free
routines and it can/should provide stubs.
2009-10-22 22:28:57 +00:00
rmind 40cf6f3659 Remove uarea swap-out functionality:
- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code.  Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
2009-10-21 21:11:57 +00:00
pooka fbd53556dc Wipe out the last vestiges of POOL_INIT with one swift stroke. In
most cases, use a proper constructor.  For proplib, give a local
equivalent of POOL_INIT for the kernel object implementation.  This
way the code structure can be preserved, and a local link set is
not hazardous anyway (unless proplib is split to several modules,
but that'll be the day).

tested by booting a kernel in qemu and compile-testing i386/ALL
2009-09-13 18:45:10 +00:00
dyoung 2261ca8c07 In lwp_create(), take a reference to l2's filedesc_t instead of
taking a reference to curlwp's by calling fd_hold().  If lwp_create()
is called from fork1(), then l2 != curlwp, but l2's and not curlwp's
filedesc_t whose reference we should take.

This change stops the problem I describe in
<http://mail-index.netbsd.org/tech-kern/2009/07/09/msg005422.html>,
where /dev/rsd0a is never properly closed after fsck / runs on it.
This change seems to quiet my USB backup drive, sd0 at scsibus0 at
umass0, which had stopped spinning down when it was not in use:
The unit probably stayed open after mount(8) tried (and failed:
errant fstab entry) to mount it.

I am confident that this change is an improvement, but I doubt that
it is the last word on the matter.  I hate to get under the filedesc_t
abstraction by fiddling with fd_refcnt, and there may be something
I have missed, so somebody with greater understanding of the file
descriptors code should have a look.
2009-07-10 23:07:54 +00:00
ad 3cb7a24bec Make descriptor access and file allocation cheaper in many cases,
mostly by avoiding a bunch of atomic operations.
2009-05-23 18:28:05 +00:00
ad f0545a5e5b - Add lwp_pctr(), get an LWP's preemption/ctxsw counter.
- Fix a preemption bug in CURCPU_IDLE_P() that can lead to a bogus
  assertion failure on DEBUG kernels.
- Fix MP/preemption races with timecounter detachment.
2009-05-23 18:21:20 +00:00
ad ddf65d893c Update the big comment block. 2009-04-04 22:34:03 +00:00
rmind 4f1720c349 lwp_create: fix the locking bugs on affinity ingerition path (mea culpa).
pset_assign: traverse the list of LWPs safely.
sched_setaffinity: free cpuset (unused path) outside the lock.

Reviewed (with feedback) by <ad>.
2009-03-03 21:55:06 +00:00
ad 3c32363107 PR kern/36183 problem with ptrace and multithreaded processes
Fix the crashy test case that Thor provided.
2009-02-04 21:17:39 +00:00
wrstuden 04ca26c586 Tweak change to move SA support from userret() to lwp_userret().
1) Since we want to check for upcalls only once, take LW_SA_UPCALL
out of the while(l->l_flags & LW_USERRET) loop.

2) since the goal is to keep SA code out of userret() (and especially
all the emulations that include userret() but will never do SA),
ALWAYS set LW_SA_UPCALL when we set SAVP_FLAG_NOUPCALLS. Drop the
test for it in lwp_userret() since it will never be set bare.

3) Adapt sa_upcall_userret() to clear LW_SA_UPCALL if it's no longer
needed. If we have gained upcalls since sa_yield(), we will deliver
them next time around.

Tested by skrll at.
2008-10-28 22:11:36 +00:00
ad a9327b33e2 Undo revivesa damage to userret(). 2008-10-21 11:51:23 +00:00
wrstuden fc7511b00e Merge wrstuden-revivesa into HEAD. 2008-10-15 06:51:17 +00:00
rmind 337b081fed - Replace lwp_t::l_sched_info with union: pointer and timeslice.
- Change minimal time-quantum to ~20 ms.
- Thus remove unneeded pool in M2, and unused sched_lwp_exit().
- Do not increase l_slptime twice for SCHED_4BSD (regression fix).
2008-10-07 09:48:27 +00:00
rmind 4f91cff093 - Disallow setting of affinity for zombie LWPs.
- Fix the possible NULL dereference when LWP exiting.
- Fix the inhertance of affinity.
2008-07-14 01:19:37 +00:00
rmind 30dfdb2897 lwp_migrate: if LWP is still on the CPU (LP_RUNNING), it must be handled
like LSONPROC.  Should fix PR/38588.  OK by <ad>.
2008-07-02 19:53:12 +00:00
rmind 160268aca6 Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.
2008-07-02 19:49:58 +00:00
ad b7f5063255 lwp_lock_retry: return a pointer to the lock acquired. No functional change. 2008-06-16 09:45:20 +00:00
rmind 481ae1556f - Add general cpuset macros.
- Use kcpuset name for kernel-only functions.
- Use cpuid_t to specify CPU ID.
- Unify all cpuset users.

API is expected to be stable now.
2008-06-16 01:41:20 +00:00
christos f30b5785d5 Don't expose struct cpuset, share the l_affinity flag and only allocate it
if we need to. This is not a compatible change, but the syscalls are new
enough and they don't need to be versioned. Approved by rmind.
2008-06-15 20:32:57 +00:00
ad ea8a92578d If vfork(), we want the LWP to run fast and on the same CPU
as its parent, so that it can reuse the VM context and cache
footprint on the local CPU.
2008-06-02 13:58:07 +00:00
ad 2feabc3836 PR kern/38812 race between lwp_exit_switchaway and exit1/coredump
Move the LWP RUNNING and TIMEINTR flags into the thread-private flag word.
2008-05-31 21:26:01 +00:00
rmind 29170d3854 Simplifcation for running LWP migration. Removes double-locking in
mi_switch(), migration for LSONPROC is now performed via idle loop.
Handles/fixes on-CPU case in lwp_migrate(), misc.

Closes PR/38169, idea of migration via idle loop by Andrew Doran.
2008-05-29 22:33:27 +00:00
ad 208df81d99 Move lwp_exit_switchaway() into kern_synch.c. Instead of always switching
to the idle loop, pick a new LWP from the run queue.
2008-05-27 17:51:17 +00:00
ad 93e0e98369 Take the mutex pointer and waiters count out of sleepq_t: the values can
be or are maintained elsewhere. Now a sleepq_t is just a TAILQ_HEAD.
2008-05-26 12:08:38 +00:00
ad 245f0726ac Reduce ifdefs due to MULTIPROCESSOR slightly. 2008-05-19 17:06:02 +00:00
ad a4e0004be3 LOCKDEBUG: try to speed it up a bit by not using so much global state.
This will break the build briefly but will be followed by another commit
to fix that..
2008-05-06 18:40:57 +00:00
rmind 0fe9197c91 lwp_suspend: check for LW_* flags in l_flag, not l_stat. 2008-05-01 21:25:23 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
ad 4c7ba24481 Add MI code to support in-kernel preemption. Preemption is deferred by
one of the following:

- Holding kernel_lock (indicating that the code is not MT safe).
- Bracketing critical sections with kpreempt_disable/kpreempt_enable.
- Holding the interrupt priority level above IPL_NONE.

Statistics on kernel preemption are reported via event counters, and
where preemption is deferred for some reason, it's also reported via
lockstat. The LWP priority at which preemption is triggered is tuneable
via sysctl.
2008-04-28 15:36:01 +00:00
ad 1f8aca087d Disable preemption during the final stages of LWP exit. 2008-04-27 11:39:20 +00:00
ad c925598aae lwp_startup: spl0 after pmap_activate, otherwise we could be preempted
without a pmap active.
2008-04-25 14:34:41 +00:00
ad 3cef738139 lwp_userret: don't drop p_lock while holding a scheduler lock. 2008-04-24 21:47:11 +00:00