1 #!/usr/sbin/dtrace -qs 2 3 /*- 4 * Copyright (c) 2008-2012 Alexander Leidinger <netchild@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer 12 * in this position and unchanged. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * Check if the internal locks are correctly acquired/released: 31 * - no recursive locking (mtx locks, write locks) 32 * - no unlocking of already unlocked one 33 * 34 * Print stacktrace if a lock is longer locked than about 10sec or more. 35 */ 36 37 #pragma D option dynvarsize=32m 38 #pragma D option specsize=32m 39 40 BEGIN 41 { 42 check["futex_mtx"] = 0; 43 } 44 45 linuxulator*:locks:futex_mtx:locked 46 /check[probefunc] > 0/ 47 { 48 printf("ERROR: recursive lock of %s (%p),", probefunc, arg0); 49 printf(" or missing SDT probe in kernel. Stack trace follows:"); 50 stack(); 51 } 52 53 linuxulator*:locks:futex_mtx:locked 54 { 55 ++check[probefunc]; 56 @stats[probefunc] = count(); 57 58 ts[probefunc] = timestamp; 59 spec[probefunc] = speculation(); 60 } 61 62 linuxulator*:locks:futex_mtx:unlock 63 /check[probefunc] == 0/ 64 { 65 printf("ERROR: unlock attempt of unlocked %s (%p),", probefunc, arg0); 66 printf(" missing SDT probe in kernel, or dtrace program started"); 67 printf(" while the %s was already held (race condition).", probefunc); 68 printf(" Stack trace follows:"); 69 stack(); 70 } 71 72 linuxulator*:locks:futex_mtx:unlock 73 { 74 discard(spec[probefunc]); 75 spec[probefunc] = 0; 76 --check[probefunc]; 77 } 78 79 /* Timeout handling */ 80 81 tick-10s 82 /spec["futex_mtx"] != 0 && timestamp - ts["futex_mtx"] >= 9999999000/ 83 { 84 commit(spec["futex_mtx"]); 85 spec["futex_mtx"] = 0; 86 } 87 88 89 /* Statistics */ 90 91 END 92 { 93 printf("Number of locks per type:"); 94 printa(@stats); 95 } 96