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

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

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

Request diff between arbitrary revisions


Keyword substitution: kv
Default branch: MAIN


Revision 1.161: download - view: text, markup, annotated - select for diffs
Sun Dec 11 21:02:01 2011 UTC (8 weeks, 4 days ago) by avg
Branches: MAIN
CVS tags: HEAD
Diff to: previous 1.160: preferred, colored
Changes since revision 1.160: +3 -0 lines
SVN rev 228424 on 2011-12-11 21:02:01Z by avg

panic: add a switch and infrastructure for stopping other CPUs in SMP case

Historical behavior of letting other CPUs merily go on is a default for
time being.  The new behavior can be switched on via
kern.stop_scheduler_on_panic tunable and sysctl.

Stopping of the CPUs has (at least) the following benefits:
- more of the system state at panic time is preserved intact
- threads and interrupts do not interfere with dumping of the system
  state

Only one thread runs uninterrupted after panic if stop_scheduler_on_panic
is set.  That thread might call code that is also used in normal context
and that code might use locks to prevent concurrent execution of certain
parts.  Those locks might be held by the stopped threads and would never
be released.  To work around this issue, it was decided that instead of
explicit checks for panic context, we would rather put those checks
inside the locking primitives.

This change has substantial portions written and re-written by attilio
and kib at various times.  Other changes are heavily based on the ideas
and patches submitted by jhb and mdf.  bde has provided many insights
into the details and history of the current code.

The new behavior may cause problems for systems that use a USB keyboard
for interfacing with system console.  This is because of some unusual
locking patterns in the ukbd code which have to be used because on one
hand ukbd is below syscons, but on the other hand it has to interface
with other usb code that uses regular mutexes/Giant for its concurrency
protection.  Dumping to USB-connected disks may also be affected.

PR:			amd64/139614 (at least)
In cooperation with:	attilio, jhb, kib, mdf
Discussed with:		arch@, bde
Tested by:		Eugene Grosbein <eugen@grosbein.net>,
			gnn,
			Steven Hartland <killing@multiplay.co.uk>,
			glebius,
			Andrew Boyer <aboyer@averesystems.com>
			(various versions of the patch)
MFC after:		3 months (or never)

Revision 1.160: download - view: text, markup, annotated - select for diffs
Wed Nov 16 21:51:17 2011 UTC (2 months, 3 weeks ago) by pjd
Branches: MAIN
Diff to: previous 1.159: preferred, colored
Changes since revision 1.159: +15 -14 lines
SVN rev 227588 on 2011-11-16 21:51:17Z by pjd

Constify arguments for locking KPIs where possible.

This enables locking consumers to pass their own structures around as const and
be able to assert locks embedded into those structures.

Reviewed by:	ed, kib, jhb

Revision 1.158.2.2.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.158.2.2: preferred, colored; next MAIN 1.159: preferred, colored
Changes since revision 1.158.2.2: +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.159: download - view: text, markup, annotated - select for diffs
Mon Nov 7 15:43:11 2011 UTC (3 months ago) by ed
Branches: MAIN
Diff to: previous 1.158: preferred, colored
Changes since revision 1.158: +2 -1 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.158.2.2: download - view: text, markup, annotated - select for diffs
Tue Oct 11 13:45:04 2011 UTC (3 months, 4 weeks ago) by attilio
Branches: RELENG_9
CVS tags: RELENG_9_0_BP
Branch point for: RELENG_9_0
Diff to: previous 1.158.2.1: preferred, colored; branchpoint 1.158: preferred, colored; next MAIN 1.159: preferred, colored
Changes since revision 1.158.2.1: +11 -14 lines
SVN rev 226255 on 2011-10-11 13:45:04Z by attilio

Adaptive spinning for locking primitives, in read-mode, have some tuning
SYSCTLs which are inappropriate for a daily use of the machine (mostly
useful only by a developer which wants to run benchmarks on it).
Remove them before the release as long as we do not want to ship with
them in.

Now that the SYSCTLs are gone, instead than use static storage for some
constants, use real numeric constants in order to avoid eventual compiler
dumbiness and the risk to share a storage (and then a cache-line) among
CPUs when doing adaptive spinning together.

Please note that this patch is not a MFC, but an 'edge case' as commit
directly to STABLE_9.

Approved by:	re (kib)

Revision 1.158.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
Diff to: previous 1.158: preferred, colored
Changes since revision 1.158: +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.144.2.9: download - view: text, markup, annotated - select for diffs
Mon Aug 8 08:22:15 2011 UTC (6 months ago) by kib
Branches: RELENG_8
Diff to: previous 1.144.2.8: preferred, colored; branchpoint 1.144: preferred, colored; next MAIN 1.145: preferred, colored
Changes since revision 1.144.2.8: +12 -2 lines
SVN rev 224704 on 2011-08-08 08:22:15Z by kib

MFC r224581:
Fix the LK_NOSHARE lockmgr flag interaction with LK_UPGRADE and
LK_DOWNGRADE lock ops. Namely, the ops should be NOP since LK_NOSHARE
locks are always exclusive.

Revision 1.158: download - view: text, markup, annotated - select for diffs
Mon Aug 1 19:07:03 2011 UTC (6 months, 1 week ago) by kib
Branches: MAIN
CVS tags: RELENG_9_BP
Branch point for: RELENG_9
Diff to: previous 1.157: preferred, colored
Changes since revision 1.157: +12 -2 lines
SVN rev 224581 on 2011-08-01 19:07:03Z by kib

Fix the LK_NOSHARE lockmgr flag interaction with LK_UPGRADE and
LK_DOWNGRADE lock ops. Namely, the ops should be NOP since LK_NOSHARE
locks are always exclusive.

Reported by:	rmacklem
Reviewed by:	attilio
Tested by:	pho
Approved by:	re (kensmith)
MFC after:	1 week

Revision 1.144.2.8: download - view: text, markup, annotated - select for diffs
Wed Apr 27 18:00:46 2011 UTC (9 months, 2 weeks ago) by jhb
Branches: RELENG_8
Diff to: previous 1.144.2.7: preferred, colored; branchpoint 1.144: preferred, colored
Changes since revision 1.144.2.7: +0 -1 lines
SVN rev 221125 on 2011-04-27 18:00:46Z by jhb

MFC 217265:
Remove unneeded includes of <sys/linker_set.h>.  Other headers that use
it internally contain nested includes.

Requested by:	hselasky

Revision 1.157: download - view: text, markup, annotated - select for diffs
Fri Feb 25 10:11:01 2011 UTC (11 months, 2 weeks ago) by netchild
Branches: MAIN
Diff to: previous 1.156: preferred, colored
Changes since revision 1.156: +4 -0 lines
SVN rev 219028 on 2011-02-25 10:11:01Z by netchild

Add some FEATURE macros for various features (AUDIT/CAM/IPC/KTR/MAC/NFS/NTP/
PMC/SYSV/...).

No FreeBSD version bump, the userland application to query the features will
be committed last and can serve as an indication of the availablility if
needed.

Sponsored by:   Google Summer of Code 2010
Submitted by:   kibab
Reviewed by:    arch@ (parts by rwatson, trasz, jhb)
X-MFC after:    to be determined in last commit with code from this project

Revision 1.156: download - view: text, markup, annotated - select for diffs
Tue Jan 11 13:59:06 2011 UTC (12 months, 4 weeks ago) by jhb
Branches: MAIN
Diff to: previous 1.155: preferred, colored
Changes since revision 1.155: +0 -1 lines
SVN rev 217265 on 2011-01-11 13:59:06Z by jhb

Remove unneeded includes of <sys/linker_set.h>.  Other headers that use
it internally contain nested includes.

Reviewed by:	bde

Revision 1.110.2.2.2.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.110.2.2: preferred, colored; next MAIN 1.111: preferred, colored
Changes since revision 1.110.2.2: +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.144.2.7.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.144.2.7: preferred, colored; next MAIN 1.144.2.8: preferred, colored
Changes since revision 1.144.2.7: +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.110.2.2: download - view: text, markup, annotated - select for diffs
Fri Aug 20 20:58:57 2010 UTC (17 months, 2 weeks ago) by jhb
Branches: RELENG_7
CVS tags: RELENG_7_4_BP
Branch point for: RELENG_7_4
Diff to: previous 1.110.2.1: preferred, colored; branchpoint 1.110: preferred, colored; next MAIN 1.111: preferred, colored
Changes since revision 1.110.2.1: +34 -0 lines
SVN rev 211533 on 2010-08-20 20:58:57Z by jhb

Revert 210173 as it did not properly fix the bug.  It assumed that the
VI_LOCK() for a given vnode was used as the internal interlock for that
vnode's v_lock lockmgr lock.  This is not the case.  Instead, add dedicated
routines to toggle the LK_NOSHARE and LK_CANRECURSE flags.  These routines
lock the lockmgr lock's internal interlock to synchronize the updates to
the flags member with other threads attempting to acquire the lock.  The
VN_LOCK_A*() macros now invoke these routines, and the softupdates code
uses these routines to temporarly enable recursion on buffer locks.

Reviewed by:	kib

Revision 1.155: download - view: text, markup, annotated - select for diffs
Fri Aug 20 19:46:50 2010 UTC (17 months, 3 weeks ago) by jhb
Branches: MAIN
Diff to: previous 1.154: preferred, colored
Changes since revision 1.154: +28 -0 lines
SVN rev 211531 on 2010-08-20 19:46:50Z by jhb

Add dedicated routines to toggle lockmgr flags such as LK_NOSHARE and
LK_CANRECURSE after a lock is created.  Use them to implement macros that
otherwise manipulated the flags directly.  Assert that the associated
lockmgr lock is exclusively locked by the current thread when manipulating
these flags to ensure the flag updates are safe.  This last change required
some minor shuffling in a few filesystems to exclusively lock a brand new
vnode slightly earlier.

Reviewed by:	kib
MFC after:	3 days

Revision 1.144.2.7.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.144.2.7: preferred, colored; next MAIN 1.144.2.8: preferred, colored
Changes since revision 1.144.2.7: +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.110.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.110.2.1: preferred, colored; next MAIN 1.110.2.2: preferred, colored
Changes since revision 1.110.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.144.2.7: download - view: text, markup, annotated - select for diffs
Mon Jan 18 14:43:44 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.144.2.6: preferred, colored; branchpoint 1.144: preferred, colored
Changes since revision 1.144.2.6: +142 -15 lines
SVN rev 202576 on 2010-01-18 14:43:44Z by attilio

MFC r200447,201703,201709-201710:
In current code, threads performing an interruptible sleep
will leave the waiters flag on forcing the owner to do a wakeup even
when the waiter queue is empty.
That operation may lead to a deadlock in the case of doing a fake wakeup
on the "preferred" queue while the other queue has real waiters on it,
because nobody is going to wakeup the 2nd queue waiters and they will
sleep indefinitively.
A similar bug, is present, for lockmgr in the case the waiters are
sleeping with LK_SLEEPFAIL on.

Add a sleepqueue interface which does report the actual number of waiters
on a specified queue of a waitchannel and track if at least one sleepfail
waiter is present or not. In presence of this or empty "preferred" queue,
wakeup both waiters queues.

Discussed with:	kib
Tested by:	Pete French <petefrench at ticketswitch dot com>,
		Justin Head <justin at encarnate dot com>

