![]() |
|
|||
0001 #!/bin/bash 0002 # SPDX-License-Identifier: GPL-2.0 0003 # 0004 # Here's how to use this: 0005 # 0006 # This script is used to help find functions that are being traced by function 0007 # tracer or function graph tracing that causes the machine to reboot, hang, or 0008 # crash. Here's the steps to take. 0009 # 0010 # First, determine if function tracing is working with a single function: 0011 # 0012 # (note, if this is a problem with function_graph tracing, then simply 0013 # replace "function" with "function_graph" in the following steps). 0014 # 0015 # # cd /sys/kernel/debug/tracing 0016 # # echo schedule > set_ftrace_filter 0017 # # echo function > current_tracer 0018 # 0019 # If this works, then we know that something is being traced that shouldn't be. 0020 # 0021 # # echo nop > current_tracer 0022 # 0023 # # cat available_filter_functions > ~/full-file 0024 # # ftrace-bisect ~/full-file ~/test-file ~/non-test-file 0025 # # cat ~/test-file > set_ftrace_filter 0026 # 0027 # *** Note *** this will take several minutes. Setting multiple functions is 0028 # an O(n^2) operation, and we are dealing with thousands of functions. So go 0029 # have coffee, talk with your coworkers, read facebook. And eventually, this 0030 # operation will end. 0031 # 0032 # # echo function > current_tracer 0033 # 0034 # If it crashes, we know that ~/test-file has a bad function. 0035 # 0036 # Reboot back to test kernel. 0037 # 0038 # # cd /sys/kernel/debug/tracing 0039 # # mv ~/test-file ~/full-file 0040 # 0041 # If it didn't crash. 0042 # 0043 # # echo nop > current_tracer 0044 # # mv ~/non-test-file ~/full-file 0045 # 0046 # Get rid of the other test file from previous run (or save them off somewhere). 0047 # # rm -f ~/test-file ~/non-test-file 0048 # 0049 # And start again: 0050 # 0051 # # ftrace-bisect ~/full-file ~/test-file ~/non-test-file 0052 # 0053 # The good thing is, because this cuts the number of functions in ~/test-file 0054 # by half, the cat of it into set_ftrace_filter takes half as long each 0055 # iteration, so don't talk so much at the water cooler the second time. 0056 # 0057 # Eventually, if you did this correctly, you will get down to the problem 0058 # function, and all we need to do is to notrace it. 0059 # 0060 # The way to figure out if the problem function is bad, just do: 0061 # 0062 # # echo <problem-function> > set_ftrace_notrace 0063 # # echo > set_ftrace_filter 0064 # # echo function > current_tracer 0065 # 0066 # And if it doesn't crash, we are done. 0067 # 0068 # If it does crash, do this again (there's more than one problem function) 0069 # but you need to echo the problem function(s) into set_ftrace_notrace before 0070 # enabling function tracing in the above steps. Or if you can compile the 0071 # kernel, annotate the problem functions with "notrace" and start again. 0072 # 0073 0074 0075 if [ $# -ne 3 ]; then 0076 echo 'usage: ftrace-bisect full-file test-file non-test-file' 0077 exit 0078 fi 0079 0080 full=$1 0081 test=$2 0082 nontest=$3 0083 0084 x=`cat $full | wc -l` 0085 if [ $x -eq 1 ]; then 0086 echo "There's only one function left, must be the bad one" 0087 cat $full 0088 exit 0 0089 fi 0090 0091 let x=$x/2 0092 let y=$x+1 0093 0094 if [ ! -f $full ]; then 0095 echo "$full does not exist" 0096 exit 1 0097 fi 0098 0099 if [ -f $test ]; then 0100 echo -n "$test exists, delete it? [y/N]" 0101 read a 0102 if [ "$a" != "y" -a "$a" != "Y" ]; then 0103 exit 1 0104 fi 0105 fi 0106 0107 if [ -f $nontest ]; then 0108 echo -n "$nontest exists, delete it? [y/N]" 0109 read a 0110 if [ "$a" != "y" -a "$a" != "Y" ]; then 0111 exit 1 0112 fi 0113 fi 0114 0115 sed -ne "1,${x}p" $full > $test 0116 sed -ne "$y,\$p" $full > $nontest
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |