dragonfly.git
17 years agoRename arguments to atomic_cmpset_int() to make their function more obvious.
Matthew Dillon [Fri, 2 Jun 2006 20:32:05 +0000 (20:32 +0000)]
Rename arguments to atomic_cmpset_int() to make their function more obvious.

17 years agoFix a file descriptor leak, add a missing vx_put() after linprocfs
Matthew Dillon [Fri, 2 Jun 2006 19:44:39 +0000 (19:44 +0000)]
Fix a file descriptor leak, add a missing vx_put() after linprocfs
destroys a vnode.

Reported-by: joerg@britannica.bec.de
17 years agoAdd an option which dumps the filename from the vnode's namecache link.
Matthew Dillon [Fri, 2 Jun 2006 19:39:48 +0000 (19:39 +0000)]
Add an option which dumps the filename from the vnode's namecache link.

17 years agoRemove vnode->v_id. This field used to be used to identify stale namecache
Matthew Dillon [Fri, 2 Jun 2006 04:59:54 +0000 (04:59 +0000)]
Remove vnode->v_id.  This field used to be used to identify stale namecache
entries related to parent directory linkages.  It was a terrible hack and
fortunately is no longer used.

17 years agonamecache->nc_refs is no longer protected by the MP lock. Atomic ops must
Matthew Dillon [Thu, 1 Jun 2006 22:45:19 +0000 (22:45 +0000)]
namecache->nc_refs is no longer protected by the MP lock.  Atomic ops must
be used.

17 years agoAdd some mdoc markup and remove hard sentence breaks.
Sascha Wildner [Thu, 1 Jun 2006 19:38:06 +0000 (19:38 +0000)]
Add some mdoc markup and remove hard sentence breaks.

17 years agoAdd KTR_GIANT_CONTENTION and KTR_SPIN_CONTENTION.
Sascha Wildner [Thu, 1 Jun 2006 19:35:59 +0000 (19:35 +0000)]
Add KTR_GIANT_CONTENTION and KTR_SPIN_CONTENTION.

17 years agoSince we can only hold one shared spinlock at a time anyway, change the
Matthew Dillon [Thu, 1 Jun 2006 19:02:39 +0000 (19:02 +0000)]
Since we can only hold one shared spinlock at a time anyway, change the
gd_spinlocks_rd counter into a gd_spinlock_rd pointer.  This will improve
performance for potentially contested exclusive spinlocks.  Now they can
test the per-cpu spinlock pointer directly against the spinlock being
acquired instead of testing a counter which might represent any shared
spinlock.

This also has the effect of relaxing the requirement that further
exclusive spinlocks cannot be acquired while holding a shared spinlock,
but for now we are going to leave the requirement intact.

17 years agoTeach kdump a handy new trick: -p $pid selects the records of
Joerg Sonnenberger [Thu, 1 Jun 2006 18:18:00 +0000 (18:18 +0000)]
Teach kdump a handy new trick: -p $pid selects the records of
a specific PID, making it much faster than e.g. grep of the output.
Keep track of how long the header was, useful for later additions.

Obtained-from: NetBSD

17 years agoAnother update. Clarify that a shared spinlock can be acquired while holding
Matthew Dillon [Thu, 1 Jun 2006 17:17:35 +0000 (17:17 +0000)]
Another update.  Clarify that a shared spinlock can be acquired while holding
exclusive spinlocks, but only one shared spinlock can be held and no new
exclusive spinlocks can be acquired while holding a shared spinlock.

17 years agoUpdate the manual page to reflect additional spinlock requirements.
Matthew Dillon [Thu, 1 Jun 2006 17:05:01 +0000 (17:05 +0000)]
Update the manual page to reflect additional spinlock requirements.

17 years agoIf the scheduler clock cannot call bsd4_resetpriority() due to spinlock
Matthew Dillon [Thu, 1 Jun 2006 16:49:59 +0000 (16:49 +0000)]
If the scheduler clock cannot call bsd4_resetpriority() due to spinlock
requirements, at least call need_user_resched().

17 years agoUse the MP friendly objcache instead of zalloc to allocate temporary
Matthew Dillon [Thu, 1 Jun 2006 06:10:58 +0000 (06:10 +0000)]
Use the MP friendly objcache instead of zalloc to allocate temporary
MAXPATHLEN space.

17 years agogd_tdallq is not protected by the BGL any more, it can only be manipulated
Matthew Dillon [Thu, 1 Jun 2006 05:38:46 +0000 (05:38 +0000)]
gd_tdallq is not protected by the BGL any more, it can only be manipulated
on the current cpu.  Remove the thread when it exits rather then when it is
freed.

17 years agoZap references to Digital's TurboLaser bus.
Sascha Wildner [Wed, 31 May 2006 19:06:13 +0000 (19:06 +0000)]
Zap references to Digital's TurboLaser bus.

17 years agoAdd kobj(9) manual page.
Sascha Wildner [Wed, 31 May 2006 09:42:10 +0000 (09:42 +0000)]
Add kobj(9) manual page.

Taken-from: FreeBSD

17 years agoRemove trailing whitespace and fix references.
Sascha Wildner [Tue, 30 May 2006 08:13:07 +0000 (08:13 +0000)]
Remove trailing whitespace and fix references.

17 years agoFix numerous bugs in the BSD4 scheduler introduced in recent commits.
Matthew Dillon [Mon, 29 May 2006 22:57:24 +0000 (22:57 +0000)]
Fix numerous bugs in the BSD4 scheduler introduced in recent commits.
Primarily, do not try to get a spinlock from a hard interrupt (e.g. IPI)
if spinlocks are already being held by the cpu.

This will probably have to be made an absolute rule - no spinlocks at all
in a hard interrupt / IPI (vs an interrupt thread).

17 years agoShortcut two common spinlock situations and don't bother KTR logging them.
Matthew Dillon [Mon, 29 May 2006 16:50:06 +0000 (16:50 +0000)]
Shortcut two common spinlock situations and don't bother KTR logging them.

17 years agoAdd two KTR (kernel trace) options: KTR_GIANT_CONTENTION and
Matthew Dillon [Mon, 29 May 2006 07:29:15 +0000 (07:29 +0000)]
Add two KTR (kernel trace) options: KTR_GIANT_CONTENTION and
KTR_SPIN_CONTENTION.  These will cause MP lock contention and spin lock
contention to be KTR-logged.

17 years agoRemove conditional memory allocation based on KTR_ALL. Allocate memory
Matthew Dillon [Mon, 29 May 2006 07:18:04 +0000 (07:18 +0000)]
Remove conditional memory allocation based on KTR_ALL.  Allocate memory
for all cpus based on KTR only.

17 years agoClean up compiler warnings when KTR is enabled but KTR_ALL is not.
Matthew Dillon [Mon, 29 May 2006 06:47:29 +0000 (06:47 +0000)]
Clean up compiler warnings when KTR is enabled but KTR_ALL is not.

17 years agoFurther isolate the user process scheduler data by moving more variables
Matthew Dillon [Mon, 29 May 2006 03:57:21 +0000 (03:57 +0000)]
Further isolate the user process scheduler data by moving more variables
from the globaldata structure to the scheduler module(s).

Make the user process scheduler MP safe.  Make the LWKT 'pull thread'
(to a different cpu) feature MP safe.  Streamline the user process
scheduler API.

Do a near complete rewrite of the BSD4 scheduler.  Remote reschedules
(reschedules to other cpus), cpu pickup of queued processes, and locality
of reference handling should make the new BSD4 scheduler a lot more
responsive.

Add a demonstration user process scheduler called 'dummy'
(kern/usched_dummy.c).  Add a kenv variable 'kern.user_scheduler' that
can be set to the desired scheduler on boot (i.e. 'bsd4' or 'dummy').

NOTE: Until more of the system is taken out from under the MP lock,
these changes actually slow things down slightly.  Buildworlds are
about ~2.7% slower.

17 years agoGet rid -y/-Y (sort by interactive measure). The interactive measure has
Matthew Dillon [Sun, 28 May 2006 23:12:09 +0000 (23:12 +0000)]
Get rid -y/-Y (sort by interactive measure).  The interactive measure has
been removed.

17 years agoMark various forms of read() and write() MPSAFE. Note that the MP lock is
Matthew Dillon [Sat, 27 May 2006 20:17:17 +0000 (20:17 +0000)]
Mark various forms of read() and write() MPSAFE.  Note that the MP lock is
still acquire, but now its a lot deeper in the fileops.

Mark dup(), dup2(), close(), closefrom(), and fcntl() MPSAFE.  Some code
paths don't have to get the MP lock, but most still do deeper into the
fileops.

17 years agoAdd a spinlock(9) manual page (based on a writeup by Matt).
Sascha Wildner [Sat, 27 May 2006 17:22:46 +0000 (17:22 +0000)]
Add a spinlock(9) manual page (based on a writeup by Matt).

17 years agoCheck cvs commit's -m argument for being a filename and ask the user
Simon Schubert [Sat, 27 May 2006 11:59:44 +0000 (11:59 +0000)]
Check cvs commit's -m argument for being a filename and ask the user
if he is serious.  This should in the future prevent log messages like
"/tmp/mycommit.txt", which happen when -m is used instead of -F.

17 years agoRemove /usr/share/examples/ibcs2 via 'make upgrade'.
Sascha Wildner [Sat, 27 May 2006 10:10:07 +0000 (10:10 +0000)]
Remove /usr/share/examples/ibcs2 via 'make upgrade'.

17 years agoClear the new VMAYHAVELOCKS flag when after an unlock we determine that
Matthew Dillon [Sat, 27 May 2006 02:03:17 +0000 (02:03 +0000)]
Clear the new VMAYHAVELOCKS flag when after an unlock we determine that
there are no more locks and no pending locks.

17 years agoGreatly reduce the MP locking that occurs in closef(), and remove
Matthew Dillon [Sat, 27 May 2006 01:57:42 +0000 (01:57 +0000)]
Greatly reduce the MP locking that occurs in closef(), and remove
unnecessary VOP_ADVLOCK calls in both closef() and fdrop() by adding
a new vnode flag, VMAYHAVELOCKS, that we can check before doing the
VOP_ADVLOCK mess.

17 years agoImplement msleep(). This function is similar to the FreeBSD msleep() except
Matthew Dillon [Sat, 27 May 2006 01:51:27 +0000 (01:51 +0000)]
Implement msleep().  This function is similar to the FreeBSD msleep() except
it interlocks with a spinlock instead of a mutex.  The spinlock must be
exclusively held on entry.  msleep() will atomically sleep and release the
spinlock, then reacquire the spinlock when it wakes up.

A novel approach to the interlock is used.  DragonFly's tsleep/wakeup
mechanism is a per-cpu mechanism, with a local array of cpu masks, one
entry per hash index.  A wakeup simpy sends an IPI message to each target
cpu whos bitmap bit is set in the ident's hash entry.

This allows us to interlock simply by entering a critical section and
setting our bit, then releasing the mutex, then tsleep()ing as per normal.
No additional locks are required.  The critical section will delay any wakeup
race with us simply by delaying the IPI message that is potentially
in-transit to our cpu.

Requested-by: Numerous people, and its time has come now.
17 years agoAdd a read-ahead version of ffs_blkatoff() called ffs_blkatoff_ra(). This
Matthew Dillon [Fri, 26 May 2006 19:57:33 +0000 (19:57 +0000)]
Add a read-ahead version of ffs_blkatoff() called ffs_blkatoff_ra().  This
code was basically extracted from ffs_read().  ffs_read() now calls
ffs_blkatoff_ra().  ufs_readdir() now also calls ffs_blkatoff_ra().

17 years ago- Uniformly use .In for header file references.
Sascha Wildner [Fri, 26 May 2006 19:39:41 +0000 (19:39 +0000)]
- Uniformly use .In for header file references.

- Fix numerous wrong directory names.

17 years agoRemove FFS function hooks used by UFS. Simply make direct calls from ufs
Matthew Dillon [Fri, 26 May 2006 17:07:48 +0000 (17:07 +0000)]
Remove FFS function hooks used by UFS.  Simply make direct calls from ufs
to ffs.  The original ufs routines don't exist anymore anyhow and EXT2 no
longer references UFS files directly.  UFS and FFS have been 'one' filesystem
for two decades.  These hooks are no longer needed.

