Skip site navigation (1)Skip section navigation (2)

CVS log for src/sys/kern/subr_turnstile.c

[BACK] Up to [FreeBSD] / src / sys / kern

Request diff between arbitrary revisions


Keyword substitution: kv
Default branch: MAIN


Revision 1.178.2.1.2.1: download - view: text, markup, annotated - select for diffs
Fri Nov 11 04:20:22 2011 UTC (2 months, 4 weeks ago) by kensmith
Branches: RELENG_9_0
CVS tags: RELENG_9_0_0_RELEASE
Diff to: previous 1.178.2.1: preferred, colored; next MAIN 1.179: preferred, colored
Changes since revision 1.178.2.1: +0 -0 lines
SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)

Revision 1.179: download - view: text, markup, annotated - select for diffs
Mon Nov 7 15:43:11 2011 UTC (3 months ago) by ed
Branches: MAIN
CVS tags: HEAD
Diff to: previous 1.178: preferred, colored
Changes since revision 1.178: +3 -2 lines
SVN rev 227309 on 2011-11-07 15:43:11Z by ed

Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.

The SYSCTL_NODE macro defines a list that stores all child-elements of
that node. If there's no SYSCTL_DECL macro anywhere else, there's no
reason why it shouldn't be static.

Revision 1.178.2.1: download - view: text, markup, annotated - select for diffs
Fri Sep 23 00:51:37 2011 UTC (4 months, 2 weeks ago) by kensmith
Branches: RELENG_9
CVS tags: RELENG_9_0_BP
Branch point for: RELENG_9_0
Diff to: previous 1.178: preferred, colored; next MAIN 1.179: preferred, colored
Changes since revision 1.178: +0 -0 lines
SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)

Revision 1.175.2.3: download - view: text, markup, annotated - select for diffs
Thu Mar 3 17:04:57 2011 UTC (11 months, 1 week ago) by jhb
Branches: RELENG_8
Diff to: previous 1.175.2.2: preferred, colored; branchpoint 1.175: preferred, colored; next MAIN 1.176: preferred, colored
Changes since revision 1.175.2.2: +1 -2 lines
SVN rev 219234 on 2011-03-03 17:04:57Z by jhb

MFC 200761,218272:
Always assert that the turnstile chain lock is held in turnstile_wait()
and remove a duplicate hash lookup.

Revision 1.169.2.2: download - view: text, markup, annotated - select for diffs
Thu Mar 3 17:04:45 2011 UTC (11 months, 1 week ago) by jhb
Branches: RELENG_7
Diff to: previous 1.169.2.1: preferred, colored; branchpoint 1.169: preferred, colored; next MAIN 1.170: preferred, colored
Changes since revision 1.169.2.1: +1 -2 lines
SVN rev 219233 on 2011-03-03 17:04:45Z by jhb

MFC 200761,218272:
Always assert that the turnstile chain lock is held in turnstile_wait()
and remove a duplicate hash lookup.

Revision 1.178: download - view: text, markup, annotated - select for diffs
Fri Feb 4 14:16:41 2011 UTC (12 months ago) by jhb
Branches: MAIN
CVS tags: RELENG_9_BP
Branch point for: RELENG_9
Diff to: previous 1.177: preferred, colored
Changes since revision 1.177: +1 -2 lines
SVN rev 218272 on 2011-02-04 14:16:41Z by jhb

Always assert that the turnstile chain lock is held in turnstile_wait()
and remove a duplicate hash lookup.

MFC after:	1 week

Revision 1.169.2.1.8.1: download - view: text, markup, annotated - select for diffs
Tue Dec 21 17:10:29 2010 UTC (13 months, 2 weeks ago) by kensmith
Branches: RELENG_7_4
CVS tags: RELENG_7_4_0_RELEASE
Diff to: previous 1.169.2.1: preferred, colored; next MAIN 1.169.2.2: preferred, colored
Changes since revision 1.169.2.1: +0 -0 lines
SVN rev 216618 on 2010-12-21 17:10:29Z by kensmith

Copy stable/7 to releng/7.4 in preparation for FreeBSD-7.4 release.

Approved by:	re (implicit)

Revision 1.175.2.2.4.1: download - view: text, markup, annotated - select for diffs
Tue Dec 21 17:09:25 2010 UTC (13 months, 2 weeks ago) by kensmith
Branches: RELENG_8_2
CVS tags: RELENG_8_2_0_RELEASE
Diff to: previous 1.175.2.2: preferred, colored; next MAIN 1.175.2.3: preferred, colored
Changes since revision 1.175.2.2: +0 -0 lines
SVN rev 216617 on 2010-12-21 17:09:25Z by kensmith

Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.

Approved by:	re (implicit)

Revision 1.175.2.2.2.1: download - view: text, markup, annotated - select for diffs
Mon Jun 14 02:09:06 2010 UTC (19 months, 3 weeks ago) by kensmith
Branches: RELENG_8_1
CVS tags: RELENG_8_1_0_RELEASE
Diff to: previous 1.175.2.2: preferred, colored; next MAIN 1.175.2.3: preferred, colored
Changes since revision 1.175.2.2: +0 -0 lines
SVN rev 209145 on 2010-06-14 02:09:06Z by kensmith

Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.

Approved by:	re (implicit)

Revision 1.169.2.1.6.1: download - view: text, markup, annotated - select for diffs
Wed Feb 10 00:26:20 2010 UTC (23 months, 4 weeks ago) by kensmith
Branches: RELENG_7_3
CVS tags: RELENG_7_3_0_RELEASE
Diff to: previous 1.169.2.1: preferred, colored; next MAIN 1.169.2.2: preferred, colored
Changes since revision 1.169.2.1: +0 -0 lines
SVN rev 203736 on 2010-02-10 00:26:20Z by kensmith

Copy stable/7 to releng/7.3 as part of the 7.3-RELEASE process.

Approved by:	re (implicit)

Revision 1.175.2.2: download - view: text, markup, annotated - select for diffs
Mon Jan 25 12:05:51 2010 UTC (2 years ago) by attilio
Branches: RELENG_8
CVS tags: RELENG_8_2_BP, RELENG_8_1_BP
Branch point for: RELENG_8_2, RELENG_8_1
Diff to: previous 1.175.2.1: preferred, colored; branchpoint 1.175: preferred, colored
Changes since revision 1.175.2.1: +2 -0 lines
SVN rev 202966 on 2010-01-25 12:05:51Z by attilio

MFC r201879:
Introduce the new kernel thread called "deadlock resolver".
It is used in order to seek within the threads state and heuristically
understand if there is any deadlock happening.

In order to implement it, the sq_type in sleepqueues is mandatory and not
only compiled along with INVARIANTS option. Additively, a new sleepqueue
function, sleepq_type() is added, returning the type of the sleepqueue
linked to a wchan.
Three new sysctls are added in order to configure the thread:
debug.deadlkres.slptime_threshold
debug.deadlkres.blktime_threshold
debug.deadlkres.sleepfreq

rappresenting the thresholds for sleep and block time that will lead to
a deadlock matching (when exceeded), while the sleepfreq rappresents the
number of seconds between 2 consecutive thread runnings.
In order to enable the deadlock resolver thread recompile your kernel
with the option DEADLKRES.

Sponsored by:	Sandvine Incorporated

Revision 1.177: download - view: text, markup, annotated - select for diffs
Sat Jan 9 01:46:38 2010 UTC (2 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.176: preferred, colored
Changes since revision 1.176: +2 -0 lines
SVN rev 201879 on 2010-01-09 01:46:38Z by attilio

Introduce the new kernel thread called "deadlock resolver".
While the name is pretentious, a good explanation of its targets is
reported in this 17 months old presentation e-mail:
http://lists.freebsd.org/pipermail/freebsd-arch/2008-August/008452.html

In order to implement it, the sq_type in sleepqueues is mandatory and not
only compiled along with INVARIANTS option. Additively, a new sleepqueue
function, sleepq_type() is added, returning the type of the sleepqueue
linked to a wchan.
Three new sysctls are added in order to configure the thread:
debug.deadlkres.slptime_threshold
debug.deadlkres.blktime_threshold
debug.deadlkres.sleepfreq

rappresenting the thresholds for sleep and block time that will lead to
a deadlock matching (when exceeded), while the sleepfreq rappresents the
number of seconds between 2 consecutive thread runnings.
In order to enable the deadlock resolver thread recompile your kernel
with the option DEADLKRES.

Reviewed by:	jeff
Tested by:	pho, Giovanni Trematerra
Sponsored by:	Nokia Incorporated, Sandvine Incorporated
MFC after:	2 weeks

Revision 1.176: download - view: text, markup, annotated - select for diffs
Sun Dec 20 22:55:27 2009 UTC (2 years, 1 month ago) by ed
Branches: MAIN
Diff to: previous 1.175: preferred, colored
Changes since revision 1.175: +1 -1 lines
SVN rev 200761 on 2009-12-20 22:55:27Z by ed

Fix indentation.

Revision 1.175.2.1.2.1: download - view: text, markup, annotated - select for diffs
Sun Oct 25 01:10:29 2009 UTC (2 years, 3 months ago) by kensmith
Branches: RELENG_8_0
CVS tags: RELENG_8_0_0_RELEASE
Diff to: previous 1.175.2.1: preferred, colored; next MAIN 1.175.2.2: preferred, colored
Changes since revision 1.175.2.1: +0 -0 lines
SVN rev 198460 on 2009-10-25 01:10:29Z by kensmith

Copy stable/8 to releng/8.0 as part of 8.0-RELEASE release procedure.

Approved by:	re (implicit)

Revision 1.175.2.1: download - view: text, markup, annotated - select for diffs
Mon Aug 3 08:13:06 2009 UTC (2 years, 6 months ago) by kensmith
Branches: RELENG_8
CVS tags: RELENG_8_0_BP
Branch point for: RELENG_8_0
Diff to: previous 1.175: preferred, colored
Changes since revision 1.175: +0 -0 lines
SVN rev 196045 on 2009-08-03 08:13:06Z by kensmith

Copy head to stable/8 as part of 8.0 Release cycle.

Approved by:	re (Implicit)

Revision 1.169.2.1.4.1: download - view: text, markup, annotated - select for diffs
Wed Apr 15 03:14:26 2009 UTC (2 years, 9 months ago) by kensmith
Branches: RELENG_7_2
CVS tags: RELENG_7_2_0_RELEASE
Diff to: previous 1.169.2.1: preferred, colored; next MAIN 1.169.2.2: preferred, colored
Changes since revision 1.169.2.1: +0 -0 lines
SVN rev 191087 on 2009-04-15 03:14:26Z by kensmith

Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.

Approved by:	re (implicit)

Revision 1.169.2.1.2.1: download - view: text, markup, annotated - select for diffs
Tue Nov 25 02:59:29 2008 UTC (3 years, 2 months ago) by kensmith
Branches: RELENG_7_1
CVS tags: RELENG_7_1_0_RELEASE
Diff to: previous 1.169.2.1: preferred, colored; next MAIN 1.169.2.2: preferred, colored
Changes since revision 1.169.2.1: +0 -0 lines
SVN rev 185281 on 2008-11-25 02:59:29Z by kensmith

Create releng/7.1 in preparation for moving into RC phase of 7.1 release
cycle.

Approved by:	re (implicit)

Revision 1.152.2.11.4.1: download - view: text, markup, annotated - select for diffs
Thu Oct 2 02:57:24 2008 UTC (3 years, 4 months ago) by kensmith
Branches: RELENG_6_4
CVS tags: RELENG_6_4_0_RELEASE
Diff to: previous 1.152.2.11: preferred, colored; next MAIN 1.153: preferred, colored
Changes since revision 1.152.2.11: +0 -0 lines
SVN rev 183531 on 2008-10-02 02:57:24Z by kensmith

Create releng/6.4 from stable/6 in preparation for 6.4-RC1.

Approved by:	re (implicit)

Revision 1.169.2.1: download - view: text, markup, annotated - select for diffs
Tue Sep 16 20:04:37 2008 UTC (3 years, 4 months ago) by jhb
Branches: RELENG_7
CVS tags: RELENG_7_4_BP, RELENG_7_3_BP, RELENG_7_2_BP, RELENG_7_1_BP
Branch point for: RELENG_7_4, RELENG_7_3, RELENG_7_2, RELENG_7_1
Diff to: previous 1.169: preferred, colored
Changes since revision 1.169: +4 -3 lines
SVN rev 183098 on 2008-09-16 20:04:37Z by jhb

MFC: Set UMA_ZONE_NOFREE for turnstiles so that the per-turnstile spin
locks are type stable.

Approved by:	re (kib)

Revision 1.175: download - view: text, markup, annotated - select for diffs
Mon Sep 15 22:45:14 2008 UTC (3 years, 4 months ago) by sam
Branches: MAIN
CVS tags: RELENG_8_BP
Branch point for: RELENG_8
Diff to: previous 1.174: preferred, colored
Changes since revision 1.174: +2 -1 lines
SVN rev 183054 on 2008-09-15 22:45:14Z by sam

Make ddb command registration dynamic so modules can extend
the command set (only so long as the module is present):
o add db_command_register and db_command_unregister to add and remove
  commands, respectively
o replace linker sets with SYSINIT's (and SYSUINIT's) that register
  commands
o expose 3 list heads: db_cmd_table, db_show_table, and db_show_all_table
  for registering top-level commands, show operands, and show all operands,
  respectively

While here also:
o sort command lists
o add DB_ALIAS, DB_SHOW_ALIAS, and DB_SHOW_ALL_ALIAS to add aliases
  for existing commands
o add "show all trace" as an alias for "show alltrace"
o add "show all locks" as an alias for "show alllocks"

Submitted by:	Guillaume Ballet <gballet@gmail.com> (original version)
Reviewed by:	jhb
MFC after:	1 month

Revision 1.174: download - view: text, markup, annotated - select for diffs
Mon Sep 8 21:40:15 2008 UTC (3 years, 5 months ago) by jhb
Branches: MAIN
Diff to: previous 1.173: preferred, colored
Changes since revision 1.173: +4 -3 lines
SVN rev 182879 on 2008-09-08 21:40:15Z by jhb

- Reduce scope of #ifdef's in uma_zcreate() call in init_turnstile0().
- Set UMA_ZONE_NOFREE so that the per-turnstile spin locks are type stable
  to avoid a race where one thread might dereference a lock in a free'd
  turnstile that was previously used by another thread.

Theorized by:	tegge (2)
MFC after:	1 week

Revision 1.173: download - view: text, markup, annotated - select for diffs
Thu Apr 17 04:20:10 2008 UTC (3 years, 9 months ago) by jeff
Branches: MAIN
Diff to: previous 1.172: preferred, colored
Changes since revision 1.172: +1 -2 lines
 - Make SCHED_STATS more generic by adding a wrapper to create the
   variables and sysctl nodes.
 - In reset walk the children of kern_sched_stats and reset the counters
   via the oid_arg1 pointer.  This allows us to add arbitrary counters to
   the tree and still reset them properly.
 - Define a set of switch types to be passed with flags to mi_switch().
   These types are named SWT_*.  These types correspond to SCHED_STATS
   counters and are automatically handled in this way.
 - Make the new SWT_ types more specific than the older switch stats.
   There are now stats for idle switches, remote idle wakeups, remote
   preemption ithreads idling, etc.
 - Add switch statistics for ULE's pickcpu algorithm.  These stats include
   how much migration there is, how often affinity was successful, how
   often threads were migrated to the local cpu on wakeup, etc.

