dragonfly.git
13 years agoMerge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
Matthew Dillon [Sat, 4 Sep 2010 18:30:55 +0000 (11:30 -0700)]
Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly

13 years agokernel - More tty/pty fixes
Matthew Dillon [Sat, 4 Sep 2010 18:28:21 +0000 (11:28 -0700)]
kernel - More tty/pty fixes

* Notify the pty master when the slave closes.

* Fix the zombie state stuff.  Clear the zombie state on initial open of
  either side, prior to running any modem controls.

* This appears to fix screen and tmux.

Reported-by: YONETANI Tomokazu <qhwt+dfly@les.ath.cx>, Antonio Huete Jimenez <tuxillo@crater.dragonflybsd.org>
13 years agoinclude - Install smbus headers in the system.
Antonio Huete Jimenez [Sat, 4 Sep 2010 16:17:38 +0000 (18:17 +0200)]
include - Install smbus headers in the system.

This will fix gkrellm build as it was trying to
include smb.h, which wasn't in /usr/include/machine
anymore.

In-collaboration-with: <swildner@>

13 years agotruss - Take care of a couple segfaults.
Antonio Huete Jimenez [Thu, 2 Sep 2010 05:19:01 +0000 (07:19 +0200)]
truss - Take care of a couple segfaults.

Reported-by: Johannes Hofmann <Johannes.Hofmann@gmx.de>
DragonFly-bug: <http://bugs.dragonflybsd.org/issue1610>

13 years agodloader - Fix *_load variable override issue
Matthew Dillon [Wed, 1 Sep 2010 18:23:53 +0000 (11:23 -0700)]
dloader - Fix *_load variable override issue

* Setting a local variable that is already set wasn't working
  due to a programming snafu, so *_load overrides in /boot/loader.conf
  were not working properly.  Fixed!

13 years agokernel - Fix multiple tty_token issues related to vt switching and X
Matthew Dillon [Wed, 1 Sep 2010 17:56:16 +0000 (10:56 -0700)]
kernel - Fix multiple tty_token issues related to vt switching and X

* Numerous places where gettoken/reltoken was not matched up

* Of particular note the multi-line macros in fbreg.h did not have
  any do/while() protection and were being used in if() macro()
  situations which caused massive issues.

Reported-by: Everyone
13 years agobuild - Fix kernel / modules install from object dir or module source dir
Matthew Dillon [Wed, 1 Sep 2010 16:07:51 +0000 (09:07 -0700)]
build - Fix kernel / modules install from object dir or module source dir

* Only installkernel from /usr/src was installing the modules in the
  right place.

* Add a default KERNEL?= in kmod.mk to try to correct the problem.

Reported-by: YONETANI Tomokazu <qhwt+dfly@les.ath.cx>
13 years agovkernel - Fix early boot seg-fault
Matthew Dillon [Wed, 1 Sep 2010 15:42:00 +0000 (08:42 -0700)]
vkernel - Fix early boot seg-fault

* kprintf() needs 'mycpu' to work now, the vkernel was trying to use it
  too early.

Reported-by: Ilya Dryomov
13 years agoRemove formatted spinlock manpages via 'make upgrade', too.
Sascha Wildner [Wed, 1 Sep 2010 10:43:31 +0000 (12:43 +0200)]
Remove formatted spinlock manpages via 'make upgrade', too.

13 years agoboot system and buildkernel - Additional work
Matthew Dillon [Wed, 1 Sep 2010 07:41:14 +0000 (00:41 -0700)]
boot system and buildkernel - Additional work

* Make boot <directory> work.  Note however that dloader does not preload
  the kernel+modules so basically all you get here is the kernel and acpi
  with the current menu system setup.

  The dloader way (for the moment) is:

cd kernel
loadall
boot

* Fix console=<blah>.  dloader was not mirroring the variable to the
  environment.  Also do the same for currdev, loaddev, and bootfile.
  (kernelname and module_path were already mirrored).

* Fix non-numeric menus.  'a' (kernel.alt), 'b' (kernel.bak),
  and 'R' (reboot).

* Space now halts the countdown.

* Add the boot-without ACPI option back into dloader.menu.

* Move the handling of the kernelname kenv variable out of machine
  specific code and into kern/init_main.c

13 years agokernel - Fix token mismatch in tty code.
Matthew Dillon [Wed, 1 Sep 2010 06:36:14 +0000 (23:36 -0700)]
kernel - Fix token mismatch in tty code.

* Fix issue when a tty is stopped/started with ^S/^Q related to
  recent tokenization work.

13 years agobuild - Adjust kern.post.mk warning
Matthew Dillon [Wed, 1 Sep 2010 05:25:33 +0000 (22:25 -0700)]
build - Adjust kern.post.mk warning

* installkernel was blowing away the modules before warning that the
  boot was out of date.  Warn before blowing away anything (and
  abort the installkernel).

13 years agobuild - cleanup
Matthew Dillon [Wed, 1 Sep 2010 04:45:12 +0000 (21:45 -0700)]
build - cleanup

* These files were renamed, remove the originals.

13 years agoboot system and buildkernel - Remove the thrice damned forth interpreter
Matthew Dillon [Wed, 1 Sep 2010 04:38:56 +0000 (21:38 -0700)]
boot system and buildkernel - Remove the thrice damned forth interpreter

* Remove the forth interpreter from the build.  The last straw was when
  I tried to fix the module path and 6 hours later still couldn't get
  it right.

* Write a C based menu system and loader, replacing what the forth code
  used to do.  This is about 85% complete (tftp and boot chaining issues
  are not handled).  This took exactly one day to do, by the way.

* Reformulate installkernel to now create a directory /boot/kernel.blah
  and place the kernel and modules inside that directory.

13 years agosyscons - more token-related fixes
Alex Hornung [Tue, 31 Aug 2010 09:45:59 +0000 (10:45 +0100)]
syscons - more token-related fixes

* Make init_scp explicitly acquiring a token for what it needs.

* Also acquire token for vidsw operation in scinit.

Reported-by: Rumko
Dragonfly-bug: http://bugs.dragonflybsd.org/issue1814

13 years agoiwi(4): Oops. These changes weren't meant to be committed (yet).
Sascha Wildner [Tue, 31 Aug 2010 08:18:07 +0000 (10:18 +0200)]
iwi(4): Oops. These changes weren't meant to be committed (yet).

13 years agowpi(4): sc is no longer used for locking (fixes LINT).
Sascha Wildner [Tue, 31 Aug 2010 08:10:24 +0000 (10:10 +0200)]
wpi(4): sc is no longer used for locking (fixes LINT).

13 years agosyscons - sc_set_pixel_mode() returned without releasing tty_token
YONETANI Tomokazu [Tue, 31 Aug 2010 07:48:23 +0000 (16:48 +0900)]
syscons - sc_set_pixel_mode() returned without releasing tty_token

