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