dragonfly.git
12 years agolibc: Add wcscasecmp function
John Marino [Mon, 21 Nov 2011 22:13:43 +0000 (23:13 +0100)]
libc: Add wcscasecmp function

This function performs a case-insensitive string comparison test on
wide characters.  It is a GNU extension, not POSIX.  Some packages
in pkgsrc require it.

12 years agokernel -- nata: Raise ATA timeout for FLUSHCACHE requests.
Venkatesh Srinivas [Mon, 21 Nov 2011 23:09:38 +0000 (15:09 -0800)]
kernel -- nata: Raise ATA timeout for FLUSHCACHE requests.

(S)ATA devices may take longer than the default ata timeout to respond to
FLUSHCACHE requests, particularly when they are spinning-up. Seen with
Western Digital Caviar Green SATA disks.

From: FreeBSD PR 136182 (http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/136182)

12 years agodfr2text, tbridge.9 - fix typos/etc
Alex Hornung [Mon, 21 Nov 2011 20:55:31 +0000 (20:55 +0000)]
dfr2text, tbridge.9 - fix typos/etc

12 years agoDisable aps(4) in the GENERIC kernels.
Sascha Wildner [Mon, 21 Nov 2011 11:09:39 +0000 (12:09 +0100)]
Disable aps(4) in the GENERIC kernels.

Its probe routine doesn't play nice with the Intel S5520SC motherboard.
Until that is properly fixed, disable it as it is not strictly needed.

Reported-by: Michael Kosarev <russiane39@gmail.com>
12 years agotest commit
Sascha Wildner [Mon, 21 Nov 2011 09:50:48 +0000 (10:50 +0100)]
test commit

12 years agokernel/scsi: Use __unused instead of assigning to itself.
Sascha Wildner [Mon, 21 Nov 2011 05:34:51 +0000 (06:34 +0100)]
kernel/scsi: Use __unused instead of assigning to itself.

12 years agokernel/nfs: Fix two wrong sizeofs.
Sascha Wildner [Mon, 21 Nov 2011 04:31:52 +0000 (05:31 +0100)]
kernel/nfs: Fix two wrong sizeofs.

