dragonfly.git
13 years agokernel - Switch to exclusive spinlocks in the coretemp sensor
Matthew Dillon [Mon, 30 Aug 2010 06:20:12 +0000 (23:20 -0700)]
kernel - Switch to exclusive spinlocks in the coretemp sensor

* No impact on performance.

* TODO: spinlocks are being held across major kernel calls in the
  detach code which is not legal.

13 years agokernel - Switch to exclusive spinlocks in kern_descrip.c
Matthew Dillon [Mon, 30 Aug 2010 06:13:59 +0000 (23:13 -0700)]
kernel - Switch to exclusive spinlocks in kern_descrip.c

* This isn't expected to have much of an effect on performance and I want
  to get rid of shared spinlocks.  If it becomes an issue for descriptor
  lookups we could actually move to a spinless lookup/hold model using
  defered frees.

13 years agokernel - Refactor uidinfo a little
Matthew Dillon [Mon, 30 Aug 2010 05:48:02 +0000 (22:48 -0700)]
kernel - Refactor uidinfo a little

* Fix a MP drop race with uidinfo and get rid of the shared spinlock.

  Also fix areas where the spinlock was improperly enclosing complex
  code.

13 years agokernel - Refactor plimit a little
Matthew Dillon [Mon, 30 Aug 2010 05:22:05 +0000 (22:22 -0700)]
kernel - Refactor plimit a little

* Use only exclusive spinlocks, I will be removing shared spinlocks.

* Refactor the cpu test such that the hot path does not acquire
  any spinlocks.

13 years agokernel - Fix spinlock use in syscons
Matthew Dillon [Mon, 30 Aug 2010 05:13:07 +0000 (22:13 -0700)]
kernel - Fix spinlock use in syscons

* Spinlocks cannot be held across complex calls, particularly calls
  that might block or switch.

  This fixes a spinlock panic during lwkt.tty_mpsafe testing.

13 years agokernel - remove syscall_mpsafe and trap_mpsafe sysctls
Matthew Dillon [Mon, 30 Aug 2010 04:45:24 +0000 (21:45 -0700)]
kernel - remove syscall_mpsafe and trap_mpsafe sysctls

* traps and system calls are always mpsafe, we don't need
  these sysctls any more.

13 years agokernel - kobj code cleanup
Matthew Dillon [Mon, 30 Aug 2010 03:05:44 +0000 (20:05 -0700)]
kernel - kobj code cleanup

* Cleanup remains of KOBJ_STATS

13 years agokernel - Minor documentation
Matthew Dillon [Mon, 30 Aug 2010 02:59:48 +0000 (19:59 -0700)]
kernel - Minor documentation

13 years agokernel - Possibly fix a bug in aic7xxx
Matthew Dillon [Mon, 30 Aug 2010 02:58:29 +0000 (19:58 -0700)]
kernel - Possibly fix a bug in aic7xxx

* An attempt to compile -O2 revealed three uninitialized fields
  falling through to call that pokes them into the chip.  Initialize
  the fields.

13 years agokernel - Compact KOBJOPLOOKUP() kobj method core macro
Matthew Dillon [Mon, 30 Aug 2010 02:32:45 +0000 (19:32 -0700)]
kernel - Compact KOBJOPLOOKUP() kobj method core macro

* Replace the longish KOBJOPLOOKUP() macro with a procedure call
  to kobj_lookup_method().  Do all the heavy lifting in the procedure.

  Reduces the nominal kernel size by 67K.

13 years agoaicasm: Mark stop() __dead2.
Sascha Wildner [Mon, 30 Aug 2010 00:38:15 +0000 (02:38 +0200)]
aicasm: Mark stop() __dead2.

13 years agokernel - Fix usb keyboard problems with ehci & ddb
Matthew Dillon [Sun, 29 Aug 2010 22:10:21 +0000 (15:10 -0700)]
kernel - Fix usb keyboard problems with ehci & ddb

* Be sure to save the status of the xfer before reissuing the xfer
  in an interrupt pipe callback.

  This fixes an issue where ukbd thought the keyboard events from
  ehci were illegal because the status of the transfer was always
  IN_PROGRESS instead of COMPLETE.

  Interrupt pipes reissue their xfers prior to making the callback
  in order to ensure that the xfer is not somewhere in no-man's land
  if the callback enters the debugger (i.e. ctl-alt-esc).

13 years agoMPSAFE TTY - Cleanup ukbd and atkbd, fix unregistration bug
Matthew Dillon [Sun, 29 Aug 2010 22:09:22 +0000 (15:09 -0700)]
MPSAFE TTY - Cleanup ukbd and atkbd, fix unregistration bug

* Cleanup code, fix unregistration module.  Fixes panic on usb keyboard
  unplug.

13 years agokernel - Fix UP build
Matthew Dillon [Sun, 29 Aug 2010 20:48:31 +0000 (13:48 -0700)]
kernel - Fix UP build

* Declare panic_cpu_gd whether UP or SMP.

* Properly reinit the spinlock whether UP or SMP

Reported-by: swildner
13 years agoMPSAFE TTY - Refactor the keyboard switch code to make all drivers MPSAFE
Matthew Dillon [Sun, 29 Aug 2010 20:45:58 +0000 (13:45 -0700)]
MPSAFE TTY - Refactor the keyboard switch code to make all drivers MPSAFE

* Add a per-kbd lock.

* Replace the keyboard kbd_*() macros with function wrappers which acquire
  and release the per-kbd lock on behalf of each keyboard driver.  The
  wrapper code also understands polled mode and will not acquire/release
  locks in polled mode (aka debugger).