17 years ago* Fix a number of cases where too much kernel memory might be allocated to
Matthew Dillon [Fri, 26 May 2006 16:56:34 +0000 (16:56 +0000)]
* Fix a number of cases where too much kernel memory might be allocated to
  satisfy a directory read operation.

* Calculate a minimum of (1) allocated directory cookie and limit the maximum
  to 1024.

* Rewrite ufs_readdir() (part 1/2) to use the buffer cache instead of
  allocating a kernel buffer and to do better validation of the scanned
  directory entries.

* Use a simpler fix for EXT2FS.

Reported-by: [NetBSD.org #7471]
17 years agoAdd #include <sys/lock.h> where needed to support get_mplock().
Matthew Dillon [Fri, 26 May 2006 15:55:13 +0000 (15:55 +0000)]
Add #include <sys/lock.h> where needed to support get_mplock().

Reported-by: YONETANI Tomokazu <qhwt+dfly@les.ath.cx>
17 years ago* Make falloc() MPSAFE. filehead (the file list) and nfiles are now
Matthew Dillon [Fri, 26 May 2006 02:26:26 +0000 (02:26 +0000)]
* Make falloc() MPSAFE.  filehead (the file list) and nfiles are now
  static and fully MPSAFE.

* Add a MPSAFE procedure which scans all struct file's in the system.

* Substantially rework unp_gc().  It is not quite MPSAFE yet, but all of
  its struct file accesses and file list scanning should be.

17 years agoMore MP work.
Matthew Dillon [Fri, 26 May 2006 00:33:13 +0000 (00:33 +0000)]
More MP work.

* Incorporate fd_knlistsize initialization into fsetfd().

* Mark all fileops vectors as MPSAFE (but get the mplock for most of them).
  Clean up a number of fileops routines, mainly *_ioctl().

* Make crget(), crhold(), and crfree() MPSAFE.  crfree still needs the mplock
  on the last release.  Give ucred a spinlock to handle the crfree()
  0 transition race.

17 years agoFix several buffer cache issues related to B_NOCACHE.
Matthew Dillon [Thu, 25 May 2006 19:31:15 +0000 (19:31 +0000)]
Fix several buffer cache issues related to B_NOCACHE.

* Do not set B_NOCACHE when calling vinvalbuf(... V_SAVE).  This will
  destroy dirty VM backing store associated with clean buffers before
  the VM system has a chance to check for and flush them.

  Taken-from: FreeBSD

* Properly set B_NOCACHE when destroying buffers related to truncated data.

* Fix a bug in vnode_pager_setsize() that was recently introduced.
  v_filesize was being set before a new/old size comparison, causing a
  file truncation to not destroy related VM pages past the new EOF.

* Remove a bogus B_NOCACHE|B_DIRTY test in brelse().  This was originally
  intended to be a B_NOCACHE|B_DELWRITE test which then cleared B_NOCACHE,
  but now that B_NOCACHE operation has been fixed it really does indicate that
  the buffer, its contents, and its backing store are to be destroyed, even
  if the buffer is marked B_DELWRI.

  Instead of clearing B_NOCACHE when B_DELWRITE is found to be set, clear
  B_DELWRITE when B_NOCACHE is found to be set.

  Note that B_NOCACHE is still cleared when bdirty() is called in order to
  ensure that data is not lost when softupdates and other code do a
  'B_NOCACHE + bwrite' sequence.  Softupdates can redirty a buffer in its
  io completion hook and a write error can also redirty a buffer.

* The VMIO buffer rundown seems to have mophed into a state where the
  distinction between NFS and non-NFS buffers can be removed.  Remove
  the test.

17 years agoConvert almost all of the remaining manual traversals of the allproc
Matthew Dillon [Thu, 25 May 2006 07:36:37 +0000 (07:36 +0000)]
Convert almost all of the remaining manual traversals of the allproc
list over to allproc_scan().

The allproc_scan() code is MPSAFE, and code which before just cached
a proc pointer now PHOLD's it as well, but access to the various proc
fields is *NOT* yet MPSAFE.  Still, we are closer now.

17 years agoAdjust pamp_growkernel(), elf_brand_inuse(), and ktrace() to use
Matthew Dillon [Thu, 25 May 2006 04:17:09 +0000 (04:17 +0000)]
Adjust pamp_growkernel(), elf_brand_inuse(), and ktrace() to use
allproc_scan() instead of scanning the process list manually.

17 years agoModifying lk_flags during lock reinitialization requires a spinlock.
Matthew Dillon [Thu, 25 May 2006 02:46:38 +0000 (02:46 +0000)]
Modifying lk_flags during lock reinitialization requires a spinlock.

17 years agoWhen a vnode is vgone()'d its v_ops is replaced with dead_vnode_ops.
Matthew Dillon [Thu, 25 May 2006 01:20:07 +0000 (01:20 +0000)]
When a vnode is vgone()'d its v_ops is replaced with dead_vnode_ops.
dead_vnode_ops replaces VOP_LOCK with a dummy routine that just returns
TRUE.

This blows up anyone actually trying to access the vnode by improperly
returning a successful lock which then panics the machine when the caller
tries to unlock it.  This also screws up VOP_LOCK vs vx_lock() interactions
and can theoretically create other problems.

Normally vgone()'d vnodes have no references and this isn't a problem.
The two notable exceptions are (1) when revoke() is called on a device
(i.e. tty), and (2) when a procfs or linprocfs vnode is destroyed due
to a process exit while another process is accessing it.

Remove dead_lock().  Dead vnodes revert to defaultops which implement
the expected lockmgr lock.

17 years agoFix issues with an incorrectly initialized buffer when formatting a floppy.
Matthew Dillon [Wed, 24 May 2006 21:50:11 +0000 (21:50 +0000)]
Fix issues with an incorrectly initialized buffer when formatting a floppy.

Reported-by: Stefan Krueger <skrueger@meinberlikomm.de>
17 years agoMove the code that inserts a new process into the allproc list into its
Matthew Dillon [Wed, 24 May 2006 18:59:51 +0000 (18:59 +0000)]
Move the code that inserts a new process into the allproc list into its
own procedure, proc_add_allproc().  Make it MPSAFE.

Integrate pid generation for the new process into proc_add_allproc(), move
all related code from kern_fork.c to kern_proc.c.

Change procfs to use the new allproc scanning function.

17 years agoStart consolidating process related code into kern_proc.c. Implement
Matthew Dillon [Wed, 24 May 2006 17:44:04 +0000 (17:44 +0000)]
Start consolidating process related code into kern_proc.c.  Implement
a few MPSAFE functions to mess with the allproc and zombproc lists, and a
callback for scanning allproc.

Adjust linprocfs to use the new callback as a test.

17 years agoregen
Simon Schubert [Wed, 24 May 2006 12:42:01 +0000 (12:42 +0000)]
regen

17 years agounbreak world: spell MPSAFE correctly
Simon Schubert [Wed, 24 May 2006 12:40:19 +0000 (12:40 +0000)]
unbreak world: spell MPSAFE correctly

17 years agospinlock more of the file descriptor code. No appreciable difference in
Matthew Dillon [Wed, 24 May 2006 03:23:35 +0000 (03:23 +0000)]
spinlock more of the file descriptor code.  No appreciable difference in
performance on buildworld tests.

Change getvnode() to holdvnode() and use semantics similar to holdsock().
The old getvnode() code wasn't fhold()ing the file pointer.  The new
holdvnode() code does.

17 years agoMove all the resource limit handling code into a new file, kern/kern_plimit.c.
Matthew Dillon [Tue, 23 May 2006 20:35:12 +0000 (20:35 +0000)]
Move all the resource limit handling code into a new file, kern/kern_plimit.c.
Add spinlocks for access, and mark getrlimit and setrlimit as being MPSAFE.

Document how LWPs will have to be handled - basically we will have to unshare
the resource structure once we start allowing multiple LWPs per process, but
we can otherwise leave it in the proc structure.

17 years agoThe pageout daemon does not usually page out pages it considers active.
Matthew Dillon [Tue, 23 May 2006 01:21:48 +0000 (01:21 +0000)]
The pageout daemon does not usually page out pages it considers active.
However, under certain types of heavy memory use it is possible to keep
nearly all of a machine's pages marked active.  This can result in a
degenerate situation where the pageout demon pages out so few pages that
it might as well not be operating at all, resulting in a machine lockup.

Adjust the pageout daemon to dig into active pages based on its loop
counter.  This counter will start to go up when the pageout daemon is not
able to keep up.  The higher counter gets, the more active pages
become candidates for paging.  We depend on fault-in rate limiting to
avoid thrashing to the point of inaccessibility.

Also-thanks-to: Peter Holms filesystem and load testing suite (stress2).

17 years agoSync to head. Add a verbose option to vmpageinfo which dumps all the
Matthew Dillon [Tue, 23 May 2006 01:00:05 +0000 (01:00 +0000)]
Sync to head.  Add a verbose option to vmpageinfo which dumps all the
vm_page structures.

17 years agoFix a minor bug in fdcopy() in the last commit, Consolidate the
Matthew Dillon [Mon, 22 May 2006 21:33:11 +0000 (21:33 +0000)]
Fix a minor bug in fdcopy() in the last commit, Consolidate the
fd_lastfile and fd_freefile fixup code to its own little inline function.

17 years agoDo a major cleanup of the file descriptor handling code in preparation for
Matthew Dillon [Mon, 22 May 2006 21:21:26 +0000 (21:21 +0000)]
Do a major cleanup of the file descriptor handling code in preparation for
making the descriptor table MPSAFE.  Introduce a new feature that allows a
file descriptor number to be reserved without having to assign a file
pointer to it.  This allows code such as open(), dup(), etc to reserve
descriptors to work with without having to worry about the related file
being ripped out from under them by another thread sharing the descriptor
table.

falloc() - This function allocates the file pointer and descriptor as
before, but does NOT associate the file pointer with the
descriptor.

Before this change another thread could access the file
pointer while the system call creating it was blocked,
before the system call had a chance to completely initialize
the file pointer.

The caller must call fsetfd() to assign or clear the
reserved descriptor.

fsetfd() - Is now responsible for associating a file pointer with a
previously reserved descriptor or clearing the reservation.

fdealloc() - This hack existed to deal with open/dup races against other
threads.  The above changes remove the possibility so this
routine has been deleted.

dup code - kern_dup() and dupfdopen() have been completely rewritten.
They are much cleaner and less obtuse now.  Additional race
conditions in the original code were also found and fixed.

funsetfd() - Now returns the file pointer that was cleared and takes
responsibility for adjusting fd_lastfile.

NOTE: fd_lastfile is inclusive of any reserved descriptors.

fdcopy() - While not yet MPSAFE, fdcopy now properly handles races
against other threads.

fdp->fd_lastfile -
This field was not being properly updated in certain failure
cases.  This commit fixes that.  Also, if all a process's
descriptors were closed this field was incorrectly left at
0 when it should have been set to -1.

fdp->fd_files - A number of code blocks were trying to optimize a for()
loop over all file descriptors by caching a pointer to
fd_files.  This is a problem because fd_files can be
reallocated if code within the loop blocks.  These loops
have been rewritten.

17 years agoMop up remains of the ibcs2/streams/svr4 removal:
Sascha Wildner [Mon, 22 May 2006 06:26:30 +0000 (06:26 +0000)]
Mop up remains of the ibcs2/streams/svr4 removal:

* Remove streams(4) and svr4(4) manual pages.

* Add associated modules and their manual pages to the list of files
  to be removed upon 'make upgrade'.

* Remove IBCS2 and SPX_HACK options.

* Change M_ZOMBIE definition back to static.

* Fix miscellaneous references & comments.

17 years agoGive struct filedesc and struct file a spinlock, and do some initial
Matthew Dillon [Mon, 22 May 2006 00:52:31 +0000 (00:52 +0000)]
Give struct filedesc and struct file a spinlock, and do some initial
(incomplete) lockup work.

Performance impact: No measurable impact.

17 years agoImplement a much faster spinlock.
Matthew Dillon [Sun, 21 May 2006 20:23:29 +0000 (20:23 +0000)]
Implement a much faster spinlock.

* Spinlocks can't conflict with FAST interrupts without deadlocking anyway,
  so instead of using a critical section simply do not allow an interrupt
  thread to preempt the current thread if it is holding a spinlock.  This
  cuts spinlock overhead in half.

* Implement shared spinlocks in addition to exclusive spinlocks.  Shared
  spinlocks would be used, e.g. for file descriptor table lookups.

* Cache a shared spinlock by using the spinlock's lock field as a bitfield,
  one for each cpu (bit 31 for exclusive locks).  A shared spinlock sets
  its cpu's shared bit and does not bother clearing it on unlock.

  This means that multiple, parallel shared spinlock accessors do NOT incur
  a cache conflict on the spinlock.  ALL parallel shared accessors operate
  at full speed (~10ns vs ~40-100ns in overhead).  90% of the 10ns in
  overhead is due to a necessary MFENCE to interlock against exclusive
  spinlocks on the mutex.  However, this MFENCE only has to play with
  pending cpu-local memory writes so it will always run at near full speed.

* Exclusive spinlocks in the face of previously cached shared spinlocks
  are now slightly more expensive because they have to clear the cached
  shared spinlock bits by checking the globaldata structure for each
  conflicting cpu to see if it is still holding a shared spinlock.  However,
  only the initial (unavoidable) atomic swap involves potential cache
  conflicts.  The shared bit checks involve only memory reads and the
  situation should be self-correcting from a performance standpoint since
  the shared bits then get cleared.

* Add sysctl's for basic spinlock performance testing.  Setting
  debug.spin_lock_test issues a test.  Tests #2 and #3 loop
  debug.spin_test_count times.  p.s. these tests will stall the whole
   machine.

1       Test the indefinite wait code
2       Time the best-case exclusive lock overhead
3       Time the best-case shared lock overhead

* TODO: A shared->exclusive spinlock upgrade inline with positive feedback,
  and an exclusive->shared spinlock downgrade inline.

17 years agoMisc mdoc(7) cleanup:
Sascha Wildner [Sun, 21 May 2006 14:15:06 +0000 (14:15 +0000)]
Misc mdoc(7) cleanup:

* Fix section numbers.

* Fix .Xr abuse.

* Remove reference to obsolete plot(1) manual page.

* Fix typo.

17 years agoOnly _KERNEL code can optimize based on SMP vs UP. User code must always
Matthew Dillon [Sun, 21 May 2006 05:31:14 +0000 (05:31 +0000)]
Only _KERNEL code can optimize based on SMP vs UP.  User code must always
assume SMP and generate a "lock; " prefix.

17 years agoClean up more #include files. Create an internal __boolean_t so two or
Matthew Dillon [Sun, 21 May 2006 03:43:48 +0000 (03:43 +0000)]
Clean up more #include files.  Create an internal __boolean_t so two or
three sys/ header files don't have to juggle the type.  Use
_KERNEL_STRUCTURES in variuos pieces of user code that delve into kvm.

Reported-by: Rumko <rumcic@gmail.com>, walt <wa1ter@myrealbox.com>
17 years agoA little script that runs through all the header files and checks that
Matthew Dillon [Sun, 21 May 2006 00:27:59 +0000 (00:27 +0000)]
A little script that runs through all the header files and checks that
they can be singly included, or that they generate the appropriate
#error or #warning.  The following flags combinations are used:

_KERNEL kernel access
_KERNEL_STRUCTURES userland access to kernel structures
[none] userland access

17 years agoRemove the (unmaintained for 10+ years) svr4 and ibcs2 emulation code.
Matthew Dillon [Sat, 20 May 2006 18:26:36 +0000 (18:26 +0000)]
Remove the (unmaintained for 10+ years) svr4 and ibcs2 emulation code.
Poof, gone.

17 years agoRemove so_gencnt and so_gen_t. The generation counter is not used any more.
Matthew Dillon [Sat, 20 May 2006 17:41:42 +0000 (17:41 +0000)]
Remove so_gencnt and so_gen_t.  The generation counter is not used any more.

17 years agoFix a build issue with libnetgraph. net/bpf.h does not need to include
Matthew Dillon [Sat, 20 May 2006 16:48:51 +0000 (16:48 +0000)]
Fix a build issue with libnetgraph.  net/bpf.h does not need to include
sys/mbuf.h, not even for _KERNEL compiles.

Reported-by: Rumko <rumcic@gmail.com>
17 years ago- Add ral(4) for Ralink RT2500/RT2501/RT2600 chip based wireless NIC
Sepherosa Ziehau [Sat, 20 May 2006 09:13:09 +0000 (09:13 +0000)]
- Add ral(4) for Ralink RT2500/RT2501/RT2600 chip based wireless NIC
- Add ral(4) to GENERIC and LINT
- Add man page for ral(4)
Reviewed-by: swildner
Thank Damien Bergamini for his work on this driver

For RT2500:
- Fix a ieee80211_node leakage
- Due to the inter-dependency nature of DONE/(ENCRYPT|DECRYPT) intr, reap desc
  rings twice if one of them comes.  This change gives me ~17.6% TX performance
  boost on my ASUS WL-107G (WPA is used here):
  Original way of TX/RX intr processing
  ------------------------------------------------------------
  Client connecting to sephe-test, TCP port 5001
  TCP window size: 32.5 KByte (default)
  ------------------------------------------------------------
  [  3] local 192.168.2.14 port 1063 connected with 192.168.2.254 port 5001
  [  3]  0.0- 5.0 sec  10.2 MBytes  17.1 Mbits/sec
  [  3]  5.0-10.0 sec  9.95 MBytes  16.7 Mbits/sec
  [  3] 10.0-15.0 sec  9.67 MBytes  16.2 Mbits/sec
  [  3] 15.0-20.0 sec  10.1 MBytes  17.0 Mbits/sec
  [  3] 20.0-25.0 sec  10.2 MBytes  17.1 Mbits/sec
  [  3] 25.0-30.0 sec  10.0 MBytes  16.8 Mbits/sec
  [  3] 30.0-35.0 sec  9.91 MBytes  16.6 Mbits/sec
  [  3] 35.0-40.0 sec  10.3 MBytes  17.2 Mbits/sec
  [  3] 40.0-45.0 sec  9.87 MBytes  16.6 Mbits/sec
  [  3] 45.0-50.0 sec  9.94 MBytes  16.7 Mbits/sec
  [  3] 50.0-55.0 sec  10.2 MBytes  17.2 Mbits/sec
  [  3] 55.0-60.0 sec  9.73 MBytes  16.3 Mbits/sec
  [  3]  0.0-60.0 sec    120 MBytes  16.8 Mbits/sec

  Adapted way of TX/RX intr processing
  ------------------------------------------------------------
  Client connecting to sephe-test, TCP port 5001
  TCP window size: 32.5 KByte (default)
  ------------------------------------------------------------
  [  3] local 192.168.2.14 port 1062 connected with 192.168.2.254 port 5001
  [  3]  0.0- 5.0 sec  11.8 MBytes  19.8 Mbits/sec
  [  3]  5.0-10.0 sec  11.5 MBytes  19.4 Mbits/sec
  [  3] 10.0-15.0 sec  11.1 MBytes  18.7 Mbits/sec
  [  3] 15.0-20.0 sec  12.0 MBytes  20.1 Mbits/sec
  [  3] 20.0-25.0 sec  12.6 MBytes  21.2 Mbits/sec
  [  3] 25.0-30.0 sec  11.7 MBytes  19.6 Mbits/sec
  [  3] 30.0-35.0 sec  12.3 MBytes  20.7 Mbits/sec
  [  3] 35.0-40.0 sec  11.9 MBytes  19.9 Mbits/sec
  [  3] 40.0-45.0 sec  11.9 MBytes  19.9 Mbits/sec
  [  3] 45.0-50.0 sec  12.2 MBytes  20.4 Mbits/sec
  [  3] 50.0-55.0 sec  12.1 MBytes  20.2 Mbits/sec
  [  3] 55.0-60.0 sec  12.3 MBytes  20.7 Mbits/sec
  [  3]  0.0-60.0 sec    143 MBytes  20.0 Mbits/sec

Obtained-from: FreeBSD

17 years ago- Add ciphy for PHY modules produced by Cicada Semiconductor
Sepherosa Ziehau [Sat, 20 May 2006 07:15:17 +0000 (07:15 +0000)]
- Add ciphy for PHY modules produced by Cicada Semiconductor
- Add vge(4) for VIA VT612x GigE, which may have ciphy as its PHY module
- Add vge(4) into GENERIC and LINT
- Add man page for vge(4)

Thank Bill Paul for his work on this driver.
Thank Sascha Wildner for preparing the man page.

Obtained-from: FreeBSD
Tested-by: herrgard <herrgard@gmail.com>
NOTE:
Although polling(4) is claimed to be supported by this driver, but it does not
work that well with vge(4) (extremely slow, ~7000ms for ping, as reported by
herrgard).

17 years agoEmbed the netmsg in the mbuf itself rather than allocating one for
Matthew Dillon [Sat, 20 May 2006 06:32:41 +0000 (06:32 +0000)]
Embed the netmsg in the mbuf itself rather than allocating one for
each received packet.  This greatly reduces the overhead in the
network receive path (removing a malloc() and free()).

17 years agoregen
Sepherosa Ziehau [Sat, 20 May 2006 04:35:30 +0000 (04:35 +0000)]
regen

17 years agoAdd model id for Cicada Semiconductor PHY modules
Sepherosa Ziehau [Sat, 20 May 2006 04:27:16 +0000 (04:27 +0000)]
Add model id for Cicada Semiconductor PHY modules

17 years agoregen
Sepherosa Ziehau [Sat, 20 May 2006 03:28:07 +0000 (03:28 +0000)]
regen

17 years agoAdd VIA 612X GigE product id
Sepherosa Ziehau [Sat, 20 May 2006 03:24:53 +0000 (03:24 +0000)]
Add VIA 612X GigE product id

17 years agoI'm growing tired of having to add #include lines for header files that
Matthew Dillon [Sat, 20 May 2006 02:42:15 +0000 (02:42 +0000)]
I'm growing tired of having to add #include lines for header files that
the include file(s) I really want depend on.

Go through nearly all major system include files and add appropriately
#ifndef'd #include lines to include all dependant header files.  Kernel
source files now only need to #include the header files they directly
depend on.

So, for example, if I wanted to add a SYSCTL to a kernel source file,
I would only have to #include <sys/sysctl.h> to bring in the support for
it, rather then four or five header files in addition to <sys/sysctl.h>.

17 years agoRecent lwkt_token work broke UP builds. Fix the token code to operate
Matthew Dillon [Fri, 19 May 2006 18:26:29 +0000 (18:26 +0000)]
Recent lwkt_token work broke UP builds.  Fix the token code to operate
properly for both UP and SMP builds.  The SMP build uses spinlocks to
control access and also to do the preemption check.  The tokens are
explicitly obtained when a thread is switched in and released when a
thread is (non-preemptively) switched out.  Spinlocks cannot be
used for this purpose on UP because they are coded to a degenerate
case on a UP build.

On a UP build an explicit preemption check is needed, but no spinlock or
per-thread counter is required because the definition of a token is that
it is only 'held' while a thread is actually running or preempted.  So,
by definition, a token can always be obtained and held by a thread on UP
EXCEPT in the case where a preempting thread is trying to obtain a token
held by the preempted thread.

Conditionalize elements in the lwkt_token structure definition to guarentee
that SMP fields cannot be used in UP builds or vise-versa.  The lwkt_token
structure is made the same size for both builds.  Also remove some of
the degenerate spinlock functions (spin_trylock() and spin_tryunlock())
for UP builds to force a compile-time error if an attempt is made to use
them.  spin_lock*() and spin_unlock*() are retained as degenerate cases
on UP.

Reported-by: Sascha Wildner <saw@online.de>, walt <wa1ter@myrealbox.com>
17 years agoConvert most manual accesses to filedesc->fd_files[] into the appropriate
Matthew Dillon [Fri, 19 May 2006 07:33:46 +0000 (07:33 +0000)]
Convert most manual accesses to filedesc->fd_files[] into the appropriate
holdfp() call.  Fix a number of places where ops were being executed
on the file pointer without holding a private reference to it (mainly
fo_ioctl(), revoke(), and lseek()).

Create procedures in kern_descrip.c to set and clear descriptor flags
and to handle the bootstrap filedesc for proc0.  Replace manual code
elsewhere with calls to the new procedures.

Move getvnode() to kern_descrip.c.  Remove nsmb_getfp().  Use holdfp()
instead.

17 years agoConsolidate the file descriptor destruction code used when a newly created
Matthew Dillon [Fri, 19 May 2006 05:15:36 +0000 (05:15 +0000)]
Consolidate the file descriptor destruction code used when a newly created
file descriptor must be destroyed due to an error into a new procedure,
fdealloc(), rather then manually repeating it over and over again.

Move holdsock() and holdfp() into kern/kern_descrip.c.

17 years agoRemove the last vestiges of UF_MAPPED. All the removed code was already
Matthew Dillon [Thu, 18 May 2006 18:58:28 +0000 (18:58 +0000)]
Remove the last vestiges of UF_MAPPED.  All the removed code was already
commented out.

17 years agoMake spinlocks panic-friendly.
Matthew Dillon [Thu, 18 May 2006 17:53:45 +0000 (17:53 +0000)]
Make spinlocks panic-friendly.

* Add code to detect indefinite waits.  If a spinlock cannot be obtained
  after one second a warning is issued to the console.  After 10 seconds
  a DDB backtrace is output to the console.

* Count the number of contested events, short and long, via two sysctls:
  debug.spinlocks_contested1 and debug.spinlocks.contested2.

* Add a sysctl to test the indefinite wait code: sysctl debug.spin_lock_test=1.
  (only if INVARIANTS is turned on).

* If an indefinite wait occurs while the system is paniced, the spinlock
  code will hand the spinlock over to the requester after 1 second.  This
  should allow panics to proceed even if they occur at a bad point in the
  code.

* lwkt_switch normally panics if spinlocks are held by the current thread
  (and it tries to switch).  Do not panic if the system is already in a
  panic.  This should allow the system to restabilize itself due to the
  indefinite wait panic handling code, well enough to generate a dump
  or enter into DDB, anyhow.

17 years agoReplace the LWKT token code's passive management of token ownership with
Matthew Dillon [Thu, 18 May 2006 16:25:20 +0000 (16:25 +0000)]
Replace the LWKT token code's passive management of token ownership with
active management based on Jeff's spin locks (which themselves are an
adaptation of Sun spinlocks, I tihnk).

