Commit Graph

105 Commits

Author SHA1 Message Date
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
ad 284c2b9aef Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.
2008-04-24 18:39:20 +00:00
ad 6d70f903e6 Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
  be sent from a hardware interrupt handler. Signal activity must be
  deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
  and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
2008-04-24 15:35:27 +00:00
rmind 5c0e3318e2 Adjust comments: spc_mutex is now always a per-CPU lock, L_INMEM -> LW_INMEM,
L_WSUSPEND -> LW_WSUSPEND, and remove white-spaces, while here.
2008-04-15 18:54:30 +00:00
ad be04ac4896 Make rusage collection per-LWP and collate in the appropriate places.
cloned threads need a little bit more work but the locking needs to
be fixed first.
2008-03-27 19:06:51 +00:00
ad 25b10dbb15 lwp_ctl_alloc: initialize lcp_kaddr to vm_map_min(kernel_map), in order to
prevent uvm_map() from spuriously failing.
2008-03-23 16:39:34 +00:00
ad 5214147407 LWP_CACHE_CREDS: instead of testing (l_cred != p_cred), use a per-LWP
flag bit to indicate a pending cred update. Avoids touching one item of
shared state in the syscall path.
2008-03-22 17:53:34 +00:00
ad a9ca7a3734 Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.
2008-03-21 21:54:58 +00:00
ad c42a4d1422 Add a boolean parameter to syncobj_t::sobj_unsleep. If true we want the
existing behaviour: the unsleep method unlocks and wakes the swapper if
needs be. If false, the caller is doing a batch operation and will take
care of that later. This is kind of ugly, but it's difficult for the caller
to know which lock to release in some situations.
2008-03-17 16:54:51 +00:00
ad 32b8f98e7d lwp_ctl_exit: fix a use-after-free that caused the following:
_lwp_ctl()	<- works
execve()	<- tears down lwpctl state
_lwp_ctl()	<- fails erroneously
2008-03-07 18:06:04 +00:00
rmind 9850c0557d sys__sched_getparam and sys__sched_getaffinity: Do not assume that LWP
with LID=1 exists, use LIST_FIRST(&p->p_lwps) instead.
Fixes PR/37987 by <yamt>.

While here, adjust license.
2008-02-22 22:32:49 +00:00
yamt 1a5be26b7e wrap a long line. 2008-01-28 12:23:42 +00:00
yamt 21832401a4 lwp_free: add assertions. 2008-01-28 10:24:45 +00:00
rmind 5c71a4d49f Implementation of processor-sets, affinity and POSIX real-time extensions.
Add schedctl(8) - a program to control scheduling of processes and threads.

Notes:
- This is supported only by SCHED_M2;
- Migration of LWP mechanism will be revisited;

Proposed on: <tech-kern>. Reviewed by: <ad>.
2008-01-15 03:37:10 +00:00
ad 79aa087ae2 - lwp_exit: if the LWP has a name, rename it to "(zombie)".
- lwp_free: don't leak l_name.
2008-01-12 18:06:40 +00:00
yamt 2e8a5bee68 lwp_ctl_alloc: fix error handling. 2008-01-07 11:41:29 +00:00
ad 4a780c9ae2 Merge vmlocking2 to head. 2008-01-02 11:48:20 +00:00
ad ea3f10f7e0 Merge more changes from vmlocking2, mainly:
- Locking improvements.
- Use pool_cache for more items.
2007-12-26 16:01:34 +00:00
yamt 949e16d902 use binuptime for l_stime/l_rtime. 2007-12-22 01:14:53 +00:00
yamt 555511ff96 include <sys/user.h>. 2007-12-13 05:25:03 +00:00
yamt 0c38201391 add ddb "whatis" command. inspired from solaris ::whatis dcmd. 2007-12-13 02:45:09 +00:00
ad 27f20ecf58 Soft interrupts can now take proclist_lock, so there is no need to
double-lock alllwp or allproc.
2007-12-03 20:26:24 +00:00
ad 9027344d32 For the slow path soft interrupts, arrange to have the priority of a
borrowed user LWP raised into the 'kernel RT' range if the LWP sleeps
(which is unlikely).
2007-12-03 17:14:59 +00:00
ad e2aaefb859 - mi_switch: adjust so that we don't have to hold the old LWP locked across
context switch, since cpu_switchto() can be slow under certain conditions.
  From rmind@ with adjustments by me.
- lwpctl: allow LWPs to reregister instead of returning EINVAL. Just return
  their existing lwpctl user address.
2007-12-02 14:55:32 +00:00
skrll 1587bff9f0 Explicitly include <uvm/uvm_object.h> 2007-11-13 11:38:35 +00:00
yamt a05590a3d6 lwp_ctl_alloc: fix a mutex_enter/exit mismatch. 2007-11-13 08:38:06 +00:00
ad b668a9a05f Add _lwp_ctl() system call: provides a bidirectional, per-LWP communication
area between processes and the kernel.
2007-11-12 23:11:58 +00:00
matt 11910619f7 Change some initialization of static queues to compile time.
(xxx_INIT to xxx_HEAD_INITIALIZER).  Drop code which inits
non-auto (global or static) variables to 0 since that's
already implied by being non-auto.  Init some static/global
cpu_simple_locks at compile time.
2007-11-11 23:22:23 +00:00
ad d18c6ca4de Merge from vmlocking:
- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.
2007-11-07 00:23:13 +00:00
ad d831186d55 Merge scheduler changes from the vmlocking branch. All discussed on
tech-kern:

