kern_lockstat.c revision 285663
1192853Ssson/*- 2192853Ssson * Copyright 2008-2009 Stacey Son <sson@FreeBSD.org> 3192853Ssson * 4192853Ssson * Redistribution and use in source and binary forms, with or without 5192853Ssson * modification, are permitted provided that the following conditions 6192853Ssson * are met: 7192853Ssson * 1. Redistributions of source code must retain the above copyright 8192853Ssson * notice, this list of conditions and the following disclaimer. 9192853Ssson * 2. Redistributions in binary form must reproduce the above copyright 10192853Ssson * notice, this list of conditions and the following disclaimer in the 11192853Ssson * documentation and/or other materials provided with the distribution. 12192853Ssson * 13192853Ssson * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14192853Ssson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15192853Ssson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16192853Ssson * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17192853Ssson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18192853Ssson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19192853Ssson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20192853Ssson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21192853Ssson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22192853Ssson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23192853Ssson * SUCH DAMAGE. 24192853Ssson * 25192853Ssson * $FreeBSD: head/sys/kern/kern_lockstat.c 285663 2015-07-18 00:22:00Z markj $ 26192853Ssson */ 27192853Ssson 28192853Ssson/* 29192853Ssson * Backend for the lock tracing (lockstat) kernel support. This is required 30192853Ssson * to allow a module to load even though DTrace kernel support may not be 31192853Ssson * present. 32192853Ssson * 33192853Ssson */ 34192853Ssson 35192853Ssson#ifdef KDTRACE_HOOKS 36192853Ssson 37192853Ssson#include <sys/time.h> 38192853Ssson#include <sys/types.h> 39192853Ssson#include <sys/lockstat.h> 40192853Ssson 41192853Ssson/* 42192853Ssson * The following must match the type definition of dtrace_probe. It is 43192853Ssson * defined this way to avoid having to rely on CDDL code. 44192853Ssson */ 45192853Sssonuint32_t lockstat_probemap[LS_NPROBES]; 46192853Sssonvoid (*lockstat_probe_func)(uint32_t, uintptr_t, uintptr_t, 47192853Ssson uintptr_t, uintptr_t, uintptr_t); 48285663Smarkjint lockstat_enabled = 0; 49192853Ssson 50192853Sssonuint64_t 51192853Sssonlockstat_nsecs(void) 52192853Ssson{ 53192853Ssson struct bintime bt; 54192853Ssson uint64_t ns; 55192853Ssson 56285663Smarkj if (!lockstat_enabled) 57285663Smarkj return (0); 58285663Smarkj 59192853Ssson binuptime(&bt); 60192853Ssson ns = bt.sec * (uint64_t)1000000000; 61192853Ssson ns += ((uint64_t)1000000000 * (uint32_t)(bt.frac >> 32)) >> 32; 62192853Ssson return (ns); 63192853Ssson} 64192853Ssson 65192853Ssson#endif /* KDTRACE_HOOKS */ 66