LWKT tokens still have the same behavior.  That is, even though tokens now
use a spinlock internally, they are still active only while the thread
is running (or preempted).  When a thread non-preemptively switches away
all held tokens are released as before and when a thread
switches back in all held tokens are reacquired.

Use spinlocks instead of tokens to manage access to LWKT RW lock structures.
Use spinlocks instead of tokens to manage LWKT wait lists.

Tokens are designed to fill a niche between spinlocks and lockmgr locks.
Spinlocks are only to be used for short bits of low level code.  Tokens
are designed to be used when broad serialization is desired but when the
caller may be making calls to procedures which might block.  Lockmgr locks
are designed to be used when strict serialization is desired even across
blocking conditions.

It should be noted that token overhead is only slightly greater than
core spinlock overhead.  The only real difference is due to the extra
structural management required to record the token in the thread structure
so it can be released and reacquired.  The overhead of saving and restoring
tokens in a thread switch is very rarely exercised (i.e. only when the
underlying code actually blocks while holding a token).

This patch reduces buildworld -j 8 times by about 5 seconds (1400->1395
seconds on my test box), about 0.3%, but is expected to have a more
pronounced effect as further MP work is accomplished.

17 years agoRemove old 802.11 sources code, they have been repo copied into
Sepherosa Ziehau [Thu, 18 May 2006 14:40:49 +0000 (14:40 +0000)]
Remove old 802.11 sources code, they have been repo copied into
sys/netproto/802_11/wlan/