Sponsored by:	Nokia

Revision 1.172: download - view: text, markup, annotated - select for diffs
Thu Feb 7 06:55:38 2008 UTC (4 years ago) by jeff
Branches: MAIN
Diff to: previous 1.171: preferred, colored
Changes since revision 1.171: +7 -7 lines
 - Add THREAD_LOCKPTR_ASSERT() to assert that the thread's lock points at
   the provided lock or &blocked_lock.  The thread may be temporarily
   assigned to the blocked_lock by the scheduler so a direct comparison
   can not always be made.
 - Use THREAD_LOCKPTR_ASSERT() in the primary consumers of the scheduling
   interfaces.  The schedulers themselves still use more explicit asserts.

Sponsored by:	Nokia

Revision 1.171: download - view: text, markup, annotated - select for diffs
Wed Feb 6 01:02:13 2008 UTC (4 years ago) by jeff
Branches: MAIN
Diff to: previous 1.170: preferred, colored
Changes since revision 1.170: +3 -8 lines
Adaptive spinning in write path with readers and writer starvation avoidance.
 - Move recursion checking into rwlock inlines to free a bit for use with
   adaptive spinners.
 - Clear the RW_LOCK_WRITE_SPINNERS flag whenever the lock state changes
   causing write spinners to restart their loop.
 - Write spinners are limited by a count while readers hold the lock as
   there is no way to know for certain whether readers are running still.
 - In the read path block if there are write waiters or spinners to avoid
   starving writers.  Use a new per-thread count, td_rw_rlocks, to skip
   starvation avoidance if it might cause a deadlock.
 - Remove or change invalid assertions in turnstiles.

Reviewed by:    attilio (developed parts of the patch as well)
Sponsored by:   Nokia

Revision 1.170: download - view: text, markup, annotated - select for diffs
Wed Nov 14 06:21:23 2007 UTC (4 years, 2 months ago) by julian
Branches: MAIN
Diff to: previous 1.169: preferred, colored
Changes since revision 1.169: +4 -4 lines
generally we are interested in what thread did something as
opposed to what process. Since threads by default have teh name of the
process unless over-written with more useful information, just print the
thread name instead.

Revision 1.152.2.11: download - view: text, markup, annotated - select for diffs
Thu Sep 27 20:24:55 2007 UTC (4 years, 4 months ago) by jhb
Branches: RELENG_6
CVS tags: RELENG_6_4_BP, RELENG_6_3_BP, RELENG_6_3_0_RELEASE, RELENG_6_3
Branch point for: RELENG_6_4
Diff to: previous 1.152.2.10: preferred, colored; branchpoint 1.152: preferred, colored; next MAIN 1.153: preferred, colored
Changes since revision 1.152.2.10: +6 -6 lines
Remove the *_queue() variants of various sleepq and turnstile functions
and always require the queue to be specified to reduce diffs with HEAD.
These APIs are internal APIs only used to implement higher level primitives
such as locks and condition variables.

Approved by:	alfred

Revision 1.152.2.10: download - view: text, markup, annotated - select for diffs
Thu Sep 27 18:44:16 2007 UTC (4 years, 4 months ago) by jhb
Branches: RELENG_6
Diff to: previous 1.152.2.9: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.9: +40 -38 lines
MFC some comment updates to account for multi-queue support missed earlier
as well as a few other changes (whitespace, style, etc.) to reduce diffs
with HEAD.

Revision 1.152.2.9: download - view: text, markup, annotated - select for diffs
Thu Sep 27 18:39:18 2007 UTC (4 years, 4 months ago) by jhb
Branches: RELENG_6
Diff to: previous 1.152.2.8: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.8: +14 -17 lines
- Remove some debugging nits in the MFC of rwlocks that looked for cases
  where a reader blocked on a lock with no owner and just assert that it
  never happens like HEAD.
- Actually set td->td_tsqueue to the sub-queue of a turnstile that a
  thread is actually enqueued to.  Otherwise, the kernel would always
  think that threads were on the queue for exclusive (write) waiters
  (queue 0).  Thus, if the priority of a thread waiting on a read lock
  was adjusted while it was waiting it could result in corrupting the
  queue of waiting threads.

Revision 1.152.2.8: download - view: text, markup, annotated - select for diffs
Thu Sep 27 18:23:44 2007 UTC (4 years, 4 months ago) by jhb
Branches: RELENG_6
Diff to: previous 1.152.2.7: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.7: +54 -20 lines
MFC 1.167: Use a UMA zone to handle the turnstile objects rather than
malloc(9).

Revision 1.152.2.7: download - view: text, markup, annotated - select for diffs
Wed Sep 5 17:38:28 2007 UTC (4 years, 5 months ago) by alfred
Branches: RELENG_6
Diff to: previous 1.152.2.6: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.6: +6 -2 lines
Unbreak "options DDB" breakage from previous commit.

Revision 1.152.2.6: download - view: text, markup, annotated - select for diffs
Tue Sep 4 22:40:39 2007 UTC (4 years, 5 months ago) by alfred
Branches: RELENG_6
Diff to: previous 1.152.2.5: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.5: +134 -33 lines
Backport of optimized sx locks and rwlocks from FreeBSD 7.0.

Reviewed by: attilio, jhb
Obtained from: Juniper Networks

Revision 1.169: download - view: text, markup, annotated - select for diffs
Tue Jun 12 23:27:31 2007 UTC (4 years, 7 months ago) by jeff
Branches: MAIN
CVS tags: RELENG_7_BP, RELENG_7_0_BP, RELENG_7_0_0_RELEASE, RELENG_7_0
Branch point for: RELENG_7
Diff to: previous 1.168: preferred, colored
Changes since revision 1.168: +1 -0 lines
 - Include opt_sched.h for SCHED_STATS.

Revision 1.168: download - view: text, markup, annotated - select for diffs
Mon Jun 4 23:51:43 2007 UTC (4 years, 8 months ago) by jeff
Branches: MAIN
Diff to: previous 1.167: preferred, colored
Changes since revision 1.167: +149 -135 lines
Commit 3/14 of sched_lock decomposition.
 - Add a per-turnstile spinlock to solve potential priority propagation
   deadlocks that are possible with thread_lock().
 - The turnstile lock order is defined as the exact opposite of the
   lock order used with the sleep locks they represent.  This allows us
   to walk in reverse order in priority_propagate and this is the only
   place we wish to multiply acquire turnstile locks.
 - Use the turnstile_chain lock to protect assigning mutexes to turnstiles.
 - Change the turnstile interface to pass back turnstile pointers to the
   consumers.  This allows us to reduce some locking and makes it easier
   to cancel turnstile assignment while the turnstile chain lock is held.

Tested by:      kris, current@
Tested on:      i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)

Revision 1.167: download - view: text, markup, annotated - select for diffs
Fri May 18 06:32:24 2007 UTC (4 years, 8 months ago) by jeff
Branches: MAIN
Diff to: previous 1.166: preferred, colored
Changes since revision 1.166: +54 -21 lines
 - Convert turnstiles and sleepqueus to use UMA.  This provides a modest
   speedup and will be more useful after each gains a spinlock in the
   impending thread_lock() commit.
 - Move initialization and asserts into init/fini routines.  fini routines
   are only needed in the INVARIANTS case for now.

Submitted by:	Attilio Rao <attilio@FreeBSD.org>
Tested by:	kris, jeff

Revision 1.152.2.5: download - view: text, markup, annotated - select for diffs
Tue Jan 23 22:16:33 2007 UTC (5 years ago) by jhb
Branches: RELENG_6
Diff to: previous 1.152.2.4: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.4: +4 -0 lines
MFC: Wrap propagate_priority() in a critical section to prevent unwanted
preemptions.

Revision 1.166: download - view: text, markup, annotated - select for diffs
Tue Jan 23 08:46:50 2007 UTC (5 years ago) by jeff
Branches: MAIN
Diff to: previous 1.165: preferred, colored
Changes since revision 1.165: +1 -1 lines
 - Remove setrunqueue and replace it with direct calls to sched_add().
   setrunqueue() was mostly empty.  The few asserts and thread state
   setting were moved to the individual schedulers.  sched_add() was
   chosen to displace it for naming consistency reasons.
 - Remove adjustrunqueue, it was 4 lines of code that was ifdef'd to be
   different on all three schedulers where it was only called in one place
   each.
 - Remove the long ifdef'd out remrunqueue code.
 - Remove the now redundant ts_state.  Inspect the thread state directly.
 - Don't set TSF_* flags from kern_switch.c, we were only doing this to
   support a feature in one scheduler.
 - Change sched_choose() to return a thread rather than a td_sched.  Also,
   rely on the schedulers to return the idlethread.  This simplifies the
   logic in choosethread().  Aside from the run queue links kern_switch.c
   mostly does not care about the contents of td_sched.

Discussed with:	julian

 - Move the idle thread loop into the per scheduler area.  ULE wants to
   do something different from the other schedulers.

Suggested by:	jhb

Tested on:	x86/amd64 sched_{4BSD, ULE, CORE}.

Revision 1.165: download - view: text, markup, annotated - select for diffs
Wed Jan 17 14:58:53 2007 UTC (5 years ago) by delphij
Branches: MAIN
Diff to: previous 1.164: preferred, colored
Changes since revision 1.164: +1 -1 lines
Use FOREACH_PROC_IN_SYSTEM instead of using its unrolled form.

Revision 1.164: download - view: text, markup, annotated - select for diffs
Thu Jan 11 19:13:27 2007 UTC (5 years ago) by jhb
Branches: MAIN
Diff to: previous 1.163: preferred, colored
Changes since revision 1.163: +4 -0 lines
Wrap propagate_priority() in a critical section to prevent unwanted
preemptions when adjusting the priority of a thread that is on a run
queue.  This was only observed when FULL_PREEMPTION was enabled.

Reported by:	kris
Diagnosed by:	ups
MFC after:	1 week

Revision 1.152.2.4: download - view: text, markup, annotated - select for diffs
Thu Aug 17 19:53:06 2006 UTC (5 years, 5 months ago) by jhb
Branches: RELENG_6
CVS tags: RELENG_6_2_BP, RELENG_6_2_0_RELEASE, RELENG_6_2
Diff to: previous 1.152.2.3: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.3: +300 -2 lines
MFC several DDB improvements including the simpler 'ps', 'show proc',
'show thread' (currently doesn't work due to a ddb bug that in 6.x
that causes 'show thread' to be treated as 'show threads'), 'show lockmgr',
'show sleepchain', 'show lockchain', 'show allchains', 'show locktree',
'show sleepq', and 'show turnstile'.

Revision 1.163: download - view: text, markup, annotated - select for diffs
Tue Aug 15 18:29:01 2006 UTC (5 years, 5 months ago) by jhb
Branches: MAIN
Diff to: previous 1.162: preferred, colored
Changes since revision 1.162: +67 -0 lines
Add a new 'show sleepchain' ddb command similar to 'show lockchain' except
that it operates on lockmgr and sx locks.  This can be useful for tracking
down vnode deadlocks in VFS for example.  Note that this command is a bit
more fragile than 'show lockchain' as we have to poke around at the
wait channel of a thread to see if it points to either a struct lock or
a condition variable inside of a struct sx.  If td_wchan points to
something unmapped, then this command will terminate early due to a fault,
but no harm will be done.

Revision 1.162: download - view: text, markup, annotated - select for diffs
Tue Aug 15 16:44:18 2006 UTC (5 years, 5 months ago) by jhb
Branches: MAIN
Diff to: previous 1.161: preferred, colored
Changes since revision 1.161: +9 -5 lines
Rename 'show lockchain' to 'show locktree' and 'show threadchain' to
'show lockchain'.  The churn is because I'm about to add a new
'show sleepchain' similar to 'show lockchain' for sleep locks (lockmgr and
sx) and 'show threadchain' was a bit ambiguous as both commands show
a chain of thread dependencies, 'lockchain' is for non-sleepable locks
(mtx and rw) and 'sleepchain' is for sleepable locks.

Revision 1.152.2.3: download - view: text, markup, annotated - select for diffs
Tue Aug 1 17:40:13 2006 UTC (5 years, 6 months ago) by jhb
Branches: RELENG_6
Diff to: previous 1.152.2.2: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.2: +1 -0 lines
MFC: Sync up with HEAD in some of the locking primitive details:
- Teach WITNESS_SAVE() and WITNESS_RESTORE() to work with spin locks instead
  of only sleep locks.
- Do the extra step required when destroying a locked spin mutex.
- Initialize thread0.td_contested in init_turnstiles() rather than
  mutex_init().
- Add LOCK_CLASS() macro and sync with HEAD on its usage.  For RELENG_6
  this just maps to lock->lo_class.  (In HEAD lo_class was removed an array
  index was encoded into lo_flags instead.)
- Add subr_lock.c including adding lock_init() and lock_destroy() functions
  as we as moving the 'show lock' command into this file from kern_mutex.c.

Revision 1.161: download - view: text, markup, annotated - select for diffs
Wed Jul 12 21:25:24 2006 UTC (5 years, 6 months ago) by jhb
Branches: MAIN
Diff to: previous 1.160: preferred, colored
Changes since revision 1.160: +7 -1 lines
Honor db_pager_quit in 'show threadchain', 'show allchains', and
'show lockchain'.  This is especially helpful for the first 2 as a
threadchain could get stuck in an infinite loop during a mutex deadlock.

Revision 1.160: download - view: text, markup, annotated - select for diffs
Tue Apr 25 20:28:17 2006 UTC (5 years, 9 months ago) by jhb
Branches: MAIN
Diff to: previous 1.159: preferred, colored
Changes since revision 1.159: +138 -0 lines
Add some new commands to hopefully make it easier to diagnose lock-related
problems in ddb:
- "show threadchain [thread]" will start with the specified thread (or the
  current kdb thread by default) and show it's state.  If it is blocked on
  a lock, it will find the owner of the lock and show its state, etc.
- "show allchains" will find all of the threads that are blocked on a
  lock (but do not have any threads blocked on a lock they hold) and show
  the resulting thread chain.
- "show lockchain <lock>" takes a pointer to a lock_object (such as a
  mutex or rwlock).  If there is a turnstile for that lock, then it will
  display all the threads blocked on the lock.  In addition, for each
  thread blocked on the lock, it will display any contested locks they
  hold, and recurse on those locks to show any threads blocked on those
  locks, etc.

Revision 1.159: download - view: text, markup, annotated - select for diffs
Fri Apr 21 20:40:43 2006 UTC (5 years, 9 months ago) by jhb
Branches: MAIN
Diff to: previous 1.158: preferred, colored
Changes since revision 1.158: +2 -1 lines
Print td_name instead of p_comm if td_name is non-empty for
'show turnstile' and 'show sleepq'.