NFSKERBKEY_T (key's type) is (in <vfs/nfs/rpcv2.h>):

typedef u_char NFSKERBKEY_T[2];

and key is one of the function's args, so we need to use the type for
the sizeof, else we'll get the size of a pointer.

12 years agodfregress - fix copy&paste mistake, add newline in output
Alex Hornung [Sun, 20 Nov 2011 22:21:48 +0000 (22:21 +0000)]
dfregress - fix copy&paste mistake, add newline in output

12 years agodfregress - Add default values for args, add direct arg
Alex Hornung [Sun, 20 Nov 2011 21:55:40 +0000 (21:55 +0000)]
dfregress - Add default values for args, add direct arg

 * Use a direct argument instead of -r for the runlist file.

 * Add defaults for the -t and -o options based on the path to the
   runlist file.

Suggested-by: Sascha Wildner (swildner@)
12 years agokernel - Correct wire count statistics
Matthew Dillon [Sun, 20 Nov 2011 20:21:19 +0000 (12:21 -0800)]
kernel - Correct wire count statistics

* When wiring pages for the dma pool we also have to increment
  vmstats.v_wire_count to match the later return of the pages
  to the free pool which decrements it.

Reported-by: lentferj
12 years agokernel - Fix vm_object token deadlock (3)
Matthew Dillon [Sun, 20 Nov 2011 19:19:32 +0000 (11:19 -0800)]
kernel - Fix vm_object token deadlock (3)

* Fix bug in this commit sequence, m->object is NULL'd out after the
  free so we have to save a copy to drop.

Reported-by: marino
12 years agokernel - Fix vm_object token deadlock (2)
Matthew Dillon [Sun, 20 Nov 2011 18:17:12 +0000 (10:17 -0800)]
kernel - Fix vm_object token deadlock (2)

* Files missed in original commit.

12 years agokernel - Fix broken assertion
Matthew Dillon [Sun, 20 Nov 2011 18:00:37 +0000 (10:00 -0800)]
kernel - Fix broken assertion

* The assertion in _lwkt_trytokeref() was printing out the contents of
  an uninitialized variable.  The assertion condition itself was ok.

12 years agokernel - Fix incorrect VA on interlock
Matthew Dillon [Sun, 20 Nov 2011 17:58:50 +0000 (09:58 -0800)]
kernel - Fix incorrect VA on interlock

* The pmap_clearbit() code was interlocking the wrong VA due to an
  uninitalized variable.  This could lead to stale tlbs.

Reported-by: swildner
12 years agokernel - Fix vm_object token deadlock
Matthew Dillon [Sun, 20 Nov 2011 17:47:47 +0000 (09:47 -0800)]
kernel - Fix vm_object token deadlock

* vm_page_alloc() needs an exclusive vm_object token when recycling
  random cache pages into the free queue.  Because these are effectively
  random pages it is possible for this exclusive token to interfere
  with a shared token already held by the thread.

* Make sure we can actually get the token.  If we cannot we deactivate
  the page instead.

12 years agokernel - Fix DRM_DEBUG() macro
Matthew Dillon [Sun, 20 Nov 2011 17:45:36 +0000 (09:45 -0800)]
kernel - Fix DRM_DEBUG() macro

* It was dereferencing td->td_proc without checking whether a process
  even exists first.

Reported-by: juanfra_
12 years agokernel: Fix sizeof()s that were taking a pointer.
Sascha Wildner [Sun, 20 Nov 2011 15:39:50 +0000 (16:39 +0100)]
kernel: Fix sizeof()s that were taking a pointer.

12 years agosocket: Speed up soclose by avoiding putting the user thread into sleep
Sepherosa Ziehau [Sun, 20 Nov 2011 11:25:05 +0000 (19:25 +0800)]
socket: Speed up soclose by avoiding putting the user thread into sleep

- Embed a netmsg_base into socket, it will be used if fast soclose
  is possible
- Factor out sodiscard(), which abort the connections on the listen
  socket and set the SS_NOFDREF bit.  This function is shared across
  fast soclose and synchronized soclose
- Rename the original soclose() to soclose_sync(), which uses domsg
  to perform proto-specific operation
- If kern.ipc.soclose_fast is 1 (it is 1 by default) and SO_LINGER
  socket option is not set and the socket does not use synchronized
  msgport (e.g. UNIX domain socket), fast soclose will be used
- The fast soclose is implemented to avoid putting the caller thread
  (usually a user thread) into sleep.  It uses the socket's embeded
  "close message" with different dispatch functions based on the
  current socket state and send the "close message" (asynchronized)
  to proto thread to carry out various tasks.

The result:
On Phenom 9550 (4 core, 2.2GHz):
route change -host 127.0.0.1 -msl 50 (set MSL to 50ms)
8 parallel netperf -H 127.0.0.1 -t TCP_CC -P0 (4 runs, unit: tps)

old  33181.18  33005.66  33130.48  33010.50
new  39109.07  39032.48  39022.75  38993.72

This gives 18% performance improvement

12 years agodfregress.8: Some little cleanup.
Sascha Wildner [Sun, 20 Nov 2011 09:29:17 +0000 (10:29 +0100)]
dfregress.8: Some little cleanup.

12 years agodfr2text(8): Remove custom DEBUG_FLAGS.
Sascha Wildner [Sun, 20 Nov 2011 09:27:59 +0000 (10:27 +0100)]
dfr2text(8): Remove custom DEBUG_FLAGS.

12 years agorc.conf.5: Add some words about the recently added change_routes variable.
Sascha Wildner [Sun, 20 Nov 2011 09:10:04 +0000 (10:10 +0100)]
rc.conf.5: Add some words about the recently added change_routes variable.

12 years agort_metrics: Change msl unit to millisecond
Sepherosa Ziehau [Sun, 20 Nov 2011 06:53:09 +0000 (14:53 +0800)]
rt_metrics: Change msl unit to millisecond

12 years agofastbulk - Minor corrections & docs
Matthew Dillon [Sat, 19 Nov 2011 22:40:46 +0000 (14:40 -0800)]
fastbulk - Minor corrections & docs

* Minor correction to the setup script

* Document more targets

12 years agofastbulk - Commit to /usr/src/test/fastbulk
Matthew Dillon [Sat, 19 Nov 2011 21:54:49 +0000 (13:54 -0800)]
fastbulk - Commit to /usr/src/test/fastbulk

* Commit the fastbulk (fast pkgsrc bulk building system) that I was
  working on late last year so others can mess around with it.

* This is a set of scripts that attempt to figure out pkgsrc tree
  dependencies and then run as many package builds in parallel as
  possible, keeping track of completions which effect other dependencies
  in order to keep as many concurrent (up to NPARALLEL) builds going as
  possible.

* Once the source archives get synchronized concurrency is actually limited
  more by the sludgepile that is the pkgsrc/bmake system which we have to
  use to figure out the dependencies in the first place.  It takes a bit
  for enough of the dependency tree to build for concurrency to ramp up
  but it does pretty well once the core packages that everyone else depends
  on have been built.

* Easy tracking of the state of the build via per-package log files and
  status information in /build/fastbulk/root/tmp/logs/{good,bad,run}.
  Log files for currently running builds are placed in run and then
  moved to good or bad when the build completes.

* Remaining issues include multi-dependencies (e.g. when multiple versions
  of the same package is available for install), because other packages in
  the tree might depend on different versions of the same package,
  missing dependencies, and other conflicts.

12 years agoLINT/LINT64: Remove page breaks.
Sascha Wildner [Sat, 19 Nov 2011 20:01:29 +0000 (21:01 +0100)]
LINT/LINT64: Remove page breaks.

12 years agokernel - Add ts check to dotimeout_only()
Matthew Dillon [Sat, 19 Nov 2011 17:41:48 +0000 (09:41 -0800)]
kernel - Add ts check to dotimeout_only()

* We have to add a null-check before calling dotimeout_only().  When
  poll()/select() are called with a NULL timeout that means wait forever
  and does not mean a fixed delay.

Reported-by: YONETANI Tomokazu <y0n3t4n1@gmail.com>
12 years agokernel - Fix swapcache related crash
Matthew Dillon [Sat, 19 Nov 2011 10:32:31 +0000 (02:32 -0800)]
kernel - Fix swapcache related crash

* VM object must be held while vmobj_token serializes list, before
  the lwkt_yield() not after.

* Fixes crash when swapcache fills up and starts to remove entries.

12 years agodfregress.8 - spelling: synopsys => synopsis
Alex Hornung [Sat, 19 Nov 2011 05:24:55 +0000 (05:24 +0000)]
dfregress.8 - spelling: synopsys => synopsis

12 years agokernel - Fix crash in pmap_enter()
Matthew Dillon [Sat, 19 Nov 2011 08:06:53 +0000 (00:06 -0800)]
kernel - Fix crash in pmap_enter()

* When taking a concurrent fault in KVM on a pipe buffer the pte
  replacement path when a pte is found to already exist was not
  checking whether pt_pv was NULL or not before trying to wire its
  page.

Reported-by: n00b183
12 years agokernel - Correct unaligned results in alist_free_info()
Matthew Dillon [Sat, 19 Nov 2011 07:12:06 +0000 (23:12 -0800)]
kernel - Correct unaligned results in alist_free_info()

* alist_free_info() needs to return a power-of-2-sized and power-of-2
  aligned result in order for the caller to be able to use the information
  to allocate the resulting space.

* Fixes an issue where the kernel is unable to return a big chunk of the
  reserved DMA space back to the kernel free pool, resulting in a lot of
  wasted memory.

12 years agokernel - Implement a contiguous memory reserve for contigmalloc()
Matthew Dillon [Sat, 19 Nov 2011 05:04:00 +0000 (21:04 -0800)]
kernel - Implement a contiguous memory reserve for contigmalloc()

* We initially reserve the lower 1/4 of memory or 256MB, whichever is
  smaller.  The ALIST API is used to manage the memory.

* Once device initialization is complete, and before int is executed,
  we reduce the reserve and return pages to the normal VM paging queues.
  The reserve is reduced to ~16MB or 1/16 total memory, whichever is
  smaller.

* This can be adjusted with a tunable 'vm.dma_reserved'.

* contigmalloc() now tries the DMA reserve first.  If it fails it falls
  back to the original contigmalloc() code.  contigfree() determines whether
  the pages belong to the DMA reserve or not and will either return them
  to the reserve or free them to the normal paging queues as appropriate.

  VM pages in the reserve are left wired and not busy, and they are returned
  to the reserve in the same state.  This greatly simplifies operations that
  act on the reserve.

* Fix various bits of code that contigmalloc()'d but then kfree()'d instead
  of contigfree()'d.

12 years agokernel - Revamp subr_alist and get it ready for use
Matthew Dillon [Sat, 19 Nov 2011 04:57:16 +0000 (20:57 -0800)]
kernel - Revamp subr_alist and get it ready for use

* Fix numerous bugs in the bighint code.

* Add API functions to allow static initialization.

* When shortcutting chunks we still should flesh out the parent's whole
  array.  This makes alist_free_info() easier to implement.

* Implement alist_free_info() which provides information on the largest
  trailing chunk available (with some restrictions).  This is used to
  chop down a large preinitialization.

* Implement an allocate-after-block feature to alist_alloc()

* Implement natural alignment and boundary handling.  Allocations can only
  be in powers of 2 internally with odd-sized allocations allocating the
  larger size and then piecemeal-freeing the trailing portion.  This also
  has the effect of ensuring that the boundary and alignment will always
  be the nearest greater or equal power of 2 to the allocation request size.

12 years agokernel - Fix incorrect assertion in lwkt_token_swap()
Matthew Dillon [Fri, 18 Nov 2011 20:03:09 +0000 (12:03 -0800)]
kernel - Fix incorrect assertion in lwkt_token_swap()

* The bounds check for the two tokens was off by one, resulting in a crash
  under certain circumstances.

12 years agokernel - Fix swapcached problems when max-swap use reached (2)
Matthew Dillon [Fri, 18 Nov 2011 19:51:18 +0000 (11:51 -0800)]
kernel - Fix swapcached problems when max-swap use reached (2)

* Fix bug in last commit

12 years agokernel - Fix swapcached problems when max-swap use reached
Matthew Dillon [Fri, 18 Nov 2011 18:48:09 +0000 (10:48 -0800)]
kernel - Fix swapcached problems when max-swap use reached

* A calculation could reverse-index the limit counter and cause
  swapcached to eat an excessive amount of cpu, causing other
  processes to stall.

* Fixes network problems between avalon and the dragonfly core network.

12 years agokernel - Document vm_map_lookup_entry() better in vm/vm_map.c
Matthew Dillon [Fri, 18 Nov 2011 16:14:16 +0000 (08:14 -0800)]
kernel - Document vm_map_lookup_entry() better in vm/vm_map.c

* Add some additional code documentation.

* Issue a required cpu_ccfence() after a variable load when checking the
  vm_map_entry hint.  With the map locked shared the hint can still be
  updated concurrently even though the value, once loaded, will point to
  a stable structure.

12 years agokernel - Adjust tlb invalidation in the x86-64 pmap code
Matthew Dillon [Fri, 18 Nov 2011 16:10:41 +0000 (08:10 -0800)]
kernel - Adjust tlb invalidation in the x86-64 pmap code

* Use a locked bus cycle instruction to clear pte's in all cases.

* Remove unnecessary vm_page_hold() when removing a page table page pv.
  The page is still wired so a hold is not needed.

* Do not issue invalidation interlocks when populating a user pte, the
  invalidations issued when the user pte is removed are sufficient.

  Kernel pte's still appear to need an interlock.  It is unclear why
  (possibly early PG_PS replacement issues).

* Revamp pmap_enter() to fix a race case which could allow PG_M to get
  lost.  Any protection or wiring change fully removes the pte before
  loading a revised pte.

12 years agokernel - Fix marker in sysctl_kern_proc()
Matthew Dillon [Fri, 18 Nov 2011 16:09:11 +0000 (08:09 -0800)]
kernel - Fix marker in sysctl_kern_proc()

* The marker wasn't being marked as a marker, resulting in a
  kernel panic when two or more 'ps' commands are running concurrently
  and one blocks.

12 years agokernel - Cleanup and document
Matthew Dillon [Fri, 18 Nov 2011 16:08:24 +0000 (08:08 -0800)]
kernel - Cleanup and document

* Cleanup and document various bits of code.

12 years agorc.d/routing: Add change_routes support
Sepherosa Ziehau [Fri, 18 Nov 2011 09:38:45 +0000 (17:38 +0800)]
rc.d/routing: Add change_routes support

12 years agotbridge(9) - add man page
Alex Hornung [Fri, 18 Nov 2011 08:55:56 +0000 (08:55 +0000)]
tbridge(9) - add man page

12 years agodfregress.8 - Add info on writing testcases
Alex Hornung [Fri, 18 Nov 2011 08:26:08 +0000 (08:26 +0000)]
dfregress.8 - Add info on writing testcases

12 years agonetisr: Expose netmsg_sync_handler to avoid code duplication
Sepherosa Ziehau [Fri, 18 Nov 2011 08:42:11 +0000 (16:42 +0800)]
netisr: Expose netmsg_sync_handler to avoid code duplication

12 years agonetstat(1): Renumber the nlist[] array indices.
Sascha Wildner [Fri, 18 Nov 2011 04:41:57 +0000 (05:41 +0100)]
netstat(1): Renumber the nlist[] array indices.

I overlooked this during the atalk removal.

Reported-by: ftigeot
12 years agonetstat(1): Remove another unused prototype.
Sascha Wildner [Thu, 17 Nov 2011 21:41:05 +0000 (22:41 +0100)]
netstat(1): Remove another unused prototype.

12 years agonetgraph: Add module dependencies.
Sascha Wildner [Thu, 17 Nov 2011 21:28:09 +0000 (22:28 +0100)]
netgraph: Add module dependencies.

12 years agodfregress,dfr2text - add man pages
Alex Hornung [Fri, 18 Nov 2011 01:13:01 +0000 (01:13 +0000)]
dfregress,dfr2text - add man pages

12 years agodfregress - misc minor fixes/ make more verbose
Alex Hornung [Wed, 16 Nov 2011 17:07:58 +0000 (17:07 +0000)]
dfregress - misc minor fixes/ make more verbose

 * man page is coming soon :)