17 years agoAdd man page for 802.11
Sepherosa Ziehau [Thu, 18 May 2006 14:34:31 +0000 (14:34 +0000)]
Add man page for 802.11

Obtained-from: FreeBSD
Reviewed-by: swildner
17 years ago- Describe new 802.11 options
Sepherosa Ziehau [Thu, 18 May 2006 14:24:34 +0000 (14:24 +0000)]
- Describe new 802.11 options
- Describe missing options for bridge(4)

Obtained-from: FreeBSD
Reviewed-by: swildner
17 years agoSync 802.11 support with FreeBSD6:
Sepherosa Ziehau [Thu, 18 May 2006 13:51:46 +0000 (13:51 +0000)]
Sync 802.11 support with FreeBSD6:
    "it includes completed 802.11g, WPA, 802.11i, 802.1x, WME/WMM, AP-side
     power-save, crypto plugin framework, authenticator plugin framework,
     and access control plugin frameowrk."

Reoriganize the layout of netproto/802_11: put generic 802.11 layer, crypto
modules, authentication module and access control module into their own
directories.  Header files are still in their original place.

Nuke all of the mutexing in generic 802.11, reorganize ieee80211_node table
scanning a little bit.

Rename FreeBSD's m_append() to ieee80211_mbuf_append(), rename FreeBSD's
m_unshare() to ieee80211_mbuf_clone() and put them into
netproto/802_11/wlan/ieee80211_dragonly.c
They are not generic enough for public using, at least for now.
Pointed-out-by: hsu
Expose ieee80211_add_{ssid, xrates, rates}() which are used by acx(4)

