2 .\" Copyright (c) 2004 Dag-Erling Coïdan Smørgrav
3 .\" Copyright (c) 2005 Robert N. M. Watson
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. The name of the author may not be used to endorse or promote products
15 .\" derived from this software without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Nd kernel mutex profiling support
38 .Cd "options MUTEX_PROFILING"
42 kernel option adds support for measuring and reporting mutex use and
43 contention statistics.
44 These statistics are collated by
45 .Dq acquisition point .
46 Acquisition points are
47 distinct places in the kernel source code (identified by source file
48 name and line number) where a mutex is acquired.
50 For each acquisition point, the following statistics are accumulated:
53 The total number of non-recursive acquisitions.
55 The total time the mutex was held after being acquired at this point.
57 The longest time the mutex was ever continuously held after being
58 acquired at this point.
60 The total number of times the mutex was already held by another thread
61 when this point was reached, requiring a spin or a sleep.
63 The total number of time another thread tried to acquire the mutex
64 while it was held after having been acquired at this point.
67 In addition, the average hold time is derived from the total hold time
68 and the number of acquisitions.
72 kernel option also adds the following
74 variables to control and monitor the profiling code:
75 .Bl -tag -width indent
76 .It Va debug.mutex.prof.enable
77 Enable or disable the mutex profiling code.
78 This defaults to 0 (off).
79 .It Va debug.mutex.prof.reset
80 Reset the current mutex profiling buffers.
81 .It Va debug.mutex.prof.acquisitions
82 The total number of mutex acquisitions recorded.
83 .It Va debug.mutex.prof.records
84 The total number of acquisition points recorded.
85 Note that only active acquisition points (i.e., points that have been
86 reached at least once) are counted.
87 .It Va debug.mutex.prof.maxrecords
88 The maximum number of acquisition points the profiling code is capable
90 Since it would not be possible to call
92 from within the mutex profiling code, this is a static limit.
93 The number of records can be changed with the
96 .It Va debug.mutex.prof.rejected
97 The number of acquisition points that were ignored after the table
99 .It Va debug.mutex.prof.hashsize
100 The size of the hash table used to map acquisition points to
102 The hash size can be changed with the
105 .It Va debug.mutex.prof.collisions
106 The number of hash collisions in the acquisition point hash table.
107 .It Va debug.mutex.prof.stats
108 The actual profiling statistics in plain text.
109 The columns are as follows, from left to right:
110 .Bl -tag -width ".Va cnt_hold"
112 The longest continuous hold time in microseconds.
114 The total (accumulated) hold time in microseconds.
116 The total number of acquisitions.
118 The average hold time in microseconds, derived from the total hold time
119 and the number of acquisitions.
121 The number of times the mutex was held and another thread attempted to
124 The number of times the mutex was already locked when this point was
127 The name of the acquisition point, derived from the source file name
128 and line number, followed by the name of the mutex in parentheses.
135 Mutex profiling support appeared in
142 .An Eivind Eklund Aq eivind@FreeBSD.org ,
143 .An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org
145 .An Robert Watson Aq rwatson@FreeBSD.org .
146 This manual page was written by
147 .An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
151 option increases the size of
153 so a kernel built with that option will not work with modules built
158 option also prevents inlining of the mutex code, which results in a
159 fairly severe performance penalty.
160 It should therefore only be enabled on systems where mutex profiling
163 will introduce a substantial performance overhead that is easily
164 monitorable using other profiling tools, so combining profiling tools
169 Measurements are made and stored in nanoseconds using
171 but are presented in microseconds.
172 This should still be sufficient for the locks one would be most
173 interested in profiling (those that are held long and/or acquired
177 should generally not be used in combination with other debugging options, as
178 the results may be strongly affected by interactions between the features.
181 will report higher than normal
183 lock contention when run with
185 due to extra locking that occurs when
187 is present; likewise, using it in combination with
190 will lead to much higher lock hold times and contention in profiling output.