]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - share/man/man9/LOCK_PROFILING.9
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / share / man / man9 / LOCK_PROFILING.9
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 November 11, 2006
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
41 The
42 .Dv LOCK_PROFILING
43 kernel option adds support for measuring and reporting lock use and
44 contention statistics.
45 These statistics are collated by
46 .Dq acquisition point .
47 Acquisition points are
48 distinct places in the kernel source code (identified by source file
49 name and line number) where a lock is acquired.
50 .Pp
51 For each acquisition point, the following statistics are accumulated:
52 .Bl -bullet
53 .It
54 The longest time the lock was ever continuously held after being
55 acquired at this point.
56 .It
57 The total time the lock was held after being acquired at this point.
58 .It
59 The total time that threads have spent waiting to acquire the lock.
60 .It
61 The total number of non-recursive acquisitions.
62 .It
63 The total number of times the lock was already held by another thread
64 when this point was reached, requiring a spin or a sleep.
65 .It
66 The total number of times another thread tried to acquire the lock
67 while it was held after having been acquired at this point.
68 .El
69 .Pp
70 In addition, the average hold time and average wait time are derived
71 from the total hold time
72 and total wait time respectively and the number of acquisitions.
73 .Pp
74 The
75 .Dv LOCK_PROFILING
76 kernel option also adds the following
77 .Xr sysctl 8
78 variables to control and monitor the profiling code:
79 .Bl -tag -width indent
80 .It Va debug.lock.prof.enable
81 Enable or disable the lock profiling code.
82 This defaults to 0 (off).
83 .It Va debug.lock.prof.reset
84 Reset the current lock profiling buffers.
85 .It Va debug.lock.prof.acquisitions
86 The total number of lock acquisitions recorded.
87 .It Va debug.lock.prof.records
88 The total number of acquisition points recorded.
89 Note that only active acquisition points (i.e., points that have been
90 reached at least once) are counted.
91 .It Va debug.lock.prof.maxrecords
92 The maximum number of acquisition points the profiling code is capable
93 of monitoring.
94 Since it would not be possible to call
95 .Xr malloc 9
96 from within the lock profiling code, this is a static limit.
97 The number of records can be changed with the
98 .Dv LPROF_BUFFERS
99 kernel option.
100 .It Va debug.lock.prof.rejected
101 The number of acquisition points that were ignored after the table
102 filled up.
103 .It Va debug.lock.prof.hashsize
104 The size of the hash table used to map acquisition points to
105 statistics records.
106 The hash size can be changed with the
107 .Dv LPROF_HASH_SIZE
108 kernel option.
109 .It Va debug.lock.prof.collisions
110 The number of hash collisions in the acquisition point hash table.
111 .It Va debug.lock.prof.stats
112 The actual profiling statistics in plain text.
113 The columns are as follows, from left to right:
114 .Bl -tag -width ".Va cnt_hold"
115 .It Va max
116 The longest continuous hold time in microseconds.
117 .It Va wait_max
118 The longest continuous wait time in microseconds.
119 .It Va total
120 The total (accumulated) hold time in microseconds.
121 .It Va wait_total
122 The total (accumulated) wait time in microseconds.
123 .It Va count
124 The total number of acquisitions.
125 .It Va avg
126 The average hold time in microseconds, derived from the total hold time
127 and the number of acquisitions.
128 .It Va wait_avg
129 The average wait time in microseconds, derived from the total wait time
130 and the number of acquisitions.
131 .It Va cnt_hold
132 The number of times the lock was held and another thread attempted to
133 acquire the lock.
134 .It Va cnt_lock
135 The number of times the lock was already held when this point was
136 reached.
137 .It Va name
138 The name of the acquisition point, derived from the source file name
139 and line number, followed by the name of the lock in parentheses.
140 .El
141 .El
142 .Sh SEE ALSO
143 .Xr sysctl 8 ,
144 .Xr mutex 9
145 .Sh HISTORY
146 Mutex profiling support appeared in
147 .Fx 5.0 .
148 Generalized lock profiling support appeared in
149 .Fx 7.0 .
150 .Sh AUTHORS
151 .An -nosplit
152 The
153 .Nm MUTEX_PROFILING
154 code was written by
155 .An Eivind Eklund Aq eivind@FreeBSD.org ,
156 .An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org
157 and
158 .An Robert Watson Aq rwatson@FreeBSD.org .
159 The
160 .Nm
161 code was written by
162 .An Kip Macy Aq kmacy@FreeBSD.org .
163 This manual page was written by
164 .An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
165 .Sh NOTES
166 The
167 .Dv LOCK_PROFILING
168 option increases the size of
169 .Vt "struct lock_object" ,
170 so a kernel built with that option will not work with modules built
171 without it.
172 .Pp
173 The
174 .Dv LOCK_PROFILING
175 option also prevents inlining of the mutex code, which can result in a
176 fairly severe performance penalty.
177 This is, however, not always the case.
178 .Dv LOCK_PROFILING
179 can introduce a substantial performance overhead that is easily
180 monitorable using other profiling tools, so combining profiling tools
181 with
182 .Dv LOCK_PROFILING
183 is not recommended.
184 .Pp
185 Measurements are made and stored in nanoseconds using
186 .Xr nanotime 9 ,
187 (on architectures without a synchronized TSC) but are presented in microseconds.
188 This should still be sufficient for the locks one would be most
189 interested in profiling (those that are held long and/or acquired
190 often).
191 .Pp
192 .Dv LOCK_PROFILING
193 should generally not be used in combination with other debugging options, as
194 the results may be strongly affected by interactions between the features.
195 In particular,
196 .Dv LOCK_PROFILING
197 will report higher than normal
198 .Xr uma 9
199 lock contention when run with
200 .Dv INVARIANTS
201 due to extra locking that occurs when
202 .Dv INVARIANTS
203 is present; likewise, using it in combination with
204 .Dv WITNESS
205 will lead to much higher lock hold times and contention in profiling output.