| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
//bin/true && exec stap -g $0 ${1+"$@"} |
| 4 |
|
| 5 |
# Override NPTL's "ulimit -s" based default stacksize for new pthreads. |
| 6 |
# Invoke with # stap -g threadstacks.stp -Gsize=NNNN |
| 7 |
# ... add "-x PID" or "-c CMD", unless you wish to target the entire system. |
| 8 |
# ... due to a possible stap bug, might need to add "-d BINARY" for relevant binaries |
| 9 |
# |
| 10 |
# NB: 'size' needs to be a sufficiently large multiple of the OS pagesize, |
| 11 |
# else pthread_create(3) will fail. |
| 12 |
# |
| 13 |
# See also http://sourceware.org/ml/libc-alpha/2013-01/msg00572.html |
| 14 |
|
| 15 |
global size = 0; |
| 16 |
|
| 17 |
# Notice we're probing "/lib*/*/libpthread.so.*". On RHEL7 ppc64 |
| 18 |
# systems, the pthread library that gets used is located in |
| 19 |
# /lib64/power8/. |
| 20 |
probe process("/lib*/libc.so.*").function("allocate_stack")!, |
| 21 |
process("/lib*/libpthread.so.*").function("allocate_stack"), |
| 22 |
process("/lib*/*/libpthread.so.*").function("allocate_stack")? |
| 23 |
{ |
| 24 |
old_size = @choose_defined($attr->stacksize, |
| 25 |
@choose_defined($__default_stacksize, |
| 26 |
$__default_pthread_attr->stacksize)) |
| 27 |
if ((size != 0) && (old_size != size)) { /* requested but not yet changed */ |
| 28 |
/* change it and report */ |
| 29 |
if (@defined($attr->stacksize)) { |
| 30 |
$attr->stacksize = size |
| 31 |
printf("%s[%d] overwrote __default_stacksize@%p (%d->%d)\n", |
| 32 |
execname(), tid(), &$attr->stacksize, old_size, size) |
| 33 |
} else { |
| 34 |
if (@defined($__default_stacksize)) { |
| 35 |
$__default_stacksize = size |
| 36 |
printf("%s[%d] overwrote __default_stacksize@%p (%d->%d)\n", |
| 37 |
execname(), tid(), &$__default_stacksize, old_size, size) |
| 38 |
} |
| 39 |
else { |
| 40 |
$__default_pthread_attr->stacksize = size |
| 41 |
printf("%s[%d] overwrote __default_stacksize@%p (%d->%d)\n", |
| 42 |
execname(), tid(), &$__default_pthread_attr->stacksize, |
| 43 |
old_size, size) |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |