| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (C) 2009 Red Hat Inc. |
| 5 |
* |
| 6 |
* This copyrighted material is made available to anyone wishing to use, |
| 7 |
* modify, copy, or redistribute it subject to the terms and conditions |
| 8 |
* of the GNU General Public License v.2. |
| 9 |
* |
| 10 |
* You should have received a copy of the GNU General Public License |
| 11 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 12 |
* |
| 13 |
* |
| 14 |
* Description: displays which task is holding big kernel lock (BKL) when the |
| 15 |
* number of waiting processes reaches a certain number. |
| 16 |
* |
| 17 |
* Run: stap bkl.stp [-G backtrace=<usecs>] <number_of_processes_waiting> |
| 18 |
* |
| 19 |
* Author: Flavio Leitner <[email protected]> |
| 20 |
* Modified by Jose Castillo <[email protected]> by adding |
| 21 |
* print_backtrace() to get the codepath of the function |
| 22 |
* that holds the bkl and an optional backtrace value that |
| 23 |
* enables/disables print_backtrace(). |
| 24 |
*/ |
| 25 |
|
| 26 |
# how many tasks waiting on big lock |
| 27 |
global waiting = 0 |
| 28 |
|
| 29 |
# when the current holder first obtained the lock |
| 30 |
global holder_time |
| 31 |
|
| 32 |
# are we printing backtraces? |
| 33 |
global backtrace = -1 |
| 34 |
|
| 35 |
probe begin { |
| 36 |
printf("stap ready\n"); |
| 37 |
} |
| 38 |
|
| 39 |
probe kernel.function("_lock_kernel").call!, |
| 40 |
kernel.function("lock_kernel").call |
| 41 |
{ |
| 42 |
++waiting; |
| 43 |
} |
| 44 |
|
| 45 |
probe kernel.function("_lock_kernel").return!, |
| 46 |
kernel.function("lock_kernel").return |
| 47 |
{ |
| 48 |
# under biglock |
| 49 |
holder_time = gettimeofday_us(); |
| 50 |
--waiting; |
| 51 |
} |
| 52 |
|
| 53 |
probe kernel.function("_unlock_kernel")!, |
| 54 |
kernel.function("unlock_kernel") |
| 55 |
{ |
| 56 |
# under biglock |
| 57 |
backtrace_enabled = 0 |
| 58 |
if (waiting >= $1) { |
| 59 |
if (holder_time != 0) { |
| 60 |
waiting_time = gettimeofday_us() - holder_time |
| 61 |
if ( backtrace != -1 && waiting_time >= backtrace ) { |
| 62 |
backtrace_enabled = 1 |
| 63 |
} |
| 64 |
} |
| 65 |
else { |
| 66 |
waiting_time = -1; |
| 67 |
} |
| 68 |
|
| 69 |
printf("%-25s: waiting(%d), holder: %s(%d) %dus\n", |
| 70 |
ctime(gettimeofday_s()), |
| 71 |
waiting, |
| 72 |
execname(), |
| 73 |
pid(), |
| 74 |
(holder_time != 0) ? gettimeofday_us() - holder_time : -1); |
| 75 |
|
| 76 |
if (backtrace_enabled) |
| 77 |
print_backtrace() |
| 78 |
|
| 79 |
} |
| 80 |
holder_time = 0 |
| 81 |
} |
| 82 |
|
| 83 |
probe end { printf("stap exiting\n"); } |