* Remove all tokens and locks from the keyboard drivers.

* Do some documenting of non-blocking paths.

13 years agoiscsi_initiator(4): Fix another potential NULL pointer dereference.
Sascha Wildner [Sun, 29 Aug 2010 19:24:09 +0000 (21:24 +0200)]
iscsi_initiator(4): Fix another potential NULL pointer dereference.

so (which is sp->soc) can be NULL here, so add a check before dereferencing
it.

13 years agoiscsi_initiator(4): Fix a potential NULL pointer dereference.
Sascha Wildner [Sun, 29 Aug 2010 19:13:27 +0000 (21:13 +0200)]
iscsi_initiator(4): Fix a potential NULL pointer dereference.

If sp can be NULL (as the rest of the code suggests), we can't use sdebug()
since that prints the string with sp->sid prepended (thereby dereferencing
NULL).

Instead, use debug() and add sp->sid to its string (with a check for NULL).

While here, fix some indentation issues.

13 years ago MPSAFE TTY - Fix deadlock in reporting of probe errors.
Matthew Dillon [Sun, 29 Aug 2010 17:50:47 +0000 (10:50 -0700)]
 MPSAFE TTY - Fix deadlock in reporting of probe errors.

* When sio can't drain it reports the fact, but it was doing it while
  still holding com_lock.  Rearranging the lock fixes the problem.

* Clean up some unnecessary tty_tokens in critical code paths and rearrange
  code to not hold com_lock across tty_token acquisition calls.

* Release the com_lock around breakpoint() (<enter>~^B sequence) to
  avoid a deadlock.

* Detect and ignore a reentrant kprintf() to try to avoid a deadlock.
  The detection flag is also reset by a panic.

13 years agoMPSAFE TTY - Refactor kprintf()'s spinlock, shutdown, move cons_spin
Matthew Dillon [Sun, 29 Aug 2010 16:36:53 +0000 (09:36 -0700)]
MPSAFE TTY - Refactor kprintf()'s spinlock, shutdown, move cons_spin

* Adjust panic assertions to reduce reentrant panics.

* Redo the shutdown code to properly interlock panic_cpu_gd

* Move cons_lock into subr_prf.c and use a normal spinlock instead of
  a deprecated (w/interrupt disablement) spinlock.

  Adjust kvcprintf() when used with kputchar() to acquire cons_spin
  only if the current cpu is not the currently panicing cpu.

  Adjust kvcprintf() when used with kputchar() to acquire a hard
  critical section.

13 years agokern_sensors - MPSAFE
Alex Hornung [Sun, 29 Aug 2010 09:35:55 +0000 (10:35 +0100)]
kern_sensors - MPSAFE

* It also seems like all sensor drivers can be run mpsafe as long as
  their tasks are serialized, which happens now anyways via the
  sensor_task_lock.

13 years agoMPSAFE TTY - get rid of tokens in console path
Alex Hornung [Sun, 29 Aug 2010 16:17:20 +0000 (17:17 +0100)]
MPSAFE TTY - get rid of tokens in console path

* The console path (coming through tty_cons.c) can never block, so do
  not try to acquire tokens there.

Reported-by: Jan Lentfer
13 years agokernel - Remove unneeded get_mplock() wrappers near tokens
Matthew Dillon [Sun, 29 Aug 2010 15:13:43 +0000 (08:13 -0700)]
kernel - Remove unneeded get_mplock() wrappers near tokens

* The xx_tokens replace the mplock functionality (and for now
  they still get the mplock), so clean these up.

13 years agokernel - Uninline crit_exit()
Matthew Dillon [Sun, 29 Aug 2010 07:49:21 +0000 (00:49 -0700)]
kernel - Uninline crit_exit()

* Corrections for DEBUG_CRIT_SECTIONS (LINT build)

13 years agokernel - Uninline crit_exit()
Matthew Dillon [Sun, 29 Aug 2010 07:41:12 +0000 (00:41 -0700)]
kernel - Uninline crit_exit()

* Missing file from last commit.

13 years agokernel - Uninline crit_exit()
Matthew Dillon [Sun, 29 Aug 2010 07:10:25 +0000 (00:10 -0700)]
kernel - Uninline crit_exit()

* Have crit_exit() call an actual procedure instead of inlining it.
  This doesn't seem to effect performance any and it reduces the
  size of the kernel noticeably.

  Modern cpus heavily optimize call/return paths these days and there
  might even be advantages to the smaller code and branch-cache footprint.
  The conditionals inside crit_exit() are nearly perfectly predicted
  now that there is no differentiation between the N->(N-1) and 1->0 case.

13 years agokernel - gcc -Os/-O2 warnings pass
Matthew Dillon [Sun, 29 Aug 2010 05:37:24 +0000 (22:37 -0700)]
kernel - gcc -Os/-O2 warnings pass

* This is just a partial pass on the code to start cleaning up gcc
  warnings at higher optimization levels.

13 years agokernel - Introduce hard code sections, simplify critical sections & mplocks
Matthew Dillon [Sun, 29 Aug 2010 04:07:08 +0000 (21:07 -0700)]
kernel - Introduce hard code sections, simplify critical sections & mplocks

* Introduce hard code sections with crit_enter_hard(), crit_exit_hard(),
  lwkt_gettoken_hard() and lwkt_reltoken_hard().

  These functions create a hard code section that, like an interrupt or ipi,
  does not allow any case which might potentially block or switch threads.
  While in a hard code section any such case will assert and panic the
  system.

  For example, acquiring a token that is not already held would be disallowed
  even if the acquisition could be accomplished without blocking.  However,
  acquiring a token which is already held would be allowed.  Same with the
  mplock, lockmgr locks, etc. (mtx's and serializers have not been dealt
  with yet).