Keep using opencrypto's AES implmentation for 802.11 CCMP crypto module

Sync ifconfig(8)'s 802.11 support with FreeBSD6

Update acx(4) and ndis(4) for the new 802.11 support

Sync iwi(4), ipw(4), wi(4) and ray(4) with FreeBSD6

For iwi(4):
- Fix ieee80211_node leakage
- Use a bitmap instead of FreeBSD's "unit number alloctor" to allocate IBSS node

Add generic 802.11 layer and crypto modules into GENERIC and LINT,
authentication module and access module are only added to LINT

Unhook awi(4) from GENERIC and LINT temporarily, since as of this commit it
is broken :(  It will be fixed sometime later.

Thank Sam Leffler and many other people for their work on 802.11 support.

Thank Andrew Atrens and Adrian Michael Nida for submitting the patch.

Thank all the people that helped testing 802.11 patches for this commit

Based-on-Patch-Submitted-by:
  Andrew Atrens <atrens@nortelnetworks.com>
  Adrian Michael Nida <nida@musc.edu>

Tested-by:
  Thomas Schlesinger <schlesinger@netcologne.de>
  Johannes Hofmann <Johannes.Hofmann@gmx.de>
  Andrew Thompson <andrew@hijacked.us>
  Erik Wikström <erik-wikstrom@telia.com>

17 years agoFix static array overrun.
Sepherosa Ziehau [Thu, 18 May 2006 12:43:24 +0000 (12:43 +0000)]
Fix static array overrun.

Obtained-from: FreeBSD (Coverity ID: 916)

17 years agop_tracep -> p_tracenode, tracking changes made in recent commits.
Matthew Dillon [Thu, 18 May 2006 08:25:23 +0000 (08:25 +0000)]
p_tracep -> p_tracenode, tracking changes made in recent commits.

17 years agop_tracep -> p_tracenode, tracking changes made in recent commits.
Matthew Dillon [Thu, 18 May 2006 08:17:14 +0000 (08:17 +0000)]
p_tracep -> p_tracenode, tracking changes made in recent commits.

Reported-by: Rumko <rumcic@gmail.com>
17 years agoAdd another mutex tester for Jeff's spinlock code w/ the refcount
Matthew Dillon [Thu, 18 May 2006 02:22:46 +0000 (02:22 +0000)]
Add another mutex tester for Jeff's spinlock code w/ the refcount
optimization.

17 years agoOops, last commit was slightly premature. Fix a bug-a-boo and remove
Matthew Dillon [Wed, 17 May 2006 20:35:33 +0000 (20:35 +0000)]
Oops, last commit was slightly premature.  Fix a bug-a-boo and remove
debugging code.

17 years agoThe ktracing code was not properly matching up VOP_OPEN and VOP_CLOSE calls.
Matthew Dillon [Wed, 17 May 2006 20:20:55 +0000 (20:20 +0000)]
The ktracing code was not properly matching up VOP_OPEN and VOP_CLOSE calls.

Replace the p_tracep tracing vnode in struct proc with a pointer to
a ref-counted ktrace_node.  Ref the node instead of the vnode to prevent
the destruction of the vnode.

17 years agoUse localhost instead of 127.0.0.1, since IPv6 should work as well.
Joerg Sonnenberger [Wed, 17 May 2006 19:22:32 +0000 (19:22 +0000)]
Use localhost instead of 127.0.0.1, since IPv6 should work as well.

17 years agoPass the process (p) instead of the vnode (p->p_tracep) to the kernel tracing
Matthew Dillon [Wed, 17 May 2006 18:30:22 +0000 (18:30 +0000)]
Pass the process (p) instead of the vnode (p->p_tracep) to the kernel tracing
API functions.  This allows the vnode ref to be consolidated into one place.

17 years agoRemove the (unused) copy-on-write support for a vnode's VM object. This
Matthew Dillon [Wed, 17 May 2006 17:47:58 +0000 (17:47 +0000)]
Remove the (unused) copy-on-write support for a vnode's VM object.  This
support originally existed to support the badly implemented and severely
hacked ENABLE_VFS_IOOPT I/O optimization which was removed long ago.

This also removes a bunch of cross-module pollution in UFS.

17 years agoDocument MAKEOBJDIRPREFIX.
Sascha Wildner [Wed, 17 May 2006 14:41:48 +0000 (14:41 +0000)]
Document MAKEOBJDIRPREFIX.

Submitted-by: Trevor Kendall <trevorjk@gmail.com>
17 years agoPer default, restrict recursive queries to 127.0.0.1.
Sascha Wildner [Wed, 17 May 2006 14:25:47 +0000 (14:25 +0000)]
Per default, restrict recursive queries to 127.0.0.1.

Submitted-by: Gary <gary@velocity-servers.net>
OK-by: corecode, joerg
17 years agoRemove isinff and isnanf prototypes. Our isinf and isnan functions are
Sascha Wildner [Wed, 17 May 2006 14:06:37 +0000 (14:06 +0000)]
Remove isinff and isnanf prototypes. Our isinf and isnan functions are
type-variadic. Also remove the isinff(3) manpage I added yesterday
(I had just looked at the prototypes).

Pointed-out-by: joerg
17 years agoAdd isinff(3) manpage.
Sascha Wildner [Wed, 17 May 2006 01:44:24 +0000 (01:44 +0000)]
Add isinff(3) manpage.

17 years agoAttempt to interlock races between the buffer cache and VM backing store
Matthew Dillon [Tue, 16 May 2006 18:20:32 +0000 (18:20 +0000)]
Attempt to interlock races between the buffer cache and VM backing store
that might cause new buffers to be instantiated beyond the new file EOF
during a truncate operation.

Truncate the VM object size before attempting to flush the pages and buffers
in order to prevent new VM pages from being created beyond EOF during the
flush.  Add an extra pass on the buffer cache after truncation to make sure
the buffers have been cleaned out.  Generate a warning to the console if
buffers are found during the extra pass.

If an old buffer were left intact during a truncate, then a re-extension of
the file or directory could have resulted in granting access to the old
buffer which might have had an incorrect cached block number translation
(vs the new block allocated by the extension of the file or directory),
causing new data to be written to the wrong disk block and resulting in
file or directory corruption.  The regular file truncation/extension
code had other checks in it prior to this patch so if this problem could
occur at all before it would have been in the directory code.

There is a small chance that this race was related to reported
ufs: dirbad panics.  The M.O. matches but unfortunately there is still
no smoking gun.

17 years agoRemove vnode lock assertions that are no longer used. Remove the
Matthew Dillon [Tue, 16 May 2006 18:09:20 +0000 (18:09 +0000)]
Remove vnode lock assertions that are no longer used.  Remove the
IS_LOCKING_VFS() macro.  All VFS's are required to be locking VFSs now.

17 years agoEnable TCP wrappers in sshd.
Simon Schubert [Tue, 16 May 2006 16:26:08 +0000 (16:26 +0000)]
Enable TCP wrappers in sshd.

Reported-by: Yiorgos Adamopoulos <adamo@central.tee.gr>
17 years agoAdd a commant, which warns atomic_cmpset_int() is a !I386_CPU function
Sepherosa Ziehau [Tue, 16 May 2006 14:24:06 +0000 (14:24 +0000)]
Add a commant, which warns atomic_cmpset_int() is a !I386_CPU function

Suggested-by: joerg
17 years agoPut atomic_cmpset_int() into central place. This function was defined and
Sepherosa Ziehau [Tue, 16 May 2006 12:34:15 +0000 (12:34 +0000)]
Put atomic_cmpset_int() into central place.  This function was defined and
used in many places.

Reviewed-by: dillon
OK: davidxu