2 * Copyright 2008-2009 Stacey Son <sson@FreeBSD.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
31 #include <sys/lockstat.h>
35 SDT_PROVIDER_DEFINE(lockstat
);
37 SDT_PROBE_DEFINE1(lockstat
, , , adaptive__acquire
, "struct mtx *");
38 SDT_PROBE_DEFINE1(lockstat
, , , adaptive__release
, "struct mtx *");
39 SDT_PROBE_DEFINE2(lockstat
, , , adaptive__spin
, "struct mtx *", "uint64_t");
40 SDT_PROBE_DEFINE2(lockstat
, , , adaptive__block
, "struct mtx *", "uint64_t");
42 SDT_PROBE_DEFINE1(lockstat
, , , spin__acquire
, "struct mtx *");
43 SDT_PROBE_DEFINE1(lockstat
, , , spin__release
, "struct mtx *");
44 SDT_PROBE_DEFINE2(lockstat
, , , spin__spin
, "struct mtx *", "uint64_t");
46 SDT_PROBE_DEFINE2(lockstat
, , , rw__acquire
, "struct rwlock *", "int");
47 SDT_PROBE_DEFINE2(lockstat
, , , rw__release
, "struct rwlock *", "int");
48 SDT_PROBE_DEFINE5(lockstat
, , , rw__block
, "struct rwlock *", "uint64_t", "int",
50 SDT_PROBE_DEFINE2(lockstat
, , , rw__spin
, "struct rwlock *", "uint64_t");
51 SDT_PROBE_DEFINE1(lockstat
, , , rw__upgrade
, "struct rwlock *");
52 SDT_PROBE_DEFINE1(lockstat
, , , rw__downgrade
, "struct rwlock *");
54 SDT_PROBE_DEFINE2(lockstat
, , , sx__acquire
, "struct sx *", "int");
55 SDT_PROBE_DEFINE2(lockstat
, , , sx__release
, "struct sx *", "int");
56 SDT_PROBE_DEFINE5(lockstat
, , , sx__block
, "struct sx *", "uint64_t", "int",
58 SDT_PROBE_DEFINE2(lockstat
, , , sx__spin
, "struct sx *", "uint64_t");
59 SDT_PROBE_DEFINE1(lockstat
, , , sx__upgrade
, "struct sx *");
60 SDT_PROBE_DEFINE1(lockstat
, , , sx__downgrade
, "struct sx *");
62 SDT_PROBE_DEFINE2(lockstat
, , , thread__spin
, "struct mtx *", "uint64_t");
64 int lockstat_enabled
= 0;
67 lockstat_nsecs(struct lock_object
*lo
)
72 if (!lockstat_enabled
)
74 if ((lo
->lo_flags
& LO_NOPROFILE
) != 0)
78 ns
= bt
.sec
* (uint64_t)1000000000;
79 ns
+= ((uint64_t)1000000000 * (uint32_t)(bt
.frac
>> 32)) >> 32;