* Introduce ASSERT_LWKT_TOKEN_HARD() and ASSERT_LWKT_TOKEN_CRIT().

  These assert that a token is held and a hard critical section (hard)
  or any critical section (crit) is in place.

* Rework the critical section macros and optimize the crit_exit*() code
  to two conditionals which are usually always false regardless of
  whether critcount is transitioning 1->0 or not.  Also declare
  crit_panic() __dead2 which may produce better code.

* Rework get_mplock() to reduce code generation.  The hard code section
  assertions would have made it too big.  We still optimize the case
  where the mplock is already held.

13 years agoFix various mdoc issues in various manual pages.
Sascha Wildner [Sun, 29 Aug 2010 00:41:12 +0000 (02:41 +0200)]
Fix various mdoc issues in various manual pages.

13 years agokernel - make nrandom helper thread mpsafe
Matthew Dillon [Sun, 29 Aug 2010 00:32:52 +0000 (17:32 -0700)]
kernel - make nrandom helper thread mpsafe

* The random number generator helper thread no longer holds the mplock.

13 years agokernel - All lwkt thread now start out mpsafe part 2/2
Matthew Dillon [Sun, 29 Aug 2010 00:30:29 +0000 (17:30 -0700)]
kernel - All lwkt thread now start out mpsafe part 2/2

* Remove the TDF_MPSAFE flag entirely.  All thread creation of all
  types now start running the thread without the mplock.

  Drivers which aren't mpsafe immediately acquire the mplock.

13 years agokernel - All lwkt thread now start out mpsafe part 1/2
Matthew Dillon [Sun, 29 Aug 2010 00:18:34 +0000 (17:18 -0700)]
kernel - All lwkt thread now start out mpsafe part 1/2

* All callers of lwkt_init_thread(), lwkt_create() and lwkt_alloc_thread()
  now always pass TDF_MPSAFE and the flag is asserted in the low level
  thread creation code.

13 years agokernel - Fix telnet ttyp* allocation
Matthew Dillon [Sat, 28 Aug 2010 23:14:07 +0000 (16:14 -0700)]
kernel - Fix telnet ttyp* allocation

* Fix handling of TS_ZOMBIE, which I think I broke a few commits ago.
  This was preventing traditional pty's from being properly reused.

Reported-by: lentferj
13 years agokernel - Change lwp_fork() to not hold the mplock in the new thread
Matthew Dillon [Sat, 28 Aug 2010 22:37:07 +0000 (15:37 -0700)]
kernel - Change lwp_fork() to not hold the mplock in the new thread

* Change lwp_fork() to produce a mpsafe thread at startup instead of
  one with the mplock held.

* Change all fork_trampoline() functions and all kernel callbacks
  via cpu_set_fork_handler() to expect a thread without the
  mplock held.

* Adjust the thread procedures for aio etc (those not yet mpsafe)
  to acquire the mplock.

13 years agokernel - make kern/vfs_sync.c MPSAFE
Matthew Dillon [Sat, 28 Aug 2010 21:42:42 +0000 (14:42 -0700)]
kernel - make kern/vfs_sync.c MPSAFE

* Syncer queues already tokenized but make the syncer thread MPSAFE

* Mark the source file MPSAFE

13 years agoMerge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
Matthew Dillon [Sat, 28 Aug 2010 21:36:41 +0000 (14:36 -0700)]
Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly

13 years agokernel - unwind kthread_create() mplock
Matthew Dillon [Sat, 28 Aug 2010 21:32:41 +0000 (14:32 -0700)]
kernel - unwind kthread_create() mplock

* All kthread_create*() calls and kproc_start() calls now create
  threads which do not hold the mplock at startup.

* Add get_mplock()/rel_mplock() to threads which are not yet mpsafe.

* Remove rel_mplock() calls from thread startups which were making
  themselves mpsafe by releasing the mplock.

* Kernel eventhandler API is now MPSAFE

* Kernel kproc API is now MPSAFE

* Rename a few thread procedures to make their function more obvious.

13 years agobsd-family-tree: Sync with FreeBSD (for FreeBSD 8.1).
Sascha Wildner [Sat, 28 Aug 2010 21:23:48 +0000 (23:23 +0200)]
bsd-family-tree: Sync with FreeBSD (for FreeBSD 8.1).

13 years agomanpages: Fix some more .Dv abuse.
Sascha Wildner [Sat, 28 Aug 2010 21:21:40 +0000 (23:21 +0200)]
manpages: Fix some more .Dv abuse.

13 years agodriver.9: Fix .Dv abuse.
Sascha Wildner [Sat, 28 Aug 2010 21:10:36 +0000 (23:10 +0200)]
driver.9: Fix .Dv abuse.

13 years agosyscall.9: Some minor mdoc adjustments.
Sascha Wildner [Sat, 28 Aug 2010 21:07:42 +0000 (23:07 +0200)]
syscall.9: Some minor mdoc adjustments.

13 years agokernel - CAM mpsafe issues
Matthew Dillon [Sat, 28 Aug 2010 19:48:56 +0000 (12:48 -0700)]
kernel - CAM mpsafe issues

* Lock the CAM bus when making asynchronous xpt callbacks.  This code
  previously depended on the MP lock but failed to use the correct
  sim lock, and AHCI/SILI now use their own locks.

* Remove a few other unnecessary mplocks.

* Redo the bus counting code to be MPSAFE.