12 years agodfregress,tbridge - Move into usr.bin and sys/dev
Alex Hornung [Wed, 16 Nov 2011 10:46:08 +0000 (10:46 +0000)]
dfregress,tbridge - Move into usr.bin and sys/dev

 * cleanup of the testcases, remove duplicates, consolidate in
   test/testcases.

12 years agonetstat(1): Remove some unused prototypes.
Sascha Wildner [Thu, 17 Nov 2011 20:08:36 +0000 (21:08 +0100)]
netstat(1): Remove some unused prototypes.

12 years agokernel - Fix additional races in lwp_signotify()
Matthew Dillon [Thu, 17 Nov 2011 18:44:16 +0000 (10:44 -0800)]
kernel - Fix additional races in lwp_signotify()

* lwp_signotify() was improperly scheduling threads whos td_gd is on the
  local cpu without checking the SINTR flags.  This can catch a thread in
  the middle of being transitioned to another cpu and cause havoc.

* Only schedule the thread if the SINTR flags are set.

* We can't call setrunnable() from an IPI so adjustments have to be made
  in the remote cpu to set the lp's lwp_stat state before issuing the IPI
  and only do the scheduling of its thread from the IPI function.

Reported-by: ftigeot
12 years agokernel - more procfs work
Matthew Dillon [Thu, 17 Nov 2011 17:17:51 +0000 (09:17 -0800)]
kernel - more procfs work

