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.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
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.
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
37 .Nd kernel lock profiling support
39 .Cd "options 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.
51 For each acquisition point, the following statistics are accumulated:
54 The longest time the lock was ever continuously held after being
55 acquired at this point.
57 The total time the lock was held after being acquired at this point.
59 The total time that threads have spent waiting to acquire the lock.
61 The total number of non-recursive acquisitions.
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.
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.
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.
76 kernel option also adds the following
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.stats
86 The actual profiling statistics in plain text.
87 The columns are as follows, from left to right:
88 .Bl -tag -width ".Va cnt_hold"
90 The longest continuous hold time in microseconds.
92 The longest continuous wait time in microseconds.
94 The total (accumulated) hold time in microseconds.
96 The total (accumulated) wait time in microseconds.
98 The total number of acquisitions.
100 The average hold time in microseconds, derived from the total hold time
101 and the number of acquisitions.
103 The average wait time in microseconds, derived from the total wait time
104 and the number of acquisitions.
106 The number of times the lock was held and another thread attempted to
109 The number of times the lock was already held when this point was
112 The name of the acquisition point, derived from the source file name
113 and line number, followed by the name of the lock in parentheses.
115 .It Va debug.lock.prof.rejected
116 The number of acquisition points that were ignored after the table
118 .It Va debug.lock.prof.skipspin
119 Disable or enable the lock profiling code for the spin locks.
120 This defaults to 0 (do profiling for the spin locks).
121 .It Va debug.lock.prof.skipcount
122 Do sampling approximately every N lock acquisitions.
128 Mutex profiling support appeared in
130 Generalized lock profiling support appeared in
137 .An Eivind Eklund Aq Mt eivind@FreeBSD.org ,
138 .An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org
140 .An Robert Watson Aq Mt rwatson@FreeBSD.org .
144 .An Kip Macy Aq Mt kmacy@FreeBSD.org .
145 This manual page was written by
146 .An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
150 option increases the size of
151 .Vt "struct lock_object" ,
152 so a kernel built with that option will not work with modules built
157 option also prevents inlining of the mutex code, which can result in a
158 fairly severe performance penalty.
159 This is, however, not always the case.
161 can introduce a substantial performance overhead that is easily
162 monitorable using other profiling tools, so combining profiling tools
167 Measurements are made and stored in nanoseconds using
169 (on architectures without a synchronized TSC) but are presented in microseconds.
170 This should still be sufficient for the locks one would be most
171 interested in profiling (those that are held long and/or acquired
175 should generally not be used in combination with other debugging options, as
176 the results may be strongly affected by interactions between the features.
179 will report higher than normal
181 lock contention when run with
183 due to extra locking that occurs when
185 is present; likewise, using it in combination with
187 will lead to much higher lock hold times and contention in profiling output.