13 years agokernel - Mark vm/vm_zeroidle.c and vm/vnode_pager.c MPSAFE
Matthew Dillon [Sat, 28 Aug 2010 18:40:57 +0000 (11:40 -0700)]
kernel - Mark vm/vm_zeroidle.c and vm/vnode_pager.c MPSAFE

* These modules are MPSAFE.  Also run the vm_zeroidle thread
  MPSAFE.

13 years agokernel - make kern/imgact_resident.c MPSAFe
Matthew Dillon [Sat, 28 Aug 2010 18:27:40 +0000 (11:27 -0700)]
kernel - make kern/imgact_resident.c MPSAFe

* Get rid of the mplock and use the existing lockmgr lock to deal
  with races.

13 years agokernel - Call knote_fdclose() without the mplock.
Matthew Dillon [Sat, 28 Aug 2010 18:08:31 +0000 (11:08 -0700)]
kernel - Call knote_fdclose() without the mplock.

* knote_fdclose() handles MPSAFE/non-MPSAFE filter callbacks so we
  no longer have to call it with the mplock held.

13 years agokernel - procfs_token work
Matthew Dillon [Sat, 28 Aug 2010 18:06:08 +0000 (11:06 -0700)]
kernel - procfs_token work

* Cover proc_stop(), proc_unstop(), and setrunnable() with proc_token.
  Remove the MP lock assertion from setrunnable().

* Cover procfs operations with proc_token.

* Cover lwp_signotify() and friends with proc_token.

13 years agokernel - Add vmobj_token, misc vm-related tokenization
Matthew Dillon [Sat, 28 Aug 2010 17:26:04 +0000 (10:26 -0700)]
kernel - Add vmobj_token, misc vm-related tokenization

* Add vmobj_token to protect vm_object_list and vm_object->ref_count and
  related functions.

  Note: coalesce and collapse require both vm_token and vmobj_token,
  and vmspace_fork() requires a bunch of tokens.

* Remove miscellanious mplocks and critical sections that are no longer
  needed.

* Correct potential sysinfo kernel data visibilty issue.

* Optimize some potentially recursive vm_token/vmobj_token situations
  by adding *_locked() procedure variants.  To avoid blowing out the
  token stack.

* Remove unnecessary get_mplock() calls in vm_zone.c

* Bump gd_intr_nesting_level in the IPI processing core and assert
  that it is zero in the gettoken core.  Hard interrupts (vs interrupt
  threads) are not allowed to acquire tokens for obvious reasons.

13 years agokernel - Fix badfo_kqfilter for badfileops
Matthew Dillon [Sat, 28 Aug 2010 16:02:47 +0000 (09:02 -0700)]
kernel - Fix badfo_kqfilter for badfileops

* badfo_kqfilter() must return an error to cause the kqueue
  registraton to drop the knote, otherwise a kernel panic
  will occur because the default file_filtops isn't replaced
  and has not detach or event functions.

13 years agoMPSAFE: MPSAFE kern_sig.c
Venkatesh Srinivas [Sat, 28 Aug 2010 14:10:25 +0000 (07:10 -0700)]
MPSAFE: MPSAFE kern_sig.c

13 years agosio: Fix a typo. lwkt_gettoken -> lwkt_reltoken
Sascha Wildner [Sat, 28 Aug 2010 08:08:43 +0000 (10:08 +0200)]
sio: Fix a typo. lwkt_gettoken -> lwkt_reltoken

Reported-by: alexh
13 years agosio - Minor token fix for sio
Matthew Dillon [Sat, 28 Aug 2010 05:18:08 +0000 (22:18 -0700)]
sio - Minor token fix for sio

* comwakeup() can be called from a callout and thus must acquire
  tty_token itself instead of asserting that it is already held.

Reported-by: lentferj
13 years agovkernel - Make copyin/copyout mpsafe
Matthew Dillon [Sat, 28 Aug 2010 02:41:34 +0000 (19:41 -0700)]
vkernel - Make copyin/copyout mpsafe

* copyin and copyout are mpsafe now that the VM system is locked up,
  so remove the get_mplock()/rel_mplock() wrapper.

13 years agokernel - Adjust contention handler
Matthew Dillon [Sat, 28 Aug 2010 02:39:42 +0000 (19:39 -0700)]
kernel - Adjust contention handler

* Simplify handle_cpu_contention_mask() a little.  For vkernels we
  call pthread_yield().

* Just call cpu_pause() in cpu_spinlock_contested().  Don't do anything
  fancier, the routine is called as part of the exponential backoff
  code.

13 years agokernel - Add description to static token initializers
Matthew Dillon [Sat, 28 Aug 2010 01:28:38 +0000 (18:28 -0700)]
kernel - Add description to static token initializers

* Add a description argument for LWKT_TOKEN_xx_INITIALIZER()

13 years agoMerge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
Matthew Dillon [Sat, 28 Aug 2010 00:23:34 +0000 (17:23 -0700)]
Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly

13 years agovkernel - Fix deadlocks with cothread locks
Matthew Dillon [Sat, 28 Aug 2010 00:12:01 +0000 (17:12 -0700)]
vkernel - Fix deadlocks with cothread locks

* Callbacks into the main kernel are not allowed when holding a cothread
  lock as this could cause a deadlock between cpus.  If the callback into
  the kernel blocks the cothread lock, being a pthreads lock,
  remains locked.

* Refactor the network and disk pipeline to hold the cothread lock for
  a much shorter period of time, allowing data to be pipelined without
  any stall conditions.

* For vknet if the tx mbuf return fifo is full we wait until it isn't.

