1268355Sache/*- 2104128Seric * Copyright (c) 2006 Kip Macy kmacy@FreeBSD.org 3104128Seric * Copyright (c) 2006 Kris Kennaway kris@FreeBSD.org 4126189Sache * Copyright (c) 2006 Dag-Erling Smorgrav des@des.no 5126189Sache * 6126189Sache * Redistribution and use in source and binary forms, with or without 7126189Sache * modification, are permitted provided that the following conditions 8126189Sache * are met: 9126189Sache * 1. Redistributions of source code must retain the above copyright 10126189Sache * notice, this list of conditions and the following disclaimer. 11126189Sache * 2. Redistributions in binary form must reproduce the above copyright 12126189Sache * notice, this list of conditions and the following disclaimer in the 13126189Sache * documentation and/or other materials provided with the distribution. 14126189Sache * 15126189Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16126189Sache * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17126189Sache * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18126189Sache * ARE DISCLAIMED. IN NO EVENT SHAL THE AUTHORS BE LIABLE FOR ANY 19126189Sache * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20126189Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21126189Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22126189Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23104128Seric * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24104128Seric * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25104128Seric * SUCH DAMAGE. 26104128Seric * 27104128Seric * $FreeBSD$ 28104128Seric */ 29104128Seric 30104128Seric 31104128Seric#ifndef _SYS_LOCK_PROFILE_H_ 32104128Seric#define _SYS_LOCK_PROFILE_H_ 33104128Seric 34104128Sericstruct lock_profile_object; 35104128SericLIST_HEAD(lpohead, lock_profile_object); 36104128Seric 37104128Seric#ifdef _KERNEL 38104128Seric#ifdef LOCK_PROFILING 39104128Seric#include <machine/cpufunc.h> 40104128Seric#include <sys/lock.h> 41104128Seric 42104128Seric#ifndef USE_CPU_NANOSECONDS 43104128Sericu_int64_t nanoseconds(void); 44104128Seric#endif 45104128Seric 46104128Sericextern volatile int lock_prof_enable; 47104128Seric 48104128Sericvoid lock_profile_obtain_lock_success(struct lock_object *lo, int contested, 49104128Seric uint64_t waittime, const char *file, int line); 50104128Sericvoid lock_profile_release_lock(struct lock_object *lo); 51104128Sericvoid lock_profile_thread_exit(struct thread *td); 52126189Sache 53104128Seric 54126189Sachestatic inline void 55104128Sericlock_profile_obtain_lock_failed(struct lock_object *lo, int *contested, 56126189Sache uint64_t *waittime) 57126189Sache{ 58126189Sache if (!lock_prof_enable || (lo->lo_flags & LO_NOPROFILE) || *contested) 59104128Seric return; 60104128Seric *waittime = nanoseconds(); 61104128Seric *contested = 1; 62104128Seric} 63104128Seric 64104128Seric#else /* !LOCK_PROFILING */ 65104128Seric 66126452Sache#define lock_profile_release_lock(lo) (void)0 67126452Sache#define lock_profile_obtain_lock_failed(lo, contested, waittime) (void)0 68162574Sache#define lock_profile_obtain_lock_success(lo, contested, waittime, file, line) (void)0 69126189Sache#define lock_profile_thread_exit(td) (void)0 70104128Seric 71104128Seric#endif /* !LOCK_PROFILING */ 72104128Seric 73104128Seric#endif /* _KERNEL */ 74104128Seric 75104128Seric#endif /* _SYS_LOCK_PROFILE_H_ */ 76104128Seric