* uiomove_frombuf() takes care of indexing uio_offset and checking its
  range for us so we don't have to do it ourselves, clean up use cases
  in procfs.

* Generate somewhat more consistent text output for /proc/<pid>/map by
  formatting the map entry range with static widths.

* ps_nargvstr is a signed number, do a better range check on it.

12 years agokernel - Fix ps/thread-exit and other related ps races
Matthew Dillon [Thu, 17 Nov 2011 17:04:53 +0000 (09:04 -0800)]
kernel - Fix ps/thread-exit and other related ps races

* Adjust sysctl_kern_proc()'s kernel thread scanning code to use a marker
  instead of depending on td remaining on its proper list.  Otherwise
  blocking conditions can rip td out from under us or move it to another
  cpu, potentially resulting in a crash or livelock.  Index the scan
  backwards to avoid live-locking continuous adds to the list.

* Fix a potential race is the zombie removal code vs a ps, p->p_token was
  being released too early.

* Adjust lwkt_exit() to wait for the thread's hold count to drop to zero
  so lwkt_hold() works as advertised.

12 years agosendfile: Use asynchronized pru_send when ever possible
Sepherosa Ziehau [Thu, 17 Nov 2011 13:42:29 +0000 (21:42 +0800)]
sendfile: Use asynchronized pru_send when ever possible

On Phenom 9550 (4 core, 2.2GHz):
8 parallel netperf -H 127.0.0.1 -t TCP_SENDFILE -P0 (4 runs, unit: Mbps)

old  10509.48  12364.60  11930.55  11104.94
new  21031.34  20165.39  19888.42  19896.47

This give 70% ~ 90% performance improvement

12 years agoprotosw: Add PR_ASYNC_SEND, mainly to make sure async pru_send is supported
Sepherosa Ziehau [Thu, 17 Nov 2011 12:01:17 +0000 (20:01 +0800)]
protosw: Add PR_ASYNC_SEND, mainly to make sure async pru_send is supported

Currently on IP/TCP and IPv6/TCP set this flag

12 years agokernel -- vkernel64's trap_pfault should use VM_FAULT_BURST for usermode faults.
Venkatesh Srinivas [Thu, 17 Nov 2011 02:30:11 +0000 (18:30 -0800)]
kernel -- vkernel64's trap_pfault should use VM_FAULT_BURST for usermode faults.

From x86-64 trap_pfault.

12 years agoMerge branch 'master' of /repository/git/dragonfly
Venkatesh Srinivas [Thu, 17 Nov 2011 02:10:41 +0000 (18:10 -0800)]
Merge branch 'master' of /repository/git/dragonfly

12 years agokernel -- token: Two shared token DEBUG_LOCKS tests.
Venkatesh Srinivas [Thu, 17 Nov 2011 02:07:47 +0000 (18:07 -0800)]
kernel -- token: Two shared token DEBUG_LOCKS tests.

* New warning when a pool token is taken in shared mode.

* KASSERT when trying to take an exclusive token with that token
  already held shared.

Both tests are only active under DEBUG_LOCKS.

12 years agosystat - unsigned expansion to proper display >= 2G values on 32 bit boxes
Matthew Dillon [Thu, 17 Nov 2011 01:56:39 +0000 (17:56 -0800)]
systat - unsigned expansion to proper display >= 2G values on 32 bit boxes

* Rename putlong() to put64(), and have it takes an intmax_t argument
  instead of a long.

12 years agokernel - Move VM objects from pool tokens to per-vm-object tokens
Matthew Dillon [Wed, 16 Nov 2011 22:59:34 +0000 (14:59 -0800)]
kernel - Move VM objects from pool tokens to per-vm-object tokens

* Move VM objects from pool tokens to per-vm-object tokens.

* This fixes booting issues on i386 with vm.shared_fault=1 (pool
  tokens would sometimes coincide with the token used for kernel_object
  which causes problems on i386 due to the pmap code's use of
  kernel_map/kernel_object).

12 years agokernel - Try to fix procfs readdir race
Matthew Dillon [Wed, 16 Nov 2011 20:29:20 +0000 (12:29 -0800)]
kernel - Try to fix procfs readdir race

* procfs_allocvp() may have a pfs/vnode race which the vget() may not
  completely address.  For now make sure we can't race a vnode teardown
  when attempting to acquire a vnode with vget().

12 years agokernel - Do not use shared tokens for kernel_map
Matthew Dillon [Wed, 16 Nov 2011 19:51:29 +0000 (11:51 -0800)]
kernel - Do not use shared tokens for kernel_map

* This primarily handles a case where i386 systems can deadlock on a
  shared token -> exclusive token sequence during a page fault, because
  the i386 pmap code uses kernel_object to manage page table pages.

  x86-64 page fault code does not but for now just make the change globally.

* Should not effect performance

* Change the default for vm_

* Change the default for vm.shared_fault back to 1.

Reported-by: ejc
Submitted-by: vsrinivas
12 years agokernel - Fix bug in procfs_ioctl()
Matthew Dillon [Wed, 16 Nov 2011 18:58:32 +0000 (10:58 -0800)]
kernel - Fix bug in procfs_ioctl()

* needed pfs_pfind() instead of pfind().

Reported-by: ftigeot
12 years ago<sys/socket.h>: Bring back PF_APPLETALK too, to unbreak building lang/ruby18.
Sascha Wildner [Wed, 16 Nov 2011 18:03:23 +0000 (19:03 +0100)]
<sys/socket.h>: Bring back PF_APPLETALK too, to unbreak building lang/ruby18.

Reported-by: Eric J. Christeson <eric.j.christeson@gmail.com>
12 years agokernel - Do not call pmap_enter() in vm_fault_page*()
Matthew Dillon [Wed, 16 Nov 2011 17:12:58 +0000 (09:12 -0800)]
kernel - Do not call pmap_enter() in vm_fault_page*()

* Do not call pmap_enter() from vm_fault_page*().  This function can be
  called from foreign pmap contexts and thus the current cpu's bit may
  not be set in the target pmap cpumask.  Any pmap_enter() operation will
  thus not properly synchronize with other users of the pmap (particularly
  other foreign users).

* In addition, for callers of the umtx*() function calling pmap_enter()
  is inefficient as the correct page might already be faulted in.  Now
  because we are no longer updating the page in the pmap an older page
  may still exist in the pmap (mapped read-only as it was originally COW).

  This page may no longer be correct because the umtx*() functions
  modify the contend of the page returned by vm_fault_page() without
  necessarily mapping it.  So to keep the user visibility into the memory
  correct we unmap the old page when vm_fault_page() has to do a COW.

  This is slightly more burdensome for fork() but far less burdomsome
  for the umtx system calls and also allows procfs_memrw to work properly.

* procfs uses vm_fault_page*() to access command line arguments for
  any process and umtx*() uses it to access the memory page the umtx
  is operating in.  Relative to procfs the user process pmap is foreign
  (i.e. the current cpu's bit is not set in its pm_active) and cannot
  be properly updated via a vm_fault_page*() from procfs anyway, so the
  above new behavior for vm_fault_page*() is even more correct for
  procfs use cases.

12 years agokernel - Handle degenerate cases for fill_*regs*()
Matthew Dillon [Wed, 16 Nov 2011 17:00:26 +0000 (09:00 -0800)]
kernel - Handle degenerate cases for fill_*regs*()

* These routines can be called with the lwp in various states of disrepair
  so check for NULL and return EINVAL if required pieces are missing.

12 years agokernel - Fix races in procfs
Matthew Dillon [Wed, 16 Nov 2011 16:47:29 +0000 (08:47 -0800)]
kernel - Fix races in procfs

* Use cache_copy to acquire a stable textnch

* Do not try to access the vmspace (for process args) for processes
  in the SIDL or SZOMB state as it may be a moving target even with
  the process PHOLD()en.

12 years agokernel - Fix token ordering in sysctl_kern_proc_args(), sysctl_kern_proc_cwd()
Matthew Dillon [Wed, 16 Nov 2011 16:40:40 +0000 (08:40 -0800)]
kernel - Fix token ordering in sysctl_kern_proc_args(), sysctl_kern_proc_cwd()

* We have to PHOLD() first, then get p->p_token, not the other way around.
  Use pfind() instead of pfindn().

* Extract and ref the the ncdir from p->p_fd before calling cache_fullpath()
  on it to ensure stability.

12 years agokernel - Attempt to make procfs MPSAFE (3)
Matthew Dillon [Wed, 16 Nov 2011 05:48:59 +0000 (21:48 -0800)]
kernel - Attempt to make procfs MPSAFE (3)

* More fixes to silly bugs.  Well, I did say 'attempt' :-)

12 years agokernel - Fix VM page race when exec maps a page
Matthew Dillon [Wed, 16 Nov 2011 04:33:18 +0000 (20:33 -0800)]
kernel - Fix VM page race when exec maps a page

* When vm_page_grab() is called with VM_ALLOC_RETRY allow failures due to
  page races and retry automatically.

12 years agokernel - Attempt to make procfs MPSAFE (2)
Matthew Dillon [Wed, 16 Nov 2011 03:36:58 +0000 (19:36 -0800)]
kernel - Attempt to make procfs MPSAFE (2)

* Disallow access to processes which are trying to exit.

12 years agokernel - Attempt to make procfs MPSAFE
Matthew Dillon [Wed, 16 Nov 2011 03:28:24 +0000 (19:28 -0800)]
kernel - Attempt to make procfs MPSAFE

* pfs_pfind() now acquires the p->p_token in addition to its PHOLD().

* Replace PRELE()'s with pfs_pdone() which releases the token along
  with PRELE()

* Double-check the validity of nch's passed to cache_fullpath().  This
  probably still needs work.

Reported-by: swildner
12 years agosocket: Properly inherit AUTOLOWAT and AUTOSIZE from listen socket
Sepherosa Ziehau [Wed, 16 Nov 2011 02:23:04 +0000 (10:23 +0800)]
socket: Properly inherit AUTOLOWAT and AUTOSIZE from listen socket

The soreserve and pru_attach could set these two flags internally,
so the original code will only retain those two flags but not clear
them if the listen socket does not have them.  We now explicitly
check those two flags and then set or clear them accordingly.

12 years agotcp: Fix the dangling socket reference in the async sending message
Sepherosa Ziehau [Wed, 16 Nov 2011 01:38:27 +0000 (09:38 +0800)]
tcp: Fix the dangling socket reference in the async sending message

It is possible that tcp input path or tcp timers to drop the socket
reference and put the socket into disconnected state, when there
are still asynchronized sending messages pending on the netisr
message port.  If the user space program choose to close the tcp
socket under this situation, then the socket will be directly
freed on the syscall path since the socket has already been
disconnected, so the pending asynchronized sending messages on the
netisr message port will reference freed socket, thus cause
panic later on.

Fix the problem by explicit "sync" the netisr, which could have
pending asynchronized sending messages, before freeing the socket
on the soclose path.

12 years agokernel - Major signal path adjustments (2)
Matthew Dillon [Wed, 16 Nov 2011 00:39:59 +0000 (16:39 -0800)]
kernel - Major signal path adjustments (2)

* Add missing case that was causing kill to not wakeup threads sitting
  in lwkt_sleep().

12 years agokernel - Major signal path adjustments to fix races, tsleep race fixes, +more
Matthew Dillon [Tue, 15 Nov 2011 23:23:41 +0000 (15:23 -0800)]
kernel - Major signal path adjustments to fix races, tsleep race fixes, +more

* Refactor the signal code to properly hold the lp->lwp_token.  In
  particular the ksignal() and lwp_signotify() paths.

* The tsleep() path must also hold lp->lwp_token to properly handle
  lp->lwp_stat states and interlocks.

* Refactor the timeout code in tsleep() to ensure that endtsleep() is only
  called from the proper context, and fix races between endtsleep() and
  lwkt_switch().

* Rename proc->p_flag to proc->p_flags

* Rename lwp->lwp_flag to lwp->lwp_flags

* Add lwp->lwp_mpflags and move flags which require atomic ops (are adjusted
  when not the current thread) to the new field.

* Add td->td_mpflags and move flags which require atomic ops (are adjusted
  when not the current thread) to the new field.

* Add some freeze testing code to the x86-64 trap code (default disabled).

12 years agokernel - Fix DEBUG_LOCKS races
Matthew Dillon [Tue, 15 Nov 2011 23:13:04 +0000 (15:13 -0800)]
kernel - Fix DEBUG_LOCKS races

* DEBUG_LOCKS can race when shared tokens are in use.  Attempt to fix the
  problem.

Reported-by: tuxillo
12 years agokernel - Try to fix vrevoke() race/crash
Matthew Dillon [Tue, 15 Nov 2011 23:11:58 +0000 (15:11 -0800)]
kernel - Try to fix vrevoke() race/crash

* Try to fix situations where inactive vnodes are assocatied with a
  device.

Reported-by: marino
12 years agokernel - Normalize use of sys/buf2.h for last commit
Matthew Dillon [Tue, 15 Nov 2011 23:09:02 +0000 (15:09 -0800)]
kernel - Normalize use of sys/buf2.h for last commit

* We always include both sys/buf.h and sys/buf2.h

12 years agokernel: Fix building with 'options UDF'.
Sascha Wildner [Tue, 15 Nov 2011 15:31:19 +0000 (16:31 +0100)]
kernel: Fix building with 'options UDF'.

12 years agokernel - Greatly improve shared memory fault rate concurrency / shared tokens
Matthew Dillon [Tue, 15 Nov 2011 09:02:24 +0000 (01:02 -0800)]
kernel - Greatly improve shared memory fault rate concurrency / shared tokens

This commit rolls up a lot of work to improve postgres database operations
and the system in general.  With this changes we can pgbench -j 8 -c 40 on
our 48-core opteron monster at 140000+ tps, and the shm vm_fault rate
hits 3.1M pps.

* Implement shared tokens.  They work as advertised, with some cavets.

  It is acceptable to acquire a shared token while you already hold the same
  token exclusively, but you will deadlock if you acquire an exclusive token
  while you hold the same token shared.

  Currently exclusive tokens are not given priority over shared tokens so
  starvation is possible under certain circumstances.

* Create a critical code path in vm_fault() using the new shared token
  feature to quickly fault-in pages which already exist in the VM cache.
  pmap_object_init_pt() also uses the new feature.

  This increases fault-in concurrency by a ridiculously huge amount,
  particularly on SHM segments (say when you have a large number of postgres
  clients).  Scaling for large numbers of clients on large numbers of
  cores is significantly improved.

  This also increases fault-in concurrency for MAP_SHARED file maps.

* Expand the breadn() and cluster_read() APIs.  Implement breadnx() and
  cluster_readx() which allows a getblk()'d bp to be passed.  If *bpp is not
  NULL a bp is being passed in, otherwise the routines call getblk().

* Modify the HAMMER read path to use the new API.  Instead of calling
  getcacheblk() HAMMER now calls getblk() and checks the B_CACHE flag.
  This gives getblk() a chance to regenerate a fully cached buffer from
  VM backing store without having to acquire any hammer-related locks,
  resulting in even faster operation.

* If kern.ipc.shm_use_phys is set to 2 the VM pages will be pre-allocated.
  This can take quite a while for a large map and also lock the machine
  up for a few seconds.  Defaults to off.

* Reorder the smp_invltlb()/cpu_invltlb() combos in a few places, running
  cpu_invltlb() last.

* An invalidation interlock might be needed in pmap_enter() under certain
  circumstances, enable the code for now.

* vm_object_backing_scan_callback() was failing to properly check the
  validity of a vm_object after acquiring its token.  Add the required
  check + some debugging.

* Make vm_object_set_writeable_dirty() a bit more cache friendly.

* The vmstats sysctl was scanning every process's vm_map (requiring a
  vm_map read lock to do so), which can stall for long periods of time
  when the system is paging heavily.  Change the mechanic to a LWP flag
  which can be tested with minimal locking.