13 years agokernel - Major MPSAFE Infrastructure 2
Matthew Dillon [Fri, 27 Aug 2010 08:55:46 +0000 (01:55 -0700)]
kernel - Major MPSAFE Infrastructure 2

* Refactor buffer cache code which assumes content-stable data across
  a non-blocking BUF_LOCK().  This is no longer true.  The content must
  be reverified after the BUF_LOCK() succeeds.

* Make setting and clearing B_DELWRI atomic with buffer reassignment.

* Release cached mplock when looping in the scheduler and run
  check_splz() to avoid livelocking cpus.

* Refactor the mplock contention handling code to handle both the mplock
  and token contention.  Generate a 2uS delay for all but one cpu to
  try to avoid livelocks.

* Do not splz() from inside a spinlock, it will just panic.

* Fix the token description field for 'systat -pv 1'.

* Optimize MP_LOCK macros a bit.

13 years agoMPSAFE - TTY & related drivers
Alex Hornung [Fri, 27 Aug 2010 23:33:26 +0000 (00:33 +0100)]
MPSAFE - TTY & related drivers

* Put kern/tty_* under the tty_token (and acquire the proc_token where
  needed).

* MPSAFE all related drivers (users of kbdsw, linesw and vidsw) with the
  same tty_token.

* NOTE: syscons.c and scvgarndr.c are not really under this new lock
  yet as some really strange hangs appear. Some are related to the
  cursor drawing (which stalls the  machine if a token is held) and
  others are in some other syscons.c functions.

13 years agokernel - Major MPSAFE Infrastructure
Matthew Dillon [Fri, 27 Aug 2010 04:18:06 +0000 (21:18 -0700)]
kernel - Major MPSAFE Infrastructure

* vm_page_lookup() now requires the vm_token to be held on call instead of
  the MP lock.  And fix the few places where the routine was being called
  without the vm_token.

  Various situations where a vm_page_lookup() is performed followed by
  vm_page_wire(), without busying the page, and other similar situations,
  require the vm_token to be held across the whole block of code.

* bio_done callbacks are now MPSAFE but some drivers (ata, ccd, vinum,
  aio, nfs) are not MPSAFE yet so get the mplock for those.   They will
  be converted to a generic driver-wide token later.

* Remove critical sections that used to protect VM system related
  interrupts, replace with the vm_token.

* Spinlocks now bump thread->td_critcount in addition to
  mycpu->gd_spinlock*.  Note the ordering is important.  Then remove
  gd_spinlock* checks elsewhere that are covered by td_critcount and
  replace with assertions.

  Also use td_critcount in the kern_mutex.c code instead of gd_spinlock*.

  This fixes situations where the last crit_exit() would call splx()
  without checking for spinlocks.  Adding the additional checks would
  have made the crit_*() inlines too complex so instead we just fold
  it into td_critcount.

* lwkt_yield() no longer guarantees that lwkt_switch() will be called
  so call lwkt_switch() instead in places where a switch is required.
  For example, to unwind a preemption.  Otherwise the kernel could end
  up live-locking trying to yield because the new switch code does not
  necessarily schedule a different kernel thread.

* Add the sysctl user_pri_sched (default 0).  Setting this will make
  the LWKT scheduler more aggressively schedule user threads when
  runnable kernel threads are unable to gain token/mplock resources.
  For debugging only.

* Change the bufspin spinlock to bufqspin and bufcspin, and generally
  rework vfs_bio.c to lock numerous fields with bufcspin.  Also use
  bufcspin to interlock waitrunningbufspace() and friends.

  Remove several mplocks in vfs_bio.c that are no longer needed.

  Protect the page manipulation code in vfs_bio.c with vm_token instead
  of the mplock.

* Fix a deadlock with the FINDBLK_TEST/BUF_LOCK sequence which can occur
  due to the fact that the buffer may change its (vp,loffset) during
  the BUF_LOCK call.  Even though the code checks for this after
  the lock succeeds there is still the problem of the locking operation
  itself potentially creating a deadlock betwen two threads by locking
  an unexpected buffer when the caller is already holding other buffers
  locked.

  We do this by adding an interlock refcounter, b_refs.  getnewbuf()
  will avoid reusing such buffers.

* The syncer_token was not protecting all accesses to the syncer list.
  Fix that.

* Make HAMMER MPSAFE.  All major entry points now use a per-mount token,
  hmp->fs_token.  Backend callbacks (bioops, bio_done) use hmp->io_token.
  The cache-case for the read and getattr paths require not tokens at
  all (as before).

  The bitfield flags had to be separated into two groups to deal with
  SMP cache coherency races.

  Certain flags in the hammer_record structure had to be separated for
  the same reason.

  Certain interactions between the frontend and the backend must use
  the hmp->io_token.

  It is important to note that for any given buffer there are two
  locking entities: (1) The hammer structure and (2) The buffer cache
  buffer.  These interactions are very fragile.

  Do not allow the kernel to flush a dirty buffer if we are unable
  to obtain a norefs-interlock on the buffer, which fixes numerous
  frontend/backend MP races on the io structure.

  Add a write interlock in one of the recover_flush_buffer cases.

13 years agoMPSAFE: MPSAFE kern/kern_plimit.c
Venkatesh Srinivas [Fri, 27 Aug 2010 04:06:18 +0000 (21:06 -0700)]
MPSAFE: MPSAFE kern/kern_plimit.c

No tokens required; vm_map_protect is self-synchronized.

13 years agoMPSAFE: MPSAFE kern/kern_prot.c
Venkatesh Srinivas [Fri, 27 Aug 2010 03:50:19 +0000 (20:50 -0700)]
MPSAFE: MPSAFE kern/kern_prot.c