fixes panic on `vidcontrol MODE_nnn'

13 years agokernel - Fixup vkernel64 for build
Matthew Dillon [Tue, 31 Aug 2010 06:35:26 +0000 (23:35 -0700)]
kernel - Fixup vkernel64 for build

* Add missing declaration.

13 years agokernel - Fixup for UP build
Matthew Dillon [Tue, 31 Aug 2010 06:24:42 +0000 (23:24 -0700)]
kernel - Fixup for UP build

* Conditionalize td_mpcount accesses for SMP only

13 years agokernel - Add a workaround for tty_token during low-level boot
Matthew Dillon [Tue, 31 Aug 2010 05:31:49 +0000 (22:31 -0700)]
kernel - Add a workaround for tty_token during low-level boot

* The low level cninit() code dives into dev/video and does a ton
  of tty_token acquisitions and releases, and even after the bug
  fixes there is still something weird going on in there.

  This is a workaround to wrap a master tty_token around the
  cninit() code which prevents an early-boot crash if
  lwkt_gettoken()'s td_mpcount optimization is turned off.
  (the optimization masks the problem).

* Also assert that the mpcount remains correct after the mess
  is done initializing, if it is wrong the SMP/AP boot will
  blow up on us.

13 years agokernel - Fix td_xpcount when pushing a preemption
Matthew Dillon [Tue, 31 Aug 2010 05:24:15 +0000 (22:24 -0700)]
kernel - Fix td_xpcount when pushing a preemption

* We have to set xpcount to the sum of the victim thread's mpcount
  and xpcount, rather than just its mpcount.

Reported-by: Rumko
13 years agokernel - Fix missing release of tty_token
Matthew Dillon [Tue, 31 Aug 2010 04:28:09 +0000 (21:28 -0700)]
kernel - Fix missing release of tty_token

* Fix one missing release and one misordered release.  These were
  causing the low level SMP AP boot to enter with 2 mplock counts
  instead of 1.

13 years agokernel - Fix two mismatched locks in CAM
Matthew Dillon [Tue, 31 Aug 2010 03:56:18 +0000 (20:56 -0700)]
kernel - Fix two mismatched locks in CAM

* cam_periph_alloc() failed to release a lock in one case and had an extra
  unlock in another.

* passregister() had an extra unlock

Reported-by: Rumko
13 years agoiwi - Convert to wlan_tokens.
Joe Talbott [Tue, 31 Aug 2010 01:28:05 +0000 (21:28 -0400)]
iwi - Convert to wlan_tokens.

Submitted-By: Johannes Hofmann (jh33)
Bug-Id: 1810

13 years agoral - Fix calls to bus_dmamap_load_mbuf_segment() to use BUS_DMA_NOWAIT.
Joe Talbott [Mon, 30 Aug 2010 20:29:38 +0000 (16:29 -0400)]
ral - Fix calls to bus_dmamap_load_mbuf_segment() to use BUS_DMA_NOWAIT.

Reported-by: Max Herrgard <herrgard@gmail.com>
Tested-by: Max Herrgard <herrgard@gmail.com>
13 years agoral - Make sure nodes are properly uninitialized and reinitialized.
Joe Talbott [Mon, 30 Aug 2010 20:20:44 +0000 (16:20 -0400)]
ral - Make sure nodes are properly uninitialized and reinitialized.

Adds rt2661_newassoc() which cleans up the ieee80211_node.

Reported-by: Max Herrgard <herrgard@gmail.com>
Tested-by: Max Herrgard <herrgard@gmail.com>
13 years agowpi - Convert to use wlan_token.
Joe Talbott [Sun, 29 Aug 2010 22:53:34 +0000 (18:53 -0400)]
wpi - Convert to use wlan_token.

13 years agokernel - Separate inherited mplocks from td_mplocks and fix a gettoken bug
Matthew Dillon [Mon, 30 Aug 2010 19:29:06 +0000 (12:29 -0700)]
kernel - Separate inherited mplocks from td_mplocks and fix a gettoken bug

* Separate out td_mpcount into td_xpcount and td_mpcount.  td_xpcount
  is an inherited mpcount.  A preempting thread inherits the mpcount
  on the thread being preempted until it switches out to guarantee
  that the mplock remains atomic through the preemption (as expected
  by the poor thread that got preempted).

* Fix a serious but hard to reproduce bug in lwkt_gettoken().  This
  function marks the token reference as being MPSAFE if td_mpcount
  is non-zero even when the token is not a MPSAFE token.

  However, until this patch td_mpcount also included inherited mpcounts
  when one thread preempts another and the inherited mpcounts could
  go away if the thread blocks or switches, leaving the token unprotected.

* Fix a less serious bug where a new token reference was being populated
  prior to td_toks_stop being incremented, and where an existing token
  reference was being depopulated after td_toks_stop is decremented.
  Nothing can race us but switch around the index increment/decrement
  to protect the slot being operated upon.

* Add a ton of assertions in the interrupt, trap, and syscall paths
  To assert that the mplock, number of tokens, and critcount remain
  unchanged across driver and other calls.

13 years agokernel - Correct missing unlock in SCSI pass device
Matthew Dillon [Mon, 30 Aug 2010 19:27:11 +0000 (12:27 -0700)]
kernel - Correct missing unlock in SCSI pass device

* Correct a missing sim unlock, which matters more now that
  the sim lock might not be the mp lock.

13 years agobuildkernel - Order kernel before modules
Matthew Dillon [Mon, 30 Aug 2010 17:51:53 +0000 (10:51 -0700)]
buildkernel - Order kernel before modules

* Order the kernel before modules so a parallel build builds the kernel
  before diving into the modules.  This makes incremental building more
  convenient.

13 years agokernel - Enabled bzeront() (MOVNTI) only on SSE2-capable CPUs.
Venkatesh Srinivas [Mon, 30 Aug 2010 14:16:13 +0000 (07:16 -0700)]
kernel - Enabled bzeront() (MOVNTI) only on SSE2-capable CPUs.

13 years agospinlocks - adjust man pages and *_quick_* routines
Alex Hornung [Mon, 30 Aug 2010 12:20:49 +0000 (13:20 +0100)]
spinlocks - adjust man pages and *_quick_* routines

* Adjust man pages to reflect the recent changes (removal of shared
  spinlocks, renaming of exclusive spinlocks).

* Remove old man page symlinks and adjust new ones.

* Rename the spin_{un,}lock_wr_quick ro spin_{un,}lock_quick.

13 years agocam_xpt - Fix recently introduced typo
Alex Hornung [Mon, 30 Aug 2010 11:56:41 +0000 (12:56 +0100)]
cam_xpt - Fix recently introduced typo

* Fix a typo introduced by the previous spinlock commit.

Reported-by: Jonas Trollvik
13 years agospinlocks - Rename API to spin_{try,un,}lock
Alex Hornung [Mon, 30 Aug 2010 10:10:17 +0000 (11:10 +0100)]
spinlocks - Rename API to spin_{try,un,}lock

* Rename the API to spin_trylock, spin_unlock and spin_lock instead of
  spin_lock_wr, spin_unlock_wr and spin_trylock_wr now that we only have
  exclusive spinlocks.

* 99% of this patch was generated by a semantic coccinelle patch

13 years agosyscons MPSAFE - another attempt
Alex Hornung [Mon, 30 Aug 2010 08:14:00 +0000 (09:14 +0100)]
syscons MPSAFE - another attempt

* Do another pass on syscons and reduce the number of token
  uses significantly.

* syscons now works with a limited number of tokens, acquired almost
  only around linesw and vidsw routines, but out of the way of tty_cons.

13 years agocoretemp, sensors - Adjust spinlocks
Alex Hornung [Mon, 30 Aug 2010 06:47:34 +0000 (07:47 +0100)]
coretemp, sensors - Adjust spinlocks

* In kern_sensors, adjust the spinlocks to not be held across the sysctl
  interface management.

* In coretemp, adjust illegal spinlock across calls to kern_sensors.

Reported-by: Matt Dillon (dillon@)
13 years agokernel - poll(2) no longer supports non-standard FreeBSD extensions
Samuel J. Greear [Mon, 30 Aug 2010 08:10:24 +0000 (08:10 +0000)]
kernel - poll(2) no longer supports non-standard FreeBSD extensions

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

13 years agodevfs - Do not try printing the name of a null vnode
Samuel J. Greear [Mon, 30 Aug 2010 07:05:44 +0000 (07:05 +0000)]
devfs - Do not try printing the name of a null vnode

13 years agokernel - remove spin_lock_rd() and spin_unlock_rd()
Matthew Dillon [Mon, 30 Aug 2010 06:25:42 +0000 (23:25 -0700)]
kernel - remove spin_lock_rd() and spin_unlock_rd()

* Remove shared spinlocks entirely.  We only have exclusive spinlocks
  now.

* Strip out the exclusive/shared contention handling code.

* Slightly rework the initial exponential backoff and test.  Do the
  atomic swap after the exponential backoff instead of before so
  we do not add a superfluous backoff after actually acquiring
  the spinlock.

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.