kern_lockstat.c (285664) | kern_lockstat.c (285703) |
---|---|
1/*- 2 * Copyright 2008-2009 Stacey Son <sson@FreeBSD.org> 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 7 unchanged lines hidden (view full) --- 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 23 * SUCH DAMAGE. | 1/*- 2 * Copyright 2008-2009 Stacey Son <sson@FreeBSD.org> 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 7 unchanged lines hidden (view full) --- 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 23 * SUCH DAMAGE. |
24 * 25 * $FreeBSD: head/sys/kern/kern_lockstat.c 285664 2015-07-18 00:57:30Z markj $ | |
26 */ 27 | 24 */ 25 |
28/* 29 * Backend for the lock tracing (lockstat) kernel support. This is required 30 * to allow a module to load even though DTrace kernel support may not be 31 * present. 32 * 33 */ | 26#include <sys/cdefs.h> 27__FBSDID("$FreeBSD: head/sys/kern/kern_lockstat.c 285703 2015-07-19 22:14:09Z markj $"); |
34 | 28 |
35#ifdef KDTRACE_HOOKS 36 37#include <sys/types.h> | 29#include <sys/param.h> |
38#include <sys/lock.h> 39#include <sys/lockstat.h> | 30#include <sys/lock.h> 31#include <sys/lockstat.h> |
32#include <sys/sdt.h> |
|
40#include <sys/time.h> 41 | 33#include <sys/time.h> 34 |
42/* 43 * The following must match the type definition of dtrace_probe. It is 44 * defined this way to avoid having to rely on CDDL code. 45 */ 46uint32_t lockstat_probemap[LS_NPROBES]; 47void (*lockstat_probe_func)(uint32_t, uintptr_t, uintptr_t, 48 uintptr_t, uintptr_t, uintptr_t); | 35SDT_PROVIDER_DEFINE(lockstat); 36 37SDT_PROBE_DEFINE1(lockstat, , , adaptive__acquire, "struct mtx *"); 38SDT_PROBE_DEFINE1(lockstat, , , adaptive__release, "struct mtx *"); 39SDT_PROBE_DEFINE2(lockstat, , , adaptive__spin, "struct mtx *", "uint64_t"); 40SDT_PROBE_DEFINE2(lockstat, , , adaptive__block, "struct mtx *", "uint64_t"); 41 42SDT_PROBE_DEFINE1(lockstat, , , spin__acquire, "struct mtx *"); 43SDT_PROBE_DEFINE1(lockstat, , , spin__release, "struct mtx *"); 44SDT_PROBE_DEFINE2(lockstat, , , spin__spin, "struct mtx *", "uint64_t"); 45 46SDT_PROBE_DEFINE1(lockstat, , , rw__acquire, "struct rwlock *"); 47SDT_PROBE_DEFINE1(lockstat, , , rw__release, "struct rwlock *"); 48SDT_PROBE_DEFINE5(lockstat, , , rw__block, "struct rwlock *", "uint64_t", "int", 49 "int", "int"); 50SDT_PROBE_DEFINE2(lockstat, , , rw__spin, "struct rwlock *", "uint64_t"); 51SDT_PROBE_DEFINE1(lockstat, , , rw__upgrade, "struct rwlock *"); 52SDT_PROBE_DEFINE1(lockstat, , , rw__downgrade, "struct rwlock *"); 53 54SDT_PROBE_DEFINE1(lockstat, , , sx__acquire, "struct sx *"); 55SDT_PROBE_DEFINE1(lockstat, , , sx__release, "struct sx *"); 56SDT_PROBE_DEFINE5(lockstat, , , sx__block, "struct sx *", "uint64_t", "int", 57 "int", "int"); 58SDT_PROBE_DEFINE2(lockstat, , , sx__spin, "struct sx *", "uint64_t"); 59SDT_PROBE_DEFINE1(lockstat, , , sx__upgrade, "struct sx *"); 60SDT_PROBE_DEFINE1(lockstat, , , sx__downgrade, "struct sx *"); 61 62SDT_PROBE_DEFINE2(lockstat, , , thread__spin, "struct mtx *", "uint64_t"); 63 |
49int lockstat_enabled = 0; 50 51uint64_t 52lockstat_nsecs(struct lock_object *lo) 53{ 54 struct bintime bt; 55 uint64_t ns; 56 57 if (!lockstat_enabled) 58 return (0); 59 if ((lo->lo_flags & LO_NOPROFILE) != 0) 60 return (0); 61 62 binuptime(&bt); 63 ns = bt.sec * (uint64_t)1000000000; 64 ns += ((uint64_t)1000000000 * (uint32_t)(bt.frac >> 32)) >> 32; 65 return (ns); 66} | 64int lockstat_enabled = 0; 65 66uint64_t 67lockstat_nsecs(struct lock_object *lo) 68{ 69 struct bintime bt; 70 uint64_t ns; 71 72 if (!lockstat_enabled) 73 return (0); 74 if ((lo->lo_flags & LO_NOPROFILE) != 0) 75 return (0); 76 77 binuptime(&bt); 78 ns = bt.sec * (uint64_t)1000000000; 79 ns += ((uint64_t)1000000000 * (uint32_t)(bt.frac >> 32)) >> 32; 80 return (ns); 81} |
67 68#endif /* KDTRACE_HOOKS */ | |