Use the proc_token to synchronize kern_prot.c

13 years agoFix buildkernel
Thomas Nikolajsen [Thu, 26 Aug 2010 19:46:57 +0000 (21:46 +0200)]
Fix buildkernel

13 years agokernel - Fix tty session panic
Matthew Dillon [Thu, 26 Aug 2010 17:50:00 +0000 (10:50 -0700)]
kernel - Fix tty session panic

* Ref-count the session->s_ttyp references to ttys and do not
  destroy a tty unless it is zero.

* This should fix remaining panics in this area.  My last attempt
  to fix it (testing tp->t_session) did not work due to the possibility
  of the tty being half-closed.

13 years agopf: rename pf_task_lck to pf_mod_lck
Jan Lentfer [Thu, 26 Aug 2010 13:52:07 +0000 (15:52 +0200)]
pf: rename pf_task_lck to pf_mod_lck

    pf_task_lck was really just used in module (un)loading.
    This makes pf_task_lck free for later usage as a spin lock to
    protect data structues simialar to how it is used in FreeBSD.

    Also functions regarding pf_task_lck have been remove as these
    are one-liners anyway. Having a separate function for this
    is overkill.

13 years agoMPSAFE: MPSAFE kern/sys_pipe.c
Venkatesh Srinivas [Thu, 26 Aug 2010 02:02:19 +0000 (19:02 -0700)]
MPSAFE: MPSAFE kern/sys_pipe.c

Most of the pipe has been MPSAFE since July 2009, using its own per-pipe tokens.
Convert the remaining uses of the mplock to use the process token for sync.

13 years agoMerge branch 'master' of /repository/git/dragonfly
Venkatesh Srinivas [Thu, 26 Aug 2010 01:40:01 +0000 (18:40 -0700)]
Merge branch 'master' of /repository/git/dragonfly

13 years agoMPSAFE: MPSAFE kern/sys_process.c (kern_ptrace).
Venkatesh Srinivas [Thu, 26 Aug 2010 01:37:55 +0000 (18:37 -0700)]
MPSAFE: MPSAFE kern/sys_process.c (kern_ptrace).

Uses the process token to synchronize kern_ptrace.

13 years agokernel - document and clarify FINDBLK_TEST
Matthew Dillon [Wed, 25 Aug 2010 22:18:31 +0000 (15:18 -0700)]
kernel - document and clarify FINDBLK_TEST

* Clarify operation of FINDBLK_TEST

13 years agoBring in arcmsr(4), a driver for Areca RAID controllers.
Sascha Wildner [Tue, 24 Aug 2010 16:20:57 +0000 (18:20 +0200)]
Bring in arcmsr(4), a driver for Areca RAID controllers.

Taken-from: FreeBSD

13 years agoawk: Delete old version
Stathis Kamperis [Wed, 25 Aug 2010 20:22:10 +0000 (23:22 +0300)]
awk: Delete old version

There hasn't been any problem reported since a week.

13 years agokernel - Remove D_KQFILTER flag
Matthew Dillon [Wed, 25 Aug 2010 18:58:29 +0000 (11:58 -0700)]
kernel - Remove D_KQFILTER flag

* The D_KQFILTER flag is no longer used.

13 years agokernel - unlock pbuf prior to acquiring a spinlock
Matthew Dillon [Wed, 25 Aug 2010 18:44:11 +0000 (11:44 -0700)]
kernel - unlock pbuf prior to acquiring a spinlock

* In relpbuf() move the BUF_UNLOCK() outside the spinlock.

13 years agokernel - Make all bioops callbacks MPSAFE
Matthew Dillon [Wed, 25 Aug 2010 18:43:20 +0000 (11:43 -0700)]
kernel - Make all bioops callbacks MPSAFE

* HAMMER already assumes bioops callbacks are MPSAFE

* UFS/Softupdates now acquires the mplock in its bioops callbacks
  as necessary.

13 years agokernel - Run AHCI and SILI disk drivers MPSAFE
Matthew Dillon [Wed, 25 Aug 2010 18:40:58 +0000 (11:40 -0700)]
kernel - Run AHCI and SILI disk drivers MPSAFE

* These drivers now pass a port-disk-port lock in the cam sim registration,
  which should result in CAM callbacks being MPSAFE.

* Add a separate signalling interlock for the port threads.

* The devices were otherwise already MPSAFE, with per-port locking.

13 years agokernel - Adjust device D_MPSAFE_* flags
Matthew Dillon [Wed, 25 Aug 2010 18:35:53 +0000 (11:35 -0700)]
kernel - Adjust device D_MPSAFE_* flags

* Replace all device D_MPSAFE_* flags with just D_MPSAFE
    - Mark CAM's "da" and "cd" devices D_MPSAFE
    - Mark dm (device mapper) D_MPSAFE
    - Mark memio MPSAFE
    - Mark the disk subsystem D_MPSAFE
    - Mark the crypto device D_MPSAFE

* Devices marked D_MPSAFE now call their strategy functions without the
  mp lock.

* Do a pass on devfs and mark it MNTK_ALL_MPSAFE.  devfs was essentially
  already MPSAFE but the D_MPSAFE checks have been moved out of devfs
  and into the dev_d*() API wrappers.

13 years agoMPSAFE: MPSAFE kern/kern_umtx.c
Venkatesh Srinivas [Wed, 25 Aug 2010 17:43:46 +0000 (10:43 -0700)]
MPSAFE: MPSAFE kern/kern_umtx.c

kern_umtx uses the vm_token for synchronization, as it primarily performs VM
work along with sleep/wakeup cycles.

13 years agokernel - Fix LWKT_TOKEN_HELD() assertion
Matthew Dillon [Wed, 25 Aug 2010 16:35:58 +0000 (09:35 -0700)]
kernel - Fix LWKT_TOKEN_HELD() assertion

* Fix a null pointer dereference in ASSERT_LWKT_TOKEN_HELD().

Reported-by: alexh
13 years agoMPSAFE: MPSAFE kern/kern_slaballoc.c
Venkatesh Srinivas [Wed, 25 Aug 2010 15:35:24 +0000 (08:35 -0700)]
MPSAFE: MPSAFE kern/kern_slaballoc.c

The kernel slab allocator uses the vm_token as its synchronization point.

13 years agoMPSAFE: MPSAFE kern/kern_uuid,c
Venkatesh Srinivas [Wed, 25 Aug 2010 14:53:31 +0000 (07:53 -0700)]
MPSAFE: MPSAFE kern/kern_uuid,c

kern_uuid already protected itself with a lockmgr lock; holding the mplock was
not required.

13 years agocrit_exit - Correct panic conditions
Alex Hornung [Wed, 25 Aug 2010 09:09:03 +0000 (10:09 +0100)]
crit_exit - Correct panic conditions

* Now that critical sections have been moved out of the td_pri and use
  their own td_critcount, we also need to adjust the panic conditions
  accordingly.

13 years agokernel - Make sys_ioctl() MPSAFE
Matthew Dillon [Wed, 25 Aug 2010 07:02:05 +0000 (00:02 -0700)]
kernel - Make sys_ioctl() MPSAFE

* Tokenize the ioctl mapper and stay MPSAFE through the fo_ioctl() call.
  Beyond that it will be determined by the fops driver and for vnodes
  will be determined by the MNTK_*_MPSAFE flags.

* HAMMER's ioctls will now be entered without holding the MP lock, aka
  reblock, prune.

13 years agokernel - Change PROP_RWLOCK from spinlock to mtx
Matthew Dillon [Wed, 25 Aug 2010 06:54:56 +0000 (23:54 -0700)]
kernel - Change PROP_RWLOCK from spinlock to mtx

* The PROP_RWLOCK can be held across switches and sleeps and so cannot
  be a spinlock.

* Fixes spinlocks-held-during-switch panic.

13 years agokernel - lock sim in cam_periph_alloc()
Matthew Dillon [Wed, 25 Aug 2010 04:02:54 +0000 (21:02 -0700)]
kernel - lock sim in cam_periph_alloc()

* cam_periph_alloc() is called from places where the sim lock is not
  being held.  Acquire the lock internally as needed.

13 years agovm: Idlezero changes
Venkatesh Srinivas [Wed, 25 Aug 2010 03:31:07 +0000 (20:31 -0700)]
vm: Idlezero changes

* Restore yield to idlezero loop; we lwkt_yield() every 64-bytes rather than
  every page now.
* Unmark as MPSAFE; we are not MPSAFE, we hold the MP lock. When the page
  queues are safe to access with the vm token alone, we can revert to a prior
  edition of this code, which was mpsafe.

13 years agotmpfs: Allow kmalloc from M_TMPFSNAME zone to return NULL; handle null cases.
Venkatesh Srinivas [Wed, 25 Aug 2010 03:03:34 +0000 (20:03 -0700)]
tmpfs: Allow kmalloc from M_TMPFSNAME zone to return NULL; handle null cases.

tmpfs now survives fsstress without panicing the system.

13 years agotmpfs: Convert dirent malloc zone to a per-mount zone.
Venkatesh Srinivas [Wed, 25 Aug 2010 01:51:35 +0000 (18:51 -0700)]
tmpfs: Convert dirent malloc zone to a per-mount zone.

13 years agotmpfs: Convert tmpfs node allocation zone into a per-mount pool.
Venkatesh Srinivas [Wed, 25 Aug 2010 01:37:54 +0000 (18:37 -0700)]
tmpfs: Convert tmpfs node allocation zone into a per-mount pool.

Each tmpfs mount tracked the number and max nodes separately, leading to an
inaccurate measure of the limit of the tmpfs node malloc zone. We now create
a kmalloc zone for each mount, as in HAMMER (hammer_vfsops.c).

13 years agoioprio(1): Higher priorities receive more I/O time; note in manpage.
Venkatesh Srinivas [Wed, 25 Aug 2010 00:39:51 +0000 (17:39 -0700)]
ioprio(1): Higher priorities receive more I/O time; note in manpage.

13 years agoHAMMER VFS - Add another lwkt_user_yield()
Matthew Dillon [Tue, 24 Aug 2010 23:09:48 +0000 (16:09 -0700)]
HAMMER VFS - Add another lwkt_user_yield()

* Add a lwkt_user_yield() call to reverse b-tree iterations, which are
  used by the pruning code.  Forward iterations already call
  lwkt_user_yield().

13 years agoHAMMER VFS - Make all entry points MPSAFE, remove giant & critical sections
Matthew Dillon [Tue, 24 Aug 2010 23:04:59 +0000 (16:04 -0700)]
HAMMER VFS - Make all entry points MPSAFE, remove giant & critical sections

* All VFS, VOP, ioops, and bio_done entry points are now mpsafe and no
  longer use giant.

* Implement hmp->fs_token and hmp->io_token for each HAMMER mount.

  All operations that previously needed the MP lock now use hmp->fs_token.
  All operations that interact with BIO callbacks now use hmp->io_token.
  All critical sections now use io_token (these previously interlocked
  against IO callbacks).

  NOTE: read (for cached data) and getattr were MPSAFE before and