- Invert priority space so that zero is the lowest priority. Rearrange
  number and type of priority levels into bands. Add new bands like
  'kernel real time'.
- Ignore the priority level passed to tsleep. Compute priority for
  sleep dynamically.
- For SCHED_4BSD, make priority adjustment per-LWP, not per-process.
2007-11-06 00:42:39 +00:00
rmind 6673d94694 - Fix a comment: LSIDL is covered by spc_mutex, not spc_lwplock.
- mi_switch: Add a comment that spc_lwplock might not necessary be held.
2007-10-13 00:30:26 +00:00
rmind a21233e46b Import of SCHED_M2 - the implementation of new scheduler, which is based
on the original approach of SVR4 with some inspirations about balancing
and migration from Solaris.  It implements per-CPU runqueues, provides a
real-time (RT) and time-sharing (TS) queues, ready to support a POSIX
real-time extensions, and also prepared for the support of CPU affinity.

The following lines in the kernel config enables the SCHED_M2:

no options SCHED_4BSD
options SCHED_M2

The scheduler seems to be stable.  Further work will come soon.

http://mail-index.netbsd.org/tech-kern/2007/10/04/0001.html
http://www.netbsd.org/~rmind/m2/mysql_bench_ro_4x_local.png
Thanks <ad> for the benchmarks!
2007-10-09 19:00:13 +00:00
ad 0a0689eebd Merge from vmlocking: fix LWP reference counting problems. 2007-10-08 18:11:11 +00:00
ad e36f46b00e curlwp appears to be set by all active copies of cpu_switchto - remove
the MI assignments and assert that it's set in mi_switch().
2007-09-25 21:38:56 +00:00
ad 513227e941 - Fix sleepq_block() to return EINTR if the LWP is cancelled. Pointed out
by yamt@.

- Introduce SOBJ_SLEEPQ_LIFO, and use for LWPs sleeping via _lwp_park.
  libpthread enqueues most waiters in LIFO order to try and wake LWPs that
  ran recently, since their working set is more likely to be in cache.
  Matching the order of insertion reduces the time spent searching queues
  in the kernel.

- Do not boost the priority of LWPs sleeping in _lwp_park, just let them
  sleep at their user priority level. LWPs waiting for some I/O event in
  the kernel still wait with kernel priority and get woken more quickly.
  This needs more evaluation and is to be revisited, but the effect on a
  variety of benchmarks is positive.

- When waking LWPs, do not send an IPI to remote CPUs or arrange for the
  current LWP to be preempted unless (a) the thread being awoken has kernel
  priority and has higher priority than the currently running thread or (b)
  the remote CPU is idle.
2007-09-06 23:58:56 +00:00
rmind 00cdc8df70 sys__lwp_suspend: implement waiting for target LWP status changes (or
process exiting). Removes XXXLWP.

Reviewed by <ad> some time ago..
2007-08-02 01:48:44 +00:00
tnn 95342a9670 Fix previous; lwp status are states, not flags. 2007-07-31 09:56:31 +00:00
tnn 7a9d8e5613 proc_representative_lwp:
- Correct expression for checking if the lwp is running.
 - Remove dead code. Ok'd by Andrew Doran.
2007-07-31 00:52:04 +00:00
ad 46022e56e5 Update the blurb to match reality. 2007-07-28 00:12:26 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
yamt f03010953f merge yamt-idlelwp branch. asked by core@. some ports still needs work.
from doc/BRANCHES:

	idle lwp, and some changes depending on it.

	1. separate context switching and thread scheduling.
	   (cf. gmcgarry_ctxsw)
	2. implement idle lwp.
	3. clean up related MD/MI interfaces.
	4. make scheduler(s) modular.
2007-05-17 14:51:11 +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 59d979c5f1 Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
2007-03-12 18:18:22 +00:00
ad 681b77eb72 lwp_userret: if the process is exiting, don't bother looking for signals. 2007-03-04 20:59:00 +00:00
yamt e781af39bd implement priority inheritance. 2007-02-26 09:20:52 +00:00
thorpej dd962f8680 Pick up some additional files that were missed before due to conflicts
with newlock2 merge:

Replace the Mach-derived boolean_t type with the C99 bool type.  A
future commit will replace use of TRUE and FALSE with true and false.
2007-02-21 23:48:10 +00:00
ad 67323d2552 When sending signals, only boost the priority of the receiving LWP if
the process is being killed.
2007-02-20 17:47:03 +00:00
dsl d64834e4f1 Add code to support per-system call statistics:
option SYSCALL_STATS	counts the number of times each system call is made
option SYSCALL_TIMES	counts the amount of time spent in each system call
Currently the counting hooks have only been added to the i386 system call
handler, and the time spent in interrupts is not subtracted.
It ought also be possible to add the times to the processes profiling
counters in order to get a more accurate user/system/interrupt split.
The counts themselves are readable via the sysctl interface.
2007-02-18 16:58:15 +00:00