* Have the phys_pager mark the page as dirty too, to make sure nothing
  tries to free it.

* Remove the spinlock in pmap_prefault_ok(), since we do not delete page
  table pages it shouldn't be needed.

* Add a required cpu_ccfence() in pmap_inval.c.  The code generated prior
  to this fix was still correct, and this makes sure it stays that way.

* Replace several manual wiring cases with calls to vm_page_wire().

12 years agovkernel: Remove unused variable.
Sascha Wildner [Tue, 15 Nov 2011 06:58:57 +0000 (07:58 +0100)]
vkernel: Remove unused variable.

12 years agops - Fix broken column alignment for programs w/ large RSS/VSZ
Matthew Dillon [Tue, 15 Nov 2011 04:01:41 +0000 (20:01 -0800)]
ps - Fix broken column alignment for programs w/ large RSS/VSZ

* A RSS or VSZ >= 1GB is displayed in gigabytes with a decimal point
  to naturally draw the human eye to the distinction.

* Fixes the broken column alignment which occurs in these cases

12 years agosystat - Handle larger numbers, cleanup
Matthew Dillon [Tue, 15 Nov 2011 03:30:11 +0000 (19:30 -0800)]
systat - Handle larger numbers, cleanup

* Print more precision for numbers greater than 999k

* Normalize displayed values so everything is in bytes
  (converted to kBytes, mBytes, gBytes, etc as required).

* Remove the -pv 1 contention display, which is not currently
  operational in the kernel anyway.

12 years agokernel: Kill an obsolete comment.
Sascha Wildner [Tue, 15 Nov 2011 02:42:45 +0000 (03:42 +0100)]
kernel: Kill an obsolete comment.

Reported-by: vsrinivas
12 years agodrm.4: Add some words about using both an on-board and another card with DRI.
Sascha Wildner [Tue, 15 Nov 2011 02:05:06 +0000 (03:05 +0100)]
drm.4: Add some words about using both an on-board and another card with DRI.

Submitted-by: Juan Francisco Cantero Hurtado <iam@juanfra.info>
Dragonfly-bug: <http://bugs.dragonflybsd.org/issues/2178>

12 years agoemx: Use MPSAFE callout
Sepherosa Ziehau [Tue, 15 Nov 2011 01:25:10 +0000 (09:25 +0800)]
emx: Use MPSAFE callout

12 years ago<sys/socket.h>: Re-add AF_APPLETALK to unbreak building net/netatalk (pkgsrc).
Sascha Wildner [Mon, 14 Nov 2011 19:49:40 +0000 (20:49 +0100)]
<sys/socket.h>: Re-add AF_APPLETALK to unbreak building net/netatalk (pkgsrc).

Reported-by: Max Herrgard <herrgard@gmail.com>
12 years agodfregress - An automated test driver and framework
Alex Hornung [Sun, 30 Oct 2011 01:21:59 +0000 (01:21 +0000)]
dfregress - An automated test driver and framework

 * dfregress is a simple test framework and test automation driver. It
   supports both normal userland testcases and kernel test cases.

 * It's key aim is to make it simple, if not outright dead easy, to
   write test cases. A test case is a simple program using
   printf/fprintf and exit - no magic needed. A kernel test case is a
   very small module that just needs to implement a few functions and
   call a logging and result function.

 * Sample output of the text frontend (Frontends are explained further
   down the text): http://leaf.dragonflybsd.org/~alexh/dfregress.txt

 * dfregress is very UNIXy, it uses makefiles to build the testcases,
   stdout/stderr redirection from the testcases (no fancy output
   functions needed in the testcases) and evaluates the normal return
   value of the testcase (no need to call fancy functions).

 * For kernel testcases it is a bit different - you do have to call
   functions to log output and to log the result, but it is very simple,
   hardly any overhead.

 * The test driver assumes that testcases are in the testcases/
   directory, but it supports several command line options.

 * The tests to run, including several options, are specified in the
   runlist file. An example runlist including all the testcases is
   included as config/runlist.run. Options that can be specified are:
   - timeout: (in seconds) after which the test is aborted if it hasn't
     finished.
   - test type (userland, kernel or buildonly)
   - make: which 'make' tool to use to build the test cases. Defaults to
     'make', but could also be 'gmake', etc.
   - nobuild: doesn't build the testcase and tries to directly execute
     it.
   - pre, post: external pre-run and post-run commands, e.g. to set up a
     vn device and to tear it down. This is to avoid duplication in test
     cases, the common setup can be factored out.
   - intpre, intpost: similar to the above, but it assumes that the
     testcase, when passed the parameter 'pre', will do the pre-setup,
     and when passed 'post' will do the post-test cleanup/setup/etc.
   - any number of command line arguments that are passed to the test
     case. (See the crypto/ test examples in the runlist).

 * A range of sample testcases are available in
   test/dfregress/testcases/sample, including a kernel testcase sample.

 * Note that many of the test cases in the testcases/ directory have
   been copied from elsewhere in the main repository and are,
   temporarily at least, duplicated.

 * The test driver is completely separated from the frontends. The test
   driver outputs the test run results in an XML-like format (plist)
   that can easily be parsed using proplib. Python and Ruby also have
   plist modules that could be used to parse the output.

 * The only available frontend is a simple C program that will parse the
   intermediate format to an easy to read plain text format. Additional
   frontends can be written in any language, as long as it is possible
   to load plists. Frontends are in the fe/ directory.

 * XXX: the default options (currently just the timeout) are still
   hardcoded in config.c.

 * The NOTES file gives details on how the test execution occurs and
   what result code can be raised at which point. This document, and a look
   at the generated plist, is all you need to write a new frontend that,
   for example, generates beautiful HTML output.
   For completeness sake, a part of NOTES is reproduced under the main commit
   message - specifically the part detailing the execution of a single test
   case.

======
Execution of a single test case:
======
1) chdir to testcase directory
        - if it fails, set RESULT_PREFAIL (sysbuf is of interest), goto (6)