continue to be MPSAFE.

13 years agokernel - Add define for MNTK_ALL_MPSAFE
Matthew Dillon [Tue, 24 Aug 2010 23:02:09 +0000 (16:02 -0700)]
kernel - Add define for MNTK_ALL_MPSAFE

* Add a define to specify all available MPSAFE flags for a vfs.

13 years agoopencrypto - Only yield for cryptosoft
Alex Hornung [Tue, 24 Aug 2010 06:54:09 +0000 (07:54 +0100)]
opencrypto - Only yield for cryptosoft

* There's no need to yield the CPU when doing hardware-assisted
  crypto. Move the lwkt_yield()s into cryptosoft.

13 years agokernel - Adjustments to fix UP kernel build
Matthew Dillon [Tue, 24 Aug 2010 05:56:05 +0000 (22:56 -0700)]
kernel - Adjustments to fix UP kernel build

* Minor SMP wrapping issues.

13 years agobuildworld - Adjust ps for recent commits
Matthew Dillon [Tue, 24 Aug 2010 05:19:41 +0000 (22:19 -0700)]
buildworld - Adjust ps for recent commits

* Fixes buildworld

13 years agosystat - Enhance systat -pv
Matthew Dillon [Tue, 24 Aug 2010 04:55:55 +0000 (21:55 -0700)]
systat - Enhance systat -pv

* Enhance the -pv option to display the contention points on all cpus

13 years agokernel - Add additional fields to kinfo_cputime
Matthew Dillon [Tue, 24 Aug 2010 04:50:29 +0000 (21:50 -0700)]
kernel - Add additional fields to kinfo_cputime

* Add a message field and address to allow the kernel to report contention
  points on the cpus to userland.

* Enhance the mplock and token subsystems to record contention points.

* Enhance the scheduler to record contention information in the
  per-cpu cpu_time structure.

13 years agokernel - rewrite the LWKT scheduler's priority mechanism
Matthew Dillon [Tue, 24 Aug 2010 01:39:45 +0000 (18:39 -0700)]
kernel - rewrite the LWKT scheduler's priority mechanism

The purpose of these changes is to begin to address the issue of cpu-bound
kernel threads.  For example, the crypto threads, or a HAMMER prune cycle
that operates entirely out of the buffer cache.  These threads tend to hicup
the system, creating temporary lockups because they never switch away due
to their nature as kernel threads.

* Change the LWKT scheduler from a strict hard priority model to
  a fair-share with hard priority queueing model.

  A kernel thread will be queued with a hard priority, giving it dibs on
  the cpu earlier if it has a higher priority.  However, if the thread
  runs past its fair-share quantum it will then become limited by that
  quantum and other lower-priority threads will be allowed to run.

* Rewrite lwkt_yield() and lwkt_user_yield(), remove uio_yield().
  Both yield functions are now very fast and can be called without
  further timing conditionals, simplifying numerous callers.

  lwkt_user_yield() now uses the fair-share quantum to determine when
  to yield the cpu for a cpu-bound kernel thread.

* Implement the new yield in the crypto kernel threads, HAMMER, and
  other places (many of which already used the old yield functions
  which didn't work very well).

* lwkt_switch() now only round-robins after the fair share
  quantum is exhausted.  It does not necessarily always round robin.

* Separate the critical section count from td_pri.  Add td_critcount.

13 years agokernel - clarify code documentation in vfs_cluster
Matthew Dillon [Mon, 23 Aug 2010 01:52:00 +0000 (18:52 -0700)]
kernel - clarify code documentation in vfs_cluster

* Clarify the operation of minreq/maxreq a little better in
  cluster_read().

13 years agokernel - Fix read event on file for select/poll API
Matthew Dillon [Sun, 22 Aug 2010 22:30:08 +0000 (15:30 -0700)]
kernel - Fix read event on file for select/poll API

* select/poll have always returned an immediate read event on regular
  files, but kqueue is expected to only return a EVFILT_READ event
  when not sitting at the file EOF.

* The kernel adds a NOTE_OLDAPI flag which filter functions can use to
  discern between select/poll and kqueue related knotes.

* Adjust filesystem filter function to always return an immediate
  event for reads via select/poll.

* Fixes guile, which for some reason beyond our ken select()'s for a
  read event on a file.

Reported-by: Johannes Hofmann <johannes.hofmann@gmx.de>
13 years agodm_target_crypt - Clean up debug
Alex Hornung [Sun, 22 Aug 2010 20:00:04 +0000 (21:00 +0100)]
dm_target_crypt - Clean up debug

* Disable the debug message showing up when a device was configured,
  which included the key.

* As a status string to dm, we give the configuration string with the
  key 0'ed out.

13 years agoopencrypto - Adjust xforms for explicit extra IV
Alex Hornung [Sun, 22 Aug 2010 19:06:22 +0000 (20:06 +0100)]
opencrypto - Adjust xforms for explicit extra IV

* Some transforms such as XTS and CTR have some private 'IV'. Since our
  cryptosoft is now concurrent, we need to keep that private IV per-op
  and not per-session as OpenBSD does. We do this by passing in the
  local IV to encrypt() and decrypt() functions, as well as reinit(),
  which was already getting it.

* We can now also use AES-XTS and AES-CTR in a concurrent environment
  without having to have multiple sessions or an explicit key.

* While here, also radically simplify the reinit() for XTS.

* With these changes we can now use aes-xts for dm_target_crypt
  successfully.