Revision 1.154: download - view: text, markup, annotated - select for diffs
Thu Jan 7 01:24:09 2010 UTC (2 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.153: preferred, colored
Changes since revision 1.153: +6 -6 lines
SVN rev 201710 on 2010-01-07 01:24:09Z by attilio

Fix typos.

Revision 1.153: download - view: text, markup, annotated - select for diffs
Thu Jan 7 01:19:01 2010 UTC (2 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.152: preferred, colored
Changes since revision 1.152: +18 -0 lines
SVN rev 201709 on 2010-01-07 01:19:01Z by attilio

Tweak comments.

Revision 1.152: download - view: text, markup, annotated - select for diffs
Thu Jan 7 00:47:50 2010 UTC (2 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.151: preferred, colored
Changes since revision 1.151: +25 -3 lines
SVN rev 201703 on 2010-01-07 00:47:50Z by attilio

Exclusive waiters sleeping with LK_SLEEPFAIL on and using interruptible
sleeps/timeout may have left spourious lk_exslpfail counts on, so clean
it up even when accessing a shared queue acquisition, giving to
lk_exslpfail the value of 'upper limit'.
In the worst case scenario, infact (mixed
interruptible sleep / LK_SLEEPFAIL waiters) what may happen is that both
queues are awaken even if that's not necessary, but still no harm.

Reported by:	Lucius Windschuh <lwindschuh at googlemail dot com>
Reviewed by:	kib
Tested by:	pho, Lucius Windschuh <lwindschuh at googlemail dot com>

Revision 1.151: download - view: text, markup, annotated - select for diffs
Sat Dec 12 21:31:07 2009 UTC (2 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.150: preferred, colored
Changes since revision 1.150: +92 -13 lines
SVN rev 200447 on 2009-12-12 21:31:07Z by attilio

In current code, threads performing an interruptible sleep (on both
sxlock, via the sx_{s, x}lock_sig() interface, or plain lockmgr), will
leave the waiters flag on forcing the owner to do a wakeup even when if
the waiter queue is empty.
That operation may lead to a deadlock in the case of doing a fake wakeup
on the "preferred" (based on the wakeup algorithm) queue while the other
queue has real waiters on it, because nobody is going to wakeup the 2nd
queue waiters and they will sleep indefinitively.

A similar bug, is present, for lockmgr in the case the waiters are
sleeping with LK_SLEEPFAIL on.  In this case, even if the waiters queue
is not empty, the waiters won't progress after being awake but they will
just fail, still not taking care of the 2nd queue waiters (as instead the
lock owned doing the wakeup would expect).

In order to fix this bug in a cheap way (without adding too much locking
and complicating too much the semantic) add a sleepqueue interface which
does report the actual number of waiters on a specified queue of a
waitchannel (sleepq_sleepcnt()) and use it in order to determine if the
exclusive waiters (or shared waiters) are actually present on the lockmgr
(or sx) before to give them precedence in the wakeup algorithm.
This fix alone, however doesn't solve the LK_SLEEPFAIL bug. In order to
cope with it, add the tracking of how many exclusive LK_SLEEPFAIL waiters
a lockmgr has and if all the waiters on the exclusive waiters queue are
LK_SLEEPFAIL just wake both queues.

The sleepq_sleepcnt() introduction and ABI breakage require
__FreeBSD_version bumping.

Reported by:	avg, kib, pho
Reviewed by:	kib
Tested by:	pho

Revision 1.144.2.6: download - view: text, markup, annotated - select for diffs
Sun Nov 22 16:11:20 2009 UTC (2 years, 2 months ago) by attilio
Branches: RELENG_8
Diff to: previous 1.144.2.5: preferred, colored; branchpoint 1.144: preferred, colored
Changes since revision 1.144.2.5: +1 -0 lines
SVN rev 199653 on 2009-11-22 16:11:20Z by attilio

MFC r199008:
Track lockmgr_disown() in the stack.

Revision 1.150: download - view: text, markup, annotated - select for diffs
Fri Nov 6 22:33:03 2009 UTC (2 years, 3 months ago) by attilio
Branches: MAIN
Diff to: previous 1.149: preferred, colored
Changes since revision 1.149: +1 -0 lines
SVN rev 199008 on 2009-11-06 22:33:03Z by attilio

Save the sack when doing a lockmgr_disown() call.

Requested by:	kib
MFC:		3 days

Revision 1.144.2.5.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.144.2.5: preferred, colored; next MAIN 1.144.2.6: preferred, colored
Changes since revision 1.144.2.5: +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.144.2.5: download - view: text, markup, annotated - select for diffs
Mon Oct 12 15:32:00 2009 UTC (2 years, 3 months ago) by attilio
Branches: RELENG_8
CVS tags: RELENG_8_0_BP
Branch point for: RELENG_8_0
Diff to: previous 1.144.2.4: preferred, colored; branchpoint 1.144: preferred, colored
Changes since revision 1.144.2.4: +3 -3 lines
SVN rev 197981 on 2009-10-12 15:32:00Z by attilio

MFC r197643, r197735:
When releasing a read/shared lock we need to use a write memory barrier
in order to avoid, on architectures which doesn't have strong ordered
writes, CPU instructions reordering.

Approved by:	re (kib)

Revision 1.149: download - view: text, markup, annotated - select for diffs
Sat Oct 3 15:02:55 2009 UTC (2 years, 4 months ago) by attilio
Branches: MAIN
Diff to: previous 1.148: preferred, colored
Changes since revision 1.148: +3 -3 lines
SVN rev 197735 on 2009-10-03 15:02:55Z by attilio

When releasing a lockmgr held in shared way we need to use a write memory
barrier in order to avoid, on architectures which doesn't have strong
ordered writes, CPU instructions reordering.

Diagnosed by:	fabio

Revision 1.144.2.4: download - view: text, markup, annotated - select for diffs
Wed Sep 9 09:34:13 2009 UTC (2 years, 5 months ago) by attilio
Branches: RELENG_8
Diff to: previous 1.144.2.3: preferred, colored; branchpoint 1.144: preferred, colored
Changes since revision 1.144.2.3: +11 -14 lines
SVN rev 197024 on 2009-09-09 09:34:13Z by attilio

Adaptive spinning for locking primitives, in read-mode, have some tuning
SYSCTLs which are inappropriate for a daily use of the machine (mostly
useful only by a developer which wants to run benchmarks on it).
Remove them before the release as long as we do not want to ship with
them in.

Now that the SYSCTLs are gone, instead than use static storage for some
constants, use real numeric constants in order to avoid eventual compiler
dumbiness and the risk to share a storage (and then a cache-line) among
CPUs when doing adaptive spinning together.

Pleasse note that the sys/linker_set.h inclusion in lockmgr and sx lock
support could have been gone, but re@ preferred them to be in order to
minimize the risk of problems on future merging.

Please note that this patch is not a MFC, but an 'edge case' as commit
directly to stable/8, which creates a diverging from HEAD.

Tested by:      Giovanni Trematerra <giovanni dot trematerra at gmail dot com>
Approved by:	re (kib)

Revision 1.144.2.3: download - view: text, markup, annotated - select for diffs
Wed Sep 9 09:17:31 2009 UTC (2 years, 5 months ago) by attilio
Branches: RELENG_8
Diff to: previous 1.144.2.2: preferred, colored; branchpoint 1.144: preferred, colored
Changes since revision 1.144.2.2: +11 -2 lines
SVN rev 197023 on 2009-09-09 09:17:31Z by attilio

MFC r196772:
fix adaptive spinning in lockmgr by using correctly GIANT_RESTORE and
continue statement and improve adaptive spinning for sx lock by just
doing once GIANT_SAVE.

Approved by:	re (kib)

Revision 1.148: download - view: text, markup, annotated - select for diffs
Tue Sep 8 13:19:05 2009 UTC (2 years, 5 months ago) by phk
Branches: MAIN
Diff to: previous 1.147: preferred, colored
Changes since revision 1.147: +0 -1 lines
SVN rev 196970 on 2009-09-08 13:19:05Z by phk

Revert previous commit and add myself to the list of people who should
know better than to commit with a cat in the area.

Revision 1.147: download - view: text, markup, annotated - select for diffs
Tue Sep 8 13:16:55 2009 UTC (2 years, 5 months ago) by phk
Branches: MAIN
Diff to: previous 1.146: preferred, colored
Changes since revision 1.146: +1 -0 lines
SVN rev 196969 on 2009-09-08 13:16:55Z by phk

Add necessary include.

Revision 1.146: download - view: text, markup, annotated - select for diffs
Wed Sep 2 17:33:51 2009 UTC (2 years, 5 months ago) by attilio
Branches: MAIN
Diff to: previous 1.145: preferred, colored
Changes since revision 1.145: +11 -2 lines
SVN rev 196772 on 2009-09-02 17:33:51Z by attilio

Fix some bugs related to adaptive spinning:

In the lockmgr support:
- GIANT_RESTORE() is just called when the sleep finishes, so the current
  code can ends up into a giant unlock problem.  Fix it by appropriately
  call GIANT_RESTORE() when needed.  Note that this is not exactly ideal
  because for any interation of the adaptive spinning we drop and restore
  Giant, but the overhead should be not a factor.
- In the lock held in exclusive mode case, after the adaptive spinning is
  brought to completition, we should just retry to acquire the lock
  instead to fallthrough. Fix that.
- Fix a style nit

In the sx support:
- Call GIANT_SAVE() before than looping. This saves some overhead because
  in the current code GIANT_SAVE() is called several times.

Tested by:	Giovanni Trematerra <giovanni dot trematerra at gmail dot com>

Revision 1.144.2.2: download - view: text, markup, annotated - select for diffs
Mon Aug 17 16:33:53 2009 UTC (2 years, 5 months ago) by attilio
Branches: RELENG_8
Diff to: previous 1.144.2.1: preferred, colored; branchpoint 1.144: preferred, colored
Changes since revision 1.144.2.1: +3 -0 lines
SVN rev 196336 on 2009-08-17 16:33:53Z by attilio

MFC r196334:

* Change the scope of the ASSERT_ATOMIC_LOAD() from a generic check to
  a pointer-fetching specific operation check. Consequently, rename the
  operation ASSERT_ATOMIC_LOAD_PTR().
* Fix the implementation of ASSERT_ATOMIC_LOAD_PTR() by checking
  directly alignment on the word boundry, for all the given specific
  architectures. That's a bit too strict for some common case, but it
  assures safety.
* Add a comment explaining the scope of the macro
* Add a new stub in the lockmgr specific implementation

Tested by: marcel (initial version), marius
Reviewed by: rwatson, jhb (comment specific review)
Approved by: re (kib)

Revision 1.145: download - view: text, markup, annotated - select for diffs
Mon Aug 17 16:17:21 2009 UTC (2 years, 5 months ago) by attilio
Branches: MAIN
Diff to: previous 1.144: preferred, colored
Changes since revision 1.144: +3 -0 lines
SVN rev 196334 on 2009-08-17 16:17:21Z by attilio

* Change the scope of the ASSERT_ATOMIC_LOAD() from a generic check to
  a pointer-fetching specific operation check. Consequently, rename the
  operation ASSERT_ATOMIC_LOAD_PTR().
* Fix the implementation of ASSERT_ATOMIC_LOAD_PTR() by checking
  directly alignment on the word boundry, for all the given specific
  architectures. That's a bit too strict for some common case, but it
  assures safety.
* Add a comment explaining the scope of the macro
* Add a new stub in the lockmgr specific implementation

Tested by: marcel (initial version), marius
Reviewed by: rwatson, jhb (comment specific review)
Approved by: re (kib)

Revision 1.144.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
Diff to: previous 1.144: preferred, colored
Changes since revision 1.144: +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.144: download - view: text, markup, annotated - select for diffs
Wed Jun 17 01:55:42 2009 UTC (2 years, 7 months ago) by attilio
Branches: MAIN
CVS tags: RELENG_8_BP
Branch point for: RELENG_8
Diff to: previous 1.143: preferred, colored
Changes since revision 1.143: +204 -18 lines
SVN rev 194317 on 2009-06-17 01:55:42Z by attilio

Introduce support for adaptive spinning in lockmgr.
Actually, as it did receive few tuning, the support is disabled by
default, but it can opt-in with the option ADAPTIVE_LOCKMGRS.
Due to the nature of lockmgrs, adaptive spinning needs to be
selectively enabled for any interested lockmgr.
The support is bi-directional, or, in other ways, it will work in both
cases if the lock is held in read or write way.  In particular, the
read path is passible of further tunning using the sysctls
debug.lockmgr.retries and debug.lockmgr.loops .  Ideally, such sysctls
should be axed or compiled out before release.

Addictionally note that adaptive spinning doesn't cope well with
LK_SLEEPFAIL.  The reason is that many (and probabilly all) consumers
of LK_SLEEPFAIL are mainly interested in knowing if the interlock was
dropped or not in order to reacquire it and re-test initial conditions.
This directly interacts with adaptive spinning because lockmgr needs
to drop the interlock while spinning in order to avoid a deadlock
(further details in the comments inside the patch).

Final note: finding someone willing to help on tuning this with
relevant workloads would be either very important and appreciated.

Tested by:	jeff, pho
Requested by:	many

Revision 1.143: download - view: text, markup, annotated - select for diffs
Tue Jun 2 13:03:35 2009 UTC (2 years, 8 months ago) by attilio
Branches: MAIN
Diff to: previous 1.142: preferred, colored
Changes since revision 1.142: +6 -5 lines
SVN rev 193307 on 2009-06-02 13:03:35Z by attilio

Handle lock recursion differenty by always checking against LO_RECURSABLE
instead the lock own flag itself.

Tested by:	pho

Revision 1.142: download - view: text, markup, annotated - select for diffs
Tue May 26 20:28:22 2009 UTC (2 years, 8 months ago) by sson
Branches: MAIN
Diff to: previous 1.141: preferred, colored
Changes since revision 1.141: +17 -1 lines
SVN rev 192853 on 2009-05-26 20:28:22Z by sson

Add the OpenSolaris dtrace lockstat provider.  The lockstat provider
adds probes for mutexes, reader/writer and shared/exclusive locks to
gather contention statistics and other locking information for
dtrace scripts, the lockstat(1M) command and other potential
consumers.

Reviewed by:	attilio jhb jb
Approved by:	gnn (mentor)

Revision 1.141: download - view: text, markup, annotated - select for diffs
Tue May 12 17:05:40 2009 UTC (2 years, 8 months ago) by trasz
Branches: MAIN
Diff to: previous 1.140: preferred, colored
Changes since revision 1.140: +1 -0 lines
SVN rev 192022 on 2009-05-12 17:05:40Z by trasz

Add missing 'break' statement.

Found with:	Coverity Prevent(tm)
CID:		3919

Revision 1.110.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.110.2.1: preferred, colored; next MAIN 1.110.2.2: preferred, colored
Changes since revision 1.110.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.140: download - view: text, markup, annotated - select for diffs
Sun Mar 15 08:03:54 2009 UTC (2 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.139: preferred, colored
Changes since revision 1.139: +5 -4 lines
SVN rev 189846 on 2009-03-15 08:03:54Z by jeff

 - Wrap lock profiling state variables in #ifdef LOCK_PROFILING blocks.

Revision 1.139: download - view: text, markup, annotated - select for diffs
Sat Mar 14 11:43:02 2009 UTC (2 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.138: preferred, colored
Changes since revision 1.138: +3 -1 lines
SVN rev 189788 on 2009-03-14 11:43:02Z by jeff

 - Call lock_profile_release when we're transitioning a lock to be owned by
   LK_KERNPROC.

Discussed with:		attilio

Revision 1.138: download - view: text, markup, annotated - select for diffs
Fri Feb 6 20:06:48 2009 UTC (3 years ago) by jhb
Branches: MAIN
Diff to: previous 1.137: preferred, colored
Changes since revision 1.137: +3 -3 lines
SVN rev 188244 on 2009-02-06 20:06:48Z by jhb

Tweak the output of VOP_PRINT/vn_printf() some.
- Align the fifo output in fifo_print() with other vn_printf() output.
- Remove the leading space from lockmgr_printinfo() so its output lines up
  in vn_printf().
- lockmgr_printinfo() now ends with a newline, so remove an extra newline
  from vn_printf().

Revision 1.110.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.110.2.1: preferred, colored; next MAIN 1.110.2.2: preferred, colored
Changes since revision 1.110.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.89.2.6.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.89.2.6: preferred, colored; next MAIN 1.90: preferred, colored
Changes since revision 1.89.2.6: +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.137: download - view: text, markup, annotated - select for diffs
Wed Sep 10 19:13:30 2008 UTC (3 years, 5 months ago) by jhb
Branches: MAIN
Diff to: previous 1.136: preferred, colored
Changes since revision 1.136: +3 -3 lines
SVN rev 182914 on 2008-09-10 19:13:30Z by jhb

Teach WITNESS about the interlocks used with lockmgr.  This removes a bunch
of spurious witness warnings since lockmgr grew witness support.  Before
this, every time you passed an interlock to a lockmgr lock WITNESS treated
it as a LOR.

Reviewed by:	attilio

Revision 1.136: download - view: text, markup, annotated - select for diffs
Fri Aug 22 16:14:23 2008 UTC (3 years, 5 months ago) by jhb
Branches: MAIN
Diff to: previous 1.135: preferred, colored
Changes since revision 1.135: +2 -2 lines
SVN rev 182010 on 2008-08-22 16:14:23Z by jhb

Use |= rather than += when aggregrating requests to wakeup the swapper.
What we really want is an inclusive or of all the requests, and += can
in theory roll over to 0.

Revision 1.135: download - view: text, markup, annotated - select for diffs
Tue Aug 5 20:02:31 2008 UTC (3 years, 6 months ago) by jhb
Branches: MAIN
Diff to: previous 1.134: preferred, colored
Changes since revision 1.134: +16 -9 lines
SVN rev 181334 on 2008-08-05 20:02:31Z by jhb

If a thread that is swapped out is made runnable, then the setrunnable()
routine wakes up proc0 so that proc0 can swap the thread back in.
Historically, this has been done by waking up proc0 directly from
setrunnable() itself via a wakeup().  When waking up a sleeping thread
that was swapped out (the usual case when waking proc0 since only sleeping
threads are eligible to be swapped out), this resulted in a bit of
recursion (e.g. wakeup() -> setrunnable() -> wakeup()).

With sleep queues having separate locks in 6.x and later, this caused a
spin lock LOR (sleepq lock -> sched_lock/thread lock -> sleepq lock).
An attempt was made to fix this in 7.0 by making the proc0 wakeup use
the ithread mechanism for doing the wakeup.  However, this required
grabbing proc0's thread lock to perform the wakeup.  If proc0 was asleep
elsewhere in the kernel (e.g. waiting for disk I/O), then this degenerated
into the same LOR since the thread lock would be some other sleepq lock.

Fix this by deferring the wakeup of the swapper until after the sleepq
lock held by the upper layer has been locked.  The setrunnable() routine
now returns a boolean value to indicate whether or not proc0 needs to be
woken up.  The end result is that consumers of the sleepq API such as
*sleep/wakeup, condition variables, sx locks, and lockmgr, have to wakeup
proc0 if they get a non-zero return value from sleepq_abort(),
sleepq_broadcast(), or sleepq_signal().

Discussed with:	jeff
Glanced at by:	sam
Tested by:	Jurgen Weber  jurgen - ish com au
MFC after:	2 weeks

Revision 1.134: download - view: text, markup, annotated - select for diffs
Fri Jul 25 11:22:25 2008 UTC (3 years, 6 months ago) by kib
Branches: MAIN
Diff to: previous 1.133: preferred, colored
Changes since revision 1.133: +5 -5 lines
SVN rev 180798 on 2008-07-25 11:22:25Z by kib

s/alredy/already/ in the comments and the log message.

Revision 1.133: download - view: text, markup, annotated - select for diffs
Sun May 25 16:11:27 2008 UTC (3 years, 8 months ago) by attilio
Branches: MAIN
Diff to: previous 1.132: preferred, colored
Changes since revision 1.132: +1 -1 lines
The "if" semantic is not needed, just fix this.

Revision 1.132: download - view: text, markup, annotated - select for diffs
Sun Apr 13 01:21:56 2008 UTC (3 years, 9 months ago) by attilio
Branches: MAIN
Diff to: previous 1.131: preferred, colored
Changes since revision 1.131: +1 -1 lines
Use a "rel" memory barrier for disowning the lock as it cames from an
exclusive locking operation.

Revision 1.131: download - view: text, markup, annotated - select for diffs
Sat Apr 12 19:57:30 2008 UTC (3 years, 9 months ago) by attilio
Branches: MAIN
Diff to: previous 1.130: preferred, colored
Changes since revision 1.130: +78 -17 lines
- Re-introduce WITNESS support for lockmgr.  About the old implementation
  the only one difference is that lockmgr*() functions now accept
  LK_NOWITNESS flag which skips ordering for the instanced calling.
- Remove an unuseful stub in witness_checkorder() (because the above check
  doesn't allow ever happening) and allow witness_upgrade() to accept
  non-try operation too.

Revision 1.130: download - view: text, markup, annotated - select for diffs
Sat Apr 12 13:56:17 2008 UTC (3 years, 9 months ago) by attilio
Branches: MAIN
Diff to: previous 1.129: preferred, colored
Changes since revision 1.129: +2 -4 lines
- Remove a stale comment.
- Add an extra assertion in order to catch malformed requested operations.

Revision 1.110.2.1: download - view: text, markup, annotated - select for diffs
Thu Apr 10 20:28:02 2008 UTC (3 years, 10 months ago) by rwatson
Branches: RELENG_7
CVS tags: RELENG_7_3_BP, RELENG_7_2_BP, RELENG_7_1_BP
Branch point for: RELENG_7_3, RELENG_7_2, RELENG_7_1
Diff to: previous 1.110: preferred, colored
Changes since revision 1.110: +1 -1 lines
Merge Makefile:1.320, stack.9:1.4, kern_lock.c:1.114, subr_stack.c:1.4,
stack.h:1.3, redzone.c:1.2 from HEAD to RELENG_7:

  Modify stack(9) stack_print() and stack_sbuf_print() routines to use new
  linker interfaces for looking up function names and offsets from
  instruction pointers.  Create two variants of each call: one that is
  "DDB-safe" and avoids locking in the linker, and one that is safe for
  use in live kernels, by virtue of observing locking, and in particular
  safe when kernel modules are being loaded and unloaded simultaneous to
  their use.  This will allow them to be used outside of debugging
  contexts.

  Modify two of three current stack(9) consumers to use the DDB-safe
  interfaces, as they run in low-level debugging contexts, such as inside
  lockmgr(9) and the kernel memory allocator.

  Update man page.

Revision 1.129: download - view: text, markup, annotated - select for diffs
Mon Apr 7 14:46:38 2008 UTC (3 years, 10 months ago) by attilio
Branches: MAIN
Diff to: previous 1.128: preferred, colored
Changes since revision 1.128: +1 -1 lines
- Use a different encoding for lockmgr options: make them encoded by
  bit in order to allow per-bit checks on the options flag, in particular
  in the consumers code [1]
- Re-enable the check against TDP_DEADLKTREAT as the anti-waiters
  starvation patch allows exclusive waiters to override new shared
  requests.

[1] Requested by:	pjd, jeff

Revision 1.128: download - view: text, markup, annotated - select for diffs
Sun Apr 6 20:08:50 2008 UTC (3 years, 10 months ago) by attilio
Branches: MAIN
Diff to: previous 1.127: preferred, colored
Changes since revision 1.127: +809 -627 lines
Optimize lockmgr in order to get rid of the pool mutex interlock, of the
state transitioning flags and of msleep(9) callings.
Use, instead, an algorithm very similar to what sx(9) and rwlock(9)
alredy do and direct accesses to the sleepqueue(9) primitive.

In order to avoid writer starvation a mechanism very similar to what
rwlock(9) uses now is implemented, with the correspective per-thread
shared lockmgrs counter.

This patch also adds 2 new functions to lockmgr KPI: lockmgr_rw() and
lockmgr_args_rw().  These two are like the 2 "normal" versions, but they
both accept a rwlock as interlock.  In order to realize this, the general
lockmgr manager function "__lockmgr_args()" has been implemented through
the generic lock layer. It supports all the blocking primitives, but
currently only these 2 mappers live.

The patch drops the support for WITNESS atm, but it will be probabilly
added soon. Also, there is a little race in the draining code which is
also present in the current CVS stock implementation: if some sharers,
once they wakeup, are in the runqueue they can contend the lock with
the exclusive drainer.  This is hard to be fixed but the now committed
code mitigate this issue a lot better than the (past) CVS version.
In addition assertive KA_HELD and KA_UNHELD have been made mute
assertions because they are dangerous and they will be nomore supported
soon.

In order to avoid namespace pollution, stack.h is splitted into two
parts: one which includes only the "struct stack" definition (_stack.h)
and one defining the KPI.  In this way, newly added _lockmgr.h can
just include _stack.h.

Kernel ABI results heavilly changed by this commit (the now committed
version of "struct lock" is a lot smaller than the previous one) and
KPI results broken by lockmgr_rw() / lockmgr_args_rw() introduction,
so manpages and __FreeBSD_version will be updated accordingly.

Tested by:      kris, pho, jeff, danger
Reviewed by:    jeff
Sponsored by:   Google, Summer of Code program 2007

Revision 1.127: download - view: text, markup, annotated - select for diffs
Sat Mar 1 19:47:49 2008 UTC (3 years, 11 months ago) by attilio
Branches: MAIN
Diff to: previous 1.126: preferred, colored
Changes since revision 1.126: +8 -18 lines
- Handle buffer lock waiters count directly in the buffer cache instead
  than rely on the lockmgr support [1]:
  * bump the waiters only if the interlock is held
  * let brelvp() return the waiters count
  * rely on brelvp() instead than BUF_LOCKWAITERS() in order to check
    for the waiters number
- Remove a namespace pollution introduced recently with lockmgr.h
  including lock.h by including lock.h directly in the consumers and
  making it mandatory for using lockmgr.
- Modify flags accepted by lockinit():
  * introduce LK_NOPROFILE which disables lock profiling for the
    specified lockmgr
  * introduce LK_QUIET which disables ktr tracing for the specified
    lockmgr [2]
  * disallow LK_SLEEPFAIL and LK_NOWAIT to be passed there so that it
    can only be used on a per-instance basis
- Remove BUF_LOCKWAITERS() and lockwaiters() as they are no longer
  used

This patch breaks KPI so __FreBSD_version will be bumped and manpages
updated by further commits. Additively, 'struct buf' changes results in
a disturbed ABI also.

[2] Really, currently there is no ktr tracing in the lockmgr, but it
will be added soon.

[1] Submitted by:	kib
Tested by:	pho, Andrea Barberio <insomniac at slackware dot it>

Revision 1.126: download - view: text, markup, annotated - select for diffs
Mon Feb 25 18:45:56 2008 UTC (3 years, 11 months ago) by attilio
Branches: MAIN
Diff to: previous 1.125: preferred, colored
Changes since revision 1.125: +2 -5 lines
Axe the 'thread' argument from VOP_ISLOCKED() and lockstatus() as it is
always curthread.

As KPI gets broken by this patch, manpages and __FreeBSD_version will be
updated by further commits.

Tested by:	Andrea Barberio <insomniac at slackware dot it>

Revision 1.125: download - view: text, markup, annotated - select for diffs
Fri Feb 15 21:04:36 2008 UTC (3 years, 11 months ago) by attilio
Branches: MAIN
Diff to: previous 1.124: preferred, colored
Changes since revision 1.124: +44 -24 lines
- Introduce lockmgr_args() in the lockmgr space.  This function performs
  the same operation of lockmgr() but accepting a custom wmesg, prio and
  timo for the particular lock instance, overriding default values
  lkp->lk_wmesg, lkp->lk_prio and lkp->lk_timo.
- Use lockmgr_args() in order to implement BUF_TIMELOCK()
- Cleanup BUF_LOCK()
- Remove LK_INTERNAL as it is nomore used in the lockmgr namespace

Tested by:	Andrea Barberio <insomniac at slackware dot it>

Revision 1.124: download - view: text, markup, annotated - select for diffs
Wed Feb 13 20:44:18 2008 UTC (3 years, 11 months ago) by attilio
Branches: MAIN
Diff to: previous 1.123: preferred, colored
Changes since revision 1.123: +117 -28 lines
- Add real assertions to lockmgr locking primitives.
  A couple of notes for this:
  * WITNESS support, when enabled, is only used for shared locks in order
    to avoid problems with the "disowned" locks
  * KA_HELD and KA_UNHELD only exists in the lockmgr namespace in order
    to assert for a generic thread (not curthread) owning or not the
    lock.  Really, this kind of check is bogus but it seems very
    widespread in the consumers code.  So, for the moment, we cater this
    untrusted behaviour, until the consumers are not fixed and the
    options could be removed (hopefully during 8.0-CURRENT lifecycle)
  * Implementing KA_HELD and KA_UNHELD (not surported natively by
    WITNESS) made necessary the introduction of LA_MASKASSERT which
    specifies the range for default lock assertion flags
  * About other aspects, lockmgr_assert() follows exactly what other
    locking primitives offer about this operation.

- Build real assertions for buffer cache locks on the top of
  lockmgr_assert().  They can be used with the BUF_ASSERT_*(bp)
  paradigm.

- Add checks at lock destruction time and use a cookie for verifying
  lock integrity at any operation.

- Redefine BUF_LOCKFREE() in order to not use a direct assert but
  let it rely on the aforementioned destruction time check.

KPI results evidently broken, so __FreeBSD_version bumping and
manpage update result necessary and will be committed soon.

Side note: lockmgr_assert() will be used soon in order to implement
real assertions in the vnode namespace replacing the legacy and still
bogus "VOP_ISLOCKED()" way.

Tested by:      kris (earlier version)
Reviewed by:    jhb

Revision 1.123: download - view: text, markup, annotated - select for diffs
Fri Feb 8 21:45:46 2008 UTC (4 years ago) by attilio
Branches: MAIN
Diff to: previous 1.122: preferred, colored
Changes since revision 1.122: +2 -2 lines
Conver all explicit instances to VOP_ISLOCKED(arg, NULL) into
VOP_ISLOCKED(arg, curthread). Now, VOP_ISLOCKED() and lockstatus() should
only acquire curthread as argument; this will lead in axing the additional
argument from both functions, making the code cleaner.

Reviewed by: jeff, kib

Revision 1.122: download - view: text, markup, annotated - select for diffs
Wed Feb 6 13:26:01 2008 UTC (4 years ago) by attilio
Branches: MAIN
Diff to: previous 1.121: preferred, colored
Changes since revision 1.121: +1 -1 lines
td cannot be NULL in that place, so just axe out the check.

Revision 1.121: download - view: text, markup, annotated - select for diffs
Wed Feb 6 00:37:14 2008 UTC (4 years ago) by attilio
Branches: MAIN
Diff to: previous 1.120: preferred, colored
Changes since revision 1.120: +46 -11 lines
Add WITNESS support to lockmgr locking primitive.
This support tries to be as parallel as possible with other locking
primitives, but there are differences; more specifically:
- The base witness support is alredy equipped for allowing lock
  duplication acquisition as lockmgr rely on this.
- In the case of lockmgr_disown() the lock result unlocked by witness
  even if it is still held by the "kernel context"
- In the case of upgrading we can have 3 different situations:
  * Total unlocking of the shared lock and nothing else
  * Real witness upgrade if the owner is the first upgrader
  * Shared unlocking and exclusive locking if the owner is not the first
    upgrade but it is still allowed to upgrade
- LK_DRAIN is basically handled like an exclusive acquisition

Additively new options LK_NODUP and LK_NOWITNESS can now be used with
lockinit(): LK_NOWITNESS disables WITNESS for the specified lock while
LK_NODUP enable duplicated locks tracking. This will require manpages
update and a __FreeBSD_version bumping (addressed by further commits).

This patch also fixes a problem occurring if a lockmgr is held in
exclusive mode and the same owner try to acquire it in shared mode:
currently there is a spourious shared locking acquisition while what
we really want is a lock downgrade. Probabilly, this situation can be
better served with a EDEADLK failing errno return.

Side note: first testing on this patch alredy reveleated several LORs
reported, so please expect LORs cascades until resolved. NTFS also is
reported broken by WITNESS introduction. BTW, NTFS is exposing a lock
leak which needs to be fixed, and this patch can help it out if
rightly tweaked.

Tested by: kris, yar, Scot Hetzel <swhetzel at gmail dot com>

Revision 1.120: download - view: text, markup, annotated - select for diffs
Thu Jan 24 12:34:28 2008 UTC (4 years ago) by attilio
Branches: MAIN
Diff to: previous 1.119: preferred, colored
Changes since revision 1.119: +7 -24 lines
Cleanup lockmgr interface and exported KPI:
- Remove the "thread" argument from the lockmgr() function as it is
  always curthread now
- Axe lockcount() function as it is no longer used
- Axe LOCKMGR_ASSERT() as it is bogus really and no currently used.
  Hopefully this will be soonly replaced by something suitable for it.
- Remove the prototype for dumplockinfo() as the function is no longer
  present

Addictionally:
- Introduce a KASSERT() in lockstatus() in order to let it accept only
  curthread or NULL as they should only be passed
- Do a little bit of style(9) cleanup on lockmgr.h

KPI results heavilly broken by this change, so manpages and
FreeBSD_version will be modified accordingly by further commits.

Tested by: matteo

Revision 1.119: download - view: text, markup, annotated - select for diffs
Fri Jan 11 16:38:12 2008 UTC (4 years ago) by attilio
Branches: MAIN
Diff to: previous 1.118: preferred, colored
Changes since revision 1.118: +6 -3 lines
lockmgr() function will return successfully when trying to work under
panic but it won't actually lock anything.
This can lead some paths to reach lockmgr_disown() with inconsistent
lock which will let trigger the relative assertions.

Fix those in order to recognize panic situation and to not trigger.

Reported by: pho
Submitted by: kib

Revision 1.118: download - view: text, markup, annotated - select for diffs
Wed Jan 9 00:02:43 2008 UTC (4 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.117: preferred, colored
Changes since revision 1.117: +2 -2 lines
Fix a last second typo about recent lockmgr_disown() introduction.

Revision 1.117: download - view: text, markup, annotated - select for diffs
Tue Jan 8 23:48:31 2008 UTC (4 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.116: preferred, colored
Changes since revision 1.116: +42 -23 lines
Remove explicit calling of lockmgr() with the NULL argument.
Now, lockmgr() function can only be called passing curthread and the
KASSERT() is upgraded according with this.

In order to support on-the-fly owner switching, the new function
lockmgr_disown() has been introduced and gets used in BUF_KERNPROC().
KPI, so, results changed and FreeBSD version will be bumped soon.
Differently from previous code, we assume idle thread cannot try to
acquire the lockmgr as it cannot sleep, so loose the relative check[1]
in BUF_KERNPROC().

Tested by: kris

[1] kib asked for a KASSERT in the lockmgr_disown() about this
condition, but after thinking at it, as this is a well known general
rule, I found it not really necessary.

Revision 1.116: download - view: text, markup, annotated - select for diffs
Fri Dec 28 00:38:13 2007 UTC (4 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.115: preferred, colored
Changes since revision 1.115: +0 -13 lines
Trimm out now unused option LK_EXCLUPGRADE from the lockmgr namespace.
This option just adds complexity and the new implementation no longer
will support it, so axing it now that it is unused is probabilly the
better idea.

FreeBSD version is bumped in order to reflect the KPI breakage introduced
by this patch.

In the ports tree, kris found that only old OSKit code uses it, but as
it is thought to work only on 2.x kernels serie, version bumping will
solve any problem.

Revision 1.115: download - view: text, markup, annotated - select for diffs
Thu Dec 27 22:56:57 2007 UTC (4 years, 1 month ago) by attilio
Branches: MAIN
Diff to: previous 1.114: preferred, colored
Changes since revision 1.114: +9 -1 lines
In order to avoid a huge class of deadlocks (in particular in interactions
with the interlock), owner of the lock should be only curthread or at
least, for its limited usage, NULL which identifies LK_KERNPROC.

The thread "extra argument" for the lockmgr interface is going to be
removed in the near future, but for the moment, just let kernel run for
some days with this check on in order to find potential deadlocking
places around the kernel and fix them.

Revision 1.114: download - view: text, markup, annotated - select for diffs
Sat Dec 1 22:04:15 2007 UTC (4 years, 2 months ago) by rwatson
Branches: MAIN
Diff to: previous 1.113: preferred, colored
Changes since revision 1.113: +1 -1 lines
Modify stack(9) stack_print() and stack_sbuf_print() routines to use new
linker interfaces for looking up function names and offsets from
instruction pointers.  Create two variants of each call: one that is
"DDB-safe" and avoids locking in the linker, and one that is safe for
use in live kernels, by virtue of observing locking, and in particular
safe when kernel modules are being loaded and unloaded simultaneous to
their use.  This will allow them to be used outside of debugging
contexts.

Modify two of three current stack(9) consumers to use the DDB-safe
interfaces, as they run in low-level debugging contexts, such as inside
lockmgr(9) and the kernel memory allocator.

Update man page.

Revision 1.113: download - view: text, markup, annotated - select for diffs
Sat Nov 24 04:22:27 2007 UTC (4 years, 2 months ago) by attilio
Branches: MAIN
Diff to: previous 1.112: preferred, colored
Changes since revision 1.112: +0 -28 lines
transferlockers() is a very dangerous and hack-ish function as waiters
should never be moved by one lock to another.
As, luckily, nothing in our tree is using it, axe the function.

This breaks lockmgr KPI, so interested, third-party modules should update
their source code with appropriate replacement.

Ok'ed by: ups, rwatson
MFC after: 3 days

Revision 1.112: download - view: text, markup, annotated - select for diffs
Sun Nov 18 14:43:52 2007 UTC (4 years, 2 months ago) by attilio
Branches: MAIN
Diff to: previous 1.111: preferred, colored
Changes since revision 1.111: +9 -0 lines
Expand lock class with the "virtual" function lc_assert which will offer
an unified way for all the lock primitives to express lock assertions.
Currenty, lockmgrs and rmlocks don't have assertions, so just panic in
that case.
This will be a base for more callout improvements.

Ok'ed by: jhb, jeff

Revision 1.111: download - view: text, markup, annotated - select for diffs
Wed Nov 14 06:21:22 2007 UTC (4 years, 2 months ago) by julian
Branches: MAIN
Diff to: previous 1.110: preferred, colored
Changes since revision 1.110: +1 -1 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.110: download - view: text, markup, annotated - select for diffs
Fri May 18 15:04:59 2007 UTC (4 years, 8 months ago) by jhb
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.109: preferred, colored
Changes since revision 1.109: +1 -2 lines
Move lock_profile_object_{init,destroy}() into lock_{init,destroy}().

Revision 1.109: download - view: text, markup, annotated - select for diffs
Fri Mar 30 18:07:24 2007 UTC (4 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.108: preferred, colored
Changes since revision 1.108: +11 -7 lines
- Use lock_init/lock_destroy() to setup the lock_object inside of lockmgr.
  We can now use LOCK_CLASS() as a stronger check in lockmgr_chain() as a
  result.  This required putting back lk_flags as lockmgr's use of flags
  conflicted with other flags in lo_flags otherwise.
- Tweak 'show lock' output for lockmgr to match sx, rw, and mtx.

Revision 1.89.2.6: download - view: text, markup, annotated - select for diffs
Wed Mar 28 16:58:23 2007 UTC (4 years, 10 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.89.2.5: preferred, colored; branchpoint 1.89: preferred, colored; next MAIN 1.90: preferred, colored
Changes since revision 1.89.2.5: +15 -2 lines
MFC: Handle the case when a thread is blocked on a lockmgr lock with
LK_DRAIN in DDB's 'show sleepchain'.

Revision 1.108: download - view: text, markup, annotated - select for diffs
Wed Mar 21 21:20:50 2007 UTC (4 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.107: preferred, colored
Changes since revision 1.107: +1 -1 lines
Rename the 'mtx_object', 'rw_object', and 'sx_object' members of mutexes,
rwlocks, and sx locks to 'lock_object'.

Revision 1.107: download - view: text, markup, annotated - select for diffs
Wed Mar 21 19:28:20 2007 UTC (4 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.106: preferred, colored
Changes since revision 1.106: +15 -2 lines
Handle the case when a thread is blocked on a lockmgr lock with LK_DRAIN
in DDB's 'show sleepchain'.

MFC after:	3 days

Revision 1.106: download - view: text, markup, annotated - select for diffs
Fri Mar 9 16:27:11 2007 UTC (4 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.105: preferred, colored
Changes since revision 1.105: +19 -3 lines
Add two new function pointers 'lc_lock' and 'lc_unlock' to lock classes.
These functions are intended to be used to drop a lock and then reacquire
it when doing an sleep such as msleep(9).  Both functions accept a
'struct lock_object *' as their first parameter.  The 'lc_unlock' function
returns an integer that is then passed as the second paramter to the
subsequent 'lc_lock' function.  This can be used to communicate state.
For example, sx locks and rwlocks use this to indicate if the lock was
share/read locked vs exclusive/write locked.

Currently, spin mutexes and lockmgr locks do not provide working lc_lock
and lc_unlock functions.

Revision 1.105: download - view: text, markup, annotated - select for diffs
Fri Mar 9 16:19:34 2007 UTC (4 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.104: preferred, colored
Changes since revision 1.104: +3 -3 lines
Use C99-style struct member initialization for lock classes.

Revision 1.104: download - view: text, markup, annotated - select for diffs
Mon Feb 26 08:26:43 2007 UTC (4 years, 11 months ago) by kmacy
Branches: MAIN
Diff to: previous 1.103: preferred, colored
Changes since revision 1.103: +16 -13 lines
general LOCK_PROFILING cleanup

- only collect timestamps when a lock is contested - this reduces the overhead
  of collecting profiles from 20x to 5x

- remove unused function from subr_lock.c

- generalize cnt_hold and cnt_lock statistics to be kept for all locks

- NOTE: rwlock profiling generates invalid statistics (and most likely always has)
  someone familiar with that should review

Revision 1.103: download - view: text, markup, annotated - select for diffs
Mon Nov 13 05:41:46 2006 UTC (5 years, 2 months ago) by kmacy
Branches: MAIN
Diff to: previous 1.102: preferred, colored
Changes since revision 1.102: +15 -7 lines
track lock class name in a way that doesn't break WITNESS

Revision 1.102: download - view: text, markup, annotated - select for diffs
Sun Nov 12 03:30:01 2006 UTC (5 years, 2 months ago) by kmacy
Branches: MAIN
Diff to: previous 1.101: preferred, colored
Changes since revision 1.101: +2 -0 lines
show lock class in profiling output for default case where type is not specified when initializing the lock

Approved by: scottl (standing in for mentor rwatson)

Revision 1.101: download - view: text, markup, annotated - select for diffs
Sat Nov 11 03:18:06 2006 UTC (5 years, 3 months ago) by kmacy
Branches: MAIN
Diff to: previous 1.100: preferred, colored
Changes since revision 1.100: +19 -5 lines
MUTEX_PROFILING has been generalized to LOCK_PROFILING. We now profile
wait (time waited to acquire) and hold times for *all* kernel locks. If
the architecture has a system synchronized TSC, the profiling code will
use that - thereby minimizing profiling overhead. Large chunks of profiling
code have been moved out of line, the overhead measured on the T1 for when
it is compiled in but not enabled is < 1%.

Approved by: scottl (standing in for mentor rwatson)
Reviewed by: des and jhb

Revision 1.89.2.5: download - view: text, markup, annotated - select for diffs
Mon Oct 9 20:04:45 2006 UTC (5 years, 4 months ago) by tegge
Branches: RELENG_6
CVS tags: RELENG_6_2_BP, RELENG_6_2_0_RELEASE, RELENG_6_2
Diff to: previous 1.89.2.4: preferred, colored; branchpoint 1.89: preferred, colored
Changes since revision 1.89.2.4: +15 -0 lines
MFC: If the buffer lock has waiters after the buffer has changed identity
     then getnewbuf() needs to drop the buffer in order to wake waiters that
     might sleep on the buffer in the context of the old identity.

Approved by:	re (kensmith)

Revision 1.100: download - view: text, markup, annotated - select for diffs
Mon Oct 2 02:06:26 2006 UTC (5 years, 4 months ago) by tegge
Branches: MAIN
Diff to: previous 1.99: preferred, colored
Changes since revision 1.99: +15 -0 lines
If the buffer lock has waiters after the buffer has changed identity then
getnewbuf() needs to drop the buffer in order to wake waiters that might
sleep on the buffer in the context of the old identity.

Revision 1.89.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
Diff to: previous 1.89.2.3: preferred, colored; branchpoint 1.89: preferred, colored
Changes since revision 1.89.2.3: +60 -0 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.99: 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.98: preferred, colored
Changes since revision 1.98: +28 -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.98: download - view: text, markup, annotated - select for diffs
Tue Aug 15 16:42:16 2006 UTC (5 years, 5 months ago) by jhb
Branches: MAIN
Diff to: previous 1.97: preferred, colored
Changes since revision 1.97: +32 -0 lines
Add a 'show lockmgr' command that dumps the relevant details of a lockmgr
lock.

Revision 1.97: download - view: text, markup, annotated - select for diffs
Fri Jul 14 17:55:36 2006 UTC (5 years, 6 months ago) by pjd
Branches: MAIN
Diff to: previous 1.96: preferred, colored
Changes since revision 1.96: +0 -1 lines
Remove duplicated #include.

Revision 1.89.2.3: download - view: text, markup, annotated - select for diffs
Mon Mar 13 03:05:50 2006 UTC (5 years, 11 months ago) by jeff
Branches: RELENG_6
CVS tags: RELENG_6_1_BP, RELENG_6_1_0_RELEASE, RELENG_6_1
Diff to: previous 1.89.2.2: preferred, colored; branchpoint 1.89: preferred, colored
Changes since revision 1.89.2.2: +17 -34 lines
MFC Revs 1.96, 1.91, 1.90
VFS SMP fixes, stack api, softupdates fixes.

Sponsored by:	Isilon Systems, Inc.
Approved by:	re (scottl)

Revision 1.96: download - view: text, markup, annotated - select for diffs
Fri Dec 23 21:32:40 2005 UTC (6 years, 1 month ago) by jeff
Branches: MAIN
Diff to: previous 1.95: preferred, colored
Changes since revision 1.95: +0 -1 lines
 - Remove and unused include.

Submitted by:	Antoine Brodin <antoine.brodin@laposte.net>

Revision 1.74.2.4: download - view: text, markup, annotated - select for diffs
Sun Oct 2 10:11:31 2005 UTC (6 years, 4 months ago) by rwatson
Branches: RELENG_5
CVS tags: RELENG_5_5_BP, RELENG_5_5_0_RELEASE, RELENG_5_5
Diff to: previous 1.74.2.3: preferred, colored; branchpoint 1.74: preferred, colored; next MAIN 1.75: preferred, colored
Changes since revision 1.74.2.3: +9 -2 lines
Merge kern_lock.c:1.94, 1.95 from HEAD to RELENG_5:

  In lockstatus(), don't lock and unlock the interlock when testing the
  sleep lock status while kdb_active, or we risk contending with the
  mutex on another CPU, resulting in a panic when using "show
  lockedvnods" while in DDB.

  Reviewed by:    jhb
  Reported by:    kris

Revision 1.89.2.2: download - view: text, markup, annotated - select for diffs
Sun Oct 2 10:08:29 2005 UTC (6 years, 4 months ago) by rwatson
Branches: RELENG_6
CVS tags: RELENG_6_0_BP, RELENG_6_0_0_RELEASE, RELENG_6_0
Diff to: previous 1.89.2.1: preferred, colored; branchpoint 1.89: preferred, colored
Changes since revision 1.89.2.1: +1 -0 lines
Merge kern_lock.c:1.95 from HEAD to RELENG_6:

  Include kdb.h so that kdb_active is declared regardless of KDB being
  included in the kernel.

Approved by:	re (kensmith)

Revision 1.95: download - view: text, markup, annotated - select for diffs
Sun Oct 2 10:03:51 2005 UTC (6 years, 4 months ago) by rwatson
Branches: MAIN
Diff to: previous 1.94: preferred, colored
Changes since revision 1.94: +1 -0 lines
Include kdb.h so that kdb_active is declared regardless of KDB being
included in the kernel.

MFC after:	0 days

Revision 1.89.2.1: download - view: text, markup, annotated - select for diffs
Sun Oct 2 09:58:54 2005 UTC (6 years, 4 months ago) by rwatson
Branches: RELENG_6
Diff to: previous 1.89: preferred, colored
Changes since revision 1.89: +8 -2 lines
Merge kern_lock.c:1.94 from HEAD to RELENG_6:

  In lockstatus(), don't lock and unlock the interlock when testing the
  sleep lock status while kdb_active, or we risk contending with the
  mutex on another CPU, resulting in a panic when using "show
  lockedvnods" while in DDB.

  Reviewed by:    jhb
  Reported by:    kris

Approved by:	re (scottl)

Revision 1.94: download - view: text, markup, annotated - select for diffs
Tue Sep 27 21:02:59 2005 UTC (6 years, 4 months ago) by rwatson
Branches: MAIN
Diff to: previous 1.93: preferred, colored
Changes since revision 1.93: +8 -2 lines
In lockstatus(), don't lock and unlock the interlock when testing the
sleep lock status while kdb_active, or we risk contending with the
mutex on another CPU, resulting in a panic when using "show
lockedvnods" while in DDB.

MFC after:	3 days
Reviewed by:	jhb
Reported by:	kris

Revision 1.93: download - view: text, markup, annotated - select for diffs
Fri Sep 2 15:56:01 2005 UTC (6 years, 5 months ago) by ssouhlal
Branches: MAIN
Diff to: previous 1.92: preferred, colored
Changes since revision 1.92: +7 -0 lines
Print out a warning and a backtrace if we try to unlock a lockmgr that
we do not hold.

Glanced at by:	phk
MFC after:	3 days

Revision 1.92: download - view: text, markup, annotated - select for diffs
Mon Aug 29 11:34:07 2005 UTC (6 years, 5 months ago) by pjd
Branches: MAIN
Diff to: previous 1.91: preferred, colored
Changes since revision 1.91: +1 -1 lines
Add 'depth' argument to CTRSTACK() macro, which allows to reduce number
of ktr slots used. If 'depth' is equal to 0, the whole stack will be
logged, just like before.

Revision 1.91: download - view: text, markup, annotated - select for diffs
Wed Aug 3 04:59:07 2005 UTC (6 years, 6 months ago) by jeff
Branches: MAIN
Diff to: previous 1.90: preferred, colored
Changes since revision 1.90: +8 -5 lines
 - Fix a problem that slipped through review; the stack member of the lockmgr
   structure should have the lk_ prefix.
 - Add stack_print(lkp->lk_stack) to the information printed with
   lockmgr_printinfo().

Revision 1.90: download - view: text, markup, annotated - select for diffs
Wed Aug 3 04:48:21 2005 UTC (6 years, 6 months ago) by jeff
Branches: MAIN
Diff to: previous 1.89: preferred, colored
Changes since revision 1.89: +15 -34 lines
 - Replace the series of DEBUG_LOCKS hacks which tried to save the vn_lock
   caller by saving the stack of the last locker/unlocker in lockmgr.  We
   also put the stack in KTR at the moment.

Contributed by:		Antoine Brodin <antoine.brodin@laposte.net>

Revision 1.89: download - view: text, markup, annotated - select for diffs
Tue Apr 12 05:43:03 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
CVS tags: RELENG_6_BP
Branch point for: RELENG_6
Diff to: previous 1.88: preferred, colored
Changes since revision 1.88: +3 -1 lines
 - Differentiate two UPGRADE panics so I have a better idea of what's going
   on here.

Revision 1.88: download - view: text, markup, annotated - select for diffs
Wed Apr 6 10:11:14 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.87: preferred, colored
Changes since revision 1.87: +2 -26 lines
 - Remove dead code.

Revision 1.87: download - view: text, markup, annotated - select for diffs
Sun Apr 3 11:49:02 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.86: preferred, colored
Changes since revision 1.86: +14 -18 lines
 - Slightly restructure acquire() so I can add more ktr information and
   an assert to help find two strange bugs.
 - Remove some nearby spls.

Revision 1.86: download - view: text, markup, annotated - select for diffs
Thu Mar 31 05:18:19 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.85: preferred, colored
Changes since revision 1.85: +5 -1 lines
 - Add a LK_NOSHARE flag which forces all shared lock requests to be
   treated as exclusive lock requests.

Sponsored by:	Isilon Systems, Inc.

Revision 1.85: download - view: text, markup, annotated - select for diffs
Thu Mar 31 04:25:59 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.84: preferred, colored
Changes since revision 1.84: +0 -40 lines
 - Remove apause().  It makes no sense with our present mutex implementation
   since simply unlocking a mutex does not ensure that one of the waiters
   will run and acquire it.  We're more likely to reacquire the mutex
   before anyone else has a chance.  It has also bit me three times now, as
   it's not safe to drop the interlock before sleeping in many cases.

Sponsored by:	Isilon Systems, Inc.

Revision 1.84: download - view: text, markup, annotated - select for diffs
Mon Mar 28 12:52:10 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.83: preferred, colored
Changes since revision 1.83: +0 -2 lines
 - Don't bump the count twice in the LK_DRAIN case.

Sponsored by:	Isilon Systems, Inc.

Revision 1.83: download - view: text, markup, annotated - select for diffs
Fri Mar 25 00:00:44 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.82: preferred, colored
Changes since revision 1.82: +19 -17 lines
 - Restore COUNT() in all of its original glory.  Don't make it dependent
   on DEBUG as ufs will soon grow a dependency on this count.

Discussed with:	bde
Sponsored by:	Isilon Systems, Inc.

Revision 1.82: download - view: text, markup, annotated - select for diffs
Thu Mar 24 09:35:06 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.81: preferred, colored
Changes since revision 1.81: +11 -0 lines
 - Complete the implementation of td_locks.  Track the number of outstanding
   lockmgr locks that this thread owns.  This is complicated due to
   LK_KERNPROC and because lockmgr tolerates unlocking an unlocked lock.

Sponsored by:	Isilon Systes, Inc.

Revision 1.81: download - view: text, markup, annotated - select for diffs
Tue Mar 15 09:27:45 2005 UTC (6 years, 10 months ago) by jeff
Branches: MAIN
Diff to: previous 1.80: preferred, colored
Changes since revision 1.80: +8 -2 lines
 - transferlockers() requires the interlock to be SMP safe.

Sponsored by:	Isilon Systems, Inc.

Revision 1.74.2.3: download - view: text, markup, annotated - select for diffs
Mon Jan 31 23:26:16 2005 UTC (7 years ago) by imp
Branches: RELENG_5
CVS tags: RELENG_5_4_BP, RELENG_5_4_0_RELEASE, RELENG_5_4
Diff to: previous 1.74.2.2: preferred, colored; branchpoint 1.74: preferred, colored
Changes since revision 1.74.2.2: +1 -1 lines
MFC: /*- and related license changes

Revision 1.80: download - view: text, markup, annotated - select for diffs
Tue Jan 25 16:06:05 2005 UTC (7 years ago) by jeff
Branches: MAIN
Diff to: previous 1.79: preferred, colored
Changes since revision 1.79: +1 -1 lines
 - Include LK_INTERLOCK in LK_EXTFLG_MASK so that it makes its way into
   acquire.
 - Correct the condition that causes us to skip apause() to only require
   the presence of LK_INTERLOCK.

Sponsored by:	Isilon Systems, Inc.

Revision 1.79: download - view: text, markup, annotated - select for diffs
Mon Jan 24 10:20:59 2005 UTC (7 years ago) by jeff
Branches: MAIN
Diff to: previous 1.78: preferred, colored
Changes since revision 1.78: +19 -10 lines
 - Do not use APAUSE if LK_INTERLOCK is set.  We lose synchronization
   if the lockmgr interlock is dropped after the caller's interlock
   is dropped.
 - Change some lockmgr KTRs to be slightly more helpful.

Sponsored By:	Isilon Systems, Inc.

Revision 1.78: download - view: text, markup, annotated - select for diffs
Thu Jan 6 23:35:39 2005 UTC (7 years, 1 month ago) by imp
Branches: MAIN
Diff to: previous 1.77: preferred, colored
Changes since revision 1.77: +1 -1 lines
/* -> /*- for copyright notices, minor format tweaks as necessary

Revision 1.77: download - view: text, markup, annotated - select for diffs
Mon Nov 29 22:58:32 2004 UTC (7 years, 2 months ago) by ps
Branches: MAIN
Diff to: previous 1.76: preferred, colored
Changes since revision 1.76: +2 -3 lines
When upgrading the shared lock to an exclusive lock, if we discover
that the exclusive lock is already held, then we call panic. Don't
clobber internal lock state before panic'ing. This change improves
debugging if this case were to happen.

Submitted by:	Mohan Srinivasan mohans at yahoo-inc dot com
Reviewed by:	rwatson

Revision 1.74.2.2: download - view: text, markup, annotated - select for diffs
Fri Sep 3 15:45:31 2004 UTC (7 years, 5 months ago) by kan
Branches: RELENG_5
CVS tags: RELENG_5_3_BP, RELENG_5_3_0_RELEASE, RELENG_5_3
Diff to: previous 1.74.2.1: preferred, colored; branchpoint 1.74: preferred, colored
Changes since revision 1.74.2.1: +11 -4 lines
MFC r1.76:
  Reintroduce slightly modified patch from kern/69964.
  Check for LK_HAVE_EXL in both acquire invocations.

Approved by:	re (scottl)

Revision 1.76: download - view: text, markup, annotated - select for diffs
Fri Aug 27 01:41:28 2004 UTC (7 years, 5 months ago) by kan
Branches: MAIN
Diff to: previous 1.75: preferred, colored
Changes since revision 1.75: +11 -4 lines
Reintroduce slightly modified patch from kern/69964. Check for
LK_HAVE_EXL in both acquire invocations.

MFC after:	5 days

Revision 1.74.2.1: download - view: text, markup, annotated - select for diffs
Thu Aug 26 00:00:18 2004 UTC (7 years, 5 months ago) by kan
Branches: RELENG_5
Diff to: previous 1.74: preferred, colored
Changes since revision 1.74: +5 -12 lines
Back out rev. 1.74. A better fix is available and will be MFCed later
once properly tested in -current.

Approved by:	re (scottl, kensmith)

Revision 1.75: download - view: text, markup, annotated - select for diffs
Mon Aug 23 02:39:45 2004 UTC (7 years, 5 months ago) by kan
Branches: MAIN
Diff to: previous 1.74: preferred, colored
Changes since revision 1.74: +5 -12 lines
Temporarily back out r1.74 as it seems to cause a number of regressions
accordimg to numerous reports. It  might get reintroduced some time later
when an exact failure mode is understood better.

Revision 1.74: download - view: text, markup, annotated - select for diffs
Mon Aug 16 15:01:22 2004 UTC (7 years, 5 months ago) by kan
Branches: MAIN
CVS tags: RELENG_5_BP
Branch point for: RELENG_5
Diff to: previous 1.73: preferred, colored
Changes since revision 1.73: +12 -5 lines
Upgrading a lock does not play well together with acquiring an exclusive lock
and can lead to two threads being granted exclusive access. Check that no one
has the same lock in exclusive  mode before proceeding to acquire it.

The LK_WANT_EXCL and LK_WANT_UPGRADE bits act as mini-locks and can block
other threads.  Normally this is not a problem since the mini locks are
upgraded to full locks and the release of the locks will unblock the other
threads.  However if a thread reset the bits without obtaining a full lock
other threads are not awoken. Add missing wakeups for these cases.

PR:		kern/69964
Submitted by:	Stephan Uphoff <ups at tree dot com>
Very good catch by: Stephan Uphoff <ups at tree dot com>

Revision 1.73: download - view: text, markup, annotated - select for diffs
Fri Jul 23 20:12:56 2004 UTC (7 years, 6 months ago) by rwatson
Branches: MAIN
Diff to: previous 1.72: preferred, colored
Changes since revision 1.72: +1 -1 lines
Don't include a "\n" in KTR output, it confuses automatic parsing.

Revision 1.72: download - view: text, markup, annotated - select for diffs
Thu Jun 3 01:47:35 2004 UTC (7 years, 8 months ago) by tjr
Branches: MAIN
Diff to: previous 1.71: preferred, colored
Changes since revision 1.71: +2 -4 lines
Move TDF_DEADLKTREAT into td_pflags (and rename it accordingly) to avoid
having to acquire sched_lock when manipulating it in lockmgr(), uiomove(),
and uiomove_fromphys().

Reviewed by:	jhb

Revision 1.71: download - view: text, markup, annotated - select for diffs
Tue Jan 6 04:34:13 2004 UTC (8 years, 1 month ago) by kan
Branches: MAIN
Diff to: previous 1.70: preferred, colored
Changes since revision 1.70: +3 -2 lines
Add pid to the info printed in lockmgr_printinfo. This makes VFS
diagnostic messages slightly more useful.

Revision 1.70: download - view: text, markup, annotated - select for diffs
Wed Jul 16 01:00:38 2003 UTC (8 years, 6 months ago) by truckman
Branches: MAIN
CVS tags: RELENG_5_2_BP, RELENG_5_2_1_RELEASE, RELENG_5_2_0_RELEASE, RELENG_5_2
Diff to: previous 1.69: preferred, colored
Changes since revision 1.69: +3 -27 lines
Rearrange the SYSINIT order to call lockmgr_init() earlier so that
the runtime lockmgr initialization code in lockinit() can be eliminated.

Reviewed by:	jhb

Revision 1.69: download - view: text, markup, annotated - select for diffs
Sun Jul 13 01:22:20 2003 UTC (8 years, 7 months ago) by truckman
Branches: MAIN
Diff to: previous 1.68: preferred, colored
Changes since revision 1.68: +2 -2 lines
Extend the mutex pool implementation to permit the creation and use of
multiple mutex pools with different options and sizes.  Mutex pools can
be created with either the default sleep mutexes or with spin mutexes.
A dynamically created mutex pool can now be destroyed if it is no longer
needed.

Create two pools by default, one that matches the existing pool that
uses the MTX_NOWITNESS option that should be used for building higher
level locks, and a new pool with witness checking enabled.

Modify the users of the existing mutex pool to use the appropriate pool
in the new implementation.

Reviewed by:	jhb

Revision 1.68: 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.67: preferred, colored
Changes since revision 1.67: +3 -1 lines
Use __FBSDID().

Revision 1.67: download - view: text, markup, annotated - select for diffs
Tue Mar 11 20:00:37 2003 UTC (8 years, 11 months ago) by jhb
Branches: MAIN
CVS tags: RELENG_5_1_BP, RELENG_5_1_0_RELEASE, RELENG_5_1
Diff to: previous 1.66: preferred, colored
Changes since revision 1.66: +4 -4 lines
Use the KTR_LOCK mask for logging events via KTR in lockmgr() rather
than KTR_LOCKMGR.  lockmgr locks are locks just like other locks.

Revision 1.66: download - view: text, markup, annotated - select for diffs
Tue Mar 4 21:03:04 2003 UTC (8 years, 11 months ago) by jhb
Branches: MAIN
Diff to: previous 1.65: preferred, colored
Changes since revision 1.65: +3 -1 lines
Replace calls to WITNESS_SLEEP() and witness_list() with equivalent calls
to WITNESS_WARN().

Revision 1.65: download - view: text, markup, annotated - select for diffs
Tue Feb 25 03:37:46 2003 UTC (8 years, 11 months ago) by jeff
Branches: MAIN
Diff to: previous 1.64: preferred, colored
Changes since revision 1.64: +5 -8 lines
 - Add an interlock argument to BUF_LOCK and BUF_TIMELOCK.
 - Remove the buftimelock mutex and acquire the buf's interlock to protect
   these fields instead.
 - Hold the vnode interlock while locking bufs on the clean/dirty queues.
   This reduces some cases from one BUF_LOCK with a LK_NOWAIT and another
   BUF_LOCK with a LK_TIMEFAIL to a single lock.

Reviewed by:	arch, mckusick

Revision 1.64: download - view: text, markup, annotated - select for diffs
Sun Feb 16 10:39:49 2003 UTC (8 years, 11 months ago) by jeff
Branches: MAIN
Diff to: previous 1.63: preferred, colored
Changes since revision 1.63: +7 -0 lines
 - Add a WITNESS_SLEEP() for the appropriate cases in lockmgr().

Revision 1.63: download - view: text, markup, annotated - select for diffs
Wed Feb 5 19:36:58 2003 UTC (9 years ago) by julian
Branches: MAIN
Diff to: previous 1.62: preferred, colored
Changes since revision 1.62: +19 -19 lines
The lockmanager has to keep track of locks per thread, not per process.

Submitted by:	david Xu (davidxu@)
Reviewed by:	jhb@

Revision 1.62: download - view: text, markup, annotated - select for diffs
Sat Feb 1 12:17:07 2003 UTC (9 years ago) by julian
Branches: MAIN
Diff to: previous 1.61: preferred, colored
Changes since revision 1.61: +20 -20 lines
Reversion of commit by Davidxu plus fixes since applied.

I'm not convinced there is anything major wrong with the patch but
them's the rules..

I am using my "David's mentor" hat to revert this as he's
offline for a while.

Revision 1.61: download - view: text, markup, annotated - select for diffs
Sun Jan 26 11:41:34 2003 UTC (9 years ago) by davidxu
Branches: MAIN
Diff to: previous 1.60: preferred, colored
Changes since revision 1.60: +20 -20 lines
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.

A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.

Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.

Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.

KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.

When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.

The code hasn't been tested under SMP by author due to lack of hardware.

Reviewed by: julian

Revision 1.60: download - view: text, markup, annotated - select for diffs
Sat Nov 30 19:00:51 2002 UTC (9 years, 2 months ago) by mckusick
Branches: MAIN
CVS tags: RELENG_5_0_BP, RELENG_5_0_0_RELEASE, RELENG_5_0
Diff to: previous 1.59: preferred, colored
Changes since revision 1.59: +37 -6 lines
Remove a race condition / deadlock from snapshots. When
converting from individual vnode locks to the snapshot
lock, be sure to pass any waiting processes along to the
new lock as well. This transfer is done by a new function
in the lock manager, transferlockers(from_lock, to_lock);
Thanks to Lamont Granquist <lamont@scriptkiddie.org> for
his help in pounding on snapshots beyond all reason and
finding this deadlock.

Sponsored by:   DARPA & NAI Labs.

Revision 1.59: download - view: text, markup, annotated - select for diffs
Fri Oct 18 01:34:10 2002 UTC (9 years, 3 months ago) by mckusick
Branches: MAIN
Diff to: previous 1.58: preferred, colored
Changes since revision 1.58: +9 -0 lines
Have lockinit() initialize the debugging fields of a lock
when DEBUG_LOCKS is defined.

Sponsored by:	DARPA & NAI Labs.

Revision 1.58: download - view: text, markup, annotated - select for diffs
Tue Aug 27 09:59:47 2002 UTC (9 years, 5 months ago) by bde
Branches: MAIN
Diff to: previous 1.57: preferred, colored
Changes since revision 1.57: +2 -2 lines
Include <sys/lockmgr.h> for the definitions of the locking interfaces that
are implemented here instead of depending on namespace pollution in
<sys/lock.h>.  Fixed nearby include messes (1 disordered include and 1
unused include).

Revision 1.57: download - view: text, markup, annotated - select for diffs
Sun Aug 25 13:17:21 2002 UTC (9 years, 5 months ago) by charnier
Branches: MAIN
Diff to: previous 1.56: preferred, colored
Changes since revision 1.56: +3 -3 lines
Replace various spelling with FALLTHROUGH which is lint()able

Revision 1.56: download - view: text, markup, annotated - select for diffs
Thu May 30 05:55:22 2002 UTC (9 years, 8 months ago) by jeff
Branches: MAIN
Diff to: previous 1.55: preferred, colored
Changes since revision 1.55: +6 -0 lines
Record the file, line, and pid of the last successful shared lock holder. This
is useful as a last effort in debugging file system deadlocks.  This is enabled
via 'options DEBUG_LOCKS'

Revision 1.55: download - view: text, markup, annotated - select for diffs
Thu Apr 4 21:03:25 2002 UTC (9 years, 10 months ago) by jhb
Branches: MAIN
Diff to: previous 1.54: preferred, colored
Changes since revision 1.54: +2 -2 lines
Change callers of mtx_init() to pass in an appropriate lock type name.  In
most cases NULL is passed, but in some cases such as network driver locks
(which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used.

Tested on:	i386, alpha, sparc64

Revision 1.54: download - view: text, markup, annotated - select for diffs
Tue Mar 5 17:45:12 2002 UTC (9 years, 11 months ago) by eivind
Branches: MAIN
Diff to: previous 1.53: preferred, colored
Changes since revision 1.53: +1 -1 lines
Change wmesg to const char * instead of char *

Revision 1.31.2.3: download - view: text, markup, annotated - select for diffs
Tue Dec 25 01:44:44 2001 UTC (10 years, 1 month ago) by dillon
Branches: RELENG_4
CVS tags: RELENG_4_9_BP, RELENG_4_9_0_RELEASE, RELENG_4_9, RELENG_4_8_BP, RELENG_4_8_0_RELEASE, RELENG_4_8, RELENG_4_7_BP, RELENG_4_7_0_RELEASE, RELENG_4_7, RELENG_4_6_BP, RELENG_4_6_2_RELEASE, RELENG_4_6_1_RELEASE, RELENG_4_6_0_RELEASE, RELENG_4_6, RELENG_4_5_BP, RELENG_4_5_0_RELEASE, RELENG_4_5, RELENG_4_11_BP, RELENG_4_11_0_RELEASE, RELENG_4_11, RELENG_4_10_BP, RELENG_4_10_0_RELEASE, RELENG_4_10
Diff to: previous 1.31.2.2: preferred, colored; branchpoint 1.31: preferred, colored; next MAIN 1.32: preferred, colored
Changes since revision 1.31.2.2: +5 -3 lines
MFC the following:

    * LK_TIMEOUT lock flag to separate lock acquisition with and without
      a timeout (dillon)

    * use of LK_TIMEOUT in BUF_TIMELOCK to avoid timeout race aginst
      BUF_LOCK (dillon)

    * use of LK_TIMEOUT in pageout vget() code to avoid deadlock (dillon)

    * move vnode reclaim into its own kthread to avoid deadlocks (Yahoo)

    * remove 'VXLOCK interlock avoided' messages.. they can occur
      under normal operation and create a choking hazzard on the console.

    * Adjust VMIGHTFREE macro used with vnode reclaim code to avoid
      eating large amounts of cpu with little to show for it in certain
      situations.

    * Add VREF/VRELE around UFS_UPDATE() call to avoid update/reclaim
      race (note: snuck in at last minute but I accidently did a partial
      commit a moment ago and the tree is broken until I commit the rest
      of it).  This is minor and will be tested heavily.

Approved by:	Release Engineers

Revision 1.53: download - view: text, markup, annotated - select for diffs
Thu Dec 20 22:42:26 2001 UTC (10 years, 1 month ago) by dillon
Branches: MAIN
Diff to: previous 1.52: preferred, colored
Changes since revision 1.52: +4 -2 lines
Fix a BUF_TIMELOCK race against BUF_LOCK and fix a deadlock in vget()
against VM_WAIT in the pageout code.  Both fixes involve adjusting
the lockmgr's timeout capability so locks obtained with timeouts do not
interfere with locks obtained without a timeout.

Hopefully MFC: before the 4.5 release

Revision 1.52: download - view: text, markup, annotated - select for diffs
Tue Nov 13 21:55:12 2001 UTC (10 years, 2 months ago) by dillon
Branches: MAIN
Diff to: previous 1.51: preferred, colored
Changes since revision 1.51: +14 -38 lines
Create a mutex pool API for short term leaf mutexes.
Replace the manual mutex pool in kern_lock.c (lockmgr locks) with the new API.
Replace the mutexes embedded in sxlocks with the new API.

Revision 1.51: download - view: text, markup, annotated - select for diffs
Thu Oct 11 17:53:43 2001 UTC (10 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.50: preferred, colored
Changes since revision 1.50: +2 -1 lines
Add missing includes of sys/ktr.h.

Revision 1.50: download - view: text, markup, annotated - select for diffs
Wed Oct 10 20:43:50 2001 UTC (10 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.49: preferred, colored
Changes since revision 1.49: +2 -2 lines
Malloc mutexes pre-zero'd as random garbage (including 0xdeadcode) my
trigget the check to make sure we don't initalize a mutex twice.

Revision 1.49: download - view: text, markup, annotated - select for diffs
Thu Sep 13 22:33:37 2001 UTC (10 years, 4 months ago) by jhb
Branches: MAIN
Diff to: previous 1.48: preferred, colored
Changes since revision 1.48: +5 -9 lines
Fix locking on td_flags for TDF_DEADLKTREAT.  If the comments in the code
are true that curthread can change during this function, then this flag
needs to become a KSE flag, not a thread flag.

Revision 1.48: 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: KSE_MILESTONE_2
Diff to: previous 1.47: preferred, colored
Changes since revision 1.47: +15 -15 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.47: download - view: text, markup, annotated - select for diffs
Fri Aug 10 23:29:15 2001 UTC (10 years, 6 months ago) by jhb
Branches: MAIN
CVS tags: KSE_PRE_MILESTONE_2
Diff to: previous 1.46: preferred, colored
Changes since revision 1.46: +6 -1 lines
If we've panic'd already, then just bail in lockmgr rather than blocking or
possibly panic'ing again.

Revision 1.46: download - view: text, markup, annotated - select for diffs
Sat Apr 28 12:11:01 2001 UTC (10 years, 9 months ago) by alfred
Branches: MAIN
Diff to: previous 1.45: preferred, colored
Changes since revision 1.45: +2 -2 lines
Instead of asserting that a mutex is not still locked after unlocking it,
assert that the mutex is owned and not recursed prior to unlocking it.

This should give a clearer diagnostic when a programming error is caught.

Revision 1.45: download - view: text, markup, annotated - select for diffs
Fri Apr 20 22:38:40 2001 UTC (10 years, 9 months ago) by alfred
Branches: MAIN
Diff to: previous 1.44: preferred, colored
Changes since revision 1.44: +4 -2 lines
Assert that when using an interlock mutex it is not recursed when lockmgr()
is called.

Ok'd by: jhb

Revision 1.44: download - view: text, markup, annotated - select for diffs
Fri Apr 13 10:15:53 2001 UTC (10 years, 10 months ago) by alfred
Branches: MAIN
Diff to: previous 1.43: preferred, colored
Changes since revision 1.43: +5 -3 lines
convert if/panic -> KASSERT, explain what triggered the assertion

Revision 1.43: download - view: text, markup, annotated - select for diffs
Sun Apr 8 04:15:26 2001 UTC (10 years, 10 months ago) by jake
Branches: MAIN
Diff to: previous 1.42: preferred, colored
Changes since revision 1.42: +2 -2 lines
Fix a precedence bug.  ! has higher precedence than &.

Revision 1.42: download - view: text, markup, annotated - select for diffs
Fri Feb 9 16:27:41 2001 UTC (11 years ago) by jhb
Branches: MAIN
Diff to: previous 1.41: preferred, colored
Changes since revision 1.41: +11 -15 lines
Proc locking.

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: +13 -13 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
Wed Jan 24 12:35:50 2001 UTC (11 years ago) by jasone
Branches: MAIN
Diff to: previous 1.39: preferred, colored
Changes since revision 1.39: +3 -121 lines
Convert all simplelocks to mutexes and remove the simplelock implementations.

Revision 1.39: 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.38: preferred, colored
Changes since revision 1.38: +4 -4 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.38: download - view: text, markup, annotated - select for diffs
Fri Dec 1 02:18:38 2000 UTC (11 years, 2 months ago) by jake
Branches: MAIN
Diff to: previous 1.37: preferred, colored
Changes since revision 1.37: +4 -7 lines
Use msleep instead of mtx_exit; tsleep; mtx_enter, which is not safe.

Revision 1.37: download - view: text, markup, annotated - select for diffs
Fri Oct 20 07:28:00 2000 UTC (11 years, 3 months ago) by jhb
Branches: MAIN
Diff to: previous 1.36: preferred, colored
Changes since revision 1.36: +5 -6 lines
- machine/mutex.h -> sys/mutex.h
- The initial lock_mtx mutex used in the lockmgr code is initialized very
  early, so use MUTEX_DECLARE() and MTX_COLD.

Revision 1.36: download - view: text, markup, annotated - select for diffs
Thu Oct 12 22:37:28 2000 UTC (11 years, 4 months ago) by jasone
Branches: MAIN
Diff to: previous 1.35: preferred, colored
Changes since revision 1.35: +80 -23 lines
For lockmgr mutex protection, use an array of mutexes that are allocated
and initialized during boot.  This avoids bloating sizeof(struct lock).
As a side effect, it is no longer necessary to enforce the assumtion that
lockinit()/lockdestroy() calls are paired, so the LK_VALID flag has been
removed.

Idea taken from:	BSD/OS.

Revision 1.35: download - view: text, markup, annotated - select for diffs
Wed Oct 4 01:29:09 2000 UTC (11 years, 4 months ago) by jasone
Branches: MAIN
Diff to: previous 1.34: preferred, colored
Changes since revision 1.34: +48 -18 lines
Convert lockmgr locks from using simple locks to using mutexes.

Add lockdestroy() and appropriate invocations, which corresponds to
lockinit() and must be called to clean up after a lockmgr lock is no
longer needed.

Revision 1.31.2.2: download - view: text, markup, annotated - select for diffs
Sat Sep 30 02:49:35 2000 UTC (11 years, 4 months ago) by ps
Branches: RELENG_4
CVS tags: RELENG_4_4_BP, RELENG_4_4_0_RELEASE, RELENG_4_4, RELENG_4_3_BP, RELENG_4_3_0_RELEASE, RELENG_4_3, RELENG_4_2_0_RELEASE
Diff to: previous 1.31.2.1: preferred, colored; branchpoint 1.31: preferred, colored
Changes since revision 1.31.2.1: +3 -3 lines
MFC:
Remove the NCPU, NAPIC, NBUS, NINTR config options.  Make NAPIC,
NBUS, NINTR dynamic and set NCPU to a maximum of 16 under SMP.

Move MAXCPU from machine/smp.h to machine/param.h to expose MAXCPU
in the !SMP case and replace NCPUS with MAXCPU since they are
redundant.

Revision 1.34: download - view: text, markup, annotated - select for diffs
Sat Sep 23 12:18:06 2000 UTC (11 years, 4 months ago) by ps
Branches: MAIN
Diff to: previous 1.33: preferred, colored
Changes since revision 1.33: +3 -3 lines
Move MAXCPU from machine/smp.h to machine/param.h to fix breakage
with !SMP kernels.  Also, replace NCPUS with MAXCPU since they are
redundant.

Revision 1.33: download - view: text, markup, annotated - select for diffs
Sat Sep 16 18:55:04 2000 UTC (11 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.32: preferred, colored
Changes since revision 1.32: +1 -3 lines
Make LINT compile.

Revision 1.31.2.1: download - view: text, markup, annotated - select for diffs
Fri Mar 17 10:47:29 2000 UTC (11 years, 10 months ago) by ps
Branches: RELENG_4
CVS tags: RELENG_4_1_1_RELEASE, RELENG_4_1_0_RELEASE
Diff to: previous 1.31: preferred, colored
Changes since revision 1.31: +1 -17 lines
MFC: Remove MAX_PERF with extreme prejudice.

Revision 1.32: download - view: text, markup, annotated - select for diffs
Thu Mar 16 08:51:50 2000 UTC (11 years, 10 months ago) by phk
Branches: MAIN
CVS tags: PRE_SMPNG
Diff to: previous 1.31: preferred, colored
Changes since revision 1.31: +1 -17 lines
Eliminate the undocumented, experimental, non-delivering and highly
dangerous MAX_PERF option.

Revision 1.31: download - view: text, markup, annotated - select for diffs
Sat Dec 11 16:12:52 1999 UTC (12 years, 2 months ago) by eivind
Branches: MAIN
CVS tags: RELENG_4_BP, RELENG_4_0_0_RELEASE
Branch point for: RELENG_4
Diff to: previous 1.30: preferred, colored
Changes since revision 1.30: +9 -5 lines
Lock reporting and assertion changes.
* lockstatus() and VOP_ISLOCKED() gets a new process argument and a new
  return value: LK_EXCLOTHER, when the lock is held exclusively by another
  process.
* The ASSERT_VOP_(UN)LOCKED family is extended to use what this gives them
* Extend the vnode_if.src format to allow more exact specification than
  locked/unlocked.

This commit should not do any semantic changes unless you are using
DEBUG_VFS_LOCKS.

Discussed with:	grog, mch, peter, phk
Reviewed by:	peter

Revision 1.30: download - view: text, markup, annotated - select for diffs
Thu Nov 11 03:02:03 1999 UTC (12 years, 3 months ago) by alc
Branches: MAIN
Diff to: previous 1.29: preferred, colored
Changes since revision 1.29: +17 -15 lines
Correct a locking error in apause: It should always hold
the simple lock when it returns.

Also, eliminate spinning on a uniprocessor.  It's pointless.

Submitted by:	bde,
		Assar Westerlund <assar@sics.se>

Revision 1.29: download - view: text, markup, annotated - select for diffs
Mon Sep 27 00:21:43 1999 UTC (12 years, 4 months ago) by dillon
Branches: MAIN
Diff to: previous 1.28: preferred, colored
Changes since revision 1.28: +6 -3 lines
    Fix process p_locks accounting.  Conversions of the owner to LK_KERNPROC
    caused p_locks to be improperly accounted.

Submitted by:	Tor.Egge@fast.no

Revision 1.23.2.4: download - view: text, markup, annotated - select for diffs
Sun Aug 29 16:26:00 1999 UTC (12 years, 5 months ago) by peter
Branches: RELENG_3
CVS tags: RELENG_3_5_0_RELEASE, RELENG_3_4_0_RELEASE, RELENG_3_3_0_RELEASE
Diff to: previous 1.23.2.3: preferred, colored; branchpoint 1.23: preferred, colored; next MAIN 1.24: preferred, colored
Changes since revision 1.23.2.3: +1 -1 lines
$Id$ -> $FreeBSD$

Revision 1.28: download - view: text, markup, annotated - select for diffs
Sat Aug 28 00:46:13 1999 UTC (12 years, 5 months ago) by peter
Branches: MAIN
Diff to: previous 1.27: preferred, colored
Changes since revision 1.27: +1 -1 lines
$Id$ -> $FreeBSD$

Revision 1.27: download - view: text, markup, annotated - select for diffs
Mon Jun 28 07:54:58 1999 UTC (12 years, 7 months ago) by mckusick
Branches: MAIN
Diff to: previous 1.26: preferred, colored
Changes since revision 1.26: +7 -5 lines
When requesting an exclusive lock with LK_NOWAIT, do not panic
if LK_RECURSIVE is not set, as we will simply return that the
lock is busy and not actually deadlock. This allows processes
to use polling locks against buffers that they may already
hold exclusively locked.

Revision 1.26: download - view: text, markup, annotated - select for diffs
Sat Jun 26 02:46:00 1999 UTC (12 years, 7 months ago) by mckusick
Branches: MAIN
Diff to: previous 1.25: preferred, colored
Changes since revision 1.25: +18 -2 lines
Convert buffer locking from using the B_BUSY and B_WANTED flags to using
lockmgr locks. This commit should be functionally equivalent to the old
semantics. That is, all buffer locking is done with LK_EXCLUSIVE
requests. Changes to take advantage of LK_SHARED and LK_RECURSIVE will
be done in future commits.

Revision 1.23.2.3: download - view: text, markup, annotated - select for diffs
Thu May 13 23:49:56 1999 UTC (12 years, 9 months ago) by dg
Branches: RELENG_3
CVS tags: RELENG_3_2_PAO_BP, RELENG_3_2_PAO, RELENG_3_2_0_RELEASE
Diff to: previous 1.23.2.2: preferred, colored; branchpoint 1.23: preferred, colored
Changes since revision 1.23.2.2: +7 -1 lines
Brought in Luoqi's fix from PR 8416. This likely has benign priority
inversion problems, but that's much better than hanging the system.

Revision 1.23.2.2: download - view: text, markup, annotated - select for diffs
Thu May 13 23:47:45 1999 UTC (12 years, 9 months ago) by dg
Branches: RELENG_3
Diff to: previous 1.23.2.1: preferred, colored; branchpoint 1.23: preferred, colored
Changes since revision 1.23.2.1: +2 -23 lines
Backed out P_DEADLKTREAT stuff as it doesn't appear to fix the problem.

Revision 1.23.2.1: download - view: text, markup, annotated - select for diffs
Tue May 11 07:54:18 1999 UTC (12 years, 9 months ago) by dg
Branches: RELENG_3
Diff to: previous 1.23: preferred, colored
Changes since revision 1.23: +24 -3 lines
MFC: Changes to shared locking to elevate the priority over exclusive lock
when both have been requested and the P_DEADLKTREAT process flag is set.
Believed to fix PR 8416.

Revision 1.25: download - view: text, markup, annotated - select for diffs
Mon Mar 15 05:11:27 1999 UTC (12 years, 11 months ago) by julian
Branches: MAIN
CVS tags: PRE_VFS_BIO_NFS_PATCH, PRE_SMP_VMSHARE, PRE_NEWBUS, POST_VFS_BIO_NFS_PATCH, POST_SMP_VMSHARE, POST_NEWBUS, POST_MATT_MMAP_LOCK
Diff to: previous 1.24: preferred, colored
Changes since revision 1.24: +2 -2 lines
fix breakage for alphas.
Submitted by: Andrew Gallatin <gallatin@cs.duke.edu>

Revision 1.24: download - view: text, markup, annotated - select for diffs
Fri Mar 12 03:09:29 1999 UTC (12 years, 11 months ago) by julian
Branches: MAIN
Diff to: previous 1.23: preferred, colored
Changes since revision 1.23: +24 -3 lines
This solves a deadlock that can occur when read()ing into a file-mmap()
space. When doing this, it is possible to for another process to attempt
to get an exclusive lock on the vnode and deadlock the mmap/read
combination when the uiomove() call tries to obtain a second
shared lock on the vnode. There is still a potential deadlock
situation with write()/mmap().
Submitted by: Matt Dillon <dillon@freebsd.org>
Reviewed by: Luoqi Chen <luoqi@freebsd.org>
Delimmitted by tag PRE_MATT_MMAP_LOCK and POST_MATT_MMAP_LOCK
in kern/kern_lock.c kern/kern_subr.c

Revision 1.23: download - view: text, markup, annotated - select for diffs
Wed Jan 20 14:49:11 1999 UTC (13 years ago) by eivind
Branches: MAIN
CVS tags: RELENG_3_BP, RELENG_3_1_0_RELEASE, PRE_MATT_MMAP_LOCK
Branch point for: RELENG_3
Diff to: previous 1.22: preferred, colored
Changes since revision 1.22: +25 -1 lines
Add 'options DEBUG_LOCKS', which stores extra information in struct
lock, and add some macros and function parameters to make sure that
the information get to the point where it can be put in the lock
structure.

While I'm here, add DEBUG_VFS_LOCKS to LINT.

Revision 1.22: download - view: text, markup, annotated - select for diffs
Sun Jan 10 01:58:24 1999 UTC (13 years, 1 month ago) by eivind
Branches: MAIN
Diff to: previous 1.21: preferred, colored
Changes since revision 1.21: +2 -1 lines
KNFize, by bde.

Revision 1.21: download - view: text, markup, annotated - select for diffs
Fri Jan 8 17:31:08 1999 UTC (13 years, 1 month ago) by eivind
Branches: MAIN
Diff to: previous 1.20: preferred, colored
Changes since revision 1.20: +2 -9 lines
Split DIAGNOSTIC -> DIAGNOSTIC, INVARIANTS, and INVARIANT_SUPPORT as
discussed on -hackers.

Introduce 'KASSERT(assertion, ("panic message", args))' for simple
check + panic.

Reviewed by:	msmith

Revision 1.20: download - view: text, markup, annotated - select for diffs
Thu Nov 26 18:50:23 1998 UTC (13 years, 2 months ago) by eivind
Branches: MAIN
Diff to: previous 1.19: preferred, colored
Changes since revision 1.19: +2 -2 lines
Staticize.

Revision 1.19: download - view: text, markup, annotated - select for diffs
Fri Apr 17 04:53:44 1998 UTC (13 years, 9 months ago) by bde
Branches: MAIN
CVS tags: RELENG_3_0_0_RELEASE, PRE_NOBDEV, PRE_DEVFS_SLICE, POST_DEVFS_SLICE
Diff to: previous 1.18: preferred, colored
Changes since revision 1.18: +2 -2 lines
Really finish supporting compiling with `gcc -ansi'.

Revision 1.18: download - view: text, markup, annotated - select for diffs
Sat Mar 7 19:25:34 1998 UTC (13 years, 11 months ago) by dyson
Branches: MAIN
CVS tags: PRE_SOFTUPDATE, POST_SOFTUPDATE
Diff to: previous 1.17: preferred, colored
Changes since revision 1.17: +43 -10 lines
Some kern_lock code improvements.  Add missing wakeup, and enable
disabling some diagnostics when memory or speed is at a premium.

Revision 1.17: download - view: text, markup, annotated - select for diffs
Wed Feb 11 00:05:26 1998 UTC (14 years ago) by eivind
Branches: MAIN
Diff to: previous 1.16: preferred, colored
Changes since revision 1.16: +6 -2 lines
Include SIMPLELOCK_DEBUG functions even if SMP if compiling LINT; give
an error for the combination if _not_ compiling LINT.

Revision 1.16: download - view: text, markup, annotated - select for diffs
Fri Feb 6 12:13:23 1998 UTC (14 years ago) by eivind
Branches: MAIN
Diff to: previous 1.15: preferred, colored
Changes since revision 1.15: +1 -3 lines
Back out DIAGNOSTIC changes.

Revision 1.15: download - view: text, markup, annotated - select for diffs
Wed Feb 4 22:32:32 1998 UTC (14 years ago) by eivind
Branches: MAIN
Diff to: previous 1.14: preferred, colored
Changes since revision 1.14: +3 -1 lines
Turn DIAGNOSTIC into a new-style option.

Revision 1.14: download - view: text, markup, annotated - select for diffs
Fri Nov 7 08:52:55 1997 UTC (14 years, 3 months ago) by phk
Branches: MAIN
Diff to: previous 1.13: preferred, colored
Changes since revision 1.13: +1 -3 lines
Remove a bunch of variables which were unused both in GENERIC and LINT.

Found by:	-Wunused

Revision 1.13: download - view: text, markup, annotated - select for diffs
Tue Oct 28 15:58:19 1997 UTC (14 years, 3 months ago) by bde
Branches: MAIN
Diff to: previous 1.12: preferred, colored
Changes since revision 1.12: +1 -5 lines
Removed unused #includes.

Revision 1.12: download - view: text, markup, annotated - select for diffs
Sun Sep 21 04:22:52 1997 UTC (14 years, 4 months ago) by dyson
Branches: MAIN
Diff to: previous 1.11: preferred, colored
Changes since revision 1.11: +85 -77 lines
Change the M_NAMEI allocations to use the zone allocator.  This change
plus the previous changes to use the zone allocator decrease the useage
of malloc by half.  The Zone allocator will be upgradeable to be able
to use per CPU-pools, and has more intelligent usage of SPLs.  Additionally,
it has reasonable stats gathering capabilities, while making most calls
inline.

Revision 1.11: download - view: text, markup, annotated - select for diffs
Fri Aug 22 07:16:46 1997 UTC (14 years, 5 months ago) by phk
Branches: MAIN
Diff to: previous 1.10: preferred, colored
Changes since revision 1.10: +2 -2 lines
typo in comment.

Revision 1.10: download - view: text, markup, annotated - select for diffs
Tue Aug 19 00:27:07 1997 UTC (14 years, 5 months ago) by dyson
Branches: MAIN
Diff to: previous 1.9: preferred, colored
Changes since revision 1.9: +4 -3 lines
Allow lockmgr to work without a current process.  Disallowing that
was a mistake in the lockmgr rewrite.

Revision 1.9: download - view: text, markup, annotated - select for diffs
Mon Aug 18 03:29:15 1997 UTC (14 years, 5 months ago) by fsmp
Branches: MAIN
Diff to: previous 1.8: preferred, colored
Changes since revision 1.8: +5 -1 lines
Added includes of smp.h for SMP.
This eliminates a bazillion warnings about implicit s_lock & friends.

Revision 1.8: download - view: text, markup, annotated - select for diffs
Mon Aug 18 02:06:35 1997 UTC (14 years, 5 months ago) by dyson
Branches: MAIN
Diff to: previous 1.7: preferred, colored
Changes since revision 1.7: +144 -132 lines
Fix kern_lock so that it will work.  Additionally, clean-up some of the
VM systems usage of the kernel lock (lockmgr) code.  This is a first
pass implementation, and is expected to evolve as needed.  The API
for the lock manager code has not changed, but the underlying implementation
has changed significantly.  This change should not materially affect
our current SMP or UP code without non-standard parameters being used.

Revision 1.7: download - view: text, markup, annotated - select for diffs
Mon Aug 4 19:11:12 1997 UTC (14 years, 6 months ago) by fsmp
Branches: MAIN
Diff to: previous 1.6: preferred, colored
Changes since revision 1.6: +5 -5 lines
pushed down "volatility" of simplelock to actual int inside the struct.

Submitted by:	 bde@zeta.org.au, smp@csn.net

Revision 1.6: download - view: text, markup, annotated - select for diffs
Tue Apr 1 10:18:51 1997 UTC (14 years, 10 months ago) by bde
Branches: MAIN
CVS tags: pre_smp_merge, post_smp_merge, WOLLMAN_MBUF, BP_WOLLMAN_MBUF
Diff to: previous 1.5: preferred, colored
Changes since revision 1.5: +6 -5 lines
Fixed commented-out Lite2 sysctl debug.lockpausetime.

Removed unused #includes.

Revision 1.5: download - view: text, markup, annotated - select for diffs
Tue Mar 25 17:11:30 1997 UTC (14 years, 10 months ago) by peter
Branches: MAIN
Diff to: previous 1.4: preferred, colored
Changes since revision 1.4: +1 -0 lines
Add missing $Id$
Note; the RCS file has also been reconstructed to have a CSRG vendor branch.

Revision 1.4: download - view: text, markup, annotated - select for diffs
Tue Mar 25 16:38:01 1997 UTC (14 years, 10 months ago) by peter
Branches: MAIN
Diff to: previous 1.3: preferred, colored
Changes since revision 1.3: +2 -3 lines
Replace original rev 1.3;  Author: bde;  Date: 1997/02/25 17:24:43;
Fix counting of simplelocks in SIMPLELOCK_DEBUG
Fix style regression

Revision 1.3: download - view: text, markup, annotated - select for diffs
Tue Mar 25 16:36:35 1997 UTC (14 years, 10 months ago) by peter
Branches: MAIN
Diff to: previous 1.2: preferred, colored
Changes since revision 1.2: +1 -0 lines
Replace original rev 1.2;  Author: mpp;  Date: 1997/02/12 06:52:30
Add missing #include <sys/systm.h>

Revision 1.2: download - view: text, markup, annotated - select for diffs
Tue Mar 25 16:32:45 1997 UTC (14 years, 10 months ago) by peter
Branches: MAIN
Diff to: previous 1.1: preferred, colored
Changes since revision 1.1: +14 -8 lines
Replace original revision 1.1;  Author dyson;  Date: 1997/02/10 02:28:15
Changes from Lite2:
- DEBUG -> SIMPLELOCK_DEBUG
- cosmetic fixes
- bzero of lock at init time -> explicit init of members.

Revision 1.1.1.1 (vendor branch): download - view: text, markup, annotated - select for diffs
Tue Mar 25 16:27:20 1997 UTC (14 years, 10 months ago) by peter
Branches: CSRG
CVS tags: bsd_44_lite_2
Diff to: previous 1.1: preferred, colored
Changes since revision 1.1: +0 -0 lines
Import 4.4BSD-Lite2 onto CSRG branch

Revision 1.1: download - view: text, markup, annotated - select for diffs
Tue Mar 25 16:27:20 1997 UTC (14 years, 10 months ago) by peter
Branches: MAIN
Initial revision

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