| 1 |
source $srcdir/$subdir/onthefly_common.tcl |
| 2 |
|
| 3 |
set test "uprobes_onthefly" |
| 4 |
if {![installtest_p] || ![inode_uprobes_p]} { |
| 5 |
untested "$test" |
| 6 |
return |
| 7 |
} |
| 8 |
|
| 9 |
# Goal: Ensure that inode-uprobes properly support on-the-fly arming/disarming. |
| 10 |
# The script consists of a process.function and a process.function.return whose |
| 11 |
# conditions are toggled by a timer probe. We then analyze the actual debug |
| 12 |
# statements printed out to ensure the toggled probes are armed and disarmed as |
| 13 |
# expected. |
| 14 |
|
| 15 |
# Runs stap on a script with the given arguments |
| 16 |
proc run_stap {subtest args script} { |
| 17 |
global test |
| 18 |
|
| 19 |
# Now start the application |
| 20 |
set pid [exec ./$test.x &] |
| 21 |
|
| 22 |
# We always need the DEBUG flags |
| 23 |
set args "$args -DDEBUG_STP_ON_THE_FLY" |
| 24 |
|
| 25 |
# The script we use uses @entry(), which uses maps underneath. Since we will |
| 26 |
# be stressing the system, we need to ensure we will have enough space for |
| 27 |
# many map items. |
| 28 |
set args "$args -DMAXMAPENTRIES=100000" |
| 29 |
|
| 30 |
# This test seems especially prone to exceeding the default overhead |
| 31 |
# threshold in the harder subtests. Disable overload checking. |
| 32 |
set args "$args -DSTP_NO_OVERLOAD" |
| 33 |
|
| 34 |
verbose -log "running stap -e {$script} $args" |
| 35 |
# Run stap and catch any errors (we will rethrow it later) |
| 36 |
set err [catch {eval exec stap -e {$script} $args} out] |
| 37 |
verbose -log "stap rc: $err, output: $out" |
| 38 |
|
| 39 |
# Kill app |
| 40 |
kill -INT $pid 1 |
| 41 |
|
| 42 |
if {$err} {error $out} |
| 43 |
return $out |
| 44 |
} |
| 45 |
|
| 46 |
# Returns a script with some variables replaced. |
| 47 |
# SUBTEST name of subtest |
| 48 |
# ENABLED set to 1 to start the target probe as enabled, 0 as disabled |
| 49 |
# MAXTOGGLES number of times we toggle the target probe condition |
| 50 |
# TIMER if a number, then it's the period of the timer probe which |
| 51 |
# toggles the target probes, if set to 'profile' then instead a |
| 52 |
# timer.profile probe is used to toggle the target probe, if set |
| 53 |
# to 'hardcore' then both a timer.profile probe and a |
| 54 |
# kernel.trace("*") probe is used for toggling, if set to 'max' |
| 55 |
# then a lot of various probe points are used for toggling |
| 56 |
proc make_script {SUBTEST ENABLED MAXTOGGLES TIMER} { |
| 57 |
global test |
| 58 |
|
| 59 |
set script { |
| 60 |
|
| 61 |
# We want these probes to fire as deterministically as possible so that |
| 62 |
# their outputs can easily be predicted and compared. Unfortunately this |
| 63 |
# is complicated by multiple facts, including |
| 64 |
# (1) the timer might be so fast that the probes don't have time to |
| 65 |
# fire and print something, |
| 66 |
# (2) the uprobe might print something after it is re-enabled, but |
| 67 |
# before the uretprobe is re-enabled, |
| 68 |
# (3) disabling a uretprobe won't stop an already running handler. |
| 69 |
# |
| 70 |
# To get around these issues, we use a simple state machine. The states |
| 71 |
# are as follow: |
| 72 |
# |
| 73 |
# 0 = cond disabled |
| 74 |
# 1 = cond enabled, but uprobe && uretprobe not yet enabled |
| 75 |
# 2 = cond enabled, uprobe enabled, uretprobe not yet enabled |
| 76 |
# 3 = cond enabled, uprobe && uretprobe enabled, nothing printed yet |
| 77 |
# 4 = cond enabled, 'hit' printed but not 'rethit' |
| 78 |
# 5 = cond enabled, 'rethit' printed |
| 79 |
|
| 80 |
global state = ENABLED |
| 81 |
global toggles = 0 |
| 82 |
|
| 83 |
probe process("./TEST.x").function("foo") if (state > 0) { |
| 84 |
if (state == 3) { |
| 85 |
println("hit") |
| 86 |
state++; |
| 87 |
} else if (state == 1) { |
| 88 |
state++; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
probe process("./TEST.x").function("foo").return if (state > 0) { |
| 93 |
# ensure that nothing changed during the vfs_read body |
| 94 |
if (state != @entry(state)) |
| 95 |
next |
| 96 |
if (state == 4) { |
| 97 |
println("rethit") |
| 98 |
state++; |
| 99 |
} else if (state == 2) { |
| 100 |
state++; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
probe timer.us(TIMER) { |
| 105 |
if (state != 0 && state != 5) |
| 106 |
next # give probes more time to move through the states |
| 107 |
toggles++ |
| 108 |
if (toggles > MAXTOGGLES) |
| 109 |
exit() |
| 110 |
else { |
| 111 |
println("toggling") |
| 112 |
state = !state |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
probe timer.s(360) { |
| 117 |
println("timed out") |
| 118 |
exit() |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
# On ppc64, you can't probe the hcall_* tracepoints (PR17126: |
| 123 |
# tracepoints.exp testcase causing stalls/hang on ppc64). This was |
| 124 |
# worked around by making a tracepoint blocklist. However, this |
| 125 |
# test is using the '-g' (guru) argument to systemtap, which causes |
| 126 |
# systemtap to ignore the tracepoint blocklist. So, on ppc64, we'll |
| 127 |
# probe all the kernel tracepoints *except* for the ones starting |
| 128 |
# with 'h'. |
| 129 |
if {[string match ppc* $::tcl_platform(machine)]} { |
| 130 |
set kernel_trace {kernel.trace("[a-gi-z]*")} |
| 131 |
} else { |
| 132 |
set kernel_trace {kernel.trace("*")} |
| 133 |
} |
| 134 |
|
| 135 |
# Set in values |
| 136 |
set script [string map "TEST $test \ |
| 137 |
SUBTEST $SUBTEST \ |
| 138 |
ENABLED $ENABLED \ |
| 139 |
MAXTOGGLES $MAXTOGGLES" $script] |
| 140 |
if {[string match $TIMER "profile"]} { |
| 141 |
set script [string map "timer.us(TIMER) timer.profile" $script] |
| 142 |
} elseif {[string match $TIMER "hardcore"]} { |
| 143 |
set script [string map "timer.us(TIMER) \ |
| 144 |
{timer.profile, $kernel_trace}" $script] |
| 145 |
} elseif {[string match $TIMER "max"]} { |
| 146 |
set script [string map "timer.us(TIMER) \ |
| 147 |
{begin, end, error, kernel.function(\"*@workqueue.c\"), \ |
| 148 |
process.begin, process.end, $kernel_trace, \ |
| 149 |
netfilter.pf(\"NFPROTO_IPV4\").hook(\"NF_INET_LOCAL_IN\")?, \ |
| 150 |
netfilter.pf(\"NFPROTO_IPV4\").hook(\"NF_INET_LOCAL_OUT\")?, \ |
| 151 |
perf.sw.cpu_clock.sample(1000000)?, timer.profile.tick?}" $script] |
| 152 |
} else { |
| 153 |
set script [string map "TIMER $TIMER" $script] |
| 154 |
} |
| 155 |
|
| 156 |
return $script |
| 157 |
} |
| 158 |
|
| 159 |
# Creates the pattern which will be used by the is_valid_output proc to |
| 160 |
# determine if the output is valid. In other words, given the initial value of |
| 161 |
# enabled, the maximum number of toggles, and whether on-the-fly is turned on or |
| 162 |
# not, this proc determines what will be the output of stap. |
| 163 |
proc make_pattern {subtest start_enabled maxtoggles} { |
| 164 |
set pattern "" |
| 165 |
|
| 166 |
# If we're not starting as enabled, then the kprobes will be registered as |
| 167 |
# disabled. |
| 168 |
if {!$start_enabled} { |
| 169 |
lappend pattern "* not registering (uretprobe) pidx ?" |
| 170 |
lappend pattern "* not registering (uprobe) pidx ?" |
| 171 |
lappend pattern "* not registering (uprobe) pidx ?" |
| 172 |
} |
| 173 |
|
| 174 |
# For each toggle: |
| 175 |
# - if we were enabled, then we would have had 'hit' and 'rethit' lines |
| 176 |
# - if i == maxtoggles, then we'll exit so nothing more will be printed |
| 177 |
# - if i < maxtoggles, then the timer probe will output 'toggling' followed |
| 178 |
# by 'unregistering' or 'registering' lines if on-the-fly is turned on |
| 179 |
for {set i 0} {$i <= $maxtoggles} {incr i} { |
| 180 |
if {$start_enabled} { |
| 181 |
lappend pattern "hit" "rethit" |
| 182 |
} |
| 183 |
if {$i < $maxtoggles} { |
| 184 |
lappend pattern "toggling" |
| 185 |
if {$start_enabled} { |
| 186 |
set start_enabled 0 |
| 187 |
lappend pattern "* unregistering (uretprobe) pidx ?" |
| 188 |
lappend pattern "* unregistering (uprobe) pidx ?" |
| 189 |
lappend pattern "* unregistering (uprobe) pidx ?" |
| 190 |
} else { |
| 191 |
set start_enabled 1 |
| 192 |
if {$i < $maxtoggles} { |
| 193 |
lappend pattern "* registering (uretprobe) pidx ?" |
| 194 |
lappend pattern "* registering (uprobe) pidx ?" |
| 195 |
lappend pattern "* registering (uprobe) pidx ?" |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
return $pattern |
| 202 |
} |
| 203 |
|
| 204 |
set c_program { |
| 205 |
int foo(int i) { |
| 206 |
int j = i; |
| 207 |
return j+i*2; |
| 208 |
} |
| 209 |
int main(int argc, char **argv) { |
| 210 |
while (1) { |
| 211 |
argc = foo(argc); |
| 212 |
} |
| 213 |
return argc; |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
# Compile program (feed program through stdin, -x c --> C code) |
| 218 |
catch {exec gcc -g -o $test.x -x c - << $c_program} err |
| 219 |
if {$err == "" && [file exists $test.x]} { |
| 220 |
pass "$test (compilation)" |
| 221 |
} else { |
| 222 |
fail "$test (compilation)" |
| 223 |
verbose -log "GCC output: $err" |
| 224 |
return |
| 225 |
} |
| 226 |
|
| 227 |
# Various on-the-fly tests |
| 228 |
|
| 229 |
# Toggle 0, 1, 2, 3, 4, and 5 times. This is important since we test if the |
| 230 |
# probes finish well when disabled/enabled. |
| 231 |
|
| 232 |
run_subtest_valid "otf_finish_at_start_disabled" 0 0 500000 |
| 233 |
run_subtest_valid "otf_finish_at_start_enabled" 1 0 500000 |
| 234 |
run_subtest_valid "otf_start_disabled_iter_1" 0 1 500000 |
| 235 |
run_subtest_valid "otf_start_enabled_iter_1" 1 1 500000 |
| 236 |
run_subtest_valid "otf_start_disabled_iter_2" 0 2 500000 |
| 237 |
run_subtest_valid "otf_start_enabled_iter_2" 1 2 500000 |
| 238 |
run_subtest_valid "otf_start_disabled_iter_3" 0 3 500000 |
| 239 |
run_subtest_valid "otf_start_enabled_iter_3" 1 3 500000 |
| 240 |
run_subtest_valid "otf_start_disabled_iter_4" 0 4 500000 |
| 241 |
run_subtest_valid "otf_start_enabled_iter_4" 1 4 500000 |
| 242 |
run_subtest_valid "otf_start_disabled_iter_5" 0 5 500000 |
| 243 |
run_subtest_valid "otf_start_enabled_iter_5" 1 5 500000 |
| 244 |
|
| 245 |
# Small interval tests |
| 246 |
|
| 247 |
run_subtest_valid "otf_timer_100ms" 1 5 100000 |
| 248 |
run_subtest_valid "otf_timer_50ms" 1 5 50000 |
| 249 |
|
| 250 |
# NB: if we go any shorter, the kernel might not have a chance to run |
| 251 |
# systemtap_module_refresh() before the next toggling occurs, throwing off the |
| 252 |
# expected output. |
| 253 |
|
| 254 |
# Stress tests |
| 255 |
|
| 256 |
# These tests are not validated, i.e. their outputs are not checked against a |
| 257 |
# pattern (see NB above why). Instead, they're just meant to stress the |
| 258 |
# on-the-fly mechanism to ensure stap/the kernel doesn't die. So if stap is |
| 259 |
# successfully run and terminated, we just default to a pass. |
| 260 |
|
| 261 |
run_subtest_stress "otf_stress_10ms_iter_50" 1 50 10000 |
| 262 |
run_subtest_stress "otf_stress_5ms_iter_50" 1 50 5000 |
| 263 |
run_subtest_stress "otf_stress_1ms_iter_50" 1 50 1000 |
| 264 |
run_subtest_stress "otf_stress_500us_iter_50" 1 50 500 |
| 265 |
run_subtest_stress "otf_stress_100us_iter_50" 1 50 100 |
| 266 |
|
| 267 |
run_subtest_stress "otf_stress_prof_iter_2000" 1 2000 profile |
| 268 |
|
| 269 |
# Use 100 us for interval |
| 270 |
run_subtest_stress "otf_stress_hard_iter_2000" 1 2000 hardcore \ |
| 271 |
-D STP_ON_THE_FLY_INTERVAL=100000 |
| 272 |
|
| 273 |
run_subtest_stress "otf_stress_max_iter_5000" 1 5000 max \ |
| 274 |
-D STP_ON_THE_FLY_INTERVAL=100000 |
| 275 |
|
| 276 |
if {[file exists $test.x]} { |
| 277 |
file delete $test.x |
| 278 |
} |