Revision 1.158: download - view: text, markup, annotated - select for diffs
Tue Apr 18 18:16:53 2006 UTC (5 years, 9 months ago) by jhb
Branches: MAIN
Diff to: previous 1.157: preferred, colored
Changes since revision 1.157: +67 -0 lines
- Bring back turnstile_empty() which can check to see if an individual
  queue on a turnstile is empty.
- Add a turnstile_disown() function that allows a thread to give up
  ownership of a turnstile w/o waking up any waiters.

Revision 1.152.2.2: download - view: text, markup, annotated - select for diffs
Wed Apr 5 21:15:19 2006 UTC (5 years, 10 months ago) by jhb
Branches: RELENG_6
CVS tags: RELENG_6_1_BP, RELENG_6_1_0_RELEASE, RELENG_6_1
Diff to: previous 1.152.2.1: preferred, colored; branchpoint 1.152: preferred, colored
Changes since revision 1.152.2.1: +14 -8 lines
MFC: Always explicitly panic in propogate_priority() if we try to propogate
a lock's priority to a sleeping thread.

Approved by:	re (scottl)

Revision 1.157: download - view: text, markup, annotated - select for diffs
Wed Mar 29 23:24:55 2006 UTC (5 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.156: preferred, colored
Changes since revision 1.156: +14 -8 lines
Always explicitly panic in propogate_priority() if we try to propogate
a lock's priority to a sleeping thread.  When we panic, dump a stack
trace of the thread that is asleep if DDB is compiled into the kernel
just before calling panic().  This is much more informative and useful
for debugging than the current behavior of getting a page fault and not
having an easy way of determining which thread caused the original problem.

MFC after:	1 week

Revision 1.156: download - view: text, markup, annotated - select for diffs
Fri Jan 27 22:42:12 2006 UTC (6 years ago) by jhb
Branches: MAIN
Diff to: previous 1.155: preferred, colored
Changes since revision 1.155: +174 -47 lines
- Add support for having both a shared and exclusive queue of threads in
  each turnstile.  Also, allow for the owner thread pointer of a turnstile
  to be NULL.  This is needed for the upcoming reader/writer lock
  implementation.
- Add a new ddb command 'show turnstile' that will look up the turnstile
  associated with the given lock argument and display useful information
  like the list of threads blocked on each queue, etc.  If there isn't an
  active turnstile for a lock at the specified address, then the function
  will see if there is an active turnstile at the specified address and
  display info about it if so.
- Adjust the mutex code to handle the turnstile API changes.

Tested on:	i386 (all), alpha, amd64, sparc64 (1 and 3)

Revision 1.155: download - view: text, markup, annotated - select for diffs
Tue Jan 17 16:47:42 2006 UTC (6 years ago) by jhb
Branches: MAIN
Diff to: previous 1.154: preferred, colored
Changes since revision 1.154: +1 -0 lines
Initialize thread0.td_contested in init_turnstiles() rather than
mutex_init() as it is used by the turnstile code and is not mutex-specific.

Revision 1.154: download - view: text, markup, annotated - select for diffs
Tue Jan 17 16:40:20 2006 UTC (6 years ago) by jhb
Branches: MAIN
Diff to: previous 1.153: preferred, colored
Changes since revision 1.153: +0 -16 lines
Garbage collect turnstile_empty() since it is unused.

Revision 1.152.2.1: download - view: text, markup, annotated - select for diffs
Sun Oct 9 03:25:37 2005 UTC (6 years, 4 months ago) by delphij
Branches: RELENG_6
CVS tags: RELENG_6_0_BP, RELENG_6_0_0_RELEASE, RELENG_6_0
Diff to: previous 1.152: preferred, colored
Changes since revision 1.152: +0 -1 lines
MFC (by jhb):
| Trim a couple of unneeded includes.
|
| Revision  Changes    Path
| 1.153     +0 -1      src/sys/kern/subr_turnstile.c
| 1.35      +0 -1      src/sys/vm/vm_zeroidle.c

Approved by:	re (scottl)

Revision 1.153: download - view: text, markup, annotated - select for diffs
Thu Sep 29 19:13:52 2005 UTC (6 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.152: preferred, colored
Changes since revision 1.152: +0 -1 lines
Trim a couple of unneeded includes.

Revision 1.152: download - view: text, markup, annotated - select for diffs
Thu Feb 10 12:02:37 2005 UTC (7 years ago) by phk
Branches: MAIN
CVS tags: RELENG_6_BP
Branch point for: RELENG_6
Diff to: previous 1.151: preferred, colored
Changes since revision 1.151: +1 -1 lines
Make a bunch of malloc types static.

Found by:	src/tools/tools/kernxref

Revision 1.151: download - view: text, markup, annotated - select for diffs
Thu Dec 30 20:52:44 2004 UTC (7 years, 1 month ago) by jhb
Branches: MAIN
Diff to: previous 1.150: preferred, colored
Changes since revision 1.150: +120 -71 lines
Rework the interface between priority propagation (lending) and the
schedulers a bit to ensure more correct handling of priorities and fewer
priority inversions:
- Add two functions to the sched(9) API to handle priority lending:
  sched_lend_prio() and sched_unlend_prio().  The turnstile code uses these
  functions to ask the scheduler to lend a thread a set priority and to
  tell the scheduler when it thinks it is ok for a thread to stop borrowing
  priority.  The unlend case is slightly complex in that the turnstile code
  tells the scheduler what the minimum priority of the thread needs to be
  to satisfy the requirements of any other threads blocked on locks owned
  by the thread in question.  The scheduler then decides where the thread
  can go back to normal mode (if it's normal priority is high enough to
  satisfy the pending lock requests) or it it should continue to use the
  priority specified to the sched_unlend_prio() call.  This involves adding
  a new per-thread flag TDF_BORROWING that replaces the ULE-only kse flag
  for priority elevation.
- Schedulers now refuse to lower the priority of a thread that is currently
  borrowing another therad's priority.
- If a scheduler changes the priority of a thread that is currently sitting
  on a turnstile, it will call a new function turnstile_adjust() to inform
  the turnstile code of the change.  This function resorts the thread on
  the priority list of the turnstile if needed, and if the thread ends up
  at the head of the list (due to having the highest priority) and its
  priority was raised, then it will propagate that new priority to the
  owner of the lock it is blocked on.

Some additional fixes specific to the 4BSD scheduler include:
- Common code for updating the priority of a thread when the user priority
  of its associated kse group has been consolidated in a new static
  function resetpriority_thread().  One change to this function is that
  it will now only adjust the priority of a thread if it already has a
  time sharing priority, thus preserving any boosts from a tsleep() until
  the thread returns to userland.  Also, resetpriority() no longer calls
  maybe_resched() on each thread in the group. Instead, the code calling
  resetpriority() is responsible for calling resetpriority_thread() on
  any threads that need to be updated.
- schedcpu() now uses resetpriority_thread() instead of just calling
  sched_prio() directly after it updates a kse group's user priority.
- sched_clock() now uses resetpriority_thread() rather than writing
  directly to td_priority.
- sched_nice() now updates all the priorities of the threads after the
  group priority has been adjusted.

Discussed with:	bde
Reviewed by:	ups, jeffr
Tested on:	4bsd, ule
Tested on:	i386, alpha, sparc64

Revision 1.150: download - view: text, markup, annotated - select for diffs
Tue Oct 12 18:36:20 2004 UTC (7 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.149: preferred, colored
Changes since revision 1.149: +34 -12 lines
Refine the turnstile and sleep queue interfaces just a bit:
- Add a new _lock() call to each API that locks the associated chain lock
  for a lock_object pointer or wait channel.  The _lookup() functions now
  require that the chain lock be locked via _lock() when they are called.
- Change sleepq_add(), turnstile_wait() and turnstile_claim() to lookup
  the associated queue structure internally via _lookup() rather than
  accepting a pointer from the caller.  For turnstiles, this means that
  the actual lookup of the turnstile in the hash table is only done when
  the thread actually blocks rather than being done on each loop iteration
  in _mtx_lock_sleep().  For sleep queues, this means that sleepq_lookup()
  is no longer used outside of the sleep queue code except to implement an
  assertion in cv_destroy().
- Change sleepq_broadcast() and sleepq_signal() to require that the chain
  lock is already required.  For condition variables, this lets the
  cv_broadcast() and cv_signal() functions lock the sleep queue chain lock
  while testing the waiters count.  This means that the waiters count
  internal to condition variables is no longer protected by the interlock
  mutex and cv_broadcast() and cv_signal() now no longer require that the
  interlock be held when they are called.  This lets consumers of condition
  variables drop the lock before waking other threads which can result in
  fewer context switches.

MFC after:	1 month

Revision 1.147.2.2: download - view: text, markup, annotated - select for diffs
Fri Oct 8 19:47:23 2004 UTC (7 years, 4 months ago) by jhb
Branches: RELENG_5
CVS tags: RELENG_5_5_BP, RELENG_5_5_0_RELEASE, RELENG_5_5, RELENG_5_4_BP, RELENG_5_4_0_RELEASE, RELENG_5_4, RELENG_5_3_BP, RELENG_5_3_0_RELEASE, RELENG_5_3
Diff to: previous 1.147.2.1: preferred, colored; branchpoint 1.147: preferred, colored; next MAIN 1.148: preferred, colored
Changes since revision 1.147.2.1: +2 -0 lines
MFC: Add a critical section to close a priority inversion race found by
ups@.

Approved by:	re (scottl)

Revision 1.149: download - view: text, markup, annotated - select for diffs
Tue Oct 5 18:00:30 2004 UTC (7 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.148: preferred, colored
Changes since revision 1.148: +2 -0 lines
Add a critical section in turnstile_unpend() from before dropping the
turnstile chain lock until after making all the awakened threads
runnable.  First, this fixes a priority inversion race.  Second, this
attempts to finish waking up all of the threads waiting on a turnstile
before doing a preemption.

Reviewed by:	Stephan Uphoff (who found the priority inversion race)

Revision 1.147.2.1: download - view: text, markup, annotated - select for diffs
Thu Sep 9 09:45:26 2004 UTC (7 years, 5 months ago) by julian
Branches: RELENG_5
Diff to: previous 1.147: preferred, colored
Changes since revision 1.147: +1 -1 lines
MFC of:
   Give setrunqueue() and sched_add() more of a clue as to
   where they are coming from and what is expected from them.
   (  2004-09-01 02:11:28 UTC )

Approved by:    re (scottl)

Revision 1.148: download - view: text, markup, annotated - select for diffs
Wed Sep 1 02:11:27 2004 UTC (7 years, 5 months ago) by julian
Branches: MAIN
Diff to: previous 1.147: preferred, colored
Changes since revision 1.147: +1 -1 lines
Give setrunqueue() and sched_add() more of a clue as to
where they are coming from and what is expected from them.

MFC after:	2 days

Revision 1.147: download - view: text, markup, annotated - select for diffs
Sun Jul 25 23:32:32 2004 UTC (7 years, 6 months ago) by rwatson
Branches: MAIN
CVS tags: RELENG_5_BP
Branch point for: RELENG_5
Diff to: previous 1.146: preferred, colored
Changes since revision 1.146: +0 -1 lines
Revert modification of subr_turnstile.c accidentally included in the
last commit; this assertion was provided by jhb for local debugging
and not intended for broader consumption.

Revision 1.146: download - view: text, markup, annotated - select for diffs
Sun Jul 25 23:30:43 2004 UTC (7 years, 6 months ago) by rwatson
Branches: MAIN
Diff to: previous 1.145: preferred, colored
Changes since revision 1.145: +1 -0 lines
In uipc_connect(), assert that the passed thread is curthread, and pass
td into unp_connect() instead of reading curthread.

Revision 1.145: download - view: text, markup, annotated - select for diffs
Fri Jul 2 19:09:49 2004 UTC (7 years, 7 months ago) by jhb
Branches: MAIN
Diff to: previous 1.144: preferred, colored
Changes since revision 1.144: +1 -1 lines
- Change mi_switch() and sched_switch() to accept an optional thread to
  switch to.  If a non-NULL thread pointer is passed in, then the CPU will
  switch to that thread directly rather than calling choosethread() to pick
  a thread to choose to.
- Make sched_switch() aware of idle threads and know to do
  TD_SET_CAN_RUN() instead of sticking them on the run queue rather than
  requiring all callers of mi_switch() to know to do this if they can be
  called from an idlethread.
- Move constants for arguments to mi_switch() and thread_single() out of
  the middle of the function prototypes and up above into their own
  section.

Revision 1.144: download - view: text, markup, annotated - select for diffs
Tue Jun 29 03:48:49 2004 UTC (7 years, 7 months ago) by jhb
Branches: MAIN
Diff to: previous 1.143: preferred, colored
Changes since revision 1.143: +19 -7 lines
Oops, this didn't make it into my submit before I committed:  Defer
creation of the sysctl tree for the turnstile profiling stats until a
SI_SUB_LOCK sysinit.  Doing it in init_turnstiles() is too early as it is
called before mi_startup().

Revision 1.143: download - view: text, markup, annotated - select for diffs
Tue Jun 29 02:30:12 2004 UTC (7 years, 7 months ago) by jhb
Branches: MAIN
Diff to: previous 1.142: preferred, colored
Changes since revision 1.142: +48 -3 lines
Add two new kernel options to allow rudimentary profiling of the internal
hash tables used in the sleep queue and turnstile code.  Each option adds
a sysctl tree under debug containing the maximum depth of any bucket in
the hash table as well as a separate node for each bucket (or chain)
containing the current depth and maximum depth for that bucket.

Revision 1.142: download - view: text, markup, annotated - select for diffs
Tue Apr 6 19:07:21 2004 UTC (7 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.141: preferred, colored
Changes since revision 1.141: +2 -2 lines
Rename turnstile_wakeup() to turnstile_broadcast() to make the naming
more consistent with other APIs. sleepq and cv's use signal/broadcast, and
msleep uses wakeup_one/wakeup.  Prior to this turnstiles were using a
signal/wakeup mixture.

Revision 1.141: download - view: text, markup, annotated - select for diffs
Fri Mar 12 19:05:46 2004 UTC (7 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.140: preferred, colored
Changes since revision 1.140: +1 -1 lines
Fixup a comment.

Revision 1.140: download - view: text, markup, annotated - select for diffs
Fri Feb 27 18:33:09 2004 UTC (7 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.139: preferred, colored
Changes since revision 1.139: +0 -5 lines
Add an implementation of a generic sleep queue abstraction that is used
to queue threads sleeping on a wait channel similar to how turnstiles are
used to queue threads waiting for a lock.  This subsystem will be used as
the backend for sleep/wakeup and condition variables initially.  Eventually
it will also be used to replace the ithread-specific iwait thread
inhibitor.

Sleep queues are also not locked by sched_lock, so this splits sched_lock
up a bit further increasing concurrency within the scheduler.  Sleep queues
also natively support timeouts on sleeps and interruptible sleeps allowing
for the reduction of a lot of duplicated code between the sleep/wakeup and
condition variable implementations.  For more details on the sleep queue
implementation, check the comments in sys/sleepqueue.h and
kern/subr_sleepqueue.c.

Revision 1.139: download - view: text, markup, annotated - select for diffs
Fri Feb 27 16:14:26 2004 UTC (7 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.138: preferred, colored
Changes since revision 1.138: +3 -3 lines
Clarify and tweak some comments.

Revision 1.138: download - view: text, markup, annotated - select for diffs
Sun Jan 25 03:54:52 2004 UTC (8 years ago) by jeff
Branches: MAIN
Diff to: previous 1.137: preferred, colored
Changes since revision 1.137: +1 -2 lines
 - Add a flags parameter to mi_switch.  The value of flags may be SW_VOL or
   SW_INVOL.  Assert that one of these is set in mi_switch() and propery
   adjust the rusage statistics.  This is to simplify the large number of
   users of this interface which were previously all required to adjust the
   proper counter prior to calling mi_switch().  This also facilitates more
   switch and locking optimizations.
 - Change all callers of mi_switch() to pass the appropriate paramter and
   remove direct references to the process statistics.

Revision 1.134.2.1: download - view: text, markup, annotated - select for diffs
Thu Dec 11 20:01:52 2003 UTC (8 years, 2 months ago) by jhb
Branches: RELENG_5_2
CVS tags: RELENG_5_2_1_RELEASE, RELENG_5_2_0_RELEASE
Diff to: previous 1.134: preferred, colored; next MAIN 1.135: preferred, colored
Changes since revision 1.134: +12 -10 lines
MFC: Replace fix for empty turnstile race with a more general fix for the
more general race of a thread that was already woken up but still pending.
Adjust assertion for TDF_TSNOBLOCK case to allow for a thread to be on the
run queue as well as currently running.

Approved by:	re (scottl)

Revision 1.137: download - view: text, markup, annotated - select for diffs
Tue Dec 9 21:14:31 2003 UTC (8 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.136: preferred, colored
Changes since revision 1.136: +3 -2 lines
Adjust an assertion for the TDF_TSNOBLOCK race handling in
turnstile_unpend().  A racing thread that does not have TDI_LOCK set may
either be running on another CPU or it may be sitting on a run queue if it
was preempted during the very small window in turnstile_wait() between
unlocking the turnstile chain lock and locking sched_lock.

Revision 1.136: download - view: text, markup, annotated - select for diffs
Tue Dec 9 21:09:54 2003 UTC (8 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.135: preferred, colored
Changes since revision 1.135: +2 -0 lines
Assert that the we never give a thread a NULL turnstile when waking it up.

Revision 1.135: download - view: text, markup, annotated - select for diffs
Tue Dec 9 21:09:04 2003 UTC (8 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.134: preferred, colored
Changes since revision 1.134: +9 -8 lines
Revert the previous race fix and replace it with a more general fix.  The
case of a turnstile having no threads is just one instance of the more
general case where the thread we are examining has been partially awakened
already in that it has been removed from the turnstile's blocked list but
still has TDI_LOCK set.  We detect that case by checking to see if the
thread has already had a turnstile reassigned to it.

Revision 1.134: download - view: text, markup, annotated - select for diffs
Wed Nov 12 23:48:42 2003 UTC (8 years, 2 months ago) by jhb
Branches: MAIN
CVS tags: RELENG_5_2_BP
Branch point for: RELENG_5_2
Diff to: previous 1.133: preferred, colored
Changes since revision 1.133: +12 -4 lines
- Close a race where a thread on another CPU could release a contested lock
  and empty its turnstile while the blocking threads still pointed to the
  turnstile.  If the thread on the first CPU blocked on a lock owned by
  one of the threads blocked on the turnstile just woken up, then the
  first CPU could try to manipulate a bogus thread queue in the turnstile
  during priority propagation.
- Update locking notes for ts_owner and always clear ts_owner, not just
  under INVARIANTS.

Tested by:      sam (1)

Revision 1.133: download - view: text, markup, annotated - select for diffs
Wed Nov 12 14:55:45 2003 UTC (8 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.132: preferred, colored
Changes since revision 1.132: +1 -1 lines
Fix a typo in a comment.

Submitted by:	das

Revision 1.132: download - view: text, markup, annotated - select for diffs
Tue Nov 11 22:07:29 2003 UTC (8 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.131: preferred, colored
Changes since revision 1.131: +471 -758 lines
Add an implementation of turnstiles and change the sleep mutex code to use
turnstiles to implement blocking isntead of implementing a thread queue
directly.  These turnstiles are somewhat similar to those used in Solaris 7
as described in Solaris Internals but are also different.

Turnstiles do not come out of a fixed-sized pool.  Rather, each thread is
assigned a turnstile when it is created that it frees when it is destroyed.
When a thread blocks on a lock, it donates its turnstile to that lock to
serve as queue of blocked threads.  The queue associated with a given lock
is found by a lookup in a simple hash table.  The turnstile itself is
protected by a lock associated with its entry in the hash table.  This
means that sched_lock is no longer needed to contest on a mutex.  Instead,
sched_lock is only used when manipulating run queues or thread priorities.
Turnstiles also implement priority propagation inherently.

Currently turnstiles only support mutexes.  Eventually, however, turnstiles
may grow two queue's to support a non-sleepable reader/writer lock
implementation.  For more details, see the comments in sys/turnstile.h and
kern/subr_turnstile.c.

The two primary advantages from the turnstile code include: 1) the size
of struct mutex shrinks by four pointers as it no longer stores the
thread queue linkages directly, and 2) less contention on sched_lock in
SMP systems including the ability for multiple CPUs to contend on different
locks simultaneously (not that this last detail is necessarily that much of
a big win).  Note that 1) means that this commit is a kernel ABI breaker,
so don't mix old modules with a new kernel and vice versa.

Tested on:	i386 SMP, sparc64 SMP, alpha SMP

Revision 1.131: download - view: text, markup, annotated - select for diffs
Thu Jul 31 18:52:18 2003 UTC (8 years, 6 months ago) by jhb
Branches: MAIN
Diff to: previous 1.130: preferred, colored
Changes since revision 1.130: +9 -3 lines
If a spin lock is held for too long and WITNESS is enabled, then call
witness_display_spinlock() to see if we can find out where the current
owner of the spin lock last acquired the lock.

Revision 1.130: download - view: text, markup, annotated - select for diffs
Wed Jul 30 20:42:15 2003 UTC (8 years, 6 months ago) by jhb
Branches: MAIN
Diff to: previous 1.129: preferred, colored
Changes since revision 1.129: +3 -1 lines
When complaining about a sleeping thread owning a mutex, display the
thread's pid to make debugging easier for people who don't want to have to
use the intended tool for these panics (witness).

Indirectly prodded by:	kris

Revision 1.129: download - view: text, markup, annotated - select for diffs
Wed Jul 2 16:14:09 2003 UTC (8 years, 7 months ago) by jhb
Branches: MAIN
Diff to: previous 1.128: preferred, colored
Changes since revision 1.128: +9 -4 lines
- Add comments about the maintenance of the per-thread list of contested
  locks held by each thread.
- Fix a bug in the original BSD/OS code where a contested lock was not
  properly handed off from the old thread to the new thread when a
  contested lock with more than one blocked thread was transferred from
  one thread to another.
- Don't use an atomic operation to write the MTX_CONTESTED value to
  mtx_lock in the aforementioned special case.  The memory barriers and
  exclusion provided by sched_lock are sufficient.

Spotted by:	alc (2)

Revision 1.128: download - view: text, markup, annotated - select for diffs
Wed Jun 11 00:56:56 2003 UTC (8 years, 8 months ago) by obrien
Branches: MAIN
Diff to: previous 1.127: preferred, colored
Changes since revision 1.127: +3 -1 lines
Use __FBSDID().

Revision 1.127: download - view: text, markup, annotated - select for diffs
Sat May 31 21:11:01 2003 UTC (8 years, 8 months ago) by phk
Branches: MAIN
Diff to: previous 1.126: preferred, colored
Changes since revision 1.126: +1 -1 lines
Add "" around mutex name to make message less confusing.

Revision 1.126: download - view: text, markup, annotated - select for diffs
Thu Apr 17 22:28:58 2003 UTC (8 years, 9 months ago) by jhb
Branches: MAIN
CVS tags: old_RELENG_5_1_BP, old_RELENG_5_1_0_RELEASE, old_RELENG_5_1
Diff to: previous 1.125: preferred, colored
Changes since revision 1.125: +2 -7 lines
Use TD_IS_RUNNING() instead of thread_running() in the adaptive mutex
code.

Revision 1.125: download - view: text, markup, annotated - select for diffs
Thu Apr 10 17:35:44 2003 UTC (8 years, 10 months ago) by julian
Branches: MAIN
Diff to: previous 1.124: preferred, colored
Changes since revision 1.124: +2 -1 lines
Move the _oncpu entry from the KSE to the thread.
The entry in the KSE still exists but it's purpose will change a bit
when we add the ability to lock a KSE to a cpu.

Revision 1.124: download - view: text, markup, annotated - select for diffs
Sun Mar 23 11:26:11 2003 UTC (8 years, 10 months ago) by tjr
Branches: MAIN
Diff to: previous 1.123: preferred, colored
Changes since revision 1.123: +0 -43 lines
Remove unused mtx_lock_giant(), mtx_unlock_giant(), related globals
and sysctls.

Revision 1.123: download - view: text, markup, annotated - select for diffs
Tue Mar 18 08:45:23 2003 UTC (8 years, 10 months ago) by phk
Branches: MAIN
Diff to: previous 1.122: preferred, colored
Changes since revision 1.122: +0 -1 lines
Including <sys/stdint.h> is (almost?) universally only to be able to use
%j in printfs, so put a newsted include in <sys/systm.h> where the printf
prototype lives and save everybody else the trouble.

Revision 1.122: download - view: text, markup, annotated - select for diffs
Tue Mar 11 20:02:57 2003 UTC (8 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.121: preferred, colored
Changes since revision 1.121: +1 -3 lines
Axe the useless MTX_SLEEPABLE flag.  mutexes are not sleepable locks.
Nothing used this flag and WITNESS would have panic'd during mtx_init()
if anything had.

Revision 1.121: download - view: text, markup, annotated - select for diffs
Tue Mar 4 21:32:25 2003 UTC (8 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.120: preferred, colored
Changes since revision 1.120: +4 -5 lines
Remove safety belt: it is now ok to do a mtx_trylock() on a mutex you
already own.  The mtx_trylock() will fail however.  Enhance the comment
at the top of the try lock function to explain this.

Requested by:	jlemon and his evil netisr locking

Revision 1.120: download - view: text, markup, annotated - select for diffs
Tue Mar 4 20:32:41 2003 UTC (8 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.119: preferred, colored
Changes since revision 1.119: +6 -4 lines
Miscellaneous cleanups to _mtx_lock_sleep():
- Declare some local variables at the top of the function instead of in a
  nested block.
- Use mtx_owned() instead of masking off bits from mtx_lock manually.
- Read the value of mtx_lock into 'v' as a separate line rather than inside
  an if statement for clarity.  This code is hairy enough as it is.

Revision 1.119: download - view: text, markup, annotated - select for diffs
Tue Mar 4 20:30:30 2003 UTC (8 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.118: preferred, colored
Changes since revision 1.118: +4 -8 lines
Properly assert that mtx_trylock() is not called on a mutex we already
owned.  Previously the KASSERT would only trigger if we successfully
acquired a lock that we already held.  However, _obtain_lock() fails to
acquire locks that we already hold, so the KASSERT was never checked in
the case it was supposed to fail.

Revision 1.118: download - view: text, markup, annotated - select for diffs
Tue Feb 25 22:28:46 2003 UTC (8 years, 11 months ago) by mtm
Branches: MAIN
Diff to: previous 1.117: preferred, colored
Changes since revision 1.117: +15 -3 lines
Unbreak mutex profiling (at least for me).
	o Always check for null when dereferencing the filename component.
	o Implement a try-and-backoff method for allocating memory to
	  dump stats to avoid a spin-lock -> sleep-lock mutex lock order
	  panic with WITNESS.

Approved by:	des, markm (mentor)
Not objected:	jhb

Revision 1.117: download - view: text, markup, annotated - select for diffs
Tue Jan 21 20:33:27 2003 UTC (9 years ago) by des
Branches: MAIN
Diff to: previous 1.116: preferred, colored
Changes since revision 1.116: +12 -14 lines
There's absolutely no need for a struct-within-a-struct, so move the
counters out of the inner struct and remove it.

Revision 1.116: download - view: text, markup, annotated - select for diffs
Fri Oct 25 08:40:20 2002 UTC (9 years, 3 months ago) by phk
Branches: MAIN
CVS tags: old_RELENG_5_0_BP, old_RELENG_5_0_0_RELEASE, old_RELENG_5_0
Diff to: previous 1.115: preferred, colored
Changes since revision 1.115: +5 -0 lines
Disable the kernacc() check in mtx_validate() until such time that kernacc
does not require Giant.

This means that we may miss panics on a class of mutex programming bugs,
but only if running with a Chernobyl setting of debug-flags.

Spotted by:	Pete Carah <pete@ns.altadena.net>

Revision 1.115: download - view: text, markup, annotated - select for diffs
Wed Oct 23 10:26:54 2002 UTC (9 years, 3 months ago) by des
Branches: MAIN
Diff to: previous 1.114: preferred, colored
Changes since revision 1.114: +9 -10 lines
Whitespace cleanup.

Revision 1.114: download - view: text, markup, annotated - select for diffs
Tue Oct 22 16:06:28 2002 UTC (9 years, 3 months ago) by robert
Branches: MAIN
Diff to: previous 1.113: preferred, colored
Changes since revision 1.113: +14 -18 lines
Change the `mutex_prof' structure to use three variables contained
in an anonymous structure as counters, instead of an array with
preprocessor-defined names for indices.  Remove the associated XXX-
comment.

Revision 1.113: download - view: text, markup, annotated - select for diffs
Mon Oct 21 18:48:28 2002 UTC (9 years, 3 months ago) by des
Branches: MAIN
Diff to: previous 1.112: preferred, colored
Changes since revision 1.112: +28 -19 lines
Reduce the overhead of the mutex statistics gathering code, try to produce
shorter lines in the report, and clean up some minor style issues.

Revision 1.112: download - view: text, markup, annotated - select for diffs
Sat Oct 12 05:32:23 2002 UTC (9 years, 4 months ago) by jeff
Branches: MAIN
Diff to: previous 1.111: preferred, colored
Changes since revision 1.111: +2 -4 lines
 - Create a new scheduler api that is defined in sys/sched.h
 - Begin moving scheduler specific functionality into sched_4bsd.c
 - Replace direct manipulation of scheduler data with hooks provided by the
   new api.
 - Remove KSE specific state modifications and single runq assumptions from
   kern_switch.c

Reviewed by:	-arch

Revision 1.111: download - view: text, markup, annotated - select for diffs
Wed Oct 2 20:31:46 2002 UTC (9 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.110: preferred, colored
Changes since revision 1.110: +13 -13 lines
Rename the mutex thread and process states to use a more generic 'LOCK'
name instead.  (e.g., SLOCK instead of SMTX, TD_ON_LOCK() instead of
TD_ON_MUTEX())  Eventually a turnstile abstraction will be added that
will be shared with mutexes and other types of locks.  SLOCK/TDI_LOCK will
be used internally by the turnstile code and will not be specific to
mutexes.  Making the change now ensures that turnstiles can be dropped
in at a later date without affecting the ABI of userland applications.

Revision 1.110: download - view: text, markup, annotated - select for diffs
Sun Sep 29 23:28:58 2002 UTC (9 years, 4 months ago) by julian
Branches: MAIN
Diff to: previous 1.109: preferred, colored
Changes since revision 1.109: +1 -0 lines
uh, commit all of the patch

Revision 1.109: download - view: text, markup, annotated - select for diffs
Sun Sep 29 23:23:25 2002 UTC (9 years, 4 months ago) by julian
Branches: MAIN
Diff to: previous 1.108: preferred, colored
Changes since revision 1.108: +4 -2 lines
commit the version I actually tested..

Submitted by:	davidxu

Revision 1.108: download - view: text, markup, annotated - select for diffs
Sun Sep 29 23:04:33 2002 UTC (9 years, 4 months ago) by julian
Branches: MAIN
Diff to: previous 1.107: preferred, colored
Changes since revision 1.107: +2 -1 lines
Implement basic KSE loaning. This stops a hread that is blocked in BOUND mode
from stopping another thread from completing a syscall, and this allows it to
release its resources etc. Probably more related commits to follow (at least
one I know of)

Initial concept by: julian, dillon
Submitted by:	davidxu

Revision 1.107: download - view: text, markup, annotated - select for diffs
Wed Sep 11 08:13:53 2002 UTC (9 years, 5 months ago) by julian
Branches: MAIN
Diff to: previous 1.106: preferred, colored
Changes since revision 1.106: +6 -7 lines
Completely redo thread states.

Reviewed by:	davidxu@freebsd.org

Revision 1.106: download - view: text, markup, annotated - select for diffs
Tue Sep 3 18:25:16 2002 UTC (9 years, 5 months ago) by jhb
Branches: MAIN
Diff to: previous 1.105: preferred, colored
Changes since revision 1.105: +16 -4 lines
Add some KASSERT()'s to ensure that we don't perform spin mutex ops on
sleep mutexes and vice versa.  WITNESS normally should catch this but
not everyone uses WITNESS so this is a fallback to catch nasty but easy
to do bugs.

Revision 1.105: download - view: text, markup, annotated - select for diffs
Mon Aug 26 18:39:38 2002 UTC (9 years, 5 months ago) by iedowse
Branches: MAIN
Diff to: previous 1.104: preferred, colored
Changes since revision 1.104: +20 -0 lines
Add a new KTR type KTR_CONTENTION, and use it in the mutex code to
log the start and end of periods during which mtx_lock() is waiting
to acquire a sleep mutex. The log message includes the file and
line of both the waiter and the holder.

Reviewed by:	jhb, jake

Revision 1.104: download - view: text, markup, annotated - select for diffs
Sat Jul 27 16:54:23 2002 UTC (9 years, 6 months ago) by jhb
Branches: MAIN
Diff to: previous 1.103: preferred, colored
Changes since revision 1.103: +2 -2 lines
Disable optimization of spinlocks on UP kernels w/o debugging for now
since it breaks mtx_owned() on spin mutexes when used outside of
mtx_assert().  Unfortunately we currently use it in the i386 MD code
and in the sio(4) driver.

Reported by:	bde

Revision 1.103: download - view: text, markup, annotated - select for diffs
Wed Jul 3 01:50:27 2002 UTC (9 years, 7 months ago) by des
Branches: MAIN
Diff to: previous 1.102: preferred, colored
Changes since revision 1.102: +12 -11 lines
Add mtx_ prefixes to the fields used for mutex profiling, and fix a bug
where the profiling code would report the release point instead of the
acquisition point.

Requested by:	bde

Revision 1.102: download - view: text, markup, annotated - select for diffs
Sat Jun 29 17:26:18 2002 UTC (9 years, 7 months ago) by julian
Branches: MAIN
Diff to: previous 1.101: preferred, colored
Changes since revision 1.101: +16 -15 lines
Part 1 of KSE-III

The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)

Reviewed by:	Almost everyone who counts
	(at various times, peter, jhb, matt, alfred, mini, bernd,
	and a cast of thousands)

	NOTE: this is still Beta code, and contains lots of debugging stuff.
	expect slight instability in signals..

Revision 1.101: download - view: text, markup, annotated - select for diffs
Tue Jun 4 22:36:24 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.100: preferred, colored
Changes since revision 1.100: +5 -6 lines
Replace thread_runnable() with thread_running() as the latter is more
accurate.

Suggested by:	julian

Revision 1.100: download - view: text, markup, annotated - select for diffs
Tue Jun 4 21:53:48 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.99: preferred, colored
Changes since revision 1.99: +4 -1 lines
Optimize the adaptive mutex spin a bit.  Use a simple while loop with
simple reads (and on IA32, a "pause" instruction for each interation of the
loop) to spin until either the mutex owner field changes, or the lock owner
stops executing.

Suggested by:	tanimura
Tested on:	i386

Revision 1.99: download - view: text, markup, annotated - select for diffs
Tue Jun 4 21:50:02 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.98: preferred, colored
Changes since revision 1.98: +5 -3 lines
Add a private thread_runnable() macro to make the code more readable and
make the KSE diff easier to maintain.

Revision 1.98: download - view: text, markup, annotated - select for diffs
Thu May 23 03:08:42 2002 UTC (9 years, 8 months ago) by des
Branches: MAIN
Diff to: previous 1.97: preferred, colored
Changes since revision 1.97: +3 -2 lines
Make the counters uintmax_ts, and use %ju rather than %llu.

Revision 1.97: download - view: text, markup, annotated - select for diffs
Wed May 22 20:32:39 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.96: preferred, colored
Changes since revision 1.96: +5 -5 lines
Rename pause() to ia32_pause() so it doesn't conflict with the pause()
function defined in <unistd.h>.  I didn't #ifdef _KERNEL it because the
mutex implementation in libpthread will probably need this.

Revision 1.96: download - view: text, markup, annotated - select for diffs
Wed May 22 13:19:22 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.95: preferred, colored
Changes since revision 1.95: +5 -5 lines
Rename cpu_pause() to pause().  Originally I was going to make this an
MI API with empty cpu_pause() functions on other arch's, but this
functionality is definitely unique to IA-32, so I decided to leave it
as i386-only and wrap it in #ifdef's.  I should have dropped the cpu_
prefix when I made that decision.

Requested by:	bde

Revision 1.95: download - view: text, markup, annotated - select for diffs
Tue May 21 22:26:35 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.94: preferred, colored
Changes since revision 1.94: +17 -1 lines
Add appropriate IA32 "pause" instructions to improve performanec on
Pentium 4's and newer IA32 processors.  The "pause" instruction has been
verified by Intel to be a NOP on all currently existing IA32 processors
prior to the Pentium 4.

Revision 1.94: download - view: text, markup, annotated - select for diffs
Tue May 21 21:27:05 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.93: preferred, colored
Changes since revision 1.93: +1 -1 lines
Fix an old cut 'n' paste bug inherited from BSD/OS: don't increment 'i'
twice once we are in the long wait stage of spinning on a spin mutex.

Revision 1.93: download - view: text, markup, annotated - select for diffs
Tue May 21 21:13:27 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.92: preferred, colored
Changes since revision 1.92: +2 -2 lines
Whitespace fixup, properly indent the body of an else clause.

Revision 1.92: download - view: text, markup, annotated - select for diffs
Tue May 21 20:47:11 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.91: preferred, colored
Changes since revision 1.91: +26 -0 lines
Add code to make default mutexes adaptive if the ADAPTIVE_MUTEXES kernel
option is used (not on by default).

- In the case of trying to lock a mutex, if the MTX_CONTESTED flag is set,
  then we can safely read the thread pointer from the mtx_lock member while
  holding sched_lock.  We then examine the thread to see if it is currently
  executing on another CPU.  If it is, then we keep looping instead of
  blocking.
- In the case of trying to unlock a mutex, it is now possible for a mutex
  to have MTX_CONTESTED set in mtx_lock but to not have any threads
  actually blocked on it, so we need to handle that case.  In that case,
  we just release the lock as if MTX_CONTESTED was not set and return.
- We do not adaptively spin on Giant as Giant is held for long times and
  it slows SMP systems down to a crawl (it was taking several minutes,
  like 5-10 or so for my test alpha and sparc64 SMP boxes to boot up when
  they adaptively spinned on Giant).
- We only compile in the code to do this for SMP kernels, it doesn't make
  sense for UP kernels.

Tested on:	i386, alpha, sparc64

Revision 1.91: download - view: text, markup, annotated - select for diffs
Tue May 21 20:34:28 2002 UTC (9 years, 8 months ago) by jhb
Branches: MAIN
Diff to: previous 1.90: preferred, colored
Changes since revision 1.90: +8 -0 lines
Optimize spin mutexes for UP kernels without debugging to just enter and
exit critical sections.  We only contest on a spin mutex on an SMP kernel
running on an SMP machine.

Revision 1.90: download - view: text, markup, annotated - select for diffs
Thu Apr 4 20:52:27 2002 UTC (9 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.89: preferred, colored
Changes since revision 1.89: +11 -8 lines
Change mtx_init() to now take an extra argument.  The third argument is
the generic lock type for use with witness.  If this argument is NULL then
the lock name is used as the lock type.  Add a macro for a lock type name
for network driver locks.

Revision 1.89: download - view: text, markup, annotated - select for diffs
Tue Apr 2 23:26:32 2002 UTC (9 years, 10 months ago) by des
Branches: MAIN
Diff to: previous 1.88: preferred, colored
Changes since revision 1.88: +10 -16 lines
Revert to open hashing.  It makes the code simpler, and works farily well
even when the number of records approaches the size of the hash table.
Besides, the previous implementation (using linear probing) was broken :)

Also, use the newly introduced MTX_SYSINIT.

Revision 1.88: download - view: text, markup, annotated - select for diffs
Tue Apr 2 22:19:14 2002 UTC (9 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.87: preferred, colored
Changes since revision 1.87: +27 -0 lines
- Move the MI mutexes sched_lock and Giant from being declared in the
  various machdep.c's to being declared in kern_mutex.c.
- Add a new function mutex_init() used to perform early initialization
  needed for mutexes such as setting up thread0's contested lock list
  and initializing MI mutexes.  Change the various MD startup routines
  to call this function instead of duplicating all the code themselves.

Tested on:	alpha, i386

Revision 1.87: download - view: text, markup, annotated - select for diffs
Tue Apr 2 20:44:30 2002 UTC (9 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.86: preferred, colored
Changes since revision 1.86: +1 -1 lines
Spelling police.

Revision 1.86: download - view: text, markup, annotated - select for diffs
Tue Apr 2 16:05:40 2002 UTC (9 years, 10 months ago) by arr
Branches: MAIN
Diff to: previous 1.85: preferred, colored
Changes since revision 1.85: +11 -0 lines
- Add MTX_SYSINIT and SX_SYSINIT as macro glue for allowing sx and mtx
  locks to be able to setup a SYSINIT call.  This helps in places where
  a lock is needed to protect some data, but the data is not truly
  associated with a subsystem that can properly initialize it's lock.
  The macros use the mtx_sysinit() and sx_sysinit() functions,
  respectively, as the handler argument to SYSINIT().

Reviewed by: alfred, jhb, smp@

Revision 1.85: download - view: text, markup, annotated - select for diffs
Tue Apr 2 14:42:01 2002 UTC (9 years, 10 months ago) by des
Branches: MAIN
Diff to: previous 1.84: preferred, colored
Changes since revision 1.84: +28 -19 lines
Instead of get_cyclecount(9), use nanotime(9) to record acquisition and
release times.  Measurements are made and stored in nanoseconds but
presented in microseconds, which should be sufficient for the locks for
which we actually want this (those that are held long and / or often).
Also, rename some variables and structure members to unit-agnostic names.

Revision 1.84: download - view: text, markup, annotated - select for diffs
Tue Apr 2 00:01:49 2002 UTC (9 years, 10 months ago) by des
Branches: MAIN
Diff to: previous 1.83: preferred, colored
Changes since revision 1.83: +159 -2 lines
Mutex profiling code, conditional on the MUTEX_PROFILING option.  Adds the
following sysctl variables:

  debug.mutex.prof.enable	    enable / disable profiling
  debug.mutex.prof.acquisitions	    number of mutex acquisitions recorded
  debug.mutex.prof.records	    number of acquisition points recorded
  debug.mutex.prof.maxrecords	    max number of acquisition points
  debug.mutex.prof.rejected	    number of rejections (due to full table)
  debug.mutex.prof.hashsize	    hash size
  debug.mutex.prof.collisions	    number of hash collisions
  debug.mutex.prof.stats	    profiling statistics

The code records four numbers for each acquisition point (identified by
source file name and line number): longest time held, total time held,
number of non-recursive acquisitions, average time held.  The measurements
are in clock cycles (as returned by get_cyclecount(9)); this may cause
measurements on some SMP systems to be unreliable.  This can probably be
worked around by replacing get_cyclecount(9) by some incarnation of
nanotime(9).

This work was derived from initial patches by eivind.

Revision 1.83: download - view: text, markup, annotated - select for diffs
Wed Mar 27 09:23:38 2002 UTC (9 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.82: preferred, colored
Changes since revision 1.82: +3 -1 lines
Add a new mtx_init option "MTX_DUPOK" which allows duplicate acquires of locks
with this flag.  Remove the dup_list and dup_ok code from subr_witness.  Now
we just check for the flag instead of doing string compares.

Also, switch the process lock, process group lock, and uma per cpu locks over
to this interface.  The original mechanism did not work well for uma because
per cpu lock names are unique to each zone.

Approved by:	jhb

Revision 1.82: download - view: text, markup, annotated - select for diffs
Tue Mar 19 21:24:06 2002 UTC (9 years, 10 months ago) by alfred
Branches: MAIN
Diff to: previous 1.81: preferred, colored
Changes since revision 1.81: +1 -1 lines
Remove __P.

Revision 1.81: download - view: text, markup, annotated - select for diffs
Wed Feb 20 21:25:44 2002 UTC (9 years, 11 months ago) by peter
Branches: MAIN
Diff to: previous 1.80: preferred, colored
Changes since revision 1.80: +0 -5 lines
Tidy up some unused variables

Revision 1.80: download - view: text, markup, annotated - select for diffs
Mon Feb 18 17:51:47 2002 UTC (9 years, 11 months ago) by dillon
Branches: MAIN
Diff to: previous 1.79: preferred, colored
Changes since revision 1.79: +2 -0 lines
Add kern_giant_ucred to instrument Giant around ucred related operations
such a getgid(), setgid(), etc...

Revision 1.79: download - view: text, markup, annotated - select for diffs
Mon Feb 11 20:37:51 2002 UTC (9 years, 11 months ago) by julian
Branches: MAIN
Diff to: previous 1.78: preferred, colored
Changes since revision 1.78: +13 -15 lines
In  a threaded world, differnt priorirites become properties of
different entities.  Make it so.

Reviewed by:	jhb@freebsd.org (john baldwin)

Revision 1.78: download - view: text, markup, annotated - select for diffs
Sat Feb 9 00:12:53 2002 UTC (10 years ago) by jhb
Branches: MAIN
Diff to: previous 1.77: preferred, colored
Changes since revision 1.77: +1 -1 lines
Use the mtx_owner() macro in one spot in _mtx_lock_sleep() to make the
code easier to read.

Revision 1.77: download - view: text, markup, annotated - select for diffs
Tue Jan 15 14:20:33 2002 UTC (10 years ago) by jhb
Branches: MAIN
Diff to: previous 1.76: preferred, colored
Changes since revision 1.76: +2 -2 lines
Bump the limits for determining if we've held a spinlock too long as they
seem to be too short for the 500 Mhz DS20 I'm testing on.  The rather
arbitrary numbers are rather bogus anyways.  We should probably have
variables for these limits that are calibrated in the MD startup code
somehow.

Revision 1.76: download - view: text, markup, annotated - select for diffs
Sat Jan 5 08:47:11 2002 UTC (10 years, 1 month ago) by jhb
Branches: MAIN
Diff to: previous 1.75: preferred, colored
Changes since revision 1.75: +3 -11 lines
Change the preemption code for software interrupt thread schedules and
mutex releases to not require flags for the cases when preemption is
not allowed:

The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent
switching to a higher priority thread on mutex releease and swi schedule,
respectively when that switch is not safe.  Now that the critical section
API maintains a per-thread nesting count, the kernel can easily check
whether or not it should switch without relying on flags from the
programmer.  This fixes a few bugs in that all current callers of
swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from
fast interrupt handlers and the swi_sched of softclock needed this flag.
Note that to ensure that swi_sched()'s in clock and fast interrupt
handlers do not switch, these handlers have to be explicitly wrapped
in critical_enter/exit pairs.  Presently, just wrapping the handlers is
sufficient, but in the future with the fully preemptive kernel, the
interrupt must be EOI'd before critical_exit() is called.  (critical_exit()
can switch due to a deferred preemption in a fully preemptive kernel.)

I've tested the changes to the interrupt code on i386 and alpha.  I have
not tested ia64, but the interrupt code is almost identical to the alpha
code, so I expect it will work fine.  PowerPC and ARM do not yet have
interrupt code in the tree so they shouldn't be broken.  Sparc64 is
broken, but that's been ok'd by jake and tmm who will be fixing the
interrupt code for sparc64 shortly.

Reviewed by:	peter
Tested on:	i386, alpha

Revision 1.75: download - view: text, markup, annotated - select for diffs
Tue Dec 18 00:27:17 2001 UTC (10 years, 1 month ago) by jhb
Branches: MAIN
Diff to: previous 1.74: preferred, colored
Changes since revision 1.74: +3 -5 lines
Modify the critical section API as follows:
- The MD functions critical_enter/exit are renamed to start with a cpu_
  prefix.
- MI wrapper functions critical_enter/exit maintain a per-thread nesting
  count and a per-thread critical section saved state set when entering
  a critical section while at nesting level 0 and restored when exiting
  to nesting level 0.  This moves the saved state out of spin mutexes so
  that interlocking spin mutexes works properly.
- Most low-level MD code that used critical_enter/exit now use
  cpu_critical_enter/exit.  MI code such as device drivers and spin
  mutexes use the MI wrappers.  Note that since the MI wrappers store
  the state in the current thread, they do not have any return values or
  arguments.
- mtx_intr_enable() is replaced with a constant CRITICAL_FORK which is
  assigned to curthread->td_savecrit during fork_exit().

Tested on:	i386, alpha

Revision 1.74: download - view: text, markup, annotated - select for diffs
Thu Nov 15 19:08:55 2001 UTC (10 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.73: preferred, colored
Changes since revision 1.73: +1 -22 lines
Remove definition of witness and comment stating that this file implements
witness.  Witness moved off to subr_witness.c a while ago.

Revision 1.73: download - view: text, markup, annotated - select for diffs
Fri Oct 26 20:48:04 2001 UTC (10 years, 3 months ago) by dillon
Branches: MAIN
Diff to: previous 1.72: preferred, colored
Changes since revision 1.72: +42 -0 lines
Add mtx_lock_giant() and mtx_unlock_giant() wrappers for sysctl management
of Giant during the Giant unwinding phase, and start work on instrumenting
Giant for the file and proc mutexes.

These wrappers allow developers to turn on and off Giant around various
subsystems.  DEVELOPERS SHOULD NEVER TURN OFF GIANT AROUND A SUBSYSTEM JUST
BECAUSE THE SYSCTL EXISTS!  General developers should only considering
turning on Giant for a subsystem whos default is off (to help track down
bugs).  Only developers working on particular subsystems who know what
they are doing should consider turning off Giant.

These wrappers will greatly improve our ability to unwind Giant and test
the kernel on a (mostly) subsystem by subsystem basis.   They allow Giant
unwinding developers (GUDs) to emplace appropriate subsystem and structural
mutexes in the main tree and then request that the larger community test
the work by turning off Giant around the subsystem(s), without the larger
community having to mess around with patches.  These wrappers also allow
GUDs to boot into a (more likely to be) working system in the midst of
their unwinding work and to test that work under more controlled
circumstances.

There is a master sysctl, kern.giant.all, which defaults to 0 (off).  If
turned on it overrides *ALL* other kern.giant sysctls and forces Giant to
be turned on for all wrapped subsystems.  If turned off then Giant around
individual subsystems are controlled by various other kern.giant.XXX sysctls.

Code which overlaps multiple subsystems must have all related subsystem Giant
sysctls turned off in order to run without Giant.

Revision 1.72: download - view: text, markup, annotated - select for diffs
Sat Oct 20 01:22:42 2001 UTC (10 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.71: preferred, colored
Changes since revision 1.71: +4 -2 lines
The mtx_init() and sx_init() functions bzero'd locks before handing them
off to witness_init() making the check for double intializating a lock by
testing the LO_INITIALIZED flag moot.  Workaround this by checking the
LO_INITIALIZED flag ourself before we bzero the lock structure.

Revision 1.71: download - view: text, markup, annotated - select for diffs
Wed Sep 26 00:05:18 2001 UTC (10 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.70: preferred, colored
Changes since revision 1.70: +3 -3 lines
Remove superflous parens after de-macroizing.

Revision 1.70: download - view: text, markup, annotated - select for diffs
Sat Sep 22 21:19:55 2001 UTC (10 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.69: preferred, colored
Changes since revision 1.69: +25 -5 lines
Since we no longer inline any debugging code in the mutex operations, move
all the debugging code into the function versions of the mutex operations
in kern_mutex.c.  This reduced the __mtx_* macros to simply wrappers of
the _{get,rel}_lock_* macros, so the __mtx_* macros were also abolished in
favor of just calling the _{get,rel}_lock_* macros.  The tangled hairy mass
of macros calling macros is at least a bit more sane now.

Revision 1.69: download - view: text, markup, annotated - select for diffs
Wed Sep 19 22:52:59 2001 UTC (10 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.68: preferred, colored
Changes since revision 1.68: +2 -1 lines
Fix a bug in propagate priority: the kse group pointer wasn't being
updated in the loop so the new thread always seemd to have the same
priority as the original thread and no actual priorities were changed.

Revision 1.68: download - view: text, markup, annotated - select for diffs
Wed Sep 12 08:37:44 2001 UTC (10 years, 5 months ago) by julian
Branches: MAIN
CVS tags: old_KSE_MILESTONE_2
Diff to: previous 1.67: preferred, colored
Changes since revision 1.67: +106 -98 lines
KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after:    ha ha ha ha

Revision 1.67: download - view: text, markup, annotated - select for diffs
Fri Aug 24 23:00:59 2001 UTC (10 years, 5 months ago) by bmilekic
Branches: MAIN
CVS tags: old_KSE_PRE_MILESTONE_2
Diff to: previous 1.66: preferred, colored
Changes since revision 1.66: +6 -1 lines
Force a commit on kern_mutex.c to explain reason for last commit but while
I'm at it also add a comment in mtx_validate() explaining the purpose
of the last change.

Basically, this fixes booting kernels compiled with MUTEX_DEBUG. What used
to happen is before we setidt from init386() [still using BTX idt], we
called mtx_init() on several mutex locks, notably Giant and some others.
This is a problem for MUTEX_DEBUG because it enables mtx_validate() which
calls kernacc(), some of which in turn requires Giant.
Fix by calling kernacc() from mtx_validate() only if (!cold).

Revision 1.66: download - view: text, markup, annotated - select for diffs
Fri Aug 24 22:53:45 2001 UTC (10 years, 5 months ago) by bmilekic
Branches: MAIN
Diff to: previous 1.65: preferred, colored
Changes since revision 1.65: +5 -3 lines
*** empty log message ***

Revision 1.65: download - view: text, markup, annotated - select for diffs
Tue Jul 31 17:45:50 2001 UTC (10 years, 6 months ago) by jhb
Branches: MAIN
Diff to: previous 1.64: preferred, colored
Changes since revision 1.64: +4 -1 lines
If we have already panic'd then don't bother enforcing mutex asserts as
things are pretty much shot already and all panic'ing does is hurt our
chances of getting a dump.

Inspired by:	sheldonh

Revision 1.64: download - view: text, markup, annotated - select for diffs
Mon Jun 25 18:29:32 2001 UTC (10 years, 7 months ago) by jhb
Branches: MAIN
Diff to: previous 1.63: preferred, colored
Changes since revision 1.63: +4 -1 lines
Count the context switch when blocking on a mutex as a voluntary context
switch.  Count the context switch when preempting the current thread to let
a higher priority thread blocked on a mutex we just released run as an
involuntary context switch.

Reported by:	bde

Revision 1.63: download - view: text, markup, annotated - select for diffs
Fri May 4 17:15:16 2001 UTC (10 years, 9 months ago) by jhb
Branches: MAIN
Diff to: previous 1.62: preferred, colored
Changes since revision 1.62: +5 -40 lines
- Move state about lock objects out of struct lock_object and into a new
  struct lock_instance that is stored in the per-process and per-CPU lock
  lists.  Previously, the lock lists just kept a pointer to each lock held.
  That pointer is now replaced by a lock instance which contains a pointer
  to the lock object, the file and line of the last acquisition of a lock,
  and various flags about a lock including its recursion count.
- If we sleep while holding a sleepable lock, then mark that lock instance
  as having slept and ignore any lock order violations that occur while
  acquiring Giant when we wake up with slept locks.  This is ok because of
  Giant's special nature.
- Allow witness to differentiate between shared and exclusive locks and
  unlocks of a lock.  Witness will now detect the case when a lock is
  acquired first in one mode and then in another.  Mutexes are always
  locked and unlocked exclusively.  Witness will also now detect the case
  where a process attempts to unlock a shared lock while holding an
  exclusive lock and vice versa.
- Fix a bug in the lock list implementation where we used the wrong
  constant to detect the case where a lock list entry was full.

Revision 1.62: download - view: text, markup, annotated - select for diffs
Tue May 1 08:12:57 2001 UTC (10 years, 9 months ago) by markm
Branches: MAIN
Diff to: previous 1.61: preferred, colored
Changes since revision 1.61: +2 -2 lines
Undo part of the tangle of having sys/lock.h and sys/mutex.h included in
other "system" header files.

Also help the deprecation of lockmgr.h by making it a sub-include of
sys/lock.h and removing sys/lockmgr.h form kernel .c files.

Sort sys/*.h includes where possible in affected files.

OK'ed by:	bde (with reservations)

Revision 1.61: download - view: text, markup, annotated - select for diffs
Tue Apr 17 03:34:52 2001 UTC (10 years, 9 months ago) by jhb
Branches: MAIN
Diff to: previous 1.60: preferred, colored
Changes since revision 1.60: +4 -1 lines
Exit and re-enter the critical section while spinning for a spinlock so
that interrupts can come in while we are waiting for a lock.

Revision 1.60: download - view: text, markup, annotated - select for diffs
Fri Apr 13 09:29:34 2001 UTC (10 years, 9 months ago) by markm
Branches: MAIN
Diff to: previous 1.59: preferred, colored
Changes since revision 1.59: +2 -2 lines
Handle a rare but fatal race invoked sometimes when SIGSTOP is
invoked.

Revision 1.59: download - view: text, markup, annotated - select for diffs
Wed Mar 28 09:03:23 2001 UTC (10 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.58: preferred, colored
Changes since revision 1.58: +119 -1125 lines
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects.  Each lock class specifies a
  name and set of flags (or properties) shared by all locks of a given
  type.  Currently there are three lock classes: spin mutexes, sleep
  mutexes, and sx locks.  A lock object specifies properties of an
  additional lock along with a lock name and all of the extra stuff needed
  to make witness work with a given lock.  This abstract lock stuff is
  defined in sys/lock.h.  The lockmgr constants, types, and prototypes have
  been moved to sys/lockmgr.h.  For temporary backwards compatability,
  sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
  locks held.  By making this per-cpu, we do not have to jump through
  magic hoops to deal with sched_lock changing ownership during context
  switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
  proc->p_sleeplocks, which is a list of held sleep locks including sleep
  mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
  level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
  - MTX_NOWITNESS - specifies that this lock should be ignored by witness.
    This is used for the mutex that blocks a sx lock for example.
  - MTX_QUIET - this is not new, but you can pass this to mtx_init() now
    and no events will be logged for this lock, so that one doesn't have
    to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag.  Use this flag to export
  a mtx_initialized() macro that can be safely called from drivers.  Also,
  we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
  performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
  more accurate file and line numbers.

Revision 1.58: download - view: text, markup, annotated - select for diffs
Wed Mar 28 02:40:46 2001 UTC (10 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.57: preferred, colored
Changes since revision 1.57: +35 -3 lines
- Switch from using save/disable/restore_intr to using critical_enter/exit
  and change the u_int mtx_saveintr member of struct mtx to a critical_t
  mtx_savecrit.
- On the alpha we no longer need a custom _get_spin_lock() macro to avoid
  an extra PAL call, so remove it.
- Partially fix using mutexes with WITNESS in modules.  Change all the
  _mtx_{un,}lock_{spin,}_flags() macros to accept explicit file and line
  parameters and rename them to use a prefix of two underscores.  Inside
  of kern_mutex.c, generate wrapper functions for
  _mtx_{un,}lock_{spin,}_flags() (only using a prefix of one underscore)
  that are called from modules.  The macros mtx_{un,}lock_{spin,}_flags()
  are mapped to the __mtx_* macros inside of the kernel to inline the
  usual case of mutex operations and map to the internal _mtx_* functions
  in the module case so that modules will use WITNESS and KTR logging if
  the kernel is compiled with support for it.

Revision 1.57: download - view: text, markup, annotated - select for diffs
Fri Mar 9 07:24:17 2001 UTC (10 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.56: preferred, colored
Changes since revision 1.56: +9 -3 lines
Fix mtx_legal2block.  The only time that it is bad to block on a mutex is
if we hold a spin mutex, since we can trivially get into deadlocks if we
start switching out of processes that hold spinlocks.  Checking to see if
interrupts were disabled was a sort of cheap way of doing this since most
of the time interrupts were only disabled when holding a spin lock.  At
least on the i386.  To fix this properly, use a per-process counter
p_spinlocks that counts the number of spin locks currently held, and
instead of checking to see if interrupts are disabled in the witness code,
check to see if we hold any spin locks.  Since child processes always
start up with the sched lock magically held in fork_exit(), we initialize
p_spinlocks to 1 for child processes.  Note that proc0 doesn't go through
fork_exit(), so it starts with no spin locks held.

Consulting from:	cp

Revision 1.56: download - view: text, markup, annotated - select for diffs
Wed Mar 7 02:45:15 2001 UTC (10 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.55: preferred, colored
Changes since revision 1.55: +10 -2 lines
- Add an extra check in priority_propagation() for UP systems to ensure we
  don't end up back at ourselves which would indicate deadlock.
- Add the proc lock to the witness dup_list as we may hold more than one
  process lock at a time.
- Don't assert a mutex is owned in _mtx_unlock_sleep() as that is too late.
  We do the checks in the macros instead.

Revision 1.55: download - view: text, markup, annotated - select for diffs
Wed Feb 28 18:49:09 2001 UTC (10 years, 11 months ago) by julian
Branches: MAIN
Diff to: previous 1.54: preferred, colored
Changes since revision 1.54: +3 -3 lines
Shuffle netgraph mutexes a bit and hold a reference on a node
from the function that is calling the destructor.

Revision 1.54: download - view: text, markup, annotated - select for diffs
Wed Feb 28 02:53:44 2001 UTC (10 years, 11 months ago) by jake
Branches: MAIN
Diff to: previous 1.53: preferred, colored
Changes since revision 1.53: +1 -3 lines
Sigh.  Try to get priorities sorted out.  Don't bother trying to
update native priority, it is diffcult to get right and likely
to end up horribly wrong.  Use an honestly wrong fixed value
that seems to work; PUSER for user threads, and the interrupt
priority for ithreads.  Set it once when the process is created
and forget about it.

Suggested by:	bde
Pointy hat:	me

Revision 1.53: download - view: text, markup, annotated - select for diffs
Mon Feb 26 23:27:35 2001 UTC (10 years, 11 months ago) by jake
Branches: MAIN
Diff to: previous 1.52: preferred, colored
Changes since revision 1.52: +3 -12 lines
Initialize native priority to PRI_MAX.  It was usually 0 which made a
process's priority go through the roof when it released a (contested)
mutex.  Only set the native priority in mtx_lock if hasn't already
been set.

Reviewed by:	jhb

Revision 1.52: download - view: text, markup, annotated - select for diffs
Sun Feb 25 16:18:13 2001 UTC (10 years, 11 months ago) by jake
Branches: MAIN
Diff to: previous 1.51: preferred, colored
Changes since revision 1.51: +11 -11 lines
Remove brackets around variables in a function that used to be
a macro.

Revision 1.51: download - view: text, markup, annotated - select for diffs
Sun Feb 25 04:56:23 2001 UTC (10 years, 11 months ago) by julian
Branches: MAIN
Diff to: previous 1.50: preferred, colored
Changes since revision 1.50: +3 -3 lines
Move netgraph spimlock order entries out of
the #ifdef SMP section. They need to be there for UP too.

Revision 1.50: download - view: text, markup, annotated - select for diffs
Sat Feb 24 21:29:32 2001 UTC (10 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.49: preferred, colored
Changes since revision 1.49: +2 -2 lines
Grrr, s/INVARIANTS_SUPPORT/INVARIANT_SUPPORT/.

Revision 1.49: download - view: text, markup, annotated - select for diffs
Sat Feb 24 19:36:13 2001 UTC (10 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.48: preferred, colored
Changes since revision 1.48: +13 -14 lines
- Axe RETIP() as it was very i386 specific and unwieldy.  Instead, use the
  passed in filename and line number in the KTR tracepoint message.
- Even though it is #if 0'd code, change the code to detect that a process
  is an interrupt thread to check p->p_ithd against NULL rather than
  checking non-existant process flags from BSD/OS.
- Use '%p' to print pointers in KTR log messages instead of assuming
  sizeof(int) == sizeof(void *).
- Don't set p_mtxname to NULL when releasing a mutex.  It doesn't hurt
  to leave it set (we don't clear w_mesg for example) and at least at
  one time in the past, there used to be race conditions in the kernel
  that would result in setting this to NULL causing the kernel to
  dereference NULL.
- Make the _mtx_assert() function be compiled in if INVARIANTS_SUPPORT is
  defined rather than if INVARIANTS is defined so that a KLD compiled
  with INVARIANTS that uses mtx_assert() can be used with a kernel that
  just has INVARIANT_SUPPORT compiled in.

Revision 1.48: download - view: text, markup, annotated - select for diffs
Sat Feb 24 14:29:41 2001 UTC (10 years, 11 months ago) by julian
Branches: MAIN
Diff to: previous 1.47: preferred, colored
Changes since revision 1.47: +3 -1 lines
Add knowledge of the netgraph spinlocks into the Witness code.
Well, at least I think that's how it's done.

Revision 1.47: download - view: text, markup, annotated - select for diffs
Thu Feb 22 02:12:54 2001 UTC (10 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.46: preferred, colored
Changes since revision 1.46: +4 -4 lines
- Use the NOCPU constant.
- Move the ithread spin locks before sched lock and clk in preparation for
  future commits to the ithread code.

Revision 1.46: download - view: text, markup, annotated - select for diffs
Mon Feb 12 03:15:41 2001 UTC (10 years, 11 months ago) by bmilekic
Branches: MAIN
Diff to: previous 1.45: preferred, colored
Changes since revision 1.45: +11 -11 lines
Change all instances of `CURPROC' and `CURTHD' to `curproc,' in order
to stay consistent.

Requested by: bde

Revision 1.45: download - view: text, markup, annotated - select for diffs
Mon Feb 12 00:20:06 2001 UTC (10 years, 11 months ago) by jake
Branches: MAIN
Diff to: previous 1.44: preferred, colored
Changes since revision 1.44: +17 -42 lines
Implement a unified run queue and adjust priority levels accordingly.

- All processes go into the same array of queues, with different
  scheduling classes using different portions of the array.  This
  allows user processes to have their priorities propogated up into
  interrupt thread range if need be.
- I chose 64 run queues as an arbitrary number that is greater than
  32.  We used to have 4 separate arrays of 32 queues each, so this
  may not be optimal.  The new run queue code was written with this
  in mind; changing the number of run queues only requires changing
  constants in runq.h and adjusting the priority levels.
- The new run queue code takes the run queue as a parameter.  This
  is intended to be used to create per-cpu run queues.  Implement
  wrappers for compatibility with the old interface which pass in
  the global run queue structure.
- Group the priority level, user priority, native priority (before
  propogation) and the scheduling class into a struct priority.
- Change any hard coded priority levels that I found to use
  symbolic constants (TTIPRI and TTOPRI).
- Remove the curpriority global variable and use that of curproc.
  This was used to detect when a process' priority had lowered and
  it should yield.  We now effectively yield on every interrupt.
- Activate propogate_priority().  It should now have the desired
  effect without needing to also propogate the scheduling class.
- Temporarily comment out the call to vm_page_zero_idle() in the
  idle loop.  It interfered with propogate_priority() because
  the idle process needed to do a non-blocking acquire of Giant
  and then other processes would try to propogate their priority
  onto it.  The idle process should not do anything except idle.
  vm_page_zero_idle() will return in the form of an idle priority
  kernel thread which is woken up at apprioriate times by the vm
  system.
- Update struct kinfo_proc to the new priority interface.  Deliberately
  change its size by adjusting the spare fields.  It remained the same
  size, but the layout has changed, so userland processes that use it
  would parse the data incorrectly.  The size constraint should really
  be changed to an arbitrary version number.  Also add a debug.sizeof
  sysctl node for struct kinfo_proc.

Revision 1.44: download - view: text, markup, annotated - select for diffs
Sun Feb 11 02:54:13 2001 UTC (11 years ago) by bmilekic
Branches: MAIN
Diff to: previous 1.43: preferred, colored
Changes since revision 1.43: +20 -15 lines
- Place back STR string declarations for lock/unlock strings used for KTR_LOCK
  tracing in order to avoid duplication.
- Insert some tracepoints back into the mutex acq/rel code, thus ensuring
  that we can trace all lock acq/rel's again.
- All CURPROC != NULL checks are MPASS()es (under MUTEX_DEBUG) because they
  signify a serious mutex corruption.
- Change up some KASSERT()s to MPASS()es, and vice-versa, depending on the
  type of problem we're debugging (INVARIANTS is used here to check that
  the API is being used properly whereas MUTEX_DEBUG is used to ensure that
  something general isn't happening that will have bad impact on mutex
  locks).

Reminded by: jhb, jake, asmodai

Revision 1.43: download - view: text, markup, annotated - select for diffs
Fri Feb 9 20:52:02 2001 UTC (11 years ago) by jhb
Branches: MAIN
Diff to: previous 1.42: preferred, colored
Changes since revision 1.42: +3 -3 lines
Unify the two sleep lock order lists to enforce the process lock ->
uidinfo lock locking order.

Revision 1.42: download - view: text, markup, annotated - select for diffs
Fri Feb 9 15:19:41 2001 UTC (11 years ago) by jhb
Branches: MAIN
Diff to: previous 1.41: preferred, colored
Changes since revision 1.41: +60 -19 lines
- Change the 'witness_list' ddb command to 'show mutexes'.  Note that this
  will only display sleep mutexes held by the current process.
- Clean up some nits in the witness_display() function and add a ddb
  command 'show witness' that dumps the hierarchy and order lists to the
  console.
- Use queue(3) macros where appropriate.
- Resort the spin lock order list so that "com" is before "sched_lock".
  Also, add appropriate #ifdef's around SMP and i386-specific mutexes.
- Add two new mutexes used to protect the ithread lists and tables to the
  order list.

Requested by:	bde (1)

Revision 1.41: download - view: text, markup, annotated - select for diffs
Fri Feb 9 06:09:50 2001 UTC (11 years ago) by bmilekic
Branches: MAIN
Diff to: previous 1.40: preferred, colored
Changes since revision 1.40: +399 -543 lines
Change and clean the mutex lock interface.

mtx_enter(lock, type) becomes:

mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)

similarily, for releasing a lock, we now have:

mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.

The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.

Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:

MTX_QUIET and MTX_NOSWITCH

The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:

mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.

Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.

Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.

Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.

Finally, caught up to the interface changes in all sys code.

Contributors: jake, jhb, jasone (in no particular order)

Revision 1.40: download - view: text, markup, annotated - select for diffs
Sat Jan 27 07:51:34 2001 UTC (11 years ago) by jhb
Branches: MAIN
Diff to: previous 1.39: preferred, colored
Changes since revision 1.39: +11 -1 lines
Add a new ddb command 'witness_list' that lists the mutexes held by
curproc.

Requested by:	peter

Revision 1.39: download - view: text, markup, annotated - select for diffs
Wed Jan 24 12:35:50 2001 UTC (11 years ago) by jasone
Branches: MAIN
Diff to: previous 1.38: preferred, colored
Changes since revision 1.38: +7 -1 lines
Convert all simplelocks to mutexes and remove the simplelock implementations.

Revision 1.38: download - view: text, markup, annotated - select for diffs
Wed Jan 24 10:57:01 2001 UTC (11 years ago) by jhb
Branches: MAIN
Diff to: previous 1.37: preferred, colored
Changes since revision 1.37: +77 -85 lines
- Don't use a union and fun tricks to shave one extra pointer off of struct
  mtx right now as it makes debugging harder.  When we are in optimizing
  mode, we can revisit this.
- Fix the KTR trace messages to use %p rather than 0x%p to avoid duplicate
  0x's in KTR output.
- During witness_fixup, release Giant so that witness doesn't get confused.
  Also, grab all_mtx while walking the list of mutexes.
- Remove w_sleep and w_recurse.  Instead, perform checks on mutexes using
  the mutex's mtx_flags field.
- Allow debug.witness_ddb and debug.witness_skipspin to be set from the
  loader.
- Add Giant to the front of existing order_list entries to help ensure
  Giant is always first.
- Add an order entry for the various proc locks.  Note that this only
  helps keep proc in order mostly as the allproc and proctree mutexes are
  only obtained during a lockmgr operation on the specified mutex.

Revision 1.37: download - view: text, markup, annotated - select for diffs
Mon Jan 22 05:56:55 2001 UTC (11 years ago) by jasone
Branches: MAIN
Diff to: previous 1.36: preferred, colored
Changes since revision 1.36: +7 -7 lines
Print correct file name and line number in mtx_assert().

Noticed by:	jake

Revision 1.36: download - view: text, markup, annotated - select for diffs
Sun Jan 21 22:34:42 2001 UTC (11 years ago) by jasone
Branches: MAIN
Diff to: previous 1.35: preferred, colored
Changes since revision 1.35: +389 -76 lines
Move most of sys/mutex.h into kern/kern_mutex.c, thereby making the mutex
inline functions non-inlined.  Hide parts of the mutex implementation that
should not be exposed.

Make sure that WITNESS code is not executed during boot until the mutexes
are fully initialized by SI_SUB_MUTEX (the original motivation for this
commit).

Submitted by:	peter

Revision 1.35: download - view: text, markup, annotated - select for diffs
Sun Jan 21 11:05:02 2001 UTC (11 years ago) by jasone
Branches: MAIN
Diff to: previous 1.34: preferred, colored
Changes since revision 1.34: +3 -3 lines
Make the order of the static initializer for all_mtx match the order of
fields in struct mtx.

Found by:	jake

Revision 1.34: download - view: text, markup, annotated - select for diffs
Sun Jan 21 07:52:18 2001 UTC (11 years ago) by jasone
Branches: MAIN
Diff to: previous 1.33: preferred, colored
Changes since revision 1.33: +82 -30 lines
Remove MUTEX_DECLARE() and MTX_COLD.  Instead, postpone full mutex
initialization until after malloc() is safe to call, then iterate through
all mutexes and complete their initialization.

This change is necessary in order to avoid some circular bootstrapping
dependencies.

Revision 1.33: download - view: text, markup, annotated - select for diffs
Sat Jan 20 02:30:58 2001 UTC (11 years ago) by jake
Branches: MAIN
Diff to: previous 1.32: preferred, colored
Changes since revision 1.32: +1 -21 lines
- Make npx_intr INTR_MPSAFE and move acquiring Giant into the
  function itself.
- Remove a hack to allow acquiring Giant from the npx asm trap
  vector.

Revision 1.32: download - view: text, markup, annotated - select for diffs
Fri Jan 19 01:58:51 2001 UTC (11 years ago) by bmilekic
Branches: MAIN
Diff to: previous 1.31: preferred, colored
Changes since revision 1.31: +56 -21 lines
Implement MTX_RECURSE flag for mtx_init().
All calls to mtx_init() for mutexes that recurse must now include
the MTX_RECURSE bit in the flag argument variable. This change is in
preparation for an upcoming (further) mutex API cleanup.
The witness code will call panic() if a lock is found to recurse but
the MTX_RECURSE bit was not set during the lock's initialization.

The old MTX_RECURSE "state" bit (in mtx_lock) has been renamed to
MTX_RECURSED, which is more appropriate given its meaning.

The following locks have been made "recursive," thus far:
eventhandler, Giant, callout, sched_lock, possibly some others declared
in the architecture-specific code, all of the network card driver locks
in pci/, as well as some other locks in dev/ stuff that I've found to
be recursive.

Reviewed by: jhb

Revision 1.31: download - view: text, markup, annotated - select for diffs
Wed Jan 10 04:43:49 2001 UTC (11 years, 1 month ago) by jake
Branches: MAIN
Diff to: previous 1.30: preferred, colored
Changes since revision 1.30: +6 -4 lines
Use PCPU_GET, PCPU_PTR and PCPU_SET to access all per-cpu variables
other then curproc.

Revision 1.30: download - view: text, markup, annotated - select for diffs
Wed Dec 13 21:53:41 2000 UTC (11 years, 1 month ago) by jhb
Branches: MAIN
Diff to: previous 1.29: preferred, colored
Changes since revision 1.29: +66 -41 lines
- Add a new flag MTX_QUIET that can be passed to the various mtx_*
  functions.  If this flag is set, then no KTR log messages are issued.
  This is useful for blocking excessive logging, such as with the internal
  mutex used by the witness code.
- Use MTX_QUIET on all of the mtx_enter/exit operations on the internal
  mutex used by the witness code.
- If we are in a panic, don't do witness checks in witness_enter(),
  witness_exit(), and witness_try_enter(), just return.

Revision 1.29: download - view: text, markup, annotated - select for diffs
Tue Dec 12 01:14:31 2000 UTC (11 years, 2 months ago) by jake
Branches: MAIN
Diff to: previous 1.28: preferred, colored
Changes since revision 1.28: +7 -2 lines
- Add code to detect if a system call returns with locks other than Giant
  held and panic if so (conditional on witness).
- Change witness_list to return the number of locks held so this is easier.
- Add kern/syscalls.c to the kernel build if witness is defined so that the
  panic message can contain the name of the offending system call.
- Add assertions that Giant and sched_lock are not held when returning from
  a system call, which were missing for alpha and ia64.

Revision 1.28: download - view: text, markup, annotated - select for diffs
Tue Dec 12 00:37:18 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.27: preferred, colored
Changes since revision 1.27: +2 -2 lines
Oops, the witness mutex is a spin lock, so use MTX_SPIN in the call to
mtx_init().  Since the witness code ignores its internal mutex, this
doesn't result in any functional change.

Revision 1.27: download - view: text, markup, annotated - select for diffs
Fri Dec 8 21:50:32 2000 UTC (11 years, 2 months ago) by dwmalone
Branches: MAIN
Diff to: previous 1.26: preferred, colored
Changes since revision 1.26: +3 -3 lines
Convert more malloc+bzero to malloc+M_ZERO.

Submitted by:	josh@zipperup.org
Submitted by:	Robert Drehmel <robd@gmx.net>

Revision 1.26: download - view: text, markup, annotated - select for diffs
Fri Dec 1 00:10:59 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.25: preferred, colored
Changes since revision 1.25: +13 -10 lines
Split the WITNESS and MUTEX_DEBUG options apart so that WITNESS does not
depend on MUTEX_DEBUG.  The MUTEX_DEBUG option turns on extra assertions
and checks to verify that mutexes themselves are implemented properly.
The WITNESS option uses extra checks and diagnostics to verify that other
code is using mutexes properly.

Revision 1.25: download - view: text, markup, annotated - select for diffs
Thu Nov 30 00:51:16 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.24: preferred, colored
Changes since revision 1.24: +61 -25 lines
Fix up priority propagation:
- Use a better test for determining when a process is running.
- Convert some checks to assertions.
- Remove unnecessary tests.
- Save the priority before acquiring a mutex rather than in msleep(9).

Revision 1.24: download - view: text, markup, annotated - select for diffs
Wed Nov 29 20:17:15 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.23: preferred, colored
Changes since revision 1.23: +3 -1 lines
Set p_mtxname when blocking on a mutex and clear it when waking up.

Revision 1.23: download - view: text, markup, annotated - select for diffs
Wed Nov 29 18:41:19 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.22: preferred, colored
Changes since revision 1.22: +3 -2 lines
Use an atomic operation with an appropriate memory barrier when releasing
a contested sleep mutex in the case that at least two processes are blocked
on the contested mutex.

Revision 1.22: download - view: text, markup, annotated - select for diffs
Wed Nov 29 18:38:14 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.21: preferred, colored
Changes since revision 1.21: +2 -2 lines
The sched_lock mutex goes after the sio mutex in the locking order since
a software interrupt can be scheduled in the sio interrupt handler while
the sio mutex is held.

Revision 1.21: download - view: text, markup, annotated - select for diffs
Wed Nov 29 18:37:01 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.20: preferred, colored
Changes since revision 1.20: +9 -1 lines
Save the line number and filename of the last mtx_enter operation for
spin locks.  We already do this for sleep locks.

Revision 1.20: download - view: text, markup, annotated - select for diffs
Sun Nov 26 21:14:17 2000 UTC (11 years, 2 months ago) by alfred
Branches: MAIN
Diff to: previous 1.19: preferred, colored
Changes since revision 1.19: +7 -2 lines
Move the #define of _KERN_MUTEX_C_ so that it's before any system headers
are included.  System headers can include sys/mutex.h and then certain
macros do not get defined.

Reviewed by: jake

Revision 1.19: download - view: text, markup, annotated - select for diffs
Sun Nov 26 15:05:46 2000 UTC (11 years, 2 months ago) by jake
Branches: MAIN
Diff to: previous 1.18: preferred, colored
Changes since revision 1.18: +2 -1 lines
Add uidinfo hash and uidinfo struct to the witness order list.

Revision 1.18: download - view: text, markup, annotated - select for diffs
Sun Nov 19 06:02:29 2000 UTC (11 years, 2 months ago) by jake
Branches: MAIN
Diff to: previous 1.17: preferred, colored
Changes since revision 1.17: +2 -1 lines
- Protect the callout wheel with a separate spin mutex, callout_lock.
- Use the mutex in hardclock to ensure no races between it and
  softclock.
- Make softclock be INTR_MPSAFE and provide a flag,
  CALLOUT_MPSAFE, which specifies that a callout handler does not
  need giant.  There is still no way to set this flag when
  regstering a callout.

Reviewed by:	-smp@, jlemon

Revision 1.17: download - view: text, markup, annotated - select for diffs
Fri Nov 17 18:09:14 2000 UTC (11 years, 2 months ago) by jake
Branches: MAIN
Diff to: previous 1.16: preferred, colored
Changes since revision 1.16: +2 -1 lines
- Split the run queue and sleep queue linkage, so that a process
may block on a mutex while on the sleep queue without corrupting
it.
- Move dropping of Giant to after the acquire of sched_lock.

Tested by:	John Hay <jhay@icomtek.csir.co.za>
		jhb

Revision 1.16: download - view: text, markup, annotated - select for diffs
Thu Nov 16 02:16:44 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.15: preferred, colored
Changes since revision 1.15: +5 -40 lines
Don't release and acquire Giant in mi_switch().  Instead, release and
acquire Giant as needed in functions that call mi_switch().  The releases
need to be done outside of the sched_lock to avoid potential deadlocks
from trying to acquire Giant while interrupts are disabled.

Submitted by:	witness

Revision 1.15: download - view: text, markup, annotated - select for diffs
Wed Nov 15 22:08:16 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.14: preferred, colored
Changes since revision 1.14: +4 -1 lines
Include the right headers to get the DDB #define and the db_active variable.

Revision 1.14: download - view: text, markup, annotated - select for diffs
Wed Nov 15 22:01:56 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.13: preferred, colored
Changes since revision 1.13: +1 -5 lines
Declare the 'witness_spin_check' properly as a per-CPU variable in the
non-SMP case.

Revision 1.13: download - view: text, markup, annotated - select for diffs
Wed Nov 15 22:00:31 2000 UTC (11 years, 2 months ago) by jhb
Branches: MAIN
Diff to: previous 1.12: preferred, colored
Changes since revision 1.12: +2 -2 lines
Don't perform witness checks in witness_enter() during a panic.

Revision 1.12: download - view: text, markup, annotated - select for diffs
Fri Nov 10 21:21:20 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.11: preferred, colored
Changes since revision 1.11: +2 -2 lines
Minor whitespace nit in a comment.

Revision 1.11: download - view: text, markup, annotated - select for diffs
Fri Oct 27 02:59:30 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.10: preferred, colored
Changes since revision 1.10: +39 -57 lines
- Use MUTEX_DECLARE() and MTX_COLD for the WITNESS code's internal mutex so
  it can function before malloc(9) is up and running.
- Add two new options WITNESS_DDB and WITNESS_SKIPSPIN.  If WITNESS_SKIPSPIN
  is enabled, then spin mutexes are ignored by the WITNESS code.  If
  WITNESS_DDB is turned on and DDB is compiled into the kernel, then the
  kernel will drop into DDB when either a lock hierarchy violation occurs
  or mutexes are held when going to sleep.
- Add some new sysctls:
  debug.witness_ddb is a read-write sysctl that corresponds to WITNESS_DDB.
     The kernel option merely changes the default value to on at boot.
  debug.witness_skipspin is a read-only sysctl that one can use to determine
     if the kernel was compiled with WITNESS_SKIPSPIN.
- Wipe out the BSD/OS-specific lock order lists.  We get to build our own
  lists now as we add mutexes to the kernel.

Revision 1.10: download - view: text, markup, annotated - select for diffs
Wed Oct 25 04:37:54 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.9: preferred, colored
Changes since revision 1.9: +4 -4 lines
Quite some warnings.

Revision 1.9: download - view: text, markup, annotated - select for diffs
Fri Oct 20 22:45:01 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.8: preferred, colored
Changes since revision 1.8: +4 -4 lines
Propogate the 'const'ness of mutex descriptions to the witness code to
quiet warnings.

Revision 1.8: download - view: text, markup, annotated - select for diffs
Fri Oct 20 21:58:11 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.7: preferred, colored
Changes since revision 1.7: +2 -6 lines
Actually enable the witness code if the WITNESS kernel option is enabled.

Revision 1.7: download - view: text, markup, annotated - select for diffs
Fri Oct 20 20:24:40 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.6: preferred, colored
Changes since revision 1.6: +2 -2 lines
Doh.  Fix a 64-bit-ism by using uintptr_t for a temporary lock variable
instead of int.

Revision 1.6: download - view: text, markup, annotated - select for diffs
Fri Oct 20 07:26:30 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.5: preferred, colored
Changes since revision 1.5: +596 -11 lines
- Make the mutex code almost completely machine independent.  This greatly
  reducues the maintenance load for the mutex code.  The only MD portions
  of the mutex code are in machine/mutex.h now, which include the assembly
  macros for handling mutexes as well as optionally overriding the mutex
  micro-operations.  For example, we use optimized micro-ops on the x86
  platform #ifndef I386_CPU.
- Change the behavior of the SMP_DEBUG kernel option.  In the new code,
  mtx_assert() only depends on INVARIANTS, allowing other kernel developers
  to have working mutex assertiions without having to include all of the
  mutex debugging code.  The SMP_DEBUG kernel option has been renamed to
  MUTEX_DEBUG and now just controls extra mutex debugging code.
- Abolish the ugly mtx_f hack.  Instead, we dynamically allocate
  seperate mtx_debug structures on the fly in mtx_init, except for mutexes
  that are initiated very early in the boot process.   These mutexes
  are declared using a special MUTEX_DECLARE() macro, and use a new
  flag MTX_COLD when calling mtx_init.  This is still somewhat hackish,
  but it is less evil than the mtx_f filler struct, and the mtx struct is
  now the same size with and without mutex debugging code.
- Add some micro-micro-operation macros for doing the actual atomic
  operations on the mutex mtx_lock field to make it easier for other archs
  to override/optimize mutex ops if needed.  These new tiny ops also clean
  up the code in some places by replacing long atomic operation function
  calls that spanned 2-3 lines with a short 1-line macro call.
- Don't call mi_switch() from mtx_enter_hard() when we block while trying
  to obtain a sleep mutex.  Calling mi_switch() would bogusly release
  Giant before switching to the next process.  Instead, inline most of the
  code from mi_switch() in the mtx_enter_hard() function.  Note that when
  we finally kill Giant we can back this out and go back to calling
  mi_switch().

Revision 1.5: download - view: text, markup, annotated - select for diffs
Thu Sep 14 20:15:15 2000 UTC (11 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.4: preferred, colored
Changes since revision 1.4: +64 -63 lines
Remove the mtx_t, witness_t, and witness_blessed_t types.  Instead, just
use struct mtx, struct witness, and struct witness_blessed.

Requested by:	bde

Revision 1.4: download - view: text, markup, annotated - select for diffs
Sat Sep 9 23:18:48 2000 UTC (11 years, 5 months ago) by jasone
Branches: MAIN
Diff to: previous 1.3: preferred, colored
Changes since revision 1.3: +7 -9 lines
Style cleanups.  No functional changes.

Revision 1.3: download - view: text, markup, annotated - select for diffs
Sat Sep 9 22:43:22 2000 UTC (11 years, 5 months ago) by jasone
Branches: MAIN
Diff to: previous 1.2: preferred, colored
Changes since revision 1.2: +4 -4 lines
Add file and line arguments to WITNESS_ENTER() and WITNESS_EXIT, since
__FILE__ and __LINE__ don't get expanded usefully in inline functions.

Add const to all witness*() arguments that are filenames.

Revision 1.2: download - view: text, markup, annotated - select for diffs
Fri Sep 8 21:48:06 2000 UTC (11 years, 5 months ago) by jasone
Branches: MAIN
Diff to: previous 1.1: preferred, colored
Changes since revision 1.1: +5 -5 lines
Rename mtx_enter(), mtx_try_enter(), and mtx_exit() and wrap them with cpp
macros that expand to pass filename and line number information.  This is
necessary since we're using inline functions instead of macros now.

Add const to the filename pointers passed througout the mtx and witness
code.

Revision 1.1: download - view: text, markup, annotated - select for diffs
Thu Sep 7 01:32:51 2000 UTC (11 years, 5 months ago) by jasone
Branches: MAIN
Major update to the way synchronization is done in the kernel.  Highlights
include:

* Mutual exclusion is used instead of spl*().  See mutex(9).  (Note: The
  alpha port is still in transition and currently uses both.)

* Per-CPU idle processes.

* Interrupts are run in their own separate kernel threads and can be
  preempted (i386 only).

Partially contributed by:	BSDi (BSD/OS)
Submissions by (at least):	cp, dfr, dillon, grog, jake, jhb, sheldonh

Diff request

This form allows you to request diffs between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.

Log view options