10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56103Sck142721 * Common Development and Distribution License (the "License"). 66103Sck142721 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 226103Sck142721 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_LOCKSTAT_H 270Sstevel@tonic-gate #define _SYS_LOCKSTAT_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/dtrace.h> 320Sstevel@tonic-gate 330Sstevel@tonic-gate #ifdef __cplusplus 340Sstevel@tonic-gate extern "C" { 350Sstevel@tonic-gate #endif 360Sstevel@tonic-gate 370Sstevel@tonic-gate #define LS_MUTEX_ENTER_ACQUIRE 0 380Sstevel@tonic-gate #define LS_MUTEX_ENTER_BLOCK 1 390Sstevel@tonic-gate #define LS_MUTEX_ENTER_SPIN 2 400Sstevel@tonic-gate #define LS_MUTEX_EXIT_RELEASE 3 410Sstevel@tonic-gate #define LS_MUTEX_DESTROY_RELEASE 4 420Sstevel@tonic-gate #define LS_MUTEX_TRYENTER_ACQUIRE 5 430Sstevel@tonic-gate #define LS_LOCK_SET_ACQUIRE 6 440Sstevel@tonic-gate #define LS_LOCK_SET_SPIN 7 450Sstevel@tonic-gate #define LS_LOCK_SET_SPL_ACQUIRE 8 460Sstevel@tonic-gate #define LS_LOCK_SET_SPL_SPIN 9 470Sstevel@tonic-gate #define LS_LOCK_TRY_ACQUIRE 10 480Sstevel@tonic-gate #define LS_LOCK_CLEAR_RELEASE 11 490Sstevel@tonic-gate #define LS_LOCK_CLEAR_SPLX_RELEASE 12 500Sstevel@tonic-gate #define LS_CLOCK_UNLOCK_RELEASE 13 510Sstevel@tonic-gate #define LS_RW_ENTER_ACQUIRE 14 520Sstevel@tonic-gate #define LS_RW_ENTER_BLOCK 15 530Sstevel@tonic-gate #define LS_RW_EXIT_RELEASE 16 540Sstevel@tonic-gate #define LS_RW_TRYENTER_ACQUIRE 17 550Sstevel@tonic-gate #define LS_RW_TRYUPGRADE_UPGRADE 18 560Sstevel@tonic-gate #define LS_RW_DOWNGRADE_DOWNGRADE 19 570Sstevel@tonic-gate #define LS_THREAD_LOCK_ACQUIRE 20 580Sstevel@tonic-gate #define LS_THREAD_LOCK_SPIN 21 590Sstevel@tonic-gate #define LS_THREAD_LOCK_HIGH_ACQUIRE 22 600Sstevel@tonic-gate #define LS_THREAD_LOCK_HIGH_SPIN 23 610Sstevel@tonic-gate #define LS_TURNSTILE_INTERLOCK_SPIN 24 620Sstevel@tonic-gate #define LS_NPROBES 25 630Sstevel@tonic-gate 640Sstevel@tonic-gate #define LS_MUTEX_ENTER "mutex_enter" 650Sstevel@tonic-gate #define LS_MUTEX_EXIT "mutex_exit" 660Sstevel@tonic-gate #define LS_MUTEX_DESTROY "mutex_destroy" 670Sstevel@tonic-gate #define LS_MUTEX_TRYENTER "mutex_tryenter" 680Sstevel@tonic-gate #define LS_LOCK_SET "lock_set" 690Sstevel@tonic-gate #define LS_LOCK_SET_SPL "lock_set_spl" 700Sstevel@tonic-gate #define LS_LOCK_TRY "lock_try" 710Sstevel@tonic-gate #define LS_LOCK_CLEAR "lock_clear" 720Sstevel@tonic-gate #define LS_LOCK_CLEAR_SPLX "lock_clear_splx" 730Sstevel@tonic-gate #define LS_CLOCK_UNLOCK "CLOCK_UNLOCK" 740Sstevel@tonic-gate #define LS_RW_ENTER "rw_enter" 750Sstevel@tonic-gate #define LS_RW_EXIT "rw_exit" 760Sstevel@tonic-gate #define LS_RW_TRYENTER "rw_tryenter" 770Sstevel@tonic-gate #define LS_RW_TRYUPGRADE "rw_tryupgrade" 780Sstevel@tonic-gate #define LS_RW_DOWNGRADE "rw_downgrade" 790Sstevel@tonic-gate #define LS_THREAD_LOCK "thread_lock" 800Sstevel@tonic-gate #define LS_THREAD_LOCK_HIGH "thread_lock_high" 810Sstevel@tonic-gate 820Sstevel@tonic-gate #define LS_ACQUIRE "acquire" 830Sstevel@tonic-gate #define LS_RELEASE "release" 840Sstevel@tonic-gate #define LS_SPIN "spin" 850Sstevel@tonic-gate #define LS_BLOCK "block" 860Sstevel@tonic-gate #define LS_UPGRADE "upgrade" 870Sstevel@tonic-gate #define LS_DOWNGRADE "downgrade" 880Sstevel@tonic-gate 890Sstevel@tonic-gate #define LS_TYPE_ADAPTIVE "adaptive" 900Sstevel@tonic-gate #define LS_TYPE_SPIN "spin" 910Sstevel@tonic-gate #define LS_TYPE_THREAD "thread" 920Sstevel@tonic-gate #define LS_TYPE_RW "rw" 930Sstevel@tonic-gate 940Sstevel@tonic-gate #define LSA_ACQUIRE (LS_TYPE_ADAPTIVE "-" LS_ACQUIRE) 950Sstevel@tonic-gate #define LSA_RELEASE (LS_TYPE_ADAPTIVE "-" LS_RELEASE) 960Sstevel@tonic-gate #define LSA_SPIN (LS_TYPE_ADAPTIVE "-" LS_SPIN) 970Sstevel@tonic-gate #define LSA_BLOCK (LS_TYPE_ADAPTIVE "-" LS_BLOCK) 980Sstevel@tonic-gate #define LSS_ACQUIRE (LS_TYPE_SPIN "-" LS_ACQUIRE) 990Sstevel@tonic-gate #define LSS_RELEASE (LS_TYPE_SPIN "-" LS_RELEASE) 1000Sstevel@tonic-gate #define LSS_SPIN (LS_TYPE_SPIN "-" LS_SPIN) 1010Sstevel@tonic-gate #define LSR_ACQUIRE (LS_TYPE_RW "-" LS_ACQUIRE) 1020Sstevel@tonic-gate #define LSR_RELEASE (LS_TYPE_RW "-" LS_RELEASE) 1030Sstevel@tonic-gate #define LSR_BLOCK (LS_TYPE_RW "-" LS_BLOCK) 1040Sstevel@tonic-gate #define LSR_UPGRADE (LS_TYPE_RW "-" LS_UPGRADE) 1050Sstevel@tonic-gate #define LSR_DOWNGRADE (LS_TYPE_RW "-" LS_DOWNGRADE) 1060Sstevel@tonic-gate #define LST_SPIN (LS_TYPE_THREAD "-" LS_SPIN) 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate #ifndef _ASM 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate #include <sys/types.h> 1110Sstevel@tonic-gate #include <sys/inttypes.h> 1120Sstevel@tonic-gate #include <sys/systm.h> 1130Sstevel@tonic-gate #include <sys/atomic.h> 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate #ifdef _KERNEL 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * Platform-independent kernel support for the lockstat driver. 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate extern dtrace_id_t lockstat_probemap[LS_NPROBES]; 1210Sstevel@tonic-gate extern void (*lockstat_probe)(dtrace_id_t, uintptr_t, uintptr_t, 1220Sstevel@tonic-gate uintptr_t, uintptr_t, uintptr_t); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate extern int lockstat_active_threads(void); 1250Sstevel@tonic-gate extern int lockstat_depth(void); 1260Sstevel@tonic-gate extern void lockstat_hot_patch(void); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * Macros to record lockstat probes. 1300Sstevel@tonic-gate */ 1316103Sck142721 1326103Sck142721 /* used for 32 bit systems to avoid overflow */ 1336103Sck142721 #if defined(_ILP32) 1346103Sck142721 #define CLAMP32(x) ((x) > UINT_MAX ? UINT_MAX : (x)) 1356103Sck142721 #else 1366103Sck142721 #define CLAMP32(x) (x) 1376103Sck142721 #endif 1386103Sck142721 1390Sstevel@tonic-gate #define LOCKSTAT_RECORD4(probe, lp, arg0, arg1, arg2, arg3) \ 1400Sstevel@tonic-gate if (lockstat_probemap[(probe)]) { \ 1410Sstevel@tonic-gate dtrace_id_t id; \ 1420Sstevel@tonic-gate curthread->t_lockstat++; \ 1430Sstevel@tonic-gate membar_enter(); \ 1440Sstevel@tonic-gate if ((id = lockstat_probemap[(probe)]) != 0) \ 1450Sstevel@tonic-gate (*lockstat_probe)(id, (uintptr_t)(lp), (arg0), \ 1460Sstevel@tonic-gate (arg1), (arg2), (arg3)); \ 1470Sstevel@tonic-gate curthread->t_lockstat--; \ 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate #define LOCKSTAT_RECORD(probe, lp, arg) \ 1510Sstevel@tonic-gate LOCKSTAT_RECORD4(probe, lp, arg, 0, 0, 0) 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate #define LOCKSTAT_RECORD0(probe, lp) \ 1540Sstevel@tonic-gate LOCKSTAT_RECORD4(probe, lp, 0, 0, 0, 0) 1550Sstevel@tonic-gate 1566103Sck142721 /* 1576103Sck142721 * Return timestamp for start of busy-waiting (for spin probes) 1586103Sck142721 */ 159*6592Sck142721 #define LOCKSTAT_START_TIME(probe) ( \ 160*6592Sck142721 lockstat_probemap[(probe)] ? gethrtime_waitfree() : 0 \ 1616103Sck142721 ) 1626103Sck142721 1636103Sck142721 /* 1646103Sck142721 * Record elapsed time since LOCKSTAT_START_TIME was called if the 1656103Sck142721 * probe is enabled at start and end, else return 0. t_start must 1666103Sck142721 * be the value returned by LOCKSTAT_START_TIME. 1676103Sck142721 */ 1686103Sck142721 #define LOCKSTAT_RECORD_TIME(probe, lp, t_start) \ 1696103Sck142721 if (lockstat_probemap[(probe)]) { \ 1706103Sck142721 dtrace_id_t id; \ 1716103Sck142721 hrtime_t t_spin = (t_start); \ 1726103Sck142721 curthread->t_lockstat++; \ 1736103Sck142721 membar_enter(); \ 1746103Sck142721 if ((id = lockstat_probemap[(probe)]) != 0) { \ 1756103Sck142721 if (t_spin) { \ 176*6592Sck142721 t_spin = gethrtime_waitfree() - t_spin; \ 1776103Sck142721 t_spin = CLAMP32(t_spin); \ 1786103Sck142721 } \ 1796103Sck142721 (*lockstat_probe)(id, (uintptr_t)(lp), t_spin, \ 1806103Sck142721 0, 0, 0); \ 1816103Sck142721 } \ 1826103Sck142721 curthread->t_lockstat--; \ 1836103Sck142721 } 1846103Sck142721 1856103Sck142721 1860Sstevel@tonic-gate #endif /* _KERNEL */ 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate #endif /* _ASM */ 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate #ifdef __cplusplus 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate #endif 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate #endif /* _SYS_LOCKSTAT_H */ 195