xref: /freebsd/share/man/man9/LOCK_PROFILING.9 (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1.\"-
2.\" Copyright (c) 2004 Dag-Erling Coïdan Smørgrav
3.\" Copyright (c) 2005 Robert N. M. Watson
4.\" Copyright (c) 2006 Kip Macy
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. The name of the author may not be used to endorse or promote products
16.\"    derived from this software without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" $FreeBSD$
31.\"
32.Dd March 7, 2012
33.Dt LOCK_PROFILING 9
34.Os
35.Sh NAME
36.Nm LOCK_PROFILING
37.Nd kernel lock profiling support
38.Sh SYNOPSIS
39.Cd "options LOCK_PROFILING"
40.Sh DESCRIPTION
41The
42.Dv LOCK_PROFILING
43kernel option adds support for measuring and reporting lock use and
44contention statistics.
45These statistics are collated by
46.Dq acquisition point .
47Acquisition points are
48distinct places in the kernel source code (identified by source file
49name and line number) where a lock is acquired.
50.Pp
51For each acquisition point, the following statistics are accumulated:
52.Bl -bullet
53.It
54The longest time the lock was ever continuously held after being
55acquired at this point.
56.It
57The total time the lock was held after being acquired at this point.
58.It
59The total time that threads have spent waiting to acquire the lock.
60.It
61The total number of non-recursive acquisitions.
62.It
63The total number of times the lock was already held by another thread
64when this point was reached, requiring a spin or a sleep.
65.It
66The total number of times another thread tried to acquire the lock
67while it was held after having been acquired at this point.
68.El
69.Pp
70In addition, the average hold time and average wait time are derived
71from the total hold time
72and total wait time respectively and the number of acquisitions.
73.Pp
74The
75.Dv LOCK_PROFILING
76kernel option also adds the following
77.Xr sysctl 8
78variables to control and monitor the profiling code:
79.Bl -tag -width indent
80.It Va debug.lock.prof.enable
81Enable or disable the lock profiling code.
82This defaults to 0 (off).
83.It Va debug.lock.prof.reset
84Reset the current lock profiling buffers.
85.It Va debug.lock.prof.stats
86The actual profiling statistics in plain text.
87The columns are as follows, from left to right:
88.Bl -tag -width ".Va cnt_hold"
89.It Va max
90The longest continuous hold time in microseconds.
91.It Va wait_max
92The longest continuous wait time in microseconds.
93.It Va total
94The total (accumulated) hold time in microseconds.
95.It Va wait_total
96The total (accumulated) wait time in microseconds.
97.It Va count
98The total number of acquisitions.
99.It Va avg
100The average hold time in microseconds, derived from the total hold time
101and the number of acquisitions.
102.It Va wait_avg
103The average wait time in microseconds, derived from the total wait time
104and the number of acquisitions.
105.It Va cnt_hold
106The number of times the lock was held and another thread attempted to
107acquire the lock.
108.It Va cnt_lock
109The number of times the lock was already held when this point was
110reached.
111.It Va name
112The name of the acquisition point, derived from the source file name
113and line number, followed by the name of the lock in parentheses.
114.El
115.It Va debug.lock.prof.rejected
116The number of acquisition points that were ignored after the table
117filled up.
118.It Va debug.lock.prof.skipspin
119Disable or enable the lock profiling code for the spin locks.
120This defaults to 0 (do profiling for the spin locks).
121.It Va debug.lock.prof.skipcount
122Do sampling approximately every N lock acquisitions.
123.El
124.Sh SEE ALSO
125.Xr sysctl 8 ,
126.Xr mutex 9
127.Sh HISTORY
128Mutex profiling support appeared in
129.Fx 5.0 .
130Generalized lock profiling support appeared in
131.Fx 7.0 .
132.Sh AUTHORS
133.An -nosplit
134The
135.Nm MUTEX_PROFILING
136code was written by
137.An Eivind Eklund Aq Mt eivind@FreeBSD.org ,
138.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org
139and
140.An Robert Watson Aq Mt rwatson@FreeBSD.org .
141The
142.Nm
143code was written by
144.An Kip Macy Aq Mt kmacy@FreeBSD.org .
145This manual page was written by
146.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
147.Sh NOTES
148The
149.Dv LOCK_PROFILING
150option increases the size of
151.Vt "struct lock_object" ,
152so a kernel built with that option will not work with modules built
153without it.
154.Pp
155The
156.Dv LOCK_PROFILING
157option also prevents inlining of the mutex code, which can result in a
158fairly severe performance penalty.
159This is, however, not always the case.
160.Dv LOCK_PROFILING
161can introduce a substantial performance overhead that is easily
162monitorable using other profiling tools, so combining profiling tools
163with
164.Dv LOCK_PROFILING
165is not recommended.
166.Pp
167Measurements are made and stored in nanoseconds using
168.Xr nanotime 9 ,
169(on architectures without a synchronized TSC) but are presented in microseconds.
170This should still be sufficient for the locks one would be most
171interested in profiling (those that are held long and/or acquired
172often).
173.Pp
174.Dv LOCK_PROFILING
175should generally not be used in combination with other debugging options, as
176the results may be strongly affected by interactions between the features.
177In particular,
178.Dv LOCK_PROFILING
179will report higher than normal
180.Xr uma 9
181lock contention when run with
182.Dv INVARIANTS
183due to extra locking that occurs when
184.Dv INVARIANTS
185is present; likewise, using it in combination with
186.Dv WITNESS
187will lead to much higher lock hold times and contention in profiling output.
188