2) build testcase (make) (unless nobuild flag is set).
        + build_buf is used for stdout/stderr
        - if there is an internal driver error (that leads to not running the
          build command), set RESULT_PREFAIL (sysbuf is of interest), goto (6)
        - if the build command has a non-zero exit value, set the result to
          BUILDFAIL, unless it's a buildonly test case, in which it is set to
          the actual result value (TIMEOUT, SIGNALLED, FAIL)
          goto (6)

3) run 'pre' command if intpre or pre is set.
        + precmd_buf is used for stdout/stderr
        - if there is an internal driver error (that leads to not running the
          command), set RESULT_PREFAIL (sysbuf is of interest), goto (6)
        - if the pre command has a non-zero exit value, set RESULT_PREFAIL and
          goto (6)

4) run actual testcase, depending on type
        + stdout_buf is used for stdout
        + stderr_buf is used for stderr
        - for BUILDONLY: set RESULT_PASS since the build already succeeded
        - for userland and kernel: run the testcase, possibly as a different
          user (depending on the runas option), set the result to the actual
          result value (TIMEOUT, SIGNALLED, FAIL, NOTRUN)
        - if there is an internal driver error (that leads to not running the
          command), RESULT_NOTRUN is set (sysbuf is of interest)

5) run 'post' command if intpost or post is set.
        + postcmd_buf is used for stdout/stderr
        - if there is an internal driver error (that leads to not running the
          command), set RESULT_POSTFAIL (sysbuf is of interest), goto (6)
        - if the post command has a non-zero exit value, set RESULT_POSTFAIL
          and goto (6)

6) clean testcase directory (make clean) (unless nobuild flag is set).
        + cleanup_buf is used for stdout/stderr and system (driver error) buffer
        - no further action.

7) results are saved.

12 years agotcp: Use the MSL set to the rt_metrics whenever possible
Sepherosa Ziehau [Mon, 14 Nov 2011 14:31:18 +0000 (22:31 +0800)]
tcp: Use the MSL set to the rt_metrics whenever possible

12 years agort_metrics: Add rmx_msl to record user-set MSL
Sepherosa Ziehau [Mon, 14 Nov 2011 14:04:45 +0000 (22:04 +0800)]
rt_metrics: Add rmx_msl to record user-set MSL

12 years agostatfs.2: Fix indentation and add a missing .Pp.
Sascha Wildner [Mon, 14 Nov 2011 02:34:53 +0000 (03:34 +0100)]
statfs.2: Fix indentation and add a missing .Pp.

12 years agostress2: Fix a bug introduced in 3647609110201ad09b8c7b945941765be8924123.
Sascha Wildner [Mon, 14 Nov 2011 02:11:56 +0000 (03:11 +0100)]
stress2: Fix a bug introduced in 3647609110201ad09b8c7b945941765be8924123.

Even though we use statvfs() for a couple of things now, we still need
to statfs() too for getting at f_mntfromname[].

12 years agokernel: Fix linux emulation build.
Sascha Wildner [Sun, 13 Nov 2011 19:47:22 +0000 (20:47 +0100)]
kernel: Fix linux emulation build.

12 years agokernel - Improve per-cpu caching of pv_entry's
Matthew Dillon [Sun, 13 Nov 2011 17:39:14 +0000 (09:39 -0800)]
kernel - Improve per-cpu caching of pv_entry's

* The vm_zone (zalloc) code needs to be replaced with objcache, but until
  we do continue improving certain critical paths in it.

* Burst fill an empty per-cpu cache to reduce overheads when working with
  large numbers of processes with large shared address spaces (postgres,
  mysql, etc).  This reduces contention under heavy use situations.

12 years agokernel - Certain sysv_shm administrative functions still need the mp_lock
Matthew Dillon [Sun, 13 Nov 2011 17:37:38 +0000 (09:37 -0800)]
kernel - Certain sysv_shm administrative functions still need the mp_lock

* Fix a few races, particularly with the NATTCH counter, that can prevent
  the deletion of shm segments.

12 years agolibc - Bring dmalloc in for x86-64
Matthew Dillon [Sun, 13 Nov 2011 17:31:01 +0000 (09:31 -0800)]
libc - Bring dmalloc in for x86-64

* Bring in a much faster allocator for x86-64.  DMalloc is a slab alloctor
  with dynamic slab sizing capabilities, allowing slabs to be used for
  all allocation sizes.  This simplifies the code paths considerably.

* DMalloc is optimized for heavy-use situations but will still retain a
  run size similar to the old nmalloc code.  The VSZ is going to be quite
  a bit bigger, though.  The best test is w/mysqld as mysql[d] allocates
  and frees memory at a very high rate.

* DMalloc is almost completely lockless.  Slabs become owned by threads
  which can then manipulate them trivially.  Frees can operate on foreign
  slabs in a lockless manner.  A depot is used primarily as a catch-all
  for thread exits.

Written-by: Matthew Dillon
12 years agoipcs - Cleanup output format
Matthew Dillon [Sun, 13 Nov 2011 00:00:33 +0000 (16:00 -0800)]
ipcs - Cleanup output format

* Cleanup the output format a bit so fields don't run into each other

12 years agokernel - Add syscall quick return path for x86-64
Matthew Dillon [Sat, 12 Nov 2011 23:04:56 +0000 (15:04 -0800)]
kernel - Add syscall quick return path for x86-64

* Flag the case where a sysretq can be performed to quickly return
  from a system call instead of having to execute the slower doreti
  code.

* This about halves syscall times for simple system calls such as
  getuid(), and reduces longer syscalls by ~80ns or so on a fast
  3.4GHz SandyBridge, but does not seem to really effect performance
  a whole lot.

Taken-From: FreeBSD (loosely)

12 years agokernel - Use MPSAFE callouts for TCP
Matthew Dillon [Sat, 12 Nov 2011 19:28:31 +0000 (11:28 -0800)]
kernel - Use MPSAFE callouts for TCP

* Use MP callouts for tcp timers.  Since the timers do not usually fire
  this isn't that big a deal but it's still far more correct and it reduces
  lock contention.