11f198e22SChangbin Du======================== 21f198e22SChangbin Duftrace - Function Tracer 31f198e22SChangbin Du======================== 41f198e22SChangbin Du 51f198e22SChangbin DuCopyright 2008 Red Hat Inc. 61f198e22SChangbin Du 71f198e22SChangbin Du:Author: Steven Rostedt <srostedt@redhat.com> 81f198e22SChangbin Du:License: The GNU Free Documentation License, Version 1.2 91f198e22SChangbin Du (dual licensed under the GPL v2) 101f198e22SChangbin Du:Original Reviewers: Elias Oltmanns, Randy Dunlap, Andrew Morton, 111f198e22SChangbin Du John Kacur, and David Teigland. 121f198e22SChangbin Du 131f198e22SChangbin Du- Written for: 2.6.28-rc2 141f198e22SChangbin Du- Updated for: 3.10 151f198e22SChangbin Du- Updated for: 4.13 - Copyright 2017 VMware Inc. Steven Rostedt 161f198e22SChangbin Du- Converted to rst format - Changbin Du <changbin.du@intel.com> 171f198e22SChangbin Du 181f198e22SChangbin DuIntroduction 191f198e22SChangbin Du------------ 201f198e22SChangbin Du 211f198e22SChangbin DuFtrace is an internal tracer designed to help out developers and 221f198e22SChangbin Dudesigners of systems to find what is going on inside the kernel. 231f198e22SChangbin DuIt can be used for debugging or analyzing latencies and 241f198e22SChangbin Duperformance issues that take place outside of user-space. 251f198e22SChangbin Du 261f198e22SChangbin DuAlthough ftrace is typically considered the function tracer, it 271f198e22SChangbin Duis really a framework of several assorted tracing utilities. 281f198e22SChangbin DuThere's latency tracing to examine what occurs between interrupts 291f198e22SChangbin Dudisabled and enabled, as well as for preemption and from a time 301f198e22SChangbin Dua task is woken to the task is actually scheduled in. 311f198e22SChangbin Du 321f198e22SChangbin DuOne of the most common uses of ftrace is the event tracing. 331f198e22SChangbin DuThroughout the kernel is hundreds of static event points that 341f198e22SChangbin Ducan be enabled via the tracefs file system to see what is 351f198e22SChangbin Dugoing on in certain parts of the kernel. 361f198e22SChangbin Du 373e28c5caSManbingSee events.rst for more information. 381f198e22SChangbin Du 391f198e22SChangbin Du 401f198e22SChangbin DuImplementation Details 411f198e22SChangbin Du---------------------- 421f198e22SChangbin Du 4381a2d578SMauro Carvalho ChehabSee Documentation/trace/ftrace-design.rst for details for arch porters and such. 441f198e22SChangbin Du 451f198e22SChangbin Du 461f198e22SChangbin DuThe File System 471f198e22SChangbin Du--------------- 481f198e22SChangbin Du 491f198e22SChangbin DuFtrace uses the tracefs file system to hold the control files as 501f198e22SChangbin Duwell as the files to display output. 511f198e22SChangbin Du 521f198e22SChangbin DuWhen tracefs is configured into the kernel (which selecting any ftrace 531f198e22SChangbin Duoption will do) the directory /sys/kernel/tracing will be created. To mount 541f198e22SChangbin Duthis directory, you can add to your /etc/fstab file:: 551f198e22SChangbin Du 561f198e22SChangbin Du tracefs /sys/kernel/tracing tracefs defaults 0 0 571f198e22SChangbin Du 581f198e22SChangbin DuOr you can mount it at run time with:: 591f198e22SChangbin Du 601f198e22SChangbin Du mount -t tracefs nodev /sys/kernel/tracing 611f198e22SChangbin Du 621f198e22SChangbin DuFor quicker access to that directory you may want to make a soft link to 631f198e22SChangbin Duit:: 641f198e22SChangbin Du 651f198e22SChangbin Du ln -s /sys/kernel/tracing /tracing 661f198e22SChangbin Du 671f198e22SChangbin Du.. attention:: 681f198e22SChangbin Du 691f198e22SChangbin Du Before 4.1, all ftrace tracing control files were within the debugfs 701f198e22SChangbin Du file system, which is typically located at /sys/kernel/debug/tracing. 711f198e22SChangbin Du For backward compatibility, when mounting the debugfs file system, 721f198e22SChangbin Du the tracefs file system will be automatically mounted at: 731f198e22SChangbin Du 741f198e22SChangbin Du /sys/kernel/debug/tracing 751f198e22SChangbin Du 761f198e22SChangbin Du All files located in the tracefs file system will be located in that 771f198e22SChangbin Du debugfs file system directory as well. 781f198e22SChangbin Du 791f198e22SChangbin Du.. attention:: 801f198e22SChangbin Du 811f198e22SChangbin Du Any selected ftrace option will also create the tracefs file system. 821f198e22SChangbin Du The rest of the document will assume that you are in the ftrace directory 831f198e22SChangbin Du (cd /sys/kernel/tracing) and will only concentrate on the files within that 841f198e22SChangbin Du directory and not distract from the content with the extended 851f198e22SChangbin Du "/sys/kernel/tracing" path name. 861f198e22SChangbin Du 871f198e22SChangbin DuThat's it! (assuming that you have ftrace configured into your kernel) 881f198e22SChangbin Du 891f198e22SChangbin DuAfter mounting tracefs you will have access to the control and output files 901f198e22SChangbin Duof ftrace. Here is a list of some of the key files: 911f198e22SChangbin Du 921f198e22SChangbin Du 931f198e22SChangbin Du Note: all time values are in microseconds. 941f198e22SChangbin Du 951f198e22SChangbin Du current_tracer: 961f198e22SChangbin Du 971f198e22SChangbin Du This is used to set or display the current tracer 98d693b288SFrank A. Cancio Bello that is configured. Changing the current tracer clears 99d693b288SFrank A. Cancio Bello the ring buffer content as well as the "snapshot" buffer. 1001f198e22SChangbin Du 1011f198e22SChangbin Du available_tracers: 1021f198e22SChangbin Du 1031f198e22SChangbin Du This holds the different types of tracers that 1041f198e22SChangbin Du have been compiled into the kernel. The 1051f198e22SChangbin Du tracers listed here can be configured by 1061f198e22SChangbin Du echoing their name into current_tracer. 1071f198e22SChangbin Du 1081f198e22SChangbin Du tracing_on: 1091f198e22SChangbin Du 1101f198e22SChangbin Du This sets or displays whether writing to the trace 1111f198e22SChangbin Du ring buffer is enabled. Echo 0 into this file to disable 1121f198e22SChangbin Du the tracer or 1 to enable it. Note, this only disables 1131f198e22SChangbin Du writing to the ring buffer, the tracing overhead may 1141f198e22SChangbin Du still be occurring. 1151f198e22SChangbin Du 1161f198e22SChangbin Du The kernel function tracing_off() can be used within the 1171f198e22SChangbin Du kernel to disable writing to the ring buffer, which will 1181f198e22SChangbin Du set this file to "0". User space can re-enable tracing by 1191f198e22SChangbin Du echoing "1" into the file. 1201f198e22SChangbin Du 1211f198e22SChangbin Du Note, the function and event trigger "traceoff" will also 1221f198e22SChangbin Du set this file to zero and stop tracing. Which can also 1231f198e22SChangbin Du be re-enabled by user space using this file. 1241f198e22SChangbin Du 1251f198e22SChangbin Du trace: 1261f198e22SChangbin Du 1271f198e22SChangbin Du This file holds the output of the trace in a human 1288a815e6bSSteven Rostedt (VMware) readable format (described below). Opening this file for 129d693b288SFrank A. Cancio Bello writing with the O_TRUNC flag clears the ring buffer content. 1308a815e6bSSteven Rostedt (VMware) Note, this file is not a consumer. If tracing is off 1318a815e6bSSteven Rostedt (VMware) (no tracer running, or tracing_on is zero), it will produce 1328a815e6bSSteven Rostedt (VMware) the same output each time it is read. When tracing is on, 1338a815e6bSSteven Rostedt (VMware) it may produce inconsistent results as it tries to read 1348a815e6bSSteven Rostedt (VMware) the entire buffer without consuming it. 1351f198e22SChangbin Du 1361f198e22SChangbin Du trace_pipe: 1371f198e22SChangbin Du 1381f198e22SChangbin Du The output is the same as the "trace" file but this 1391f198e22SChangbin Du file is meant to be streamed with live tracing. 1401f198e22SChangbin Du Reads from this file will block until new data is 1411f198e22SChangbin Du retrieved. Unlike the "trace" file, this file is a 1421f198e22SChangbin Du consumer. This means reading from this file causes 1431f198e22SChangbin Du sequential reads to display more current data. Once 1441f198e22SChangbin Du data is read from this file, it is consumed, and 1451f198e22SChangbin Du will not be read again with a sequential read. The 1461f198e22SChangbin Du "trace" file is static, and if the tracer is not 1471f198e22SChangbin Du adding more data, it will display the same 1488a815e6bSSteven Rostedt (VMware) information every time it is read. 1491f198e22SChangbin Du 1501f198e22SChangbin Du trace_options: 1511f198e22SChangbin Du 1521f198e22SChangbin Du This file lets the user control the amount of data 1531f198e22SChangbin Du that is displayed in one of the above output 1541f198e22SChangbin Du files. Options also exist to modify how a tracer 1551f198e22SChangbin Du or events work (stack traces, timestamps, etc). 1561f198e22SChangbin Du 1571f198e22SChangbin Du options: 1581f198e22SChangbin Du 1591f198e22SChangbin Du This is a directory that has a file for every available 1601f198e22SChangbin Du trace option (also in trace_options). Options may also be set 1611f198e22SChangbin Du or cleared by writing a "1" or "0" respectively into the 1621f198e22SChangbin Du corresponding file with the option name. 1631f198e22SChangbin Du 1641f198e22SChangbin Du tracing_max_latency: 1651f198e22SChangbin Du 1661f198e22SChangbin Du Some of the tracers record the max latency. 1671f198e22SChangbin Du For example, the maximum time that interrupts are disabled. 1681f198e22SChangbin Du The maximum time is saved in this file. The max trace will also be 1691f198e22SChangbin Du stored, and displayed by "trace". A new max trace will only be 1701f198e22SChangbin Du recorded if the latency is greater than the value in this file 1711f198e22SChangbin Du (in microseconds). 1721f198e22SChangbin Du 1731f198e22SChangbin Du By echoing in a time into this file, no latency will be recorded 1741f198e22SChangbin Du unless it is greater than the time in this file. 1751f198e22SChangbin Du 1761f198e22SChangbin Du tracing_thresh: 1771f198e22SChangbin Du 1781f198e22SChangbin Du Some latency tracers will record a trace whenever the 1791f198e22SChangbin Du latency is greater than the number in this file. 1801f198e22SChangbin Du Only active when the file contains a number greater than 0. 1811f198e22SChangbin Du (in microseconds) 1821f198e22SChangbin Du 1831f198e22SChangbin Du buffer_size_kb: 1841f198e22SChangbin Du 1851f198e22SChangbin Du This sets or displays the number of kilobytes each CPU 1861f198e22SChangbin Du buffer holds. By default, the trace buffers are the same size 1871f198e22SChangbin Du for each CPU. The displayed number is the size of the 1881f198e22SChangbin Du CPU buffer and not total size of all buffers. The 1891f198e22SChangbin Du trace buffers are allocated in pages (blocks of memory 1901f198e22SChangbin Du that the kernel uses for allocation, usually 4 KB in size). 191a65d634eSFrank A. Cancio Bello A few extra pages may be allocated to accommodate buffer management 192a65d634eSFrank A. Cancio Bello meta-data. If the last page allocated has room for more bytes 1931f198e22SChangbin Du than requested, the rest of the page will be used, 1941f198e22SChangbin Du making the actual allocation bigger than requested or shown. 1951f198e22SChangbin Du ( Note, the size may not be a multiple of the page size 1961f198e22SChangbin Du due to buffer management meta-data. ) 1971f198e22SChangbin Du 1981f198e22SChangbin Du Buffer sizes for individual CPUs may vary 1991f198e22SChangbin Du (see "per_cpu/cpu0/buffer_size_kb" below), and if they do 2001f198e22SChangbin Du this file will show "X". 2011f198e22SChangbin Du 2021f198e22SChangbin Du buffer_total_size_kb: 2031f198e22SChangbin Du 2041f198e22SChangbin Du This displays the total combined size of all the trace buffers. 2051f198e22SChangbin Du 2061f198e22SChangbin Du free_buffer: 2071f198e22SChangbin Du 2081f198e22SChangbin Du If a process is performing tracing, and the ring buffer should be 2091f198e22SChangbin Du shrunk "freed" when the process is finished, even if it were to be 2101f198e22SChangbin Du killed by a signal, this file can be used for that purpose. On close 2111f198e22SChangbin Du of this file, the ring buffer will be resized to its minimum size. 2121f198e22SChangbin Du Having a process that is tracing also open this file, when the process 2131f198e22SChangbin Du exits its file descriptor for this file will be closed, and in doing so, 2141f198e22SChangbin Du the ring buffer will be "freed". 2151f198e22SChangbin Du 2161f198e22SChangbin Du It may also stop tracing if disable_on_free option is set. 2171f198e22SChangbin Du 2181f198e22SChangbin Du tracing_cpumask: 2191f198e22SChangbin Du 2201f198e22SChangbin Du This is a mask that lets the user only trace on specified CPUs. 2211f198e22SChangbin Du The format is a hex string representing the CPUs. 2221f198e22SChangbin Du 2231f198e22SChangbin Du set_ftrace_filter: 2241f198e22SChangbin Du 2251f198e22SChangbin Du When dynamic ftrace is configured in (see the 2261f198e22SChangbin Du section below "dynamic ftrace"), the code is dynamically 2271f198e22SChangbin Du modified (code text rewrite) to disable calling of the 2281f198e22SChangbin Du function profiler (mcount). This lets tracing be configured 2291f198e22SChangbin Du in with practically no overhead in performance. This also 2301f198e22SChangbin Du has a side effect of enabling or disabling specific functions 2311f198e22SChangbin Du to be traced. Echoing names of functions into this file 2321f198e22SChangbin Du will limit the trace to only those functions. 23332fb7ef6SSteffen Maier This influences the tracers "function" and "function_graph" 23432fb7ef6SSteffen Maier and thus also function profiling (see "function_profile_enabled"). 2351f198e22SChangbin Du 2361f198e22SChangbin Du The functions listed in "available_filter_functions" are what 2371f198e22SChangbin Du can be written into this file. 2381f198e22SChangbin Du 2391f198e22SChangbin Du This interface also allows for commands to be used. See the 2401f198e22SChangbin Du "Filter commands" section for more details. 2411f198e22SChangbin Du 2425b8914a6SFrank A. Cancio Bello As a speed up, since processing strings can be quite expensive 243f79b3f33SSteven Rostedt (VMware) and requires a check of all functions registered to tracing, instead 244f79b3f33SSteven Rostedt (VMware) an index can be written into this file. A number (starting with "1") 245f79b3f33SSteven Rostedt (VMware) written will instead select the same corresponding at the line position 246f79b3f33SSteven Rostedt (VMware) of the "available_filter_functions" file. 247f79b3f33SSteven Rostedt (VMware) 2481f198e22SChangbin Du set_ftrace_notrace: 2491f198e22SChangbin Du 2501f198e22SChangbin Du This has an effect opposite to that of 2511f198e22SChangbin Du set_ftrace_filter. Any function that is added here will not 2521f198e22SChangbin Du be traced. If a function exists in both set_ftrace_filter 2531f198e22SChangbin Du and set_ftrace_notrace, the function will _not_ be traced. 2541f198e22SChangbin Du 2551f198e22SChangbin Du set_ftrace_pid: 2561f198e22SChangbin Du 2571f198e22SChangbin Du Have the function tracer only trace the threads whose PID are 2581f198e22SChangbin Du listed in this file. 2591f198e22SChangbin Du 2601f198e22SChangbin Du If the "function-fork" option is set, then when a task whose 2611f198e22SChangbin Du PID is listed in this file forks, the child's PID will 2621f198e22SChangbin Du automatically be added to this file, and the child will be 2631f198e22SChangbin Du traced by the function tracer as well. This option will also 2641f198e22SChangbin Du cause PIDs of tasks that exit to be removed from the file. 2651f198e22SChangbin Du 2662ab2a092SSteven Rostedt (VMware) set_ftrace_notrace_pid: 2672ab2a092SSteven Rostedt (VMware) 2682ab2a092SSteven Rostedt (VMware) Have the function tracer ignore threads whose PID are listed in 2692ab2a092SSteven Rostedt (VMware) this file. 2702ab2a092SSteven Rostedt (VMware) 2712ab2a092SSteven Rostedt (VMware) If the "function-fork" option is set, then when a task whose 2722ab2a092SSteven Rostedt (VMware) PID is listed in this file forks, the child's PID will 2732ab2a092SSteven Rostedt (VMware) automatically be added to this file, and the child will not be 2742ab2a092SSteven Rostedt (VMware) traced by the function tracer as well. This option will also 2752ab2a092SSteven Rostedt (VMware) cause PIDs of tasks that exit to be removed from the file. 2762ab2a092SSteven Rostedt (VMware) 2772ab2a092SSteven Rostedt (VMware) If a PID is in both this file and "set_ftrace_pid", then this 2782ab2a092SSteven Rostedt (VMware) file takes precedence, and the thread will not be traced. 2792ab2a092SSteven Rostedt (VMware) 2801f198e22SChangbin Du set_event_pid: 2811f198e22SChangbin Du 2821f198e22SChangbin Du Have the events only trace a task with a PID listed in this file. 2831f198e22SChangbin Du Note, sched_switch and sched_wake_up will also trace events 2841f198e22SChangbin Du listed in this file. 2851f198e22SChangbin Du 2861f198e22SChangbin Du To have the PIDs of children of tasks with their PID in this file 2871f198e22SChangbin Du added on fork, enable the "event-fork" option. That option will also 2881f198e22SChangbin Du cause the PIDs of tasks to be removed from this file when the task 2891f198e22SChangbin Du exits. 2901f198e22SChangbin Du 2912ab2a092SSteven Rostedt (VMware) set_event_notrace_pid: 2922ab2a092SSteven Rostedt (VMware) 2932ab2a092SSteven Rostedt (VMware) Have the events not trace a task with a PID listed in this file. 2942ab2a092SSteven Rostedt (VMware) Note, sched_switch and sched_wakeup will trace threads not listed 2952ab2a092SSteven Rostedt (VMware) in this file, even if a thread's PID is in the file if the 2962ab2a092SSteven Rostedt (VMware) sched_switch or sched_wakeup events also trace a thread that should 2972ab2a092SSteven Rostedt (VMware) be traced. 2982ab2a092SSteven Rostedt (VMware) 2992ab2a092SSteven Rostedt (VMware) To have the PIDs of children of tasks with their PID in this file 3002ab2a092SSteven Rostedt (VMware) added on fork, enable the "event-fork" option. That option will also 3012ab2a092SSteven Rostedt (VMware) cause the PIDs of tasks to be removed from this file when the task 3022ab2a092SSteven Rostedt (VMware) exits. 3032ab2a092SSteven Rostedt (VMware) 3041f198e22SChangbin Du set_graph_function: 3051f198e22SChangbin Du 3061f198e22SChangbin Du Functions listed in this file will cause the function graph 3071f198e22SChangbin Du tracer to only trace these functions and the functions that 3081f198e22SChangbin Du they call. (See the section "dynamic ftrace" for more details). 30932fb7ef6SSteffen Maier Note, set_ftrace_filter and set_ftrace_notrace still affects 31032fb7ef6SSteffen Maier what functions are being traced. 3111f198e22SChangbin Du 3121f198e22SChangbin Du set_graph_notrace: 3131f198e22SChangbin Du 3141f198e22SChangbin Du Similar to set_graph_function, but will disable function graph 3151f198e22SChangbin Du tracing when the function is hit until it exits the function. 3161f198e22SChangbin Du This makes it possible to ignore tracing functions that are called 3171f198e22SChangbin Du by a specific function. 3181f198e22SChangbin Du 3191f198e22SChangbin Du available_filter_functions: 3201f198e22SChangbin Du 3211f198e22SChangbin Du This lists the functions that ftrace has processed and can trace. 3221f198e22SChangbin Du These are the function names that you can pass to 32332fb7ef6SSteffen Maier "set_ftrace_filter", "set_ftrace_notrace", 32432fb7ef6SSteffen Maier "set_graph_function", or "set_graph_notrace". 3251f198e22SChangbin Du (See the section "dynamic ftrace" below for more details.) 3261f198e22SChangbin Du 32783f74441SJiri Olsa available_filter_functions_addrs: 32883f74441SJiri Olsa 32983f74441SJiri Olsa Similar to available_filter_functions, but with address displayed 33083f74441SJiri Olsa for each function. The displayed address is the patch-site address 33183f74441SJiri Olsa and can differ from /proc/kallsyms address. 33283f74441SJiri Olsa 3331f198e22SChangbin Du dyn_ftrace_total_info: 3341f198e22SChangbin Du 3351f198e22SChangbin Du This file is for debugging purposes. The number of functions that 3361f198e22SChangbin Du have been converted to nops and are available to be traced. 3371f198e22SChangbin Du 3381f198e22SChangbin Du enabled_functions: 3391f198e22SChangbin Du 3401f198e22SChangbin Du This file is more for debugging ftrace, but can also be useful 3411f198e22SChangbin Du in seeing if any function has a callback attached to it. 3421f198e22SChangbin Du Not only does the trace infrastructure use ftrace function 3431f198e22SChangbin Du trace utility, but other subsystems might too. This file 3441f198e22SChangbin Du displays all functions that have a callback attached to them 3451f198e22SChangbin Du as well as the number of callbacks that have been attached. 3461f198e22SChangbin Du Note, a callback may also call multiple functions which will 3471f198e22SChangbin Du not be listed in this count. 3481f198e22SChangbin Du 3491f198e22SChangbin Du If the callback registered to be traced by a function with 3501f198e22SChangbin Du the "save regs" attribute (thus even more overhead), a 'R' 3511f198e22SChangbin Du will be displayed on the same line as the function that 3521f198e22SChangbin Du is returning registers. 3531f198e22SChangbin Du 3541f198e22SChangbin Du If the callback registered to be traced by a function with 3551f198e22SChangbin Du the "ip modify" attribute (thus the regs->ip can be changed), 3561f198e22SChangbin Du an 'I' will be displayed on the same line as the function that 3571f198e22SChangbin Du can be overridden. 3581f198e22SChangbin Du 3596ce2c04fSSteven Rostedt (Google) If a non ftrace trampoline is attached (BPF) a 'D' will be displayed. 3606ce2c04fSSteven Rostedt (Google) Note, normal ftrace trampolines can also be attached, but only one 3616ce2c04fSSteven Rostedt (Google) "direct" trampoline can be attached to a given function at a time. 3626ce2c04fSSteven Rostedt (Google) 3636ce2c04fSSteven Rostedt (Google) Some architectures can not call direct trampolines, but instead have 3646ce2c04fSSteven Rostedt (Google) the ftrace ops function located above the function entry point. In 3656ce2c04fSSteven Rostedt (Google) such cases an 'O' will be displayed. 3666ce2c04fSSteven Rostedt (Google) 3676ce2c04fSSteven Rostedt (Google) If a function had either the "ip modify" or a "direct" call attached to 3686ce2c04fSSteven Rostedt (Google) it in the past, a 'M' will be shown. This flag is never cleared. It is 3696ce2c04fSSteven Rostedt (Google) used to know if a function was every modified by the ftrace infrastructure, 3706ce2c04fSSteven Rostedt (Google) and can be used for debugging. 3716ce2c04fSSteven Rostedt (Google) 3721f198e22SChangbin Du If the architecture supports it, it will also show what callback 3731f198e22SChangbin Du is being directly called by the function. If the count is greater 3741f198e22SChangbin Du than 1 it most likely will be ftrace_ops_list_func(). 3751f198e22SChangbin Du 3766ad18000SHaocheng Xie If the callback of a function jumps to a trampoline that is 3776ad18000SHaocheng Xie specific to the callback and which is not the standard trampoline, 3781f198e22SChangbin Du its address will be printed as well as the function that the 3791f198e22SChangbin Du trampoline calls. 3801f198e22SChangbin Du 3816ce2c04fSSteven Rostedt (Google) touched_functions: 3826ce2c04fSSteven Rostedt (Google) 3836ce2c04fSSteven Rostedt (Google) This file contains all the functions that ever had a function callback 3846ce2c04fSSteven Rostedt (Google) to it via the ftrace infrastructure. It has the same format as 3856ce2c04fSSteven Rostedt (Google) enabled_functions but shows all functions that have every been 3866ce2c04fSSteven Rostedt (Google) traced. 3876ce2c04fSSteven Rostedt (Google) 3886ce2c04fSSteven Rostedt (Google) To see any function that has every been modified by "ip modify" or a 3896ce2c04fSSteven Rostedt (Google) direct trampoline, one can perform the following command: 3906ce2c04fSSteven Rostedt (Google) 3916ce2c04fSSteven Rostedt (Google) grep ' M ' /sys/kernel/tracing/touched_functions 3926ce2c04fSSteven Rostedt (Google) 3931f198e22SChangbin Du function_profile_enabled: 3941f198e22SChangbin Du 3951f198e22SChangbin Du When set it will enable all functions with either the function 3961f198e22SChangbin Du tracer, or if configured, the function graph tracer. It will 3971f198e22SChangbin Du keep a histogram of the number of functions that were called 3981f198e22SChangbin Du and if the function graph tracer was configured, it will also keep 3991f198e22SChangbin Du track of the time spent in those functions. The histogram 4001f198e22SChangbin Du content can be displayed in the files: 4011f198e22SChangbin Du 4021fee4f77SMasami Hiramatsu trace_stat/function<cpu> ( function0, function1, etc). 4031f198e22SChangbin Du 4041fee4f77SMasami Hiramatsu trace_stat: 4051f198e22SChangbin Du 4061f198e22SChangbin Du A directory that holds different tracing stats. 4071f198e22SChangbin Du 4081f198e22SChangbin Du kprobe_events: 4091f198e22SChangbin Du 4103e28c5caSManbing Enable dynamic trace points. See kprobetrace.rst. 4111f198e22SChangbin Du 4121f198e22SChangbin Du kprobe_profile: 4131f198e22SChangbin Du 4143e28c5caSManbing Dynamic trace points stats. See kprobetrace.rst. 4151f198e22SChangbin Du 4161f198e22SChangbin Du max_graph_depth: 4171f198e22SChangbin Du 4181f198e22SChangbin Du Used with the function graph tracer. This is the max depth 4191f198e22SChangbin Du it will trace into a function. Setting this to a value of 4201f198e22SChangbin Du one will show only the first kernel function that is called 4211f198e22SChangbin Du from user space. 4221f198e22SChangbin Du 4231f198e22SChangbin Du printk_formats: 4241f198e22SChangbin Du 4251f198e22SChangbin Du This is for tools that read the raw format files. If an event in 4261f198e22SChangbin Du the ring buffer references a string, only a pointer to the string 4271f198e22SChangbin Du is recorded into the buffer and not the string itself. This prevents 4281f198e22SChangbin Du tools from knowing what that string was. This file displays the string 4291f198e22SChangbin Du and address for the string allowing tools to map the pointers to what 4301f198e22SChangbin Du the strings were. 4311f198e22SChangbin Du 4321f198e22SChangbin Du saved_cmdlines: 4331f198e22SChangbin Du 4341f198e22SChangbin Du Only the pid of the task is recorded in a trace event unless 4351f198e22SChangbin Du the event specifically saves the task comm as well. Ftrace 4361f198e22SChangbin Du makes a cache of pid mappings to comms to try to display 4371f198e22SChangbin Du comms for events. If a pid for a comm is not listed, then 4381f198e22SChangbin Du "<...>" is displayed in the output. 4391f198e22SChangbin Du 4401f198e22SChangbin Du If the option "record-cmd" is set to "0", then comms of tasks 4411f198e22SChangbin Du will not be saved during recording. By default, it is enabled. 4421f198e22SChangbin Du 4431f198e22SChangbin Du saved_cmdlines_size: 4441f198e22SChangbin Du 4451f198e22SChangbin Du By default, 128 comms are saved (see "saved_cmdlines" above). To 4461f198e22SChangbin Du increase or decrease the amount of comms that are cached, echo 4475b8914a6SFrank A. Cancio Bello the number of comms to cache into this file. 4481f198e22SChangbin Du 4491f198e22SChangbin Du saved_tgids: 4501f198e22SChangbin Du 4511f198e22SChangbin Du If the option "record-tgid" is set, on each scheduling context switch 4521f198e22SChangbin Du the Task Group ID of a task is saved in a table mapping the PID of 4531f198e22SChangbin Du the thread to its TGID. By default, the "record-tgid" option is 4541f198e22SChangbin Du disabled. 4551f198e22SChangbin Du 4561f198e22SChangbin Du snapshot: 4571f198e22SChangbin Du 4581f198e22SChangbin Du This displays the "snapshot" buffer and also lets the user 4591f198e22SChangbin Du take a snapshot of the current running trace. 4601f198e22SChangbin Du See the "Snapshot" section below for more details. 4611f198e22SChangbin Du 4621f198e22SChangbin Du stack_max_size: 4631f198e22SChangbin Du 4641f198e22SChangbin Du When the stack tracer is activated, this will display the 4651f198e22SChangbin Du maximum stack size it has encountered. 4661f198e22SChangbin Du See the "Stack Trace" section below. 4671f198e22SChangbin Du 4681f198e22SChangbin Du stack_trace: 4691f198e22SChangbin Du 4701f198e22SChangbin Du This displays the stack back trace of the largest stack 4711f198e22SChangbin Du that was encountered when the stack tracer is activated. 4721f198e22SChangbin Du See the "Stack Trace" section below. 4731f198e22SChangbin Du 4741f198e22SChangbin Du stack_trace_filter: 4751f198e22SChangbin Du 4761f198e22SChangbin Du This is similar to "set_ftrace_filter" but it limits what 4771f198e22SChangbin Du functions the stack tracer will check. 4781f198e22SChangbin Du 4791f198e22SChangbin Du trace_clock: 4801f198e22SChangbin Du 4811f198e22SChangbin Du Whenever an event is recorded into the ring buffer, a 4821f198e22SChangbin Du "timestamp" is added. This stamp comes from a specified 4831f198e22SChangbin Du clock. By default, ftrace uses the "local" clock. This 4841f198e22SChangbin Du clock is very fast and strictly per cpu, but on some 4851f198e22SChangbin Du systems it may not be monotonic with respect to other 4861f198e22SChangbin Du CPUs. In other words, the local clocks may not be in sync 4871f198e22SChangbin Du with local clocks on other CPUs. 4881f198e22SChangbin Du 4891f198e22SChangbin Du Usual clocks for tracing:: 4901f198e22SChangbin Du 4911f198e22SChangbin Du # cat trace_clock 4921f198e22SChangbin Du [local] global counter x86-tsc 4931f198e22SChangbin Du 4941f198e22SChangbin Du The clock with the square brackets around it is the one in effect. 4951f198e22SChangbin Du 4961f198e22SChangbin Du local: 4971f198e22SChangbin Du Default clock, but may not be in sync across CPUs 4981f198e22SChangbin Du 4991f198e22SChangbin Du global: 5001f198e22SChangbin Du This clock is in sync with all CPUs but may 5011f198e22SChangbin Du be a bit slower than the local clock. 5021f198e22SChangbin Du 5031f198e22SChangbin Du counter: 5041f198e22SChangbin Du This is not a clock at all, but literally an atomic 5051f198e22SChangbin Du counter. It counts up one by one, but is in sync 5061f198e22SChangbin Du with all CPUs. This is useful when you need to 5071f198e22SChangbin Du know exactly the order events occurred with respect to 5081f198e22SChangbin Du each other on different CPUs. 5091f198e22SChangbin Du 5101f198e22SChangbin Du uptime: 5111f198e22SChangbin Du This uses the jiffies counter and the time stamp 5121f198e22SChangbin Du is relative to the time since boot up. 5131f198e22SChangbin Du 5141f198e22SChangbin Du perf: 5151f198e22SChangbin Du This makes ftrace use the same clock that perf uses. 5161f198e22SChangbin Du Eventually perf will be able to read ftrace buffers 5171f198e22SChangbin Du and this will help out in interleaving the data. 5181f198e22SChangbin Du 5191f198e22SChangbin Du x86-tsc: 5201f198e22SChangbin Du Architectures may define their own clocks. For 5211f198e22SChangbin Du example, x86 uses its own TSC cycle clock here. 5221f198e22SChangbin Du 5231f198e22SChangbin Du ppc-tb: 5241f198e22SChangbin Du This uses the powerpc timebase register value. 5251f198e22SChangbin Du This is in sync across CPUs and can also be used 5261f198e22SChangbin Du to correlate events across hypervisor/guest if 5271f198e22SChangbin Du tb_offset is known. 5281f198e22SChangbin Du 5291f198e22SChangbin Du mono: 5301f198e22SChangbin Du This uses the fast monotonic clock (CLOCK_MONOTONIC) 5311f198e22SChangbin Du which is monotonic and is subject to NTP rate adjustments. 5321f198e22SChangbin Du 5331f198e22SChangbin Du mono_raw: 5341f198e22SChangbin Du This is the raw monotonic clock (CLOCK_MONOTONIC_RAW) 5352a1e03caSAmir Livneh which is monotonic but is not subject to any rate adjustments 5361f198e22SChangbin Du and ticks at the same rate as the hardware clocksource. 5371f198e22SChangbin Du 5381f198e22SChangbin Du boot: 539a3ed0e43SThomas Gleixner This is the boot clock (CLOCK_BOOTTIME) and is based on the 540a3ed0e43SThomas Gleixner fast monotonic clock, but also accounts for time spent in 541a3ed0e43SThomas Gleixner suspend. Since the clock access is designed for use in 542a3ed0e43SThomas Gleixner tracing in the suspend path, some side effects are possible 543a3ed0e43SThomas Gleixner if clock is accessed after the suspend time is accounted before 544a3ed0e43SThomas Gleixner the fast mono clock is updated. In this case, the clock update 545a3ed0e43SThomas Gleixner appears to happen slightly sooner than it normally would have. 546a3ed0e43SThomas Gleixner Also on 32-bit systems, it's possible that the 64-bit boot offset 547a3ed0e43SThomas Gleixner sees a partial update. These effects are rare and post 548a3ed0e43SThomas Gleixner processing should be able to handle them. See comments in the 549a3ed0e43SThomas Gleixner ktime_get_boot_fast_ns() function for more information. 5501f198e22SChangbin Du 5514d1257bbSKurt Kanzenbach tai: 5524d1257bbSKurt Kanzenbach This is the tai clock (CLOCK_TAI) and is derived from the wall- 5534d1257bbSKurt Kanzenbach clock time. However, this clock does not experience 5544d1257bbSKurt Kanzenbach discontinuities and backwards jumps caused by NTP inserting leap 5554d1257bbSKurt Kanzenbach seconds. Since the clock access is designed for use in tracing, 5564d1257bbSKurt Kanzenbach side effects are possible. The clock access may yield wrong 5574d1257bbSKurt Kanzenbach readouts in case the internal TAI offset is updated e.g., caused 5584d1257bbSKurt Kanzenbach by setting the system time or using adjtimex() with an offset. 5594d1257bbSKurt Kanzenbach These effects are rare and post processing should be able to 5604d1257bbSKurt Kanzenbach handle them. See comments in the ktime_get_tai_fast_ns() 5614d1257bbSKurt Kanzenbach function for more information. 5624d1257bbSKurt Kanzenbach 5631f198e22SChangbin Du To set a clock, simply echo the clock name into this file:: 5641f198e22SChangbin Du 565680014d6SLinus Torvalds # echo global > trace_clock 5661f198e22SChangbin Du 567d693b288SFrank A. Cancio Bello Setting a clock clears the ring buffer content as well as the 568d693b288SFrank A. Cancio Bello "snapshot" buffer. 569d693b288SFrank A. Cancio Bello 5701f198e22SChangbin Du trace_marker: 5711f198e22SChangbin Du 5721f198e22SChangbin Du This is a very useful file for synchronizing user space 5731f198e22SChangbin Du with events happening in the kernel. Writing strings into 5741f198e22SChangbin Du this file will be written into the ftrace buffer. 5751f198e22SChangbin Du 5761f198e22SChangbin Du It is useful in applications to open this file at the start 5771f198e22SChangbin Du of the application and just reference the file descriptor 5781f198e22SChangbin Du for the file:: 5791f198e22SChangbin Du 5801f198e22SChangbin Du void trace_write(const char *fmt, ...) 5811f198e22SChangbin Du { 5821f198e22SChangbin Du va_list ap; 5831f198e22SChangbin Du char buf[256]; 5841f198e22SChangbin Du int n; 5851f198e22SChangbin Du 5861f198e22SChangbin Du if (trace_fd < 0) 5871f198e22SChangbin Du return; 5881f198e22SChangbin Du 5891f198e22SChangbin Du va_start(ap, fmt); 5901f198e22SChangbin Du n = vsnprintf(buf, 256, fmt, ap); 5911f198e22SChangbin Du va_end(ap); 5921f198e22SChangbin Du 5931f198e22SChangbin Du write(trace_fd, buf, n); 5941f198e22SChangbin Du } 5951f198e22SChangbin Du 5961f198e22SChangbin Du start:: 5971f198e22SChangbin Du 5989c1ab6d5SLeo Yan trace_fd = open("trace_marker", O_WRONLY); 5991f198e22SChangbin Du 600d3439f9dSSteven Rostedt (VMware) Note: Writing into the trace_marker file can also initiate triggers 601d3439f9dSSteven Rostedt (VMware) that are written into /sys/kernel/tracing/events/ftrace/print/trigger 602d3439f9dSSteven Rostedt (VMware) See "Event triggers" in Documentation/trace/events.rst and an 603d3439f9dSSteven Rostedt (VMware) example in Documentation/trace/histogram.rst (Section 3.) 604d3439f9dSSteven Rostedt (VMware) 6051f198e22SChangbin Du trace_marker_raw: 6061f198e22SChangbin Du 6071747db54SRandy Dunlap This is similar to trace_marker above, but is meant for binary data 6081f198e22SChangbin Du to be written to it, where a tool can be used to parse the data 6091f198e22SChangbin Du from trace_pipe_raw. 6101f198e22SChangbin Du 6111f198e22SChangbin Du uprobe_events: 6121f198e22SChangbin Du 6131f198e22SChangbin Du Add dynamic tracepoints in programs. 6143e28c5caSManbing See uprobetracer.rst 6151f198e22SChangbin Du 6161f198e22SChangbin Du uprobe_profile: 6171f198e22SChangbin Du 6181f198e22SChangbin Du Uprobe statistics. See uprobetrace.txt 6191f198e22SChangbin Du 6201f198e22SChangbin Du instances: 6211f198e22SChangbin Du 6221f198e22SChangbin Du This is a way to make multiple trace buffers where different 6231f198e22SChangbin Du events can be recorded in different buffers. 6241f198e22SChangbin Du See "Instances" section below. 6251f198e22SChangbin Du 6261f198e22SChangbin Du events: 6271f198e22SChangbin Du 6281f198e22SChangbin Du This is the trace event directory. It holds event tracepoints 6291f198e22SChangbin Du (also known as static tracepoints) that have been compiled 6301f198e22SChangbin Du into the kernel. It shows what event tracepoints exist 6311f198e22SChangbin Du and how they are grouped by system. There are "enable" 6321f198e22SChangbin Du files at various levels that can enable the tracepoints 6331f198e22SChangbin Du when a "1" is written to them. 6341f198e22SChangbin Du 6353e28c5caSManbing See events.rst for more information. 6361f198e22SChangbin Du 6371f198e22SChangbin Du set_event: 6381f198e22SChangbin Du 6391f198e22SChangbin Du By echoing in the event into this file, will enable that event. 6401f198e22SChangbin Du 6413e28c5caSManbing See events.rst for more information. 6421f198e22SChangbin Du 6431f198e22SChangbin Du available_events: 6441f198e22SChangbin Du 6451f198e22SChangbin Du A list of events that can be enabled in tracing. 6461f198e22SChangbin Du 6473e28c5caSManbing See events.rst for more information. 6481f198e22SChangbin Du 6492a56bb59SLinus Torvalds timestamp_mode: 6502a56bb59SLinus Torvalds 6512a56bb59SLinus Torvalds Certain tracers may change the timestamp mode used when 6522a56bb59SLinus Torvalds logging trace events into the event buffer. Events with 6532a56bb59SLinus Torvalds different modes can coexist within a buffer but the mode in 6542a56bb59SLinus Torvalds effect when an event is logged determines which timestamp mode 6552a56bb59SLinus Torvalds is used for that event. The default timestamp mode is 6562a56bb59SLinus Torvalds 'delta'. 6572a56bb59SLinus Torvalds 6582a56bb59SLinus Torvalds Usual timestamp modes for tracing: 6592a56bb59SLinus Torvalds 6602a56bb59SLinus Torvalds # cat timestamp_mode 6612a56bb59SLinus Torvalds [delta] absolute 6622a56bb59SLinus Torvalds 6632a56bb59SLinus Torvalds The timestamp mode with the square brackets around it is the 6642a56bb59SLinus Torvalds one in effect. 6652a56bb59SLinus Torvalds 6662a56bb59SLinus Torvalds delta: Default timestamp mode - timestamp is a delta against 6672a56bb59SLinus Torvalds a per-buffer timestamp. 6682a56bb59SLinus Torvalds 6692a56bb59SLinus Torvalds absolute: The timestamp is a full timestamp, not a delta 6702a56bb59SLinus Torvalds against some other value. As such it takes up more 6712a56bb59SLinus Torvalds space and is less efficient. 6722a56bb59SLinus Torvalds 6731f198e22SChangbin Du hwlat_detector: 6741f198e22SChangbin Du 6751f198e22SChangbin Du Directory for the Hardware Latency Detector. 6761f198e22SChangbin Du See "Hardware Latency Detector" section below. 6771f198e22SChangbin Du 6781f198e22SChangbin Du per_cpu: 6791f198e22SChangbin Du 6801f198e22SChangbin Du This is a directory that contains the trace per_cpu information. 6811f198e22SChangbin Du 6821f198e22SChangbin Du per_cpu/cpu0/buffer_size_kb: 6831f198e22SChangbin Du 6841f198e22SChangbin Du The ftrace buffer is defined per_cpu. That is, there's a separate 6851f198e22SChangbin Du buffer for each CPU to allow writes to be done atomically, 6861f198e22SChangbin Du and free from cache bouncing. These buffers may have different 6871f198e22SChangbin Du size buffers. This file is similar to the buffer_size_kb 6881f198e22SChangbin Du file, but it only displays or sets the buffer size for the 6891f198e22SChangbin Du specific CPU. (here cpu0). 6901f198e22SChangbin Du 6911f198e22SChangbin Du per_cpu/cpu0/trace: 6921f198e22SChangbin Du 6931f198e22SChangbin Du This is similar to the "trace" file, but it will only display 6941f198e22SChangbin Du the data specific for the CPU. If written to, it only clears 6951f198e22SChangbin Du the specific CPU buffer. 6961f198e22SChangbin Du 6971f198e22SChangbin Du per_cpu/cpu0/trace_pipe 6981f198e22SChangbin Du 6991f198e22SChangbin Du This is similar to the "trace_pipe" file, and is a consuming 7001f198e22SChangbin Du read, but it will only display (and consume) the data specific 7011f198e22SChangbin Du for the CPU. 7021f198e22SChangbin Du 7031f198e22SChangbin Du per_cpu/cpu0/trace_pipe_raw 7041f198e22SChangbin Du 7051f198e22SChangbin Du For tools that can parse the ftrace ring buffer binary format, 7061f198e22SChangbin Du the trace_pipe_raw file can be used to extract the data 7071f198e22SChangbin Du from the ring buffer directly. With the use of the splice() 7081f198e22SChangbin Du system call, the buffer data can be quickly transferred to 7091f198e22SChangbin Du a file or to the network where a server is collecting the 7101f198e22SChangbin Du data. 7111f198e22SChangbin Du 7121f198e22SChangbin Du Like trace_pipe, this is a consuming reader, where multiple 7131f198e22SChangbin Du reads will always produce different data. 7141f198e22SChangbin Du 7151f198e22SChangbin Du per_cpu/cpu0/snapshot: 7161f198e22SChangbin Du 7171f198e22SChangbin Du This is similar to the main "snapshot" file, but will only 7181f198e22SChangbin Du snapshot the current CPU (if supported). It only displays 7191f198e22SChangbin Du the content of the snapshot for a given CPU, and if 7201f198e22SChangbin Du written to, only clears this CPU buffer. 7211f198e22SChangbin Du 7221f198e22SChangbin Du per_cpu/cpu0/snapshot_raw: 7231f198e22SChangbin Du 7241f198e22SChangbin Du Similar to the trace_pipe_raw, but will read the binary format 7251f198e22SChangbin Du from the snapshot buffer for the given CPU. 7261f198e22SChangbin Du 7271f198e22SChangbin Du per_cpu/cpu0/stats: 7281f198e22SChangbin Du 7291f198e22SChangbin Du This displays certain stats about the ring buffer: 7301f198e22SChangbin Du 7311f198e22SChangbin Du entries: 7321f198e22SChangbin Du The number of events that are still in the buffer. 7331f198e22SChangbin Du 7341f198e22SChangbin Du overrun: 7351f198e22SChangbin Du The number of lost events due to overwriting when 7361f198e22SChangbin Du the buffer was full. 7371f198e22SChangbin Du 7381f198e22SChangbin Du commit overrun: 7391f198e22SChangbin Du Should always be zero. 7401f198e22SChangbin Du This gets set if so many events happened within a nested 7411f198e22SChangbin Du event (ring buffer is re-entrant), that it fills the 7421f198e22SChangbin Du buffer and starts dropping events. 7431f198e22SChangbin Du 7441f198e22SChangbin Du bytes: 7451f198e22SChangbin Du Bytes actually read (not overwritten). 7461f198e22SChangbin Du 7471f198e22SChangbin Du oldest event ts: 7481f198e22SChangbin Du The oldest timestamp in the buffer 7491f198e22SChangbin Du 7501f198e22SChangbin Du now ts: 7511f198e22SChangbin Du The current timestamp 7521f198e22SChangbin Du 7531f198e22SChangbin Du dropped events: 7541f198e22SChangbin Du Events lost due to overwrite option being off. 7551f198e22SChangbin Du 7561f198e22SChangbin Du read events: 7571f198e22SChangbin Du The number of events read. 7581f198e22SChangbin Du 7591f198e22SChangbin DuThe Tracers 7601f198e22SChangbin Du----------- 7611f198e22SChangbin Du 7621f198e22SChangbin DuHere is the list of current tracers that may be configured. 7631f198e22SChangbin Du 7641f198e22SChangbin Du "function" 7651f198e22SChangbin Du 7661f198e22SChangbin Du Function call tracer to trace all kernel functions. 7671f198e22SChangbin Du 7681f198e22SChangbin Du "function_graph" 7691f198e22SChangbin Du 7701f198e22SChangbin Du Similar to the function tracer except that the 7711f198e22SChangbin Du function tracer probes the functions on their entry 7721f198e22SChangbin Du whereas the function graph tracer traces on both entry 7731f198e22SChangbin Du and exit of the functions. It then provides the ability 7741f198e22SChangbin Du to draw a graph of function calls similar to C code 7751f198e22SChangbin Du source. 7761f198e22SChangbin Du 7771f198e22SChangbin Du "blk" 7781f198e22SChangbin Du 7791f198e22SChangbin Du The block tracer. The tracer used by the blktrace user 7801f198e22SChangbin Du application. 7811f198e22SChangbin Du 7821f198e22SChangbin Du "hwlat" 7831f198e22SChangbin Du 7841f198e22SChangbin Du The Hardware Latency tracer is used to detect if the hardware 7851f198e22SChangbin Du produces any latency. See "Hardware Latency Detector" section 7861f198e22SChangbin Du below. 7871f198e22SChangbin Du 7881f198e22SChangbin Du "irqsoff" 7891f198e22SChangbin Du 7901f198e22SChangbin Du Traces the areas that disable interrupts and saves 7911f198e22SChangbin Du the trace with the longest max latency. 7921f198e22SChangbin Du See tracing_max_latency. When a new max is recorded, 7931f198e22SChangbin Du it replaces the old trace. It is best to view this 7941f198e22SChangbin Du trace with the latency-format option enabled, which 7951f198e22SChangbin Du happens automatically when the tracer is selected. 7961f198e22SChangbin Du 7971f198e22SChangbin Du "preemptoff" 7981f198e22SChangbin Du 7991f198e22SChangbin Du Similar to irqsoff but traces and records the amount of 8001f198e22SChangbin Du time for which preemption is disabled. 8011f198e22SChangbin Du 8021f198e22SChangbin Du "preemptirqsoff" 8031f198e22SChangbin Du 8041f198e22SChangbin Du Similar to irqsoff and preemptoff, but traces and 8051f198e22SChangbin Du records the largest time for which irqs and/or preemption 8061f198e22SChangbin Du is disabled. 8071f198e22SChangbin Du 8081f198e22SChangbin Du "wakeup" 8091f198e22SChangbin Du 8101f198e22SChangbin Du Traces and records the max latency that it takes for 8111f198e22SChangbin Du the highest priority task to get scheduled after 8121f198e22SChangbin Du it has been woken up. 8131f198e22SChangbin Du Traces all tasks as an average developer would expect. 8141f198e22SChangbin Du 8151f198e22SChangbin Du "wakeup_rt" 8161f198e22SChangbin Du 8171f198e22SChangbin Du Traces and records the max latency that it takes for just 8181f198e22SChangbin Du RT tasks (as the current "wakeup" does). This is useful 8191f198e22SChangbin Du for those interested in wake up timings of RT tasks. 8201f198e22SChangbin Du 8211f198e22SChangbin Du "wakeup_dl" 8221f198e22SChangbin Du 8231f198e22SChangbin Du Traces and records the max latency that it takes for 8241f198e22SChangbin Du a SCHED_DEADLINE task to be woken (as the "wakeup" and 8251f198e22SChangbin Du "wakeup_rt" does). 8261f198e22SChangbin Du 8271f198e22SChangbin Du "mmiotrace" 8281f198e22SChangbin Du 8291f198e22SChangbin Du A special tracer that is used to trace binary module. 8301f198e22SChangbin Du It will trace all the calls that a module makes to the 8311f198e22SChangbin Du hardware. Everything it writes and reads from the I/O 8321f198e22SChangbin Du as well. 8331f198e22SChangbin Du 8341f198e22SChangbin Du "branch" 8351f198e22SChangbin Du 8361f198e22SChangbin Du This tracer can be configured when tracing likely/unlikely 8371f198e22SChangbin Du calls within the kernel. It will trace when a likely and 8381f198e22SChangbin Du unlikely branch is hit and if it was correct in its prediction 8391f198e22SChangbin Du of being correct. 8401f198e22SChangbin Du 8411f198e22SChangbin Du "nop" 8421f198e22SChangbin Du 8431f198e22SChangbin Du This is the "trace nothing" tracer. To remove all 8441f198e22SChangbin Du tracers from tracing simply echo "nop" into 8451f198e22SChangbin Du current_tracer. 8461f198e22SChangbin Du 84726a94491STom ZanussiError conditions 84826a94491STom Zanussi---------------- 84926a94491STom Zanussi 85026a94491STom Zanussi For most ftrace commands, failure modes are obvious and communicated 85126a94491STom Zanussi using standard return codes. 85226a94491STom Zanussi 85326a94491STom Zanussi For other more involved commands, extended error information may be 85426a94491STom Zanussi available via the tracing/error_log file. For the commands that 85526a94491STom Zanussi support it, reading the tracing/error_log file after an error will 85626a94491STom Zanussi display more detailed information about what went wrong, if 85726a94491STom Zanussi information is available. The tracing/error_log file is a circular 85826a94491STom Zanussi error log displaying a small number (currently, 8) of ftrace errors 85926a94491STom Zanussi for the last (8) failed commands. 86026a94491STom Zanussi 86126a94491STom Zanussi The extended error information and usage takes the form shown in 86226a94491STom Zanussi this example:: 86326a94491STom Zanussi 8642abfcd29SRoss Zwisler # echo xxx > /sys/kernel/tracing/events/sched/sched_wakeup/trigger 86526a94491STom Zanussi echo: write error: Invalid argument 86626a94491STom Zanussi 8672abfcd29SRoss Zwisler # cat /sys/kernel/tracing/error_log 86826a94491STom Zanussi [ 5348.887237] location: error: Couldn't yyy: zzz 86926a94491STom Zanussi Command: xxx 87026a94491STom Zanussi ^ 87126a94491STom Zanussi [ 7517.023364] location: error: Bad rrr: sss 87226a94491STom Zanussi Command: ppp qqq 87326a94491STom Zanussi ^ 87426a94491STom Zanussi 87526a94491STom Zanussi To clear the error log, echo the empty string into it:: 87626a94491STom Zanussi 8772abfcd29SRoss Zwisler # echo > /sys/kernel/tracing/error_log 8781f198e22SChangbin Du 8791f198e22SChangbin DuExamples of using the tracer 8801f198e22SChangbin Du---------------------------- 8811f198e22SChangbin Du 8821f198e22SChangbin DuHere are typical examples of using the tracers when controlling 8831f198e22SChangbin Duthem only with the tracefs interface (without using any 8841f198e22SChangbin Duuser-land utilities). 8851f198e22SChangbin Du 8861f198e22SChangbin DuOutput format: 8871f198e22SChangbin Du-------------- 8881f198e22SChangbin Du 8891f198e22SChangbin DuHere is an example of the output format of the file "trace":: 8901f198e22SChangbin Du 8911f198e22SChangbin Du # tracer: function 8921f198e22SChangbin Du # 8931f198e22SChangbin Du # entries-in-buffer/entries-written: 140080/250280 #P:4 8941f198e22SChangbin Du # 8951f198e22SChangbin Du # _-----=> irqs-off 8961f198e22SChangbin Du # / _----=> need-resched 8971f198e22SChangbin Du # | / _---=> hardirq/softirq 8981f198e22SChangbin Du # || / _--=> preempt-depth 8991f198e22SChangbin Du # ||| / delay 9001f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 9011f198e22SChangbin Du # | | | |||| | | 9021f198e22SChangbin Du bash-1977 [000] .... 17284.993652: sys_close <-system_call_fastpath 9031f198e22SChangbin Du bash-1977 [000] .... 17284.993653: __close_fd <-sys_close 9041f198e22SChangbin Du bash-1977 [000] .... 17284.993653: _raw_spin_lock <-__close_fd 9051f198e22SChangbin Du sshd-1974 [003] .... 17284.993653: __srcu_read_unlock <-fsnotify 9061f198e22SChangbin Du bash-1977 [000] .... 17284.993654: add_preempt_count <-_raw_spin_lock 9071f198e22SChangbin Du bash-1977 [000] ...1 17284.993655: _raw_spin_unlock <-__close_fd 9081f198e22SChangbin Du bash-1977 [000] ...1 17284.993656: sub_preempt_count <-_raw_spin_unlock 9091f198e22SChangbin Du bash-1977 [000] .... 17284.993657: filp_close <-__close_fd 9101f198e22SChangbin Du bash-1977 [000] .... 17284.993657: dnotify_flush <-filp_close 9111f198e22SChangbin Du sshd-1974 [003] .... 17284.993658: sys_select <-system_call_fastpath 9121f198e22SChangbin Du .... 9131f198e22SChangbin Du 9141f198e22SChangbin DuA header is printed with the tracer name that is represented by 9151f198e22SChangbin Duthe trace. In this case the tracer is "function". Then it shows the 9161f198e22SChangbin Dunumber of events in the buffer as well as the total number of entries 9171f198e22SChangbin Duthat were written. The difference is the number of entries that were 9181f198e22SChangbin Dulost due to the buffer filling up (250280 - 140080 = 110200 events 9191f198e22SChangbin Dulost). 9201f198e22SChangbin Du 9211f198e22SChangbin DuThe header explains the content of the events. Task name "bash", the task 9221f198e22SChangbin DuPID "1977", the CPU that it was running on "000", the latency format 9231f198e22SChangbin Du(explained below), the timestamp in <secs>.<usecs> format, the 9241f198e22SChangbin Dufunction name that was traced "sys_close" and the parent function that 9251f198e22SChangbin Ducalled this function "system_call_fastpath". The timestamp is the time 9261f198e22SChangbin Duat which the function was entered. 9271f198e22SChangbin Du 9281f198e22SChangbin DuLatency trace format 9291f198e22SChangbin Du-------------------- 9301f198e22SChangbin Du 9311f198e22SChangbin DuWhen the latency-format option is enabled or when one of the latency 9321f198e22SChangbin Dutracers is set, the trace file gives somewhat more information to see 9331f198e22SChangbin Duwhy a latency happened. Here is a typical trace:: 9341f198e22SChangbin Du 9351f198e22SChangbin Du # tracer: irqsoff 9361f198e22SChangbin Du # 9371f198e22SChangbin Du # irqsoff latency trace v1.1.5 on 3.8.0-test+ 9381f198e22SChangbin Du # -------------------------------------------------------------------- 9391f198e22SChangbin Du # latency: 259 us, #4/4, CPU#2 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 9401f198e22SChangbin Du # ----------------- 9411f198e22SChangbin Du # | task: ps-6143 (uid:0 nice:0 policy:0 rt_prio:0) 9421f198e22SChangbin Du # ----------------- 9431f198e22SChangbin Du # => started at: __lock_task_sighand 9441f198e22SChangbin Du # => ended at: _raw_spin_unlock_irqrestore 9451f198e22SChangbin Du # 9461f198e22SChangbin Du # 9471f198e22SChangbin Du # _------=> CPU# 9481f198e22SChangbin Du # / _-----=> irqs-off 9491f198e22SChangbin Du # | / _----=> need-resched 9501f198e22SChangbin Du # || / _---=> hardirq/softirq 9511f198e22SChangbin Du # ||| / _--=> preempt-depth 9521f198e22SChangbin Du # |||| / delay 9531f198e22SChangbin Du # cmd pid ||||| time | caller 9541f198e22SChangbin Du # \ / ||||| \ | / 9551f198e22SChangbin Du ps-6143 2d... 0us!: trace_hardirqs_off <-__lock_task_sighand 9561f198e22SChangbin Du ps-6143 2d..1 259us+: trace_hardirqs_on <-_raw_spin_unlock_irqrestore 9571f198e22SChangbin Du ps-6143 2d..1 263us+: time_hardirqs_on <-_raw_spin_unlock_irqrestore 9581f198e22SChangbin Du ps-6143 2d..1 306us : <stack trace> 9591f198e22SChangbin Du => trace_hardirqs_on_caller 9601f198e22SChangbin Du => trace_hardirqs_on 9611f198e22SChangbin Du => _raw_spin_unlock_irqrestore 9621f198e22SChangbin Du => do_task_stat 9631f198e22SChangbin Du => proc_tgid_stat 9641f198e22SChangbin Du => proc_single_show 9651f198e22SChangbin Du => seq_read 9661f198e22SChangbin Du => vfs_read 9671f198e22SChangbin Du => sys_read 9681f198e22SChangbin Du => system_call_fastpath 9691f198e22SChangbin Du 9701f198e22SChangbin Du 9711f198e22SChangbin DuThis shows that the current tracer is "irqsoff" tracing the time 9721f198e22SChangbin Dufor which interrupts were disabled. It gives the trace version (which 9731f198e22SChangbin Dunever changes) and the version of the kernel upon which this was executed on 9741f198e22SChangbin Du(3.8). Then it displays the max latency in microseconds (259 us). The number 9751f198e22SChangbin Duof trace entries displayed and the total number (both are four: #4/4). 9761f198e22SChangbin DuVP, KP, SP, and HP are always zero and are reserved for later use. 9771f198e22SChangbin Du#P is the number of online CPUs (#P:4). 9781f198e22SChangbin Du 9791f198e22SChangbin DuThe task is the process that was running when the latency 9801f198e22SChangbin Duoccurred. (ps pid: 6143). 9811f198e22SChangbin Du 9821f198e22SChangbin DuThe start and stop (the functions in which the interrupts were 9831f198e22SChangbin Dudisabled and enabled respectively) that caused the latencies: 9841f198e22SChangbin Du 9851f198e22SChangbin Du - __lock_task_sighand is where the interrupts were disabled. 9861f198e22SChangbin Du - _raw_spin_unlock_irqrestore is where they were enabled again. 9871f198e22SChangbin Du 9881f198e22SChangbin DuThe next lines after the header are the trace itself. The header 9891f198e22SChangbin Duexplains which is which. 9901f198e22SChangbin Du 9911f198e22SChangbin Du cmd: The name of the process in the trace. 9921f198e22SChangbin Du 9931f198e22SChangbin Du pid: The PID of that process. 9941f198e22SChangbin Du 9951f198e22SChangbin Du CPU#: The CPU which the process was running on. 9961f198e22SChangbin Du 9971f198e22SChangbin Du irqs-off: 'd' interrupts are disabled. '.' otherwise. 9981f198e22SChangbin Du .. caution:: If the architecture does not support a way to 9991f198e22SChangbin Du read the irq flags variable, an 'X' will always 10001f198e22SChangbin Du be printed here. 10011f198e22SChangbin Du 10021f198e22SChangbin Du need-resched: 10031f198e22SChangbin Du - 'N' both TIF_NEED_RESCHED and PREEMPT_NEED_RESCHED is set, 10041f198e22SChangbin Du - 'n' only TIF_NEED_RESCHED is set, 10051f198e22SChangbin Du - 'p' only PREEMPT_NEED_RESCHED is set, 10061f198e22SChangbin Du - '.' otherwise. 10071f198e22SChangbin Du 10081f198e22SChangbin Du hardirq/softirq: 10091f198e22SChangbin Du - 'Z' - NMI occurred inside a hardirq 10101f198e22SChangbin Du - 'z' - NMI is running 10111f198e22SChangbin Du - 'H' - hard irq occurred inside a softirq. 10121f198e22SChangbin Du - 'h' - hard irq is running 10131f198e22SChangbin Du - 's' - soft irq is running 10141f198e22SChangbin Du - '.' - normal context. 10151f198e22SChangbin Du 10161f198e22SChangbin Du preempt-depth: The level of preempt_disabled 10171f198e22SChangbin Du 10181f198e22SChangbin DuThe above is mostly meaningful for kernel developers. 10191f198e22SChangbin Du 10201f198e22SChangbin Du time: 10211f198e22SChangbin Du When the latency-format option is enabled, the trace file 10221f198e22SChangbin Du output includes a timestamp relative to the start of the 10231f198e22SChangbin Du trace. This differs from the output when latency-format 10241f198e22SChangbin Du is disabled, which includes an absolute timestamp. 10251f198e22SChangbin Du 10261f198e22SChangbin Du delay: 10271f198e22SChangbin Du This is just to help catch your eye a bit better. And 10281f198e22SChangbin Du needs to be fixed to be only relative to the same CPU. 10291f198e22SChangbin Du The marks are determined by the difference between this 10301f198e22SChangbin Du current trace and the next trace. 10311f198e22SChangbin Du 10321f198e22SChangbin Du - '$' - greater than 1 second 10332a1e03caSAmir Livneh - '@' - greater than 100 millisecond 10342a1e03caSAmir Livneh - '*' - greater than 10 millisecond 10351f198e22SChangbin Du - '#' - greater than 1000 microsecond 10361f198e22SChangbin Du - '!' - greater than 100 microsecond 10371f198e22SChangbin Du - '+' - greater than 10 microsecond 10381f198e22SChangbin Du - ' ' - less than or equal to 10 microsecond. 10391f198e22SChangbin Du 10401f198e22SChangbin Du The rest is the same as the 'trace' file. 10411f198e22SChangbin Du 10421f198e22SChangbin Du Note, the latency tracers will usually end with a back trace 10431f198e22SChangbin Du to easily find where the latency occurred. 10441f198e22SChangbin Du 10451f198e22SChangbin Dutrace_options 10461f198e22SChangbin Du------------- 10471f198e22SChangbin Du 10481f198e22SChangbin DuThe trace_options file (or the options directory) is used to control 10491f198e22SChangbin Duwhat gets printed in the trace output, or manipulate the tracers. 10501f198e22SChangbin DuTo see what is available, simply cat the file:: 10511f198e22SChangbin Du 10521f198e22SChangbin Du cat trace_options 10531f198e22SChangbin Du print-parent 10541f198e22SChangbin Du nosym-offset 10551f198e22SChangbin Du nosym-addr 10561f198e22SChangbin Du noverbose 10571f198e22SChangbin Du noraw 10581f198e22SChangbin Du nohex 10591f198e22SChangbin Du nobin 10601f198e22SChangbin Du noblock 106180a76994SSteven Rostedt (Google) nofields 10621f198e22SChangbin Du trace_printk 10631f198e22SChangbin Du annotate 10641f198e22SChangbin Du nouserstacktrace 10651f198e22SChangbin Du nosym-userobj 10661f198e22SChangbin Du noprintk-msg-only 10671f198e22SChangbin Du context-info 10681f198e22SChangbin Du nolatency-format 10691f198e22SChangbin Du record-cmd 10701f198e22SChangbin Du norecord-tgid 10711f198e22SChangbin Du overwrite 10721f198e22SChangbin Du nodisable_on_free 10731f198e22SChangbin Du irq-info 10741f198e22SChangbin Du markers 10751f198e22SChangbin Du noevent-fork 10761f198e22SChangbin Du function-trace 10771f198e22SChangbin Du nofunction-fork 10781f198e22SChangbin Du nodisplay-graph 10791f198e22SChangbin Du nostacktrace 10801f198e22SChangbin Du nobranch 10811f198e22SChangbin Du 10821f198e22SChangbin DuTo disable one of the options, echo in the option prepended with 10831f198e22SChangbin Du"no":: 10841f198e22SChangbin Du 10851f198e22SChangbin Du echo noprint-parent > trace_options 10861f198e22SChangbin Du 10871f198e22SChangbin DuTo enable an option, leave off the "no":: 10881f198e22SChangbin Du 10891f198e22SChangbin Du echo sym-offset > trace_options 10901f198e22SChangbin Du 10911f198e22SChangbin DuHere are the available options: 10921f198e22SChangbin Du 10931f198e22SChangbin Du print-parent 10941f198e22SChangbin Du On function traces, display the calling (parent) 10951f198e22SChangbin Du function as well as the function being traced. 10961f198e22SChangbin Du :: 10971f198e22SChangbin Du 10981f198e22SChangbin Du print-parent: 10991f198e22SChangbin Du bash-4000 [01] 1477.606694: simple_strtoul <-kstrtoul 11001f198e22SChangbin Du 11011f198e22SChangbin Du noprint-parent: 11021f198e22SChangbin Du bash-4000 [01] 1477.606694: simple_strtoul 11031f198e22SChangbin Du 11041f198e22SChangbin Du 11051f198e22SChangbin Du sym-offset 11061f198e22SChangbin Du Display not only the function name, but also the 11071f198e22SChangbin Du offset in the function. For example, instead of 11081f198e22SChangbin Du seeing just "ktime_get", you will see 11091f198e22SChangbin Du "ktime_get+0xb/0x20". 11101f198e22SChangbin Du :: 11111f198e22SChangbin Du 11121f198e22SChangbin Du sym-offset: 11131f198e22SChangbin Du bash-4000 [01] 1477.606694: simple_strtoul+0x6/0xa0 11141f198e22SChangbin Du 11151f198e22SChangbin Du sym-addr 11161f198e22SChangbin Du This will also display the function address as well 11171f198e22SChangbin Du as the function name. 11181f198e22SChangbin Du :: 11191f198e22SChangbin Du 11201f198e22SChangbin Du sym-addr: 11211f198e22SChangbin Du bash-4000 [01] 1477.606694: simple_strtoul <c0339346> 11221f198e22SChangbin Du 11231f198e22SChangbin Du verbose 11241f198e22SChangbin Du This deals with the trace file when the 11251f198e22SChangbin Du latency-format option is enabled. 11261f198e22SChangbin Du :: 11271f198e22SChangbin Du 11281f198e22SChangbin Du bash 4000 1 0 00000000 00010a95 [58127d26] 1720.415ms \ 11291f198e22SChangbin Du (+0.000ms): simple_strtoul (kstrtoul) 11301f198e22SChangbin Du 11311f198e22SChangbin Du raw 11321f198e22SChangbin Du This will display raw numbers. This option is best for 11331f198e22SChangbin Du use with user applications that can translate the raw 11341f198e22SChangbin Du numbers better than having it done in the kernel. 11351f198e22SChangbin Du 11361f198e22SChangbin Du hex 11371f198e22SChangbin Du Similar to raw, but the numbers will be in a hexadecimal format. 11381f198e22SChangbin Du 11391f198e22SChangbin Du bin 11401f198e22SChangbin Du This will print out the formats in raw binary. 11411f198e22SChangbin Du 11421f198e22SChangbin Du block 11431f198e22SChangbin Du When set, reading trace_pipe will not block when polled. 11441f198e22SChangbin Du 114580a76994SSteven Rostedt (Google) fields 114680a76994SSteven Rostedt (Google) Print the fields as described by their types. This is a better 114780a76994SSteven Rostedt (Google) option than using hex, bin or raw, as it gives a better parsing 114880a76994SSteven Rostedt (Google) of the content of the event. 114980a76994SSteven Rostedt (Google) 11501f198e22SChangbin Du trace_printk 11511f198e22SChangbin Du Can disable trace_printk() from writing into the buffer. 11521f198e22SChangbin Du 11531f198e22SChangbin Du annotate 11541f198e22SChangbin Du It is sometimes confusing when the CPU buffers are full 11551f198e22SChangbin Du and one CPU buffer had a lot of events recently, thus 11561f198e22SChangbin Du a shorter time frame, were another CPU may have only had 11571f198e22SChangbin Du a few events, which lets it have older events. When 11581f198e22SChangbin Du the trace is reported, it shows the oldest events first, 11591f198e22SChangbin Du and it may look like only one CPU ran (the one with the 11601f198e22SChangbin Du oldest events). When the annotate option is set, it will 11611f198e22SChangbin Du display when a new CPU buffer started:: 11621f198e22SChangbin Du 11631f198e22SChangbin Du <idle>-0 [001] dNs4 21169.031481: wake_up_idle_cpu <-add_timer_on 11641f198e22SChangbin Du <idle>-0 [001] dNs4 21169.031482: _raw_spin_unlock_irqrestore <-add_timer_on 11651f198e22SChangbin Du <idle>-0 [001] .Ns4 21169.031484: sub_preempt_count <-_raw_spin_unlock_irqrestore 11661f198e22SChangbin Du ##### CPU 2 buffer started #### 11671f198e22SChangbin Du <idle>-0 [002] .N.1 21169.031484: rcu_idle_exit <-cpu_idle 11681f198e22SChangbin Du <idle>-0 [001] .Ns3 21169.031484: _raw_spin_unlock <-clocksource_watchdog 11691f198e22SChangbin Du <idle>-0 [001] .Ns3 21169.031485: sub_preempt_count <-_raw_spin_unlock 11701f198e22SChangbin Du 11711f198e22SChangbin Du userstacktrace 11721f198e22SChangbin Du This option changes the trace. It records a 11731f198e22SChangbin Du stacktrace of the current user space thread after 11741f198e22SChangbin Du each trace event. 11751f198e22SChangbin Du 11761f198e22SChangbin Du sym-userobj 11771f198e22SChangbin Du when user stacktrace are enabled, look up which 11781f198e22SChangbin Du object the address belongs to, and print a 11791f198e22SChangbin Du relative address. This is especially useful when 11801f198e22SChangbin Du ASLR is on, otherwise you don't get a chance to 11811f198e22SChangbin Du resolve the address to object/file/line after 11821f198e22SChangbin Du the app is no longer running 11831f198e22SChangbin Du 11841f198e22SChangbin Du The lookup is performed when you read 11851f198e22SChangbin Du trace,trace_pipe. Example:: 11861f198e22SChangbin Du 11871f198e22SChangbin Du a.out-1623 [000] 40874.465068: /root/a.out[+0x480] <-/root/a.out[+0 11881f198e22SChangbin Du x494] <- /root/a.out[+0x4a8] <- /lib/libc-2.7.so[+0x1e1a6] 11891f198e22SChangbin Du 11901f198e22SChangbin Du 11911f198e22SChangbin Du printk-msg-only 11921f198e22SChangbin Du When set, trace_printk()s will only show the format 11931f198e22SChangbin Du and not their parameters (if trace_bprintk() or 11941f198e22SChangbin Du trace_bputs() was used to save the trace_printk()). 11951f198e22SChangbin Du 11961f198e22SChangbin Du context-info 11971f198e22SChangbin Du Show only the event data. Hides the comm, PID, 11981f198e22SChangbin Du timestamp, CPU, and other useful data. 11991f198e22SChangbin Du 12001f198e22SChangbin Du latency-format 12011f198e22SChangbin Du This option changes the trace output. When it is enabled, 12021f198e22SChangbin Du the trace displays additional information about the 12031f198e22SChangbin Du latency, as described in "Latency trace format". 12041f198e22SChangbin Du 120506e0a548SSteven Rostedt (VMware) pause-on-trace 120606e0a548SSteven Rostedt (VMware) When set, opening the trace file for read, will pause 120706e0a548SSteven Rostedt (VMware) writing to the ring buffer (as if tracing_on was set to zero). 120806e0a548SSteven Rostedt (VMware) This simulates the original behavior of the trace file. 120906e0a548SSteven Rostedt (VMware) When the file is closed, tracing will be enabled again. 121006e0a548SSteven Rostedt (VMware) 1211a345a671SMasami Hiramatsu hash-ptr 1212a345a671SMasami Hiramatsu When set, "%p" in the event printk format displays the 1213a345a671SMasami Hiramatsu hashed pointer value instead of real address. 1214a345a671SMasami Hiramatsu This will be useful if you want to find out which hashed 1215a345a671SMasami Hiramatsu value is corresponding to the real value in trace log. 1216a345a671SMasami Hiramatsu 12171f198e22SChangbin Du record-cmd 12181f198e22SChangbin Du When any event or tracer is enabled, a hook is enabled 12191f198e22SChangbin Du in the sched_switch trace point to fill comm cache 12201f198e22SChangbin Du with mapped pids and comms. But this may cause some 12211f198e22SChangbin Du overhead, and if you only care about pids, and not the 12221f198e22SChangbin Du name of the task, disabling this option can lower the 12231f198e22SChangbin Du impact of tracing. See "saved_cmdlines". 12241f198e22SChangbin Du 12251f198e22SChangbin Du record-tgid 12261f198e22SChangbin Du When any event or tracer is enabled, a hook is enabled 12271f198e22SChangbin Du in the sched_switch trace point to fill the cache of 12281f198e22SChangbin Du mapped Thread Group IDs (TGID) mapping to pids. See 12291f198e22SChangbin Du "saved_tgids". 12301f198e22SChangbin Du 12311f198e22SChangbin Du overwrite 12321f198e22SChangbin Du This controls what happens when the trace buffer is 12331f198e22SChangbin Du full. If "1" (default), the oldest events are 12341f198e22SChangbin Du discarded and overwritten. If "0", then the newest 12351f198e22SChangbin Du events are discarded. 12361f198e22SChangbin Du (see per_cpu/cpu0/stats for overrun and dropped) 12371f198e22SChangbin Du 12381f198e22SChangbin Du disable_on_free 12391f198e22SChangbin Du When the free_buffer is closed, tracing will 12401f198e22SChangbin Du stop (tracing_on set to 0). 12411f198e22SChangbin Du 12421f198e22SChangbin Du irq-info 12431f198e22SChangbin Du Shows the interrupt, preempt count, need resched data. 12441f198e22SChangbin Du When disabled, the trace looks like:: 12451f198e22SChangbin Du 12461f198e22SChangbin Du # tracer: function 12471f198e22SChangbin Du # 12481f198e22SChangbin Du # entries-in-buffer/entries-written: 144405/9452052 #P:4 12491f198e22SChangbin Du # 12501f198e22SChangbin Du # TASK-PID CPU# TIMESTAMP FUNCTION 12511f198e22SChangbin Du # | | | | | 12521f198e22SChangbin Du <idle>-0 [002] 23636.756054: ttwu_do_activate.constprop.89 <-try_to_wake_up 12531f198e22SChangbin Du <idle>-0 [002] 23636.756054: activate_task <-ttwu_do_activate.constprop.89 12541f198e22SChangbin Du <idle>-0 [002] 23636.756055: enqueue_task <-activate_task 12551f198e22SChangbin Du 12561f198e22SChangbin Du 12571f198e22SChangbin Du markers 12581f198e22SChangbin Du When set, the trace_marker is writable (only by root). 12591f198e22SChangbin Du When disabled, the trace_marker will error with EINVAL 12601f198e22SChangbin Du on write. 12611f198e22SChangbin Du 12621f198e22SChangbin Du event-fork 12631f198e22SChangbin Du When set, tasks with PIDs listed in set_event_pid will have 12641f198e22SChangbin Du the PIDs of their children added to set_event_pid when those 12651f198e22SChangbin Du tasks fork. Also, when tasks with PIDs in set_event_pid exit, 12661f198e22SChangbin Du their PIDs will be removed from the file. 12671f198e22SChangbin Du 12682ab2a092SSteven Rostedt (VMware) This affects PIDs listed in set_event_notrace_pid as well. 12692ab2a092SSteven Rostedt (VMware) 12701f198e22SChangbin Du function-trace 12711f198e22SChangbin Du The latency tracers will enable function tracing 12721f198e22SChangbin Du if this option is enabled (default it is). When 12731f198e22SChangbin Du it is disabled, the latency tracers do not trace 12741f198e22SChangbin Du functions. This keeps the overhead of the tracer down 12751f198e22SChangbin Du when performing latency tests. 12761f198e22SChangbin Du 12771f198e22SChangbin Du function-fork 12781f198e22SChangbin Du When set, tasks with PIDs listed in set_ftrace_pid will 12791f198e22SChangbin Du have the PIDs of their children added to set_ftrace_pid 12801f198e22SChangbin Du when those tasks fork. Also, when tasks with PIDs in 12811f198e22SChangbin Du set_ftrace_pid exit, their PIDs will be removed from the 12821f198e22SChangbin Du file. 12831f198e22SChangbin Du 12842ab2a092SSteven Rostedt (VMware) This affects PIDs in set_ftrace_notrace_pid as well. 12852ab2a092SSteven Rostedt (VMware) 12861f198e22SChangbin Du display-graph 12871f198e22SChangbin Du When set, the latency tracers (irqsoff, wakeup, etc) will 12881f198e22SChangbin Du use function graph tracing instead of function tracing. 12891f198e22SChangbin Du 12901f198e22SChangbin Du stacktrace 12911f198e22SChangbin Du When set, a stack trace is recorded after any trace event 12921f198e22SChangbin Du is recorded. 12931f198e22SChangbin Du 12941f198e22SChangbin Du branch 12951f198e22SChangbin Du Enable branch tracing with the tracer. This enables branch 12961f198e22SChangbin Du tracer along with the currently set tracer. Enabling this 12971f198e22SChangbin Du with the "nop" tracer is the same as just enabling the 12981f198e22SChangbin Du "branch" tracer. 12991f198e22SChangbin Du 13001f198e22SChangbin Du.. tip:: Some tracers have their own options. They only appear in this 13011f198e22SChangbin Du file when the tracer is active. They always appear in the 13021f198e22SChangbin Du options directory. 13031f198e22SChangbin Du 13041f198e22SChangbin Du 13051f198e22SChangbin DuHere are the per tracer options: 13061f198e22SChangbin Du 13071f198e22SChangbin DuOptions for function tracer: 13081f198e22SChangbin Du 13091f198e22SChangbin Du func_stack_trace 13101f198e22SChangbin Du When set, a stack trace is recorded after every 13111f198e22SChangbin Du function that is recorded. NOTE! Limit the functions 13121f198e22SChangbin Du that are recorded before enabling this, with 13131f198e22SChangbin Du "set_ftrace_filter" otherwise the system performance 13141f198e22SChangbin Du will be critically degraded. Remember to disable 13151f198e22SChangbin Du this option before clearing the function filter. 13161f198e22SChangbin Du 13171f198e22SChangbin DuOptions for function_graph tracer: 13181f198e22SChangbin Du 13191f198e22SChangbin Du Since the function_graph tracer has a slightly different output 13201f198e22SChangbin Du it has its own options to control what is displayed. 13211f198e22SChangbin Du 13221f198e22SChangbin Du funcgraph-overrun 13231f198e22SChangbin Du When set, the "overrun" of the graph stack is 13241f198e22SChangbin Du displayed after each function traced. The 13251f198e22SChangbin Du overrun, is when the stack depth of the calls 13261f198e22SChangbin Du is greater than what is reserved for each task. 13271f198e22SChangbin Du Each task has a fixed array of functions to 13281f198e22SChangbin Du trace in the call graph. If the depth of the 13291f198e22SChangbin Du calls exceeds that, the function is not traced. 13301f198e22SChangbin Du The overrun is the number of functions missed 13311f198e22SChangbin Du due to exceeding this array. 13321f198e22SChangbin Du 13331f198e22SChangbin Du funcgraph-cpu 13341f198e22SChangbin Du When set, the CPU number of the CPU where the trace 13351f198e22SChangbin Du occurred is displayed. 13361f198e22SChangbin Du 13371f198e22SChangbin Du funcgraph-overhead 13381f198e22SChangbin Du When set, if the function takes longer than 13391f198e22SChangbin Du A certain amount, then a delay marker is 13401f198e22SChangbin Du displayed. See "delay" above, under the 13411f198e22SChangbin Du header description. 13421f198e22SChangbin Du 13431f198e22SChangbin Du funcgraph-proc 13441f198e22SChangbin Du Unlike other tracers, the process' command line 13451f198e22SChangbin Du is not displayed by default, but instead only 13461f198e22SChangbin Du when a task is traced in and out during a context 13471f198e22SChangbin Du switch. Enabling this options has the command 13481f198e22SChangbin Du of each process displayed at every line. 13491f198e22SChangbin Du 13501f198e22SChangbin Du funcgraph-duration 13511f198e22SChangbin Du At the end of each function (the return) 13521f198e22SChangbin Du the duration of the amount of time in the 13531f198e22SChangbin Du function is displayed in microseconds. 13541f198e22SChangbin Du 13551f198e22SChangbin Du funcgraph-abstime 13561f198e22SChangbin Du When set, the timestamp is displayed at each line. 13571f198e22SChangbin Du 13581f198e22SChangbin Du funcgraph-irqs 13591f198e22SChangbin Du When disabled, functions that happen inside an 13601f198e22SChangbin Du interrupt will not be traced. 13611f198e22SChangbin Du 13621f198e22SChangbin Du funcgraph-tail 13631f198e22SChangbin Du When set, the return event will include the function 13641f198e22SChangbin Du that it represents. By default this is off, and 13651f198e22SChangbin Du only a closing curly bracket "}" is displayed for 13661f198e22SChangbin Du the return of a function. 13671f198e22SChangbin Du 136821c094d3SDonglin Peng funcgraph-retval 136921c094d3SDonglin Peng When set, the return value of each traced function 137021c094d3SDonglin Peng will be printed after an equal sign "=". By default 137121c094d3SDonglin Peng this is off. 137221c094d3SDonglin Peng 137321c094d3SDonglin Peng funcgraph-retval-hex 137421c094d3SDonglin Peng When set, the return value will always be printed 137521c094d3SDonglin Peng in hexadecimal format. If the option is not set and 137621c094d3SDonglin Peng the return value is an error code, it will be printed 137721c094d3SDonglin Peng in signed decimal format; otherwise it will also be 137821c094d3SDonglin Peng printed in hexadecimal format. By default, this option 137921c094d3SDonglin Peng is off. 138021c094d3SDonglin Peng 13811f198e22SChangbin Du sleep-time 13821f198e22SChangbin Du When running function graph tracer, to include 13831f198e22SChangbin Du the time a task schedules out in its function. 13841f198e22SChangbin Du When enabled, it will account time the task has been 13851f198e22SChangbin Du scheduled out as part of the function call. 13861f198e22SChangbin Du 13871f198e22SChangbin Du graph-time 13881f198e22SChangbin Du When running function profiler with function graph tracer, 13891f198e22SChangbin Du to include the time to call nested functions. When this is 13901f198e22SChangbin Du not set, the time reported for the function will only 13911f198e22SChangbin Du include the time the function itself executed for, not the 13921f198e22SChangbin Du time for functions that it called. 13931f198e22SChangbin Du 13941f198e22SChangbin DuOptions for blk tracer: 13951f198e22SChangbin Du 13961f198e22SChangbin Du blk_classic 13971f198e22SChangbin Du Shows a more minimalistic output. 13981f198e22SChangbin Du 13991f198e22SChangbin Du 14001f198e22SChangbin Duirqsoff 14011f198e22SChangbin Du------- 14021f198e22SChangbin Du 14031f198e22SChangbin DuWhen interrupts are disabled, the CPU can not react to any other 14041f198e22SChangbin Duexternal event (besides NMIs and SMIs). This prevents the timer 14051f198e22SChangbin Duinterrupt from triggering or the mouse interrupt from letting 14061f198e22SChangbin Duthe kernel know of a new mouse event. The result is a latency 14071f198e22SChangbin Duwith the reaction time. 14081f198e22SChangbin Du 14091f198e22SChangbin DuThe irqsoff tracer tracks the time for which interrupts are 14101f198e22SChangbin Dudisabled. When a new maximum latency is hit, the tracer saves 14111f198e22SChangbin Duthe trace leading up to that latency point so that every time a 14121f198e22SChangbin Dunew maximum is reached, the old saved trace is discarded and the 14131f198e22SChangbin Dunew trace is saved. 14141f198e22SChangbin Du 14151f198e22SChangbin DuTo reset the maximum, echo 0 into tracing_max_latency. Here is 14161f198e22SChangbin Duan example:: 14171f198e22SChangbin Du 14181f198e22SChangbin Du # echo 0 > options/function-trace 14191f198e22SChangbin Du # echo irqsoff > current_tracer 14201f198e22SChangbin Du # echo 1 > tracing_on 14211f198e22SChangbin Du # echo 0 > tracing_max_latency 14221f198e22SChangbin Du # ls -ltr 14231f198e22SChangbin Du [...] 14241f198e22SChangbin Du # echo 0 > tracing_on 14251f198e22SChangbin Du # cat trace 14261f198e22SChangbin Du # tracer: irqsoff 14271f198e22SChangbin Du # 14281f198e22SChangbin Du # irqsoff latency trace v1.1.5 on 3.8.0-test+ 14291f198e22SChangbin Du # -------------------------------------------------------------------- 14301f198e22SChangbin Du # latency: 16 us, #4/4, CPU#0 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 14311f198e22SChangbin Du # ----------------- 14321f198e22SChangbin Du # | task: swapper/0-0 (uid:0 nice:0 policy:0 rt_prio:0) 14331f198e22SChangbin Du # ----------------- 14341f198e22SChangbin Du # => started at: run_timer_softirq 14351f198e22SChangbin Du # => ended at: run_timer_softirq 14361f198e22SChangbin Du # 14371f198e22SChangbin Du # 14381f198e22SChangbin Du # _------=> CPU# 14391f198e22SChangbin Du # / _-----=> irqs-off 14401f198e22SChangbin Du # | / _----=> need-resched 14411f198e22SChangbin Du # || / _---=> hardirq/softirq 14421f198e22SChangbin Du # ||| / _--=> preempt-depth 14431f198e22SChangbin Du # |||| / delay 14441f198e22SChangbin Du # cmd pid ||||| time | caller 14451f198e22SChangbin Du # \ / ||||| \ | / 14461f198e22SChangbin Du <idle>-0 0d.s2 0us+: _raw_spin_lock_irq <-run_timer_softirq 14471f198e22SChangbin Du <idle>-0 0dNs3 17us : _raw_spin_unlock_irq <-run_timer_softirq 14481f198e22SChangbin Du <idle>-0 0dNs3 17us+: trace_hardirqs_on <-run_timer_softirq 14491f198e22SChangbin Du <idle>-0 0dNs3 25us : <stack trace> 14501f198e22SChangbin Du => _raw_spin_unlock_irq 14511f198e22SChangbin Du => run_timer_softirq 14521f198e22SChangbin Du => __do_softirq 14531f198e22SChangbin Du => call_softirq 14541f198e22SChangbin Du => do_softirq 14551f198e22SChangbin Du => irq_exit 14561f198e22SChangbin Du => smp_apic_timer_interrupt 14571f198e22SChangbin Du => apic_timer_interrupt 14581f198e22SChangbin Du => rcu_idle_exit 14591f198e22SChangbin Du => cpu_idle 14601f198e22SChangbin Du => rest_init 14611f198e22SChangbin Du => start_kernel 14621f198e22SChangbin Du => x86_64_start_reservations 14631f198e22SChangbin Du => x86_64_start_kernel 14641f198e22SChangbin Du 14651747db54SRandy DunlapHere we see that we had a latency of 16 microseconds (which is 14661f198e22SChangbin Duvery good). The _raw_spin_lock_irq in run_timer_softirq disabled 14671f198e22SChangbin Duinterrupts. The difference between the 16 and the displayed 14681f198e22SChangbin Dutimestamp 25us occurred because the clock was incremented 14691f198e22SChangbin Dubetween the time of recording the max latency and the time of 14701f198e22SChangbin Durecording the function that had that latency. 14711f198e22SChangbin Du 14721f198e22SChangbin DuNote the above example had function-trace not set. If we set 14731f198e22SChangbin Dufunction-trace, we get a much larger output:: 14741f198e22SChangbin Du 14751f198e22SChangbin Du with echo 1 > options/function-trace 14761f198e22SChangbin Du 14771f198e22SChangbin Du # tracer: irqsoff 14781f198e22SChangbin Du # 14791f198e22SChangbin Du # irqsoff latency trace v1.1.5 on 3.8.0-test+ 14801f198e22SChangbin Du # -------------------------------------------------------------------- 14811f198e22SChangbin Du # latency: 71 us, #168/168, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 14821f198e22SChangbin Du # ----------------- 14831f198e22SChangbin Du # | task: bash-2042 (uid:0 nice:0 policy:0 rt_prio:0) 14841f198e22SChangbin Du # ----------------- 14851f198e22SChangbin Du # => started at: ata_scsi_queuecmd 14861f198e22SChangbin Du # => ended at: ata_scsi_queuecmd 14871f198e22SChangbin Du # 14881f198e22SChangbin Du # 14891f198e22SChangbin Du # _------=> CPU# 14901f198e22SChangbin Du # / _-----=> irqs-off 14911f198e22SChangbin Du # | / _----=> need-resched 14921f198e22SChangbin Du # || / _---=> hardirq/softirq 14931f198e22SChangbin Du # ||| / _--=> preempt-depth 14941f198e22SChangbin Du # |||| / delay 14951f198e22SChangbin Du # cmd pid ||||| time | caller 14961f198e22SChangbin Du # \ / ||||| \ | / 14971f198e22SChangbin Du bash-2042 3d... 0us : _raw_spin_lock_irqsave <-ata_scsi_queuecmd 14981f198e22SChangbin Du bash-2042 3d... 0us : add_preempt_count <-_raw_spin_lock_irqsave 14991f198e22SChangbin Du bash-2042 3d..1 1us : ata_scsi_find_dev <-ata_scsi_queuecmd 15001f198e22SChangbin Du bash-2042 3d..1 1us : __ata_scsi_find_dev <-ata_scsi_find_dev 15011f198e22SChangbin Du bash-2042 3d..1 2us : ata_find_dev.part.14 <-__ata_scsi_find_dev 15021f198e22SChangbin Du bash-2042 3d..1 2us : ata_qc_new_init <-__ata_scsi_queuecmd 15031f198e22SChangbin Du bash-2042 3d..1 3us : ata_sg_init <-__ata_scsi_queuecmd 15041f198e22SChangbin Du bash-2042 3d..1 4us : ata_scsi_rw_xlat <-__ata_scsi_queuecmd 15051f198e22SChangbin Du bash-2042 3d..1 4us : ata_build_rw_tf <-ata_scsi_rw_xlat 15061f198e22SChangbin Du [...] 15071f198e22SChangbin Du bash-2042 3d..1 67us : delay_tsc <-__delay 15081f198e22SChangbin Du bash-2042 3d..1 67us : add_preempt_count <-delay_tsc 15091f198e22SChangbin Du bash-2042 3d..2 67us : sub_preempt_count <-delay_tsc 15101f198e22SChangbin Du bash-2042 3d..1 67us : add_preempt_count <-delay_tsc 15111f198e22SChangbin Du bash-2042 3d..2 68us : sub_preempt_count <-delay_tsc 15121f198e22SChangbin Du bash-2042 3d..1 68us+: ata_bmdma_start <-ata_bmdma_qc_issue 15131f198e22SChangbin Du bash-2042 3d..1 71us : _raw_spin_unlock_irqrestore <-ata_scsi_queuecmd 15141f198e22SChangbin Du bash-2042 3d..1 71us : _raw_spin_unlock_irqrestore <-ata_scsi_queuecmd 15151f198e22SChangbin Du bash-2042 3d..1 72us+: trace_hardirqs_on <-ata_scsi_queuecmd 15161f198e22SChangbin Du bash-2042 3d..1 120us : <stack trace> 15171f198e22SChangbin Du => _raw_spin_unlock_irqrestore 15181f198e22SChangbin Du => ata_scsi_queuecmd 15191f198e22SChangbin Du => scsi_dispatch_cmd 15201f198e22SChangbin Du => scsi_request_fn 15211f198e22SChangbin Du => __blk_run_queue_uncond 15221f198e22SChangbin Du => __blk_run_queue 15231f198e22SChangbin Du => blk_queue_bio 1524ed00aabdSChristoph Hellwig => submit_bio_noacct 15251f198e22SChangbin Du => submit_bio 15261f198e22SChangbin Du => submit_bh 15271f198e22SChangbin Du => __ext3_get_inode_loc 15281f198e22SChangbin Du => ext3_iget 15291f198e22SChangbin Du => ext3_lookup 15301f198e22SChangbin Du => lookup_real 15311f198e22SChangbin Du => __lookup_hash 15321f198e22SChangbin Du => walk_component 15331f198e22SChangbin Du => lookup_last 15341f198e22SChangbin Du => path_lookupat 15351f198e22SChangbin Du => filename_lookup 15361f198e22SChangbin Du => user_path_at_empty 15371f198e22SChangbin Du => user_path_at 15381f198e22SChangbin Du => vfs_fstatat 15391f198e22SChangbin Du => vfs_stat 15401f198e22SChangbin Du => sys_newstat 15411f198e22SChangbin Du => system_call_fastpath 15421f198e22SChangbin Du 15431f198e22SChangbin Du 15441f198e22SChangbin DuHere we traced a 71 microsecond latency. But we also see all the 15451f198e22SChangbin Dufunctions that were called during that time. Note that by 15461f198e22SChangbin Duenabling function tracing, we incur an added overhead. This 15471f198e22SChangbin Duoverhead may extend the latency times. But nevertheless, this 15481f198e22SChangbin Dutrace has provided some very helpful debugging information. 15491f198e22SChangbin Du 155088d380ebSChangbin DuIf we prefer function graph output instead of function, we can set 155188d380ebSChangbin Dudisplay-graph option:: 15523df5ffd2SMauro Carvalho Chehab 155388d380ebSChangbin Du with echo 1 > options/display-graph 155488d380ebSChangbin Du 155588d380ebSChangbin Du # tracer: irqsoff 155688d380ebSChangbin Du # 155788d380ebSChangbin Du # irqsoff latency trace v1.1.5 on 4.20.0-rc6+ 155888d380ebSChangbin Du # -------------------------------------------------------------------- 155988d380ebSChangbin Du # latency: 3751 us, #274/274, CPU#0 | (M:desktop VP:0, KP:0, SP:0 HP:0 #P:4) 156088d380ebSChangbin Du # ----------------- 156188d380ebSChangbin Du # | task: bash-1507 (uid:0 nice:0 policy:0 rt_prio:0) 156288d380ebSChangbin Du # ----------------- 156388d380ebSChangbin Du # => started at: free_debug_processing 156488d380ebSChangbin Du # => ended at: return_to_handler 156588d380ebSChangbin Du # 156688d380ebSChangbin Du # 156788d380ebSChangbin Du # _-----=> irqs-off 156888d380ebSChangbin Du # / _----=> need-resched 156988d380ebSChangbin Du # | / _---=> hardirq/softirq 157088d380ebSChangbin Du # || / _--=> preempt-depth 157188d380ebSChangbin Du # ||| / 157288d380ebSChangbin Du # REL TIME CPU TASK/PID |||| DURATION FUNCTION CALLS 157388d380ebSChangbin Du # | | | | |||| | | | | | | 157488d380ebSChangbin Du 0 us | 0) bash-1507 | d... | 0.000 us | _raw_spin_lock_irqsave(); 157588d380ebSChangbin Du 0 us | 0) bash-1507 | d..1 | 0.378 us | do_raw_spin_trylock(); 157688d380ebSChangbin Du 1 us | 0) bash-1507 | d..2 | | set_track() { 157788d380ebSChangbin Du 2 us | 0) bash-1507 | d..2 | | save_stack_trace() { 157888d380ebSChangbin Du 2 us | 0) bash-1507 | d..2 | | __save_stack_trace() { 157988d380ebSChangbin Du 3 us | 0) bash-1507 | d..2 | | __unwind_start() { 158088d380ebSChangbin Du 3 us | 0) bash-1507 | d..2 | | get_stack_info() { 158188d380ebSChangbin Du 3 us | 0) bash-1507 | d..2 | 0.351 us | in_task_stack(); 158288d380ebSChangbin Du 4 us | 0) bash-1507 | d..2 | 1.107 us | } 158388d380ebSChangbin Du [...] 158488d380ebSChangbin Du 3750 us | 0) bash-1507 | d..1 | 0.516 us | do_raw_spin_unlock(); 158588d380ebSChangbin Du 3750 us | 0) bash-1507 | d..1 | 0.000 us | _raw_spin_unlock_irqrestore(); 158688d380ebSChangbin Du 3764 us | 0) bash-1507 | d..1 | 0.000 us | tracer_hardirqs_on(); 158788d380ebSChangbin Du bash-1507 0d..1 3792us : <stack trace> 158888d380ebSChangbin Du => free_debug_processing 158988d380ebSChangbin Du => __slab_free 159088d380ebSChangbin Du => kmem_cache_free 159188d380ebSChangbin Du => vm_area_free 159288d380ebSChangbin Du => remove_vma 159388d380ebSChangbin Du => exit_mmap 159488d380ebSChangbin Du => mmput 15952388777aSEric W. Biederman => begin_new_exec 159688d380ebSChangbin Du => load_elf_binary 159788d380ebSChangbin Du => search_binary_handler 159888d380ebSChangbin Du => __do_execve_file.isra.32 159988d380ebSChangbin Du => __x64_sys_execve 160088d380ebSChangbin Du => do_syscall_64 160188d380ebSChangbin Du => entry_SYSCALL_64_after_hwframe 16021f198e22SChangbin Du 16031f198e22SChangbin Dupreemptoff 16041f198e22SChangbin Du---------- 16051f198e22SChangbin Du 16061f198e22SChangbin DuWhen preemption is disabled, we may be able to receive 16071f198e22SChangbin Duinterrupts but the task cannot be preempted and a higher 16081f198e22SChangbin Dupriority task must wait for preemption to be enabled again 16091f198e22SChangbin Dubefore it can preempt a lower priority task. 16101f198e22SChangbin Du 16111f198e22SChangbin DuThe preemptoff tracer traces the places that disable preemption. 16121f198e22SChangbin DuLike the irqsoff tracer, it records the maximum latency for 16131f198e22SChangbin Duwhich preemption was disabled. The control of preemptoff tracer 16141f198e22SChangbin Duis much like the irqsoff tracer. 16151f198e22SChangbin Du:: 16161f198e22SChangbin Du 16171f198e22SChangbin Du # echo 0 > options/function-trace 16181f198e22SChangbin Du # echo preemptoff > current_tracer 16191f198e22SChangbin Du # echo 1 > tracing_on 16201f198e22SChangbin Du # echo 0 > tracing_max_latency 16211f198e22SChangbin Du # ls -ltr 16221f198e22SChangbin Du [...] 16231f198e22SChangbin Du # echo 0 > tracing_on 16241f198e22SChangbin Du # cat trace 16251f198e22SChangbin Du # tracer: preemptoff 16261f198e22SChangbin Du # 16271f198e22SChangbin Du # preemptoff latency trace v1.1.5 on 3.8.0-test+ 16281f198e22SChangbin Du # -------------------------------------------------------------------- 16291f198e22SChangbin Du # latency: 46 us, #4/4, CPU#1 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 16301f198e22SChangbin Du # ----------------- 16311f198e22SChangbin Du # | task: sshd-1991 (uid:0 nice:0 policy:0 rt_prio:0) 16321f198e22SChangbin Du # ----------------- 16331f198e22SChangbin Du # => started at: do_IRQ 16341f198e22SChangbin Du # => ended at: do_IRQ 16351f198e22SChangbin Du # 16361f198e22SChangbin Du # 16371f198e22SChangbin Du # _------=> CPU# 16381f198e22SChangbin Du # / _-----=> irqs-off 16391f198e22SChangbin Du # | / _----=> need-resched 16401f198e22SChangbin Du # || / _---=> hardirq/softirq 16411f198e22SChangbin Du # ||| / _--=> preempt-depth 16421f198e22SChangbin Du # |||| / delay 16431f198e22SChangbin Du # cmd pid ||||| time | caller 16441f198e22SChangbin Du # \ / ||||| \ | / 16451f198e22SChangbin Du sshd-1991 1d.h. 0us+: irq_enter <-do_IRQ 16461f198e22SChangbin Du sshd-1991 1d..1 46us : irq_exit <-do_IRQ 16471f198e22SChangbin Du sshd-1991 1d..1 47us+: trace_preempt_on <-do_IRQ 16481f198e22SChangbin Du sshd-1991 1d..1 52us : <stack trace> 16491f198e22SChangbin Du => sub_preempt_count 16501f198e22SChangbin Du => irq_exit 16511f198e22SChangbin Du => do_IRQ 16521f198e22SChangbin Du => ret_from_intr 16531f198e22SChangbin Du 16541f198e22SChangbin Du 16551f198e22SChangbin DuThis has some more changes. Preemption was disabled when an 16561f198e22SChangbin Duinterrupt came in (notice the 'h'), and was enabled on exit. 16571f198e22SChangbin DuBut we also see that interrupts have been disabled when entering 16581f198e22SChangbin Duthe preempt off section and leaving it (the 'd'). We do not know if 16591f198e22SChangbin Duinterrupts were enabled in the mean time or shortly after this 16601f198e22SChangbin Duwas over. 16611f198e22SChangbin Du:: 16621f198e22SChangbin Du 16631f198e22SChangbin Du # tracer: preemptoff 16641f198e22SChangbin Du # 16651f198e22SChangbin Du # preemptoff latency trace v1.1.5 on 3.8.0-test+ 16661f198e22SChangbin Du # -------------------------------------------------------------------- 16671f198e22SChangbin Du # latency: 83 us, #241/241, CPU#1 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 16681f198e22SChangbin Du # ----------------- 16691f198e22SChangbin Du # | task: bash-1994 (uid:0 nice:0 policy:0 rt_prio:0) 16701f198e22SChangbin Du # ----------------- 16711f198e22SChangbin Du # => started at: wake_up_new_task 16721f198e22SChangbin Du # => ended at: task_rq_unlock 16731f198e22SChangbin Du # 16741f198e22SChangbin Du # 16751f198e22SChangbin Du # _------=> CPU# 16761f198e22SChangbin Du # / _-----=> irqs-off 16771f198e22SChangbin Du # | / _----=> need-resched 16781f198e22SChangbin Du # || / _---=> hardirq/softirq 16791f198e22SChangbin Du # ||| / _--=> preempt-depth 16801f198e22SChangbin Du # |||| / delay 16811f198e22SChangbin Du # cmd pid ||||| time | caller 16821f198e22SChangbin Du # \ / ||||| \ | / 16831f198e22SChangbin Du bash-1994 1d..1 0us : _raw_spin_lock_irqsave <-wake_up_new_task 16841f198e22SChangbin Du bash-1994 1d..1 0us : select_task_rq_fair <-select_task_rq 16851f198e22SChangbin Du bash-1994 1d..1 1us : __rcu_read_lock <-select_task_rq_fair 16861f198e22SChangbin Du bash-1994 1d..1 1us : source_load <-select_task_rq_fair 16871f198e22SChangbin Du bash-1994 1d..1 1us : source_load <-select_task_rq_fair 16881f198e22SChangbin Du [...] 16891f198e22SChangbin Du bash-1994 1d..1 12us : irq_enter <-smp_apic_timer_interrupt 16901f198e22SChangbin Du bash-1994 1d..1 12us : rcu_irq_enter <-irq_enter 16911f198e22SChangbin Du bash-1994 1d..1 13us : add_preempt_count <-irq_enter 16921f198e22SChangbin Du bash-1994 1d.h1 13us : exit_idle <-smp_apic_timer_interrupt 16931f198e22SChangbin Du bash-1994 1d.h1 13us : hrtimer_interrupt <-smp_apic_timer_interrupt 16941f198e22SChangbin Du bash-1994 1d.h1 13us : _raw_spin_lock <-hrtimer_interrupt 16951f198e22SChangbin Du bash-1994 1d.h1 14us : add_preempt_count <-_raw_spin_lock 16961f198e22SChangbin Du bash-1994 1d.h2 14us : ktime_get_update_offsets <-hrtimer_interrupt 16971f198e22SChangbin Du [...] 16981f198e22SChangbin Du bash-1994 1d.h1 35us : lapic_next_event <-clockevents_program_event 16991f198e22SChangbin Du bash-1994 1d.h1 35us : irq_exit <-smp_apic_timer_interrupt 17001f198e22SChangbin Du bash-1994 1d.h1 36us : sub_preempt_count <-irq_exit 17011f198e22SChangbin Du bash-1994 1d..2 36us : do_softirq <-irq_exit 17021f198e22SChangbin Du bash-1994 1d..2 36us : __do_softirq <-call_softirq 17031f198e22SChangbin Du bash-1994 1d..2 36us : __local_bh_disable <-__do_softirq 17041f198e22SChangbin Du bash-1994 1d.s2 37us : add_preempt_count <-_raw_spin_lock_irq 17051f198e22SChangbin Du bash-1994 1d.s3 38us : _raw_spin_unlock <-run_timer_softirq 17061f198e22SChangbin Du bash-1994 1d.s3 39us : sub_preempt_count <-_raw_spin_unlock 17071f198e22SChangbin Du bash-1994 1d.s2 39us : call_timer_fn <-run_timer_softirq 17081f198e22SChangbin Du [...] 17091f198e22SChangbin Du bash-1994 1dNs2 81us : cpu_needs_another_gp <-rcu_process_callbacks 17101f198e22SChangbin Du bash-1994 1dNs2 82us : __local_bh_enable <-__do_softirq 17111f198e22SChangbin Du bash-1994 1dNs2 82us : sub_preempt_count <-__local_bh_enable 17121f198e22SChangbin Du bash-1994 1dN.2 82us : idle_cpu <-irq_exit 17131f198e22SChangbin Du bash-1994 1dN.2 83us : rcu_irq_exit <-irq_exit 17141f198e22SChangbin Du bash-1994 1dN.2 83us : sub_preempt_count <-irq_exit 17151f198e22SChangbin Du bash-1994 1.N.1 84us : _raw_spin_unlock_irqrestore <-task_rq_unlock 17161f198e22SChangbin Du bash-1994 1.N.1 84us+: trace_preempt_on <-task_rq_unlock 17171f198e22SChangbin Du bash-1994 1.N.1 104us : <stack trace> 17181f198e22SChangbin Du => sub_preempt_count 17191f198e22SChangbin Du => _raw_spin_unlock_irqrestore 17201f198e22SChangbin Du => task_rq_unlock 17211f198e22SChangbin Du => wake_up_new_task 17221f198e22SChangbin Du => do_fork 17231f198e22SChangbin Du => sys_clone 17241f198e22SChangbin Du => stub_clone 17251f198e22SChangbin Du 17261f198e22SChangbin Du 17271f198e22SChangbin DuThe above is an example of the preemptoff trace with 17281f198e22SChangbin Dufunction-trace set. Here we see that interrupts were not disabled 17291f198e22SChangbin Duthe entire time. The irq_enter code lets us know that we entered 17301f198e22SChangbin Duan interrupt 'h'. Before that, the functions being traced still 17311f198e22SChangbin Dushow that it is not in an interrupt, but we can see from the 17321f198e22SChangbin Dufunctions themselves that this is not the case. 17331f198e22SChangbin Du 17341f198e22SChangbin Dupreemptirqsoff 17351f198e22SChangbin Du-------------- 17361f198e22SChangbin Du 17371f198e22SChangbin DuKnowing the locations that have interrupts disabled or 17381f198e22SChangbin Dupreemption disabled for the longest times is helpful. But 17391f198e22SChangbin Dusometimes we would like to know when either preemption and/or 17401f198e22SChangbin Duinterrupts are disabled. 17411f198e22SChangbin Du 17421f198e22SChangbin DuConsider the following code:: 17431f198e22SChangbin Du 17441f198e22SChangbin Du local_irq_disable(); 17451f198e22SChangbin Du call_function_with_irqs_off(); 17461f198e22SChangbin Du preempt_disable(); 17471f198e22SChangbin Du call_function_with_irqs_and_preemption_off(); 17481f198e22SChangbin Du local_irq_enable(); 17491f198e22SChangbin Du call_function_with_preemption_off(); 17501f198e22SChangbin Du preempt_enable(); 17511f198e22SChangbin Du 17521f198e22SChangbin DuThe irqsoff tracer will record the total length of 17531f198e22SChangbin Ducall_function_with_irqs_off() and 17541f198e22SChangbin Ducall_function_with_irqs_and_preemption_off(). 17551f198e22SChangbin Du 17561f198e22SChangbin DuThe preemptoff tracer will record the total length of 17571f198e22SChangbin Ducall_function_with_irqs_and_preemption_off() and 17581f198e22SChangbin Ducall_function_with_preemption_off(). 17591f198e22SChangbin Du 17601f198e22SChangbin DuBut neither will trace the time that interrupts and/or 17611f198e22SChangbin Dupreemption is disabled. This total time is the time that we can 17621f198e22SChangbin Dunot schedule. To record this time, use the preemptirqsoff 17631f198e22SChangbin Dutracer. 17641f198e22SChangbin Du 17651f198e22SChangbin DuAgain, using this trace is much like the irqsoff and preemptoff 17661f198e22SChangbin Dutracers. 17671f198e22SChangbin Du:: 17681f198e22SChangbin Du 17691f198e22SChangbin Du # echo 0 > options/function-trace 17701f198e22SChangbin Du # echo preemptirqsoff > current_tracer 17711f198e22SChangbin Du # echo 1 > tracing_on 17721f198e22SChangbin Du # echo 0 > tracing_max_latency 17731f198e22SChangbin Du # ls -ltr 17741f198e22SChangbin Du [...] 17751f198e22SChangbin Du # echo 0 > tracing_on 17761f198e22SChangbin Du # cat trace 17771f198e22SChangbin Du # tracer: preemptirqsoff 17781f198e22SChangbin Du # 17791f198e22SChangbin Du # preemptirqsoff latency trace v1.1.5 on 3.8.0-test+ 17801f198e22SChangbin Du # -------------------------------------------------------------------- 17811f198e22SChangbin Du # latency: 100 us, #4/4, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 17821f198e22SChangbin Du # ----------------- 17831f198e22SChangbin Du # | task: ls-2230 (uid:0 nice:0 policy:0 rt_prio:0) 17841f198e22SChangbin Du # ----------------- 17851f198e22SChangbin Du # => started at: ata_scsi_queuecmd 17861f198e22SChangbin Du # => ended at: ata_scsi_queuecmd 17871f198e22SChangbin Du # 17881f198e22SChangbin Du # 17891f198e22SChangbin Du # _------=> CPU# 17901f198e22SChangbin Du # / _-----=> irqs-off 17911f198e22SChangbin Du # | / _----=> need-resched 17921f198e22SChangbin Du # || / _---=> hardirq/softirq 17931f198e22SChangbin Du # ||| / _--=> preempt-depth 17941f198e22SChangbin Du # |||| / delay 17951f198e22SChangbin Du # cmd pid ||||| time | caller 17961f198e22SChangbin Du # \ / ||||| \ | / 17971f198e22SChangbin Du ls-2230 3d... 0us+: _raw_spin_lock_irqsave <-ata_scsi_queuecmd 17981f198e22SChangbin Du ls-2230 3...1 100us : _raw_spin_unlock_irqrestore <-ata_scsi_queuecmd 17991f198e22SChangbin Du ls-2230 3...1 101us+: trace_preempt_on <-ata_scsi_queuecmd 18001f198e22SChangbin Du ls-2230 3...1 111us : <stack trace> 18011f198e22SChangbin Du => sub_preempt_count 18021f198e22SChangbin Du => _raw_spin_unlock_irqrestore 18031f198e22SChangbin Du => ata_scsi_queuecmd 18041f198e22SChangbin Du => scsi_dispatch_cmd 18051f198e22SChangbin Du => scsi_request_fn 18061f198e22SChangbin Du => __blk_run_queue_uncond 18071f198e22SChangbin Du => __blk_run_queue 18081f198e22SChangbin Du => blk_queue_bio 1809ed00aabdSChristoph Hellwig => submit_bio_noacct 18101f198e22SChangbin Du => submit_bio 18111f198e22SChangbin Du => submit_bh 18121f198e22SChangbin Du => ext3_bread 18131f198e22SChangbin Du => ext3_dir_bread 18141f198e22SChangbin Du => htree_dirblock_to_tree 18151f198e22SChangbin Du => ext3_htree_fill_tree 18161f198e22SChangbin Du => ext3_readdir 18171f198e22SChangbin Du => vfs_readdir 18181f198e22SChangbin Du => sys_getdents 18191f198e22SChangbin Du => system_call_fastpath 18201f198e22SChangbin Du 18211f198e22SChangbin Du 18221f198e22SChangbin DuThe trace_hardirqs_off_thunk is called from assembly on x86 when 18231f198e22SChangbin Duinterrupts are disabled in the assembly code. Without the 18241f198e22SChangbin Dufunction tracing, we do not know if interrupts were enabled 18251f198e22SChangbin Duwithin the preemption points. We do see that it started with 18261f198e22SChangbin Dupreemption enabled. 18271f198e22SChangbin Du 18281f198e22SChangbin DuHere is a trace with function-trace set:: 18291f198e22SChangbin Du 18301f198e22SChangbin Du # tracer: preemptirqsoff 18311f198e22SChangbin Du # 18321f198e22SChangbin Du # preemptirqsoff latency trace v1.1.5 on 3.8.0-test+ 18331f198e22SChangbin Du # -------------------------------------------------------------------- 18341f198e22SChangbin Du # latency: 161 us, #339/339, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 18351f198e22SChangbin Du # ----------------- 18361f198e22SChangbin Du # | task: ls-2269 (uid:0 nice:0 policy:0 rt_prio:0) 18371f198e22SChangbin Du # ----------------- 18381f198e22SChangbin Du # => started at: schedule 18391f198e22SChangbin Du # => ended at: mutex_unlock 18401f198e22SChangbin Du # 18411f198e22SChangbin Du # 18421f198e22SChangbin Du # _------=> CPU# 18431f198e22SChangbin Du # / _-----=> irqs-off 18441f198e22SChangbin Du # | / _----=> need-resched 18451f198e22SChangbin Du # || / _---=> hardirq/softirq 18461f198e22SChangbin Du # ||| / _--=> preempt-depth 18471f198e22SChangbin Du # |||| / delay 18481f198e22SChangbin Du # cmd pid ||||| time | caller 18491f198e22SChangbin Du # \ / ||||| \ | / 18501f198e22SChangbin Du kworker/-59 3...1 0us : __schedule <-schedule 18511f198e22SChangbin Du kworker/-59 3d..1 0us : rcu_preempt_qs <-rcu_note_context_switch 18521f198e22SChangbin Du kworker/-59 3d..1 1us : add_preempt_count <-_raw_spin_lock_irq 18531f198e22SChangbin Du kworker/-59 3d..2 1us : deactivate_task <-__schedule 18541f198e22SChangbin Du kworker/-59 3d..2 1us : dequeue_task <-deactivate_task 18551f198e22SChangbin Du kworker/-59 3d..2 2us : update_rq_clock <-dequeue_task 18561f198e22SChangbin Du kworker/-59 3d..2 2us : dequeue_task_fair <-dequeue_task 18571f198e22SChangbin Du kworker/-59 3d..2 2us : update_curr <-dequeue_task_fair 18581f198e22SChangbin Du kworker/-59 3d..2 2us : update_min_vruntime <-update_curr 18591f198e22SChangbin Du kworker/-59 3d..2 3us : cpuacct_charge <-update_curr 18601f198e22SChangbin Du kworker/-59 3d..2 3us : __rcu_read_lock <-cpuacct_charge 18611f198e22SChangbin Du kworker/-59 3d..2 3us : __rcu_read_unlock <-cpuacct_charge 18621f198e22SChangbin Du kworker/-59 3d..2 3us : update_cfs_rq_blocked_load <-dequeue_task_fair 18631f198e22SChangbin Du kworker/-59 3d..2 4us : clear_buddies <-dequeue_task_fair 18641f198e22SChangbin Du kworker/-59 3d..2 4us : account_entity_dequeue <-dequeue_task_fair 18651f198e22SChangbin Du kworker/-59 3d..2 4us : update_min_vruntime <-dequeue_task_fair 18661f198e22SChangbin Du kworker/-59 3d..2 4us : update_cfs_shares <-dequeue_task_fair 18671f198e22SChangbin Du kworker/-59 3d..2 5us : hrtick_update <-dequeue_task_fair 18681f198e22SChangbin Du kworker/-59 3d..2 5us : wq_worker_sleeping <-__schedule 18691f198e22SChangbin Du kworker/-59 3d..2 5us : kthread_data <-wq_worker_sleeping 18701f198e22SChangbin Du kworker/-59 3d..2 5us : put_prev_task_fair <-__schedule 18711f198e22SChangbin Du kworker/-59 3d..2 6us : pick_next_task_fair <-pick_next_task 18721f198e22SChangbin Du kworker/-59 3d..2 6us : clear_buddies <-pick_next_task_fair 18731f198e22SChangbin Du kworker/-59 3d..2 6us : set_next_entity <-pick_next_task_fair 18741f198e22SChangbin Du kworker/-59 3d..2 6us : update_stats_wait_end <-set_next_entity 18751f198e22SChangbin Du ls-2269 3d..2 7us : finish_task_switch <-__schedule 18761f198e22SChangbin Du ls-2269 3d..2 7us : _raw_spin_unlock_irq <-finish_task_switch 18771f198e22SChangbin Du ls-2269 3d..2 8us : do_IRQ <-ret_from_intr 18781f198e22SChangbin Du ls-2269 3d..2 8us : irq_enter <-do_IRQ 18791f198e22SChangbin Du ls-2269 3d..2 8us : rcu_irq_enter <-irq_enter 18801f198e22SChangbin Du ls-2269 3d..2 9us : add_preempt_count <-irq_enter 18811f198e22SChangbin Du ls-2269 3d.h2 9us : exit_idle <-do_IRQ 18821f198e22SChangbin Du [...] 18831f198e22SChangbin Du ls-2269 3d.h3 20us : sub_preempt_count <-_raw_spin_unlock 18841f198e22SChangbin Du ls-2269 3d.h2 20us : irq_exit <-do_IRQ 18851f198e22SChangbin Du ls-2269 3d.h2 21us : sub_preempt_count <-irq_exit 18861f198e22SChangbin Du ls-2269 3d..3 21us : do_softirq <-irq_exit 18871f198e22SChangbin Du ls-2269 3d..3 21us : __do_softirq <-call_softirq 18881f198e22SChangbin Du ls-2269 3d..3 21us+: __local_bh_disable <-__do_softirq 18891f198e22SChangbin Du ls-2269 3d.s4 29us : sub_preempt_count <-_local_bh_enable_ip 18901f198e22SChangbin Du ls-2269 3d.s5 29us : sub_preempt_count <-_local_bh_enable_ip 18911f198e22SChangbin Du ls-2269 3d.s5 31us : do_IRQ <-ret_from_intr 18921f198e22SChangbin Du ls-2269 3d.s5 31us : irq_enter <-do_IRQ 18931f198e22SChangbin Du ls-2269 3d.s5 31us : rcu_irq_enter <-irq_enter 18941f198e22SChangbin Du [...] 18951f198e22SChangbin Du ls-2269 3d.s5 31us : rcu_irq_enter <-irq_enter 18961f198e22SChangbin Du ls-2269 3d.s5 32us : add_preempt_count <-irq_enter 18971f198e22SChangbin Du ls-2269 3d.H5 32us : exit_idle <-do_IRQ 18981f198e22SChangbin Du ls-2269 3d.H5 32us : handle_irq <-do_IRQ 18991f198e22SChangbin Du ls-2269 3d.H5 32us : irq_to_desc <-handle_irq 19001f198e22SChangbin Du ls-2269 3d.H5 33us : handle_fasteoi_irq <-handle_irq 19011f198e22SChangbin Du [...] 19021f198e22SChangbin Du ls-2269 3d.s5 158us : _raw_spin_unlock_irqrestore <-rtl8139_poll 19031f198e22SChangbin Du ls-2269 3d.s3 158us : net_rps_action_and_irq_enable.isra.65 <-net_rx_action 19041f198e22SChangbin Du ls-2269 3d.s3 159us : __local_bh_enable <-__do_softirq 19051f198e22SChangbin Du ls-2269 3d.s3 159us : sub_preempt_count <-__local_bh_enable 19061f198e22SChangbin Du ls-2269 3d..3 159us : idle_cpu <-irq_exit 19071f198e22SChangbin Du ls-2269 3d..3 159us : rcu_irq_exit <-irq_exit 19081f198e22SChangbin Du ls-2269 3d..3 160us : sub_preempt_count <-irq_exit 19091f198e22SChangbin Du ls-2269 3d... 161us : __mutex_unlock_slowpath <-mutex_unlock 19101f198e22SChangbin Du ls-2269 3d... 162us+: trace_hardirqs_on <-mutex_unlock 19111f198e22SChangbin Du ls-2269 3d... 186us : <stack trace> 19121f198e22SChangbin Du => __mutex_unlock_slowpath 19131f198e22SChangbin Du => mutex_unlock 19141f198e22SChangbin Du => process_output 19151f198e22SChangbin Du => n_tty_write 19161f198e22SChangbin Du => tty_write 19171f198e22SChangbin Du => vfs_write 19181f198e22SChangbin Du => sys_write 19191f198e22SChangbin Du => system_call_fastpath 19201f198e22SChangbin Du 19211f198e22SChangbin DuThis is an interesting trace. It started with kworker running and 19221f198e22SChangbin Duscheduling out and ls taking over. But as soon as ls released the 19231f198e22SChangbin Durq lock and enabled interrupts (but not preemption) an interrupt 19241f198e22SChangbin Dutriggered. When the interrupt finished, it started running softirqs. 19251f198e22SChangbin DuBut while the softirq was running, another interrupt triggered. 19261f198e22SChangbin DuWhen an interrupt is running inside a softirq, the annotation is 'H'. 19271f198e22SChangbin Du 19281f198e22SChangbin Du 19291f198e22SChangbin Duwakeup 19301f198e22SChangbin Du------ 19311f198e22SChangbin Du 19321f198e22SChangbin DuOne common case that people are interested in tracing is the 19331f198e22SChangbin Dutime it takes for a task that is woken to actually wake up. 19341f198e22SChangbin DuNow for non Real-Time tasks, this can be arbitrary. But tracing 19351f198e22SChangbin Duit none the less can be interesting. 19361f198e22SChangbin Du 19371f198e22SChangbin DuWithout function tracing:: 19381f198e22SChangbin Du 19391f198e22SChangbin Du # echo 0 > options/function-trace 19401f198e22SChangbin Du # echo wakeup > current_tracer 19411f198e22SChangbin Du # echo 1 > tracing_on 19421f198e22SChangbin Du # echo 0 > tracing_max_latency 19431f198e22SChangbin Du # chrt -f 5 sleep 1 19441f198e22SChangbin Du # echo 0 > tracing_on 19451f198e22SChangbin Du # cat trace 19461f198e22SChangbin Du # tracer: wakeup 19471f198e22SChangbin Du # 19481f198e22SChangbin Du # wakeup latency trace v1.1.5 on 3.8.0-test+ 19491f198e22SChangbin Du # -------------------------------------------------------------------- 19501f198e22SChangbin Du # latency: 15 us, #4/4, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 19511f198e22SChangbin Du # ----------------- 19521f198e22SChangbin Du # | task: kworker/3:1H-312 (uid:0 nice:-20 policy:0 rt_prio:0) 19531f198e22SChangbin Du # ----------------- 19541f198e22SChangbin Du # 19551f198e22SChangbin Du # _------=> CPU# 19561f198e22SChangbin Du # / _-----=> irqs-off 19571f198e22SChangbin Du # | / _----=> need-resched 19581f198e22SChangbin Du # || / _---=> hardirq/softirq 19591f198e22SChangbin Du # ||| / _--=> preempt-depth 19601f198e22SChangbin Du # |||| / delay 19611f198e22SChangbin Du # cmd pid ||||| time | caller 19621f198e22SChangbin Du # \ / ||||| \ | / 19631f198e22SChangbin Du <idle>-0 3dNs7 0us : 0:120:R + [003] 312:100:R kworker/3:1H 19641f198e22SChangbin Du <idle>-0 3dNs7 1us+: ttwu_do_activate.constprop.87 <-try_to_wake_up 19651f198e22SChangbin Du <idle>-0 3d..3 15us : __schedule <-schedule 19661f198e22SChangbin Du <idle>-0 3d..3 15us : 0:120:R ==> [003] 312:100:R kworker/3:1H 19671f198e22SChangbin Du 19681f198e22SChangbin DuThe tracer only traces the highest priority task in the system 19691f198e22SChangbin Duto avoid tracing the normal circumstances. Here we see that 19701f198e22SChangbin Duthe kworker with a nice priority of -20 (not very nice), took 19711f198e22SChangbin Dujust 15 microseconds from the time it woke up, to the time it 19721f198e22SChangbin Duran. 19731f198e22SChangbin Du 19741f198e22SChangbin DuNon Real-Time tasks are not that interesting. A more interesting 19751f198e22SChangbin Dutrace is to concentrate only on Real-Time tasks. 19761f198e22SChangbin Du 19771f198e22SChangbin Duwakeup_rt 19781f198e22SChangbin Du--------- 19791f198e22SChangbin Du 19801f198e22SChangbin DuIn a Real-Time environment it is very important to know the 19811f198e22SChangbin Duwakeup time it takes for the highest priority task that is woken 19821f198e22SChangbin Duup to the time that it executes. This is also known as "schedule 19831f198e22SChangbin Dulatency". I stress the point that this is about RT tasks. It is 19841f198e22SChangbin Dualso important to know the scheduling latency of non-RT tasks, 19851f198e22SChangbin Dubut the average schedule latency is better for non-RT tasks. 19861f198e22SChangbin DuTools like LatencyTop are more appropriate for such 19871f198e22SChangbin Dumeasurements. 19881f198e22SChangbin Du 19891f198e22SChangbin DuReal-Time environments are interested in the worst case latency. 19901f198e22SChangbin DuThat is the longest latency it takes for something to happen, 19911f198e22SChangbin Duand not the average. We can have a very fast scheduler that may 19921f198e22SChangbin Duonly have a large latency once in a while, but that would not 19931f198e22SChangbin Duwork well with Real-Time tasks. The wakeup_rt tracer was designed 19941f198e22SChangbin Duto record the worst case wakeups of RT tasks. Non-RT tasks are 19951f198e22SChangbin Dunot recorded because the tracer only records one worst case and 19961f198e22SChangbin Dutracing non-RT tasks that are unpredictable will overwrite the 19971f198e22SChangbin Duworst case latency of RT tasks (just run the normal wakeup 19981f198e22SChangbin Dutracer for a while to see that effect). 19991f198e22SChangbin Du 20001f198e22SChangbin DuSince this tracer only deals with RT tasks, we will run this 20011f198e22SChangbin Duslightly differently than we did with the previous tracers. 20021f198e22SChangbin DuInstead of performing an 'ls', we will run 'sleep 1' under 20031f198e22SChangbin Du'chrt' which changes the priority of the task. 20041f198e22SChangbin Du:: 20051f198e22SChangbin Du 20061f198e22SChangbin Du # echo 0 > options/function-trace 20071f198e22SChangbin Du # echo wakeup_rt > current_tracer 20081f198e22SChangbin Du # echo 1 > tracing_on 20091f198e22SChangbin Du # echo 0 > tracing_max_latency 20101f198e22SChangbin Du # chrt -f 5 sleep 1 20111f198e22SChangbin Du # echo 0 > tracing_on 20121f198e22SChangbin Du # cat trace 20131f198e22SChangbin Du # tracer: wakeup 20141f198e22SChangbin Du # 20151f198e22SChangbin Du # tracer: wakeup_rt 20161f198e22SChangbin Du # 20171f198e22SChangbin Du # wakeup_rt latency trace v1.1.5 on 3.8.0-test+ 20181f198e22SChangbin Du # -------------------------------------------------------------------- 20191f198e22SChangbin Du # latency: 5 us, #4/4, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 20201f198e22SChangbin Du # ----------------- 20211f198e22SChangbin Du # | task: sleep-2389 (uid:0 nice:0 policy:1 rt_prio:5) 20221f198e22SChangbin Du # ----------------- 20231f198e22SChangbin Du # 20241f198e22SChangbin Du # _------=> CPU# 20251f198e22SChangbin Du # / _-----=> irqs-off 20261f198e22SChangbin Du # | / _----=> need-resched 20271f198e22SChangbin Du # || / _---=> hardirq/softirq 20281f198e22SChangbin Du # ||| / _--=> preempt-depth 20291f198e22SChangbin Du # |||| / delay 20301f198e22SChangbin Du # cmd pid ||||| time | caller 20311f198e22SChangbin Du # \ / ||||| \ | / 20321f198e22SChangbin Du <idle>-0 3d.h4 0us : 0:120:R + [003] 2389: 94:R sleep 20331f198e22SChangbin Du <idle>-0 3d.h4 1us+: ttwu_do_activate.constprop.87 <-try_to_wake_up 20341f198e22SChangbin Du <idle>-0 3d..3 5us : __schedule <-schedule 20351f198e22SChangbin Du <idle>-0 3d..3 5us : 0:120:R ==> [003] 2389: 94:R sleep 20361f198e22SChangbin Du 20371f198e22SChangbin Du 20381f198e22SChangbin DuRunning this on an idle system, we see that it only took 5 microseconds 20391f198e22SChangbin Duto perform the task switch. Note, since the trace point in the schedule 20401f198e22SChangbin Duis before the actual "switch", we stop the tracing when the recorded task 20411f198e22SChangbin Duis about to schedule in. This may change if we add a new marker at the 20421f198e22SChangbin Duend of the scheduler. 20431f198e22SChangbin Du 20441f198e22SChangbin DuNotice that the recorded task is 'sleep' with the PID of 2389 20451f198e22SChangbin Duand it has an rt_prio of 5. This priority is user-space priority 20461f198e22SChangbin Duand not the internal kernel priority. The policy is 1 for 20471f198e22SChangbin DuSCHED_FIFO and 2 for SCHED_RR. 20481f198e22SChangbin Du 20491f198e22SChangbin DuNote, that the trace data shows the internal priority (99 - rtprio). 20501f198e22SChangbin Du:: 20511f198e22SChangbin Du 20521f198e22SChangbin Du <idle>-0 3d..3 5us : 0:120:R ==> [003] 2389: 94:R sleep 20531f198e22SChangbin Du 20541f198e22SChangbin DuThe 0:120:R means idle was running with a nice priority of 0 (120 - 120) 20551f198e22SChangbin Duand in the running state 'R'. The sleep task was scheduled in with 20561f198e22SChangbin Du2389: 94:R. That is the priority is the kernel rtprio (99 - 5 = 94) 20571f198e22SChangbin Duand it too is in the running state. 20581f198e22SChangbin Du 20591f198e22SChangbin DuDoing the same with chrt -r 5 and function-trace set. 20601f198e22SChangbin Du:: 20611f198e22SChangbin Du 20621f198e22SChangbin Du echo 1 > options/function-trace 20631f198e22SChangbin Du 20641f198e22SChangbin Du # tracer: wakeup_rt 20651f198e22SChangbin Du # 20661f198e22SChangbin Du # wakeup_rt latency trace v1.1.5 on 3.8.0-test+ 20671f198e22SChangbin Du # -------------------------------------------------------------------- 20681f198e22SChangbin Du # latency: 29 us, #85/85, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 20691f198e22SChangbin Du # ----------------- 20701f198e22SChangbin Du # | task: sleep-2448 (uid:0 nice:0 policy:1 rt_prio:5) 20711f198e22SChangbin Du # ----------------- 20721f198e22SChangbin Du # 20731f198e22SChangbin Du # _------=> CPU# 20741f198e22SChangbin Du # / _-----=> irqs-off 20751f198e22SChangbin Du # | / _----=> need-resched 20761f198e22SChangbin Du # || / _---=> hardirq/softirq 20771f198e22SChangbin Du # ||| / _--=> preempt-depth 20781f198e22SChangbin Du # |||| / delay 20791f198e22SChangbin Du # cmd pid ||||| time | caller 20801f198e22SChangbin Du # \ / ||||| \ | / 20811f198e22SChangbin Du <idle>-0 3d.h4 1us+: 0:120:R + [003] 2448: 94:R sleep 20821f198e22SChangbin Du <idle>-0 3d.h4 2us : ttwu_do_activate.constprop.87 <-try_to_wake_up 20831f198e22SChangbin Du <idle>-0 3d.h3 3us : check_preempt_curr <-ttwu_do_wakeup 20841f198e22SChangbin Du <idle>-0 3d.h3 3us : resched_curr <-check_preempt_curr 20851f198e22SChangbin Du <idle>-0 3dNh3 4us : task_woken_rt <-ttwu_do_wakeup 20861f198e22SChangbin Du <idle>-0 3dNh3 4us : _raw_spin_unlock <-try_to_wake_up 20871f198e22SChangbin Du <idle>-0 3dNh3 4us : sub_preempt_count <-_raw_spin_unlock 20881f198e22SChangbin Du <idle>-0 3dNh2 5us : ttwu_stat <-try_to_wake_up 20891f198e22SChangbin Du <idle>-0 3dNh2 5us : _raw_spin_unlock_irqrestore <-try_to_wake_up 20901f198e22SChangbin Du <idle>-0 3dNh2 6us : sub_preempt_count <-_raw_spin_unlock_irqrestore 20911f198e22SChangbin Du <idle>-0 3dNh1 6us : _raw_spin_lock <-__run_hrtimer 20921f198e22SChangbin Du <idle>-0 3dNh1 6us : add_preempt_count <-_raw_spin_lock 20931f198e22SChangbin Du <idle>-0 3dNh2 7us : _raw_spin_unlock <-hrtimer_interrupt 20941f198e22SChangbin Du <idle>-0 3dNh2 7us : sub_preempt_count <-_raw_spin_unlock 20951f198e22SChangbin Du <idle>-0 3dNh1 7us : tick_program_event <-hrtimer_interrupt 20961f198e22SChangbin Du <idle>-0 3dNh1 7us : clockevents_program_event <-tick_program_event 20971f198e22SChangbin Du <idle>-0 3dNh1 8us : ktime_get <-clockevents_program_event 20981f198e22SChangbin Du <idle>-0 3dNh1 8us : lapic_next_event <-clockevents_program_event 20991f198e22SChangbin Du <idle>-0 3dNh1 8us : irq_exit <-smp_apic_timer_interrupt 21001f198e22SChangbin Du <idle>-0 3dNh1 9us : sub_preempt_count <-irq_exit 21011f198e22SChangbin Du <idle>-0 3dN.2 9us : idle_cpu <-irq_exit 21021f198e22SChangbin Du <idle>-0 3dN.2 9us : rcu_irq_exit <-irq_exit 21031f198e22SChangbin Du <idle>-0 3dN.2 10us : rcu_eqs_enter_common.isra.45 <-rcu_irq_exit 21041f198e22SChangbin Du <idle>-0 3dN.2 10us : sub_preempt_count <-irq_exit 21051f198e22SChangbin Du <idle>-0 3.N.1 11us : rcu_idle_exit <-cpu_idle 21061f198e22SChangbin Du <idle>-0 3dN.1 11us : rcu_eqs_exit_common.isra.43 <-rcu_idle_exit 21071f198e22SChangbin Du <idle>-0 3.N.1 11us : tick_nohz_idle_exit <-cpu_idle 21081f198e22SChangbin Du <idle>-0 3dN.1 12us : menu_hrtimer_cancel <-tick_nohz_idle_exit 21091f198e22SChangbin Du <idle>-0 3dN.1 12us : ktime_get <-tick_nohz_idle_exit 21101f198e22SChangbin Du <idle>-0 3dN.1 12us : tick_do_update_jiffies64 <-tick_nohz_idle_exit 21111f198e22SChangbin Du <idle>-0 3dN.1 13us : cpu_load_update_nohz <-tick_nohz_idle_exit 21121f198e22SChangbin Du <idle>-0 3dN.1 13us : _raw_spin_lock <-cpu_load_update_nohz 21131f198e22SChangbin Du <idle>-0 3dN.1 13us : add_preempt_count <-_raw_spin_lock 21141f198e22SChangbin Du <idle>-0 3dN.2 13us : __cpu_load_update <-cpu_load_update_nohz 21151f198e22SChangbin Du <idle>-0 3dN.2 14us : sched_avg_update <-__cpu_load_update 21161f198e22SChangbin Du <idle>-0 3dN.2 14us : _raw_spin_unlock <-cpu_load_update_nohz 21171f198e22SChangbin Du <idle>-0 3dN.2 14us : sub_preempt_count <-_raw_spin_unlock 21181f198e22SChangbin Du <idle>-0 3dN.1 15us : calc_load_nohz_stop <-tick_nohz_idle_exit 21191f198e22SChangbin Du <idle>-0 3dN.1 15us : touch_softlockup_watchdog <-tick_nohz_idle_exit 21201f198e22SChangbin Du <idle>-0 3dN.1 15us : hrtimer_cancel <-tick_nohz_idle_exit 21211f198e22SChangbin Du <idle>-0 3dN.1 15us : hrtimer_try_to_cancel <-hrtimer_cancel 21221f198e22SChangbin Du <idle>-0 3dN.1 16us : lock_hrtimer_base.isra.18 <-hrtimer_try_to_cancel 21231f198e22SChangbin Du <idle>-0 3dN.1 16us : _raw_spin_lock_irqsave <-lock_hrtimer_base.isra.18 21241f198e22SChangbin Du <idle>-0 3dN.1 16us : add_preempt_count <-_raw_spin_lock_irqsave 21251f198e22SChangbin Du <idle>-0 3dN.2 17us : __remove_hrtimer <-remove_hrtimer.part.16 21261f198e22SChangbin Du <idle>-0 3dN.2 17us : hrtimer_force_reprogram <-__remove_hrtimer 21271f198e22SChangbin Du <idle>-0 3dN.2 17us : tick_program_event <-hrtimer_force_reprogram 21281f198e22SChangbin Du <idle>-0 3dN.2 18us : clockevents_program_event <-tick_program_event 21291f198e22SChangbin Du <idle>-0 3dN.2 18us : ktime_get <-clockevents_program_event 21301f198e22SChangbin Du <idle>-0 3dN.2 18us : lapic_next_event <-clockevents_program_event 21311f198e22SChangbin Du <idle>-0 3dN.2 19us : _raw_spin_unlock_irqrestore <-hrtimer_try_to_cancel 21321f198e22SChangbin Du <idle>-0 3dN.2 19us : sub_preempt_count <-_raw_spin_unlock_irqrestore 21331f198e22SChangbin Du <idle>-0 3dN.1 19us : hrtimer_forward <-tick_nohz_idle_exit 21341f198e22SChangbin Du <idle>-0 3dN.1 20us : ktime_add_safe <-hrtimer_forward 21351f198e22SChangbin Du <idle>-0 3dN.1 20us : ktime_add_safe <-hrtimer_forward 21361f198e22SChangbin Du <idle>-0 3dN.1 20us : hrtimer_start_range_ns <-hrtimer_start_expires.constprop.11 21371f198e22SChangbin Du <idle>-0 3dN.1 20us : __hrtimer_start_range_ns <-hrtimer_start_range_ns 21381f198e22SChangbin Du <idle>-0 3dN.1 21us : lock_hrtimer_base.isra.18 <-__hrtimer_start_range_ns 21391f198e22SChangbin Du <idle>-0 3dN.1 21us : _raw_spin_lock_irqsave <-lock_hrtimer_base.isra.18 21401f198e22SChangbin Du <idle>-0 3dN.1 21us : add_preempt_count <-_raw_spin_lock_irqsave 21411f198e22SChangbin Du <idle>-0 3dN.2 22us : ktime_add_safe <-__hrtimer_start_range_ns 21421f198e22SChangbin Du <idle>-0 3dN.2 22us : enqueue_hrtimer <-__hrtimer_start_range_ns 21431f198e22SChangbin Du <idle>-0 3dN.2 22us : tick_program_event <-__hrtimer_start_range_ns 21441f198e22SChangbin Du <idle>-0 3dN.2 23us : clockevents_program_event <-tick_program_event 21451f198e22SChangbin Du <idle>-0 3dN.2 23us : ktime_get <-clockevents_program_event 21461f198e22SChangbin Du <idle>-0 3dN.2 23us : lapic_next_event <-clockevents_program_event 21471f198e22SChangbin Du <idle>-0 3dN.2 24us : _raw_spin_unlock_irqrestore <-__hrtimer_start_range_ns 21481f198e22SChangbin Du <idle>-0 3dN.2 24us : sub_preempt_count <-_raw_spin_unlock_irqrestore 21491f198e22SChangbin Du <idle>-0 3dN.1 24us : account_idle_ticks <-tick_nohz_idle_exit 21501f198e22SChangbin Du <idle>-0 3dN.1 24us : account_idle_time <-account_idle_ticks 21511f198e22SChangbin Du <idle>-0 3.N.1 25us : sub_preempt_count <-cpu_idle 21521f198e22SChangbin Du <idle>-0 3.N.. 25us : schedule <-cpu_idle 21531f198e22SChangbin Du <idle>-0 3.N.. 25us : __schedule <-preempt_schedule 21541f198e22SChangbin Du <idle>-0 3.N.. 26us : add_preempt_count <-__schedule 21551f198e22SChangbin Du <idle>-0 3.N.1 26us : rcu_note_context_switch <-__schedule 21561f198e22SChangbin Du <idle>-0 3.N.1 26us : rcu_sched_qs <-rcu_note_context_switch 21571f198e22SChangbin Du <idle>-0 3dN.1 27us : rcu_preempt_qs <-rcu_note_context_switch 21581f198e22SChangbin Du <idle>-0 3.N.1 27us : _raw_spin_lock_irq <-__schedule 21591f198e22SChangbin Du <idle>-0 3dN.1 27us : add_preempt_count <-_raw_spin_lock_irq 21601f198e22SChangbin Du <idle>-0 3dN.2 28us : put_prev_task_idle <-__schedule 21611f198e22SChangbin Du <idle>-0 3dN.2 28us : pick_next_task_stop <-pick_next_task 21621f198e22SChangbin Du <idle>-0 3dN.2 28us : pick_next_task_rt <-pick_next_task 21631f198e22SChangbin Du <idle>-0 3dN.2 29us : dequeue_pushable_task <-pick_next_task_rt 21641f198e22SChangbin Du <idle>-0 3d..3 29us : __schedule <-preempt_schedule 21651f198e22SChangbin Du <idle>-0 3d..3 30us : 0:120:R ==> [003] 2448: 94:R sleep 21661f198e22SChangbin Du 21671f198e22SChangbin DuThis isn't that big of a trace, even with function tracing enabled, 21681f198e22SChangbin Duso I included the entire trace. 21691f198e22SChangbin Du 21701f198e22SChangbin DuThe interrupt went off while when the system was idle. Somewhere 21711f198e22SChangbin Dubefore task_woken_rt() was called, the NEED_RESCHED flag was set, 21721f198e22SChangbin Duthis is indicated by the first occurrence of the 'N' flag. 21731f198e22SChangbin Du 21741f198e22SChangbin DuLatency tracing and events 21751f198e22SChangbin Du-------------------------- 21761f198e22SChangbin DuAs function tracing can induce a much larger latency, but without 21771f198e22SChangbin Duseeing what happens within the latency it is hard to know what 21781f198e22SChangbin Ducaused it. There is a middle ground, and that is with enabling 21791f198e22SChangbin Duevents. 21801f198e22SChangbin Du:: 21811f198e22SChangbin Du 21821f198e22SChangbin Du # echo 0 > options/function-trace 21831f198e22SChangbin Du # echo wakeup_rt > current_tracer 21841f198e22SChangbin Du # echo 1 > events/enable 21851f198e22SChangbin Du # echo 1 > tracing_on 21861f198e22SChangbin Du # echo 0 > tracing_max_latency 21871f198e22SChangbin Du # chrt -f 5 sleep 1 21881f198e22SChangbin Du # echo 0 > tracing_on 21891f198e22SChangbin Du # cat trace 21901f198e22SChangbin Du # tracer: wakeup_rt 21911f198e22SChangbin Du # 21921f198e22SChangbin Du # wakeup_rt latency trace v1.1.5 on 3.8.0-test+ 21931f198e22SChangbin Du # -------------------------------------------------------------------- 21941f198e22SChangbin Du # latency: 6 us, #12/12, CPU#2 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) 21951f198e22SChangbin Du # ----------------- 21961f198e22SChangbin Du # | task: sleep-5882 (uid:0 nice:0 policy:1 rt_prio:5) 21971f198e22SChangbin Du # ----------------- 21981f198e22SChangbin Du # 21991f198e22SChangbin Du # _------=> CPU# 22001f198e22SChangbin Du # / _-----=> irqs-off 22011f198e22SChangbin Du # | / _----=> need-resched 22021f198e22SChangbin Du # || / _---=> hardirq/softirq 22031f198e22SChangbin Du # ||| / _--=> preempt-depth 22041f198e22SChangbin Du # |||| / delay 22051f198e22SChangbin Du # cmd pid ||||| time | caller 22061f198e22SChangbin Du # \ / ||||| \ | / 22071f198e22SChangbin Du <idle>-0 2d.h4 0us : 0:120:R + [002] 5882: 94:R sleep 22081f198e22SChangbin Du <idle>-0 2d.h4 0us : ttwu_do_activate.constprop.87 <-try_to_wake_up 22091f198e22SChangbin Du <idle>-0 2d.h4 1us : sched_wakeup: comm=sleep pid=5882 prio=94 success=1 target_cpu=002 22101f198e22SChangbin Du <idle>-0 2dNh2 1us : hrtimer_expire_exit: hrtimer=ffff88007796feb8 22111f198e22SChangbin Du <idle>-0 2.N.2 2us : power_end: cpu_id=2 22121f198e22SChangbin Du <idle>-0 2.N.2 3us : cpu_idle: state=4294967295 cpu_id=2 22131f198e22SChangbin Du <idle>-0 2dN.3 4us : hrtimer_cancel: hrtimer=ffff88007d50d5e0 22141f198e22SChangbin Du <idle>-0 2dN.3 4us : hrtimer_start: hrtimer=ffff88007d50d5e0 function=tick_sched_timer expires=34311211000000 softexpires=34311211000000 22151f198e22SChangbin Du <idle>-0 2.N.2 5us : rcu_utilization: Start context switch 22161f198e22SChangbin Du <idle>-0 2.N.2 5us : rcu_utilization: End context switch 22171f198e22SChangbin Du <idle>-0 2d..3 6us : __schedule <-schedule 22181f198e22SChangbin Du <idle>-0 2d..3 6us : 0:120:R ==> [002] 5882: 94:R sleep 22191f198e22SChangbin Du 22201f198e22SChangbin Du 22211f198e22SChangbin DuHardware Latency Detector 22221f198e22SChangbin Du------------------------- 22231f198e22SChangbin Du 22241f198e22SChangbin DuThe hardware latency detector is executed by enabling the "hwlat" tracer. 22251f198e22SChangbin Du 22261f198e22SChangbin DuNOTE, this tracer will affect the performance of the system as it will 22271f198e22SChangbin Duperiodically make a CPU constantly busy with interrupts disabled. 22281f198e22SChangbin Du:: 22291f198e22SChangbin Du 22301f198e22SChangbin Du # echo hwlat > current_tracer 22311f198e22SChangbin Du # sleep 100 22321f198e22SChangbin Du # cat trace 22331f198e22SChangbin Du # tracer: hwlat 22341f198e22SChangbin Du # 2235b396bfdeSSteven Rostedt (VMware) # entries-in-buffer/entries-written: 13/13 #P:8 2236b396bfdeSSteven Rostedt (VMware) # 22371f198e22SChangbin Du # _-----=> irqs-off 22381f198e22SChangbin Du # / _----=> need-resched 22391f198e22SChangbin Du # | / _---=> hardirq/softirq 22401f198e22SChangbin Du # || / _--=> preempt-depth 22411f198e22SChangbin Du # ||| / delay 22421f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 22431f198e22SChangbin Du # | | | |||| | | 2244b396bfdeSSteven Rostedt (VMware) <...>-1729 [001] d... 678.473449: #1 inner/outer(us): 11/12 ts:1581527483.343962693 count:6 2245b396bfdeSSteven Rostedt (VMware) <...>-1729 [004] d... 689.556542: #2 inner/outer(us): 16/9 ts:1581527494.889008092 count:1 2246b396bfdeSSteven Rostedt (VMware) <...>-1729 [005] d... 714.756290: #3 inner/outer(us): 16/16 ts:1581527519.678961629 count:5 2247b396bfdeSSteven Rostedt (VMware) <...>-1729 [001] d... 718.788247: #4 inner/outer(us): 9/17 ts:1581527523.889012713 count:1 2248b396bfdeSSteven Rostedt (VMware) <...>-1729 [002] d... 719.796341: #5 inner/outer(us): 13/9 ts:1581527524.912872606 count:1 2249b396bfdeSSteven Rostedt (VMware) <...>-1729 [006] d... 844.787091: #6 inner/outer(us): 9/12 ts:1581527649.889048502 count:2 2250b396bfdeSSteven Rostedt (VMware) <...>-1729 [003] d... 849.827033: #7 inner/outer(us): 18/9 ts:1581527654.889013793 count:1 2251b396bfdeSSteven Rostedt (VMware) <...>-1729 [007] d... 853.859002: #8 inner/outer(us): 9/12 ts:1581527658.889065736 count:1 2252b396bfdeSSteven Rostedt (VMware) <...>-1729 [001] d... 855.874978: #9 inner/outer(us): 9/11 ts:1581527660.861991877 count:1 2253b396bfdeSSteven Rostedt (VMware) <...>-1729 [001] d... 863.938932: #10 inner/outer(us): 9/11 ts:1581527668.970010500 count:1 nmi-total:7 nmi-count:1 2254b396bfdeSSteven Rostedt (VMware) <...>-1729 [007] d... 878.050780: #11 inner/outer(us): 9/12 ts:1581527683.385002600 count:1 nmi-total:5 nmi-count:1 2255b396bfdeSSteven Rostedt (VMware) <...>-1729 [007] d... 886.114702: #12 inner/outer(us): 9/12 ts:1581527691.385001600 count:1 22561f198e22SChangbin Du 22571f198e22SChangbin Du 22581f198e22SChangbin DuThe above output is somewhat the same in the header. All events will have 22591f198e22SChangbin Duinterrupts disabled 'd'. Under the FUNCTION title there is: 22601f198e22SChangbin Du 22611f198e22SChangbin Du #1 22621f198e22SChangbin Du This is the count of events recorded that were greater than the 22631f198e22SChangbin Du tracing_threshold (See below). 22641f198e22SChangbin Du 2265b396bfdeSSteven Rostedt (VMware) inner/outer(us): 11/11 22661f198e22SChangbin Du 22671f198e22SChangbin Du This shows two numbers as "inner latency" and "outer latency". The test 22681f198e22SChangbin Du runs in a loop checking a timestamp twice. The latency detected within 22691f198e22SChangbin Du the two timestamps is the "inner latency" and the latency detected 22701f198e22SChangbin Du after the previous timestamp and the next timestamp in the loop is 22711f198e22SChangbin Du the "outer latency". 22721f198e22SChangbin Du 2273b396bfdeSSteven Rostedt (VMware) ts:1581527483.343962693 22741f198e22SChangbin Du 2275b396bfdeSSteven Rostedt (VMware) The absolute timestamp that the first latency was recorded in the window. 22761f198e22SChangbin Du 2277b396bfdeSSteven Rostedt (VMware) count:6 2278b396bfdeSSteven Rostedt (VMware) 2279b396bfdeSSteven Rostedt (VMware) The number of times a latency was detected during the window. 2280b396bfdeSSteven Rostedt (VMware) 2281b396bfdeSSteven Rostedt (VMware) nmi-total:7 nmi-count:1 22821f198e22SChangbin Du 22831f198e22SChangbin Du On architectures that support it, if an NMI comes in during the 22841f198e22SChangbin Du test, the time spent in NMI is reported in "nmi-total" (in 22851f198e22SChangbin Du microseconds). 22861f198e22SChangbin Du 22871f198e22SChangbin Du All architectures that have NMIs will show the "nmi-count" if an 22881f198e22SChangbin Du NMI comes in during the test. 22891f198e22SChangbin Du 22901f198e22SChangbin Duhwlat files: 22911f198e22SChangbin Du 22921f198e22SChangbin Du tracing_threshold 22931f198e22SChangbin Du This gets automatically set to "10" to represent 10 22941f198e22SChangbin Du microseconds. This is the threshold of latency that 22951f198e22SChangbin Du needs to be detected before the trace will be recorded. 22961f198e22SChangbin Du 22971f198e22SChangbin Du Note, when hwlat tracer is finished (another tracer is 22981f198e22SChangbin Du written into "current_tracer"), the original value for 22991f198e22SChangbin Du tracing_threshold is placed back into this file. 23001f198e22SChangbin Du 23011f198e22SChangbin Du hwlat_detector/width 23021f198e22SChangbin Du The length of time the test runs with interrupts disabled. 23031f198e22SChangbin Du 23041f198e22SChangbin Du hwlat_detector/window 23051f198e22SChangbin Du The length of time of the window which the test 23061f198e22SChangbin Du runs. That is, the test will run for "width" 23071f198e22SChangbin Du microseconds per "window" microseconds 23081f198e22SChangbin Du 23091f198e22SChangbin Du tracing_cpumask 23101f198e22SChangbin Du When the test is started. A kernel thread is created that 23111f198e22SChangbin Du runs the test. This thread will alternate between CPUs 23121f198e22SChangbin Du listed in the tracing_cpumask between each period 23131f198e22SChangbin Du (one "window"). To limit the test to specific CPUs 23141f198e22SChangbin Du set the mask in this file to only the CPUs that the test 23151f198e22SChangbin Du should run on. 23161f198e22SChangbin Du 23171f198e22SChangbin Dufunction 23181f198e22SChangbin Du-------- 23191f198e22SChangbin Du 23201f198e22SChangbin DuThis tracer is the function tracer. Enabling the function tracer 23211f198e22SChangbin Ducan be done from the debug file system. Make sure the 23221f198e22SChangbin Duftrace_enabled is set; otherwise this tracer is a nop. 23231f198e22SChangbin DuSee the "ftrace_enabled" section below. 23241f198e22SChangbin Du:: 23251f198e22SChangbin Du 23261f198e22SChangbin Du # sysctl kernel.ftrace_enabled=1 23271f198e22SChangbin Du # echo function > current_tracer 23281f198e22SChangbin Du # echo 1 > tracing_on 23291f198e22SChangbin Du # usleep 1 23301f198e22SChangbin Du # echo 0 > tracing_on 23311f198e22SChangbin Du # cat trace 23321f198e22SChangbin Du # tracer: function 23331f198e22SChangbin Du # 23341f198e22SChangbin Du # entries-in-buffer/entries-written: 24799/24799 #P:4 23351f198e22SChangbin Du # 23361f198e22SChangbin Du # _-----=> irqs-off 23371f198e22SChangbin Du # / _----=> need-resched 23381f198e22SChangbin Du # | / _---=> hardirq/softirq 23391f198e22SChangbin Du # || / _--=> preempt-depth 23401f198e22SChangbin Du # ||| / delay 23411f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 23421f198e22SChangbin Du # | | | |||| | | 23431f198e22SChangbin Du bash-1994 [002] .... 3082.063030: mutex_unlock <-rb_simple_write 23441f198e22SChangbin Du bash-1994 [002] .... 3082.063031: __mutex_unlock_slowpath <-mutex_unlock 23451f198e22SChangbin Du bash-1994 [002] .... 3082.063031: __fsnotify_parent <-fsnotify_modify 23461f198e22SChangbin Du bash-1994 [002] .... 3082.063032: fsnotify <-fsnotify_modify 23471f198e22SChangbin Du bash-1994 [002] .... 3082.063032: __srcu_read_lock <-fsnotify 23481f198e22SChangbin Du bash-1994 [002] .... 3082.063032: add_preempt_count <-__srcu_read_lock 23491f198e22SChangbin Du bash-1994 [002] ...1 3082.063032: sub_preempt_count <-__srcu_read_lock 23501f198e22SChangbin Du bash-1994 [002] .... 3082.063033: __srcu_read_unlock <-fsnotify 23511f198e22SChangbin Du [...] 23521f198e22SChangbin Du 23531f198e22SChangbin Du 23541f198e22SChangbin DuNote: function tracer uses ring buffers to store the above 23551f198e22SChangbin Duentries. The newest data may overwrite the oldest data. 23561f198e22SChangbin DuSometimes using echo to stop the trace is not sufficient because 23571f198e22SChangbin Duthe tracing could have overwritten the data that you wanted to 23581f198e22SChangbin Durecord. For this reason, it is sometimes better to disable 23591f198e22SChangbin Dutracing directly from a program. This allows you to stop the 23601f198e22SChangbin Dutracing at the point that you hit the part that you are 23611f198e22SChangbin Duinterested in. To disable the tracing directly from a C program, 23621f198e22SChangbin Dusomething like following code snippet can be used:: 23631f198e22SChangbin Du 23641f198e22SChangbin Du int trace_fd; 23651f198e22SChangbin Du [...] 23661f198e22SChangbin Du int main(int argc, char *argv[]) { 23671f198e22SChangbin Du [...] 23681f198e22SChangbin Du trace_fd = open(tracing_file("tracing_on"), O_WRONLY); 23691f198e22SChangbin Du [...] 23701f198e22SChangbin Du if (condition_hit()) { 23711f198e22SChangbin Du write(trace_fd, "0", 1); 23721f198e22SChangbin Du } 23731f198e22SChangbin Du [...] 23741f198e22SChangbin Du } 23751f198e22SChangbin Du 23761f198e22SChangbin Du 23771f198e22SChangbin DuSingle thread tracing 23781f198e22SChangbin Du--------------------- 23791f198e22SChangbin Du 23801f198e22SChangbin DuBy writing into set_ftrace_pid you can trace a 23811f198e22SChangbin Dusingle thread. For example:: 23821f198e22SChangbin Du 23831f198e22SChangbin Du # cat set_ftrace_pid 23841f198e22SChangbin Du no pid 23851f198e22SChangbin Du # echo 3111 > set_ftrace_pid 23861f198e22SChangbin Du # cat set_ftrace_pid 23871f198e22SChangbin Du 3111 23881f198e22SChangbin Du # echo function > current_tracer 23891f198e22SChangbin Du # cat trace | head 23901f198e22SChangbin Du # tracer: function 23911f198e22SChangbin Du # 23921f198e22SChangbin Du # TASK-PID CPU# TIMESTAMP FUNCTION 23931f198e22SChangbin Du # | | | | | 23941f198e22SChangbin Du yum-updatesd-3111 [003] 1637.254676: finish_task_switch <-thread_return 23951f198e22SChangbin Du yum-updatesd-3111 [003] 1637.254681: hrtimer_cancel <-schedule_hrtimeout_range 23961f198e22SChangbin Du yum-updatesd-3111 [003] 1637.254682: hrtimer_try_to_cancel <-hrtimer_cancel 23971f198e22SChangbin Du yum-updatesd-3111 [003] 1637.254683: lock_hrtimer_base <-hrtimer_try_to_cancel 23981f198e22SChangbin Du yum-updatesd-3111 [003] 1637.254685: fget_light <-do_sys_poll 23991f198e22SChangbin Du yum-updatesd-3111 [003] 1637.254686: pipe_poll <-do_sys_poll 24001f198e22SChangbin Du # echo > set_ftrace_pid 24011f198e22SChangbin Du # cat trace |head 24021f198e22SChangbin Du # tracer: function 24031f198e22SChangbin Du # 24041f198e22SChangbin Du # TASK-PID CPU# TIMESTAMP FUNCTION 24051f198e22SChangbin Du # | | | | | 24061f198e22SChangbin Du ##### CPU 3 buffer started #### 24071f198e22SChangbin Du yum-updatesd-3111 [003] 1701.957688: free_poll_entry <-poll_freewait 24081f198e22SChangbin Du yum-updatesd-3111 [003] 1701.957689: remove_wait_queue <-free_poll_entry 24091f198e22SChangbin Du yum-updatesd-3111 [003] 1701.957691: fput <-free_poll_entry 24101f198e22SChangbin Du yum-updatesd-3111 [003] 1701.957692: audit_syscall_exit <-sysret_audit 24111f198e22SChangbin Du yum-updatesd-3111 [003] 1701.957693: path_put <-audit_syscall_exit 24121f198e22SChangbin Du 24131f198e22SChangbin DuIf you want to trace a function when executing, you could use 24141f198e22SChangbin Dusomething like this simple program. 24151f198e22SChangbin Du:: 24161f198e22SChangbin Du 24171f198e22SChangbin Du #include <stdio.h> 24181f198e22SChangbin Du #include <stdlib.h> 24191f198e22SChangbin Du #include <sys/types.h> 24201f198e22SChangbin Du #include <sys/stat.h> 24211f198e22SChangbin Du #include <fcntl.h> 24221f198e22SChangbin Du #include <unistd.h> 24231f198e22SChangbin Du #include <string.h> 24241f198e22SChangbin Du 24251f198e22SChangbin Du #define _STR(x) #x 24261f198e22SChangbin Du #define STR(x) _STR(x) 24271f198e22SChangbin Du #define MAX_PATH 256 24281f198e22SChangbin Du 24291f198e22SChangbin Du const char *find_tracefs(void) 24301f198e22SChangbin Du { 24311f198e22SChangbin Du static char tracefs[MAX_PATH+1]; 24321f198e22SChangbin Du static int tracefs_found; 24331f198e22SChangbin Du char type[100]; 24341f198e22SChangbin Du FILE *fp; 24351f198e22SChangbin Du 24361f198e22SChangbin Du if (tracefs_found) 24371f198e22SChangbin Du return tracefs; 24381f198e22SChangbin Du 24391f198e22SChangbin Du if ((fp = fopen("/proc/mounts","r")) == NULL) { 24401f198e22SChangbin Du perror("/proc/mounts"); 24411f198e22SChangbin Du return NULL; 24421f198e22SChangbin Du } 24431f198e22SChangbin Du 24441f198e22SChangbin Du while (fscanf(fp, "%*s %" 24451f198e22SChangbin Du STR(MAX_PATH) 24461f198e22SChangbin Du "s %99s %*s %*d %*d\n", 24471f198e22SChangbin Du tracefs, type) == 2) { 24481f198e22SChangbin Du if (strcmp(type, "tracefs") == 0) 24491f198e22SChangbin Du break; 24501f198e22SChangbin Du } 24511f198e22SChangbin Du fclose(fp); 24521f198e22SChangbin Du 24531f198e22SChangbin Du if (strcmp(type, "tracefs") != 0) { 24541f198e22SChangbin Du fprintf(stderr, "tracefs not mounted"); 24551f198e22SChangbin Du return NULL; 24561f198e22SChangbin Du } 24571f198e22SChangbin Du 24581f198e22SChangbin Du strcat(tracefs, "/tracing/"); 24591f198e22SChangbin Du tracefs_found = 1; 24601f198e22SChangbin Du 24611f198e22SChangbin Du return tracefs; 24621f198e22SChangbin Du } 24631f198e22SChangbin Du 24641f198e22SChangbin Du const char *tracing_file(const char *file_name) 24651f198e22SChangbin Du { 24661f198e22SChangbin Du static char trace_file[MAX_PATH+1]; 24671f198e22SChangbin Du snprintf(trace_file, MAX_PATH, "%s/%s", find_tracefs(), file_name); 24681f198e22SChangbin Du return trace_file; 24691f198e22SChangbin Du } 24701f198e22SChangbin Du 24711f198e22SChangbin Du int main (int argc, char **argv) 24721f198e22SChangbin Du { 24731f198e22SChangbin Du if (argc < 1) 24741f198e22SChangbin Du exit(-1); 24751f198e22SChangbin Du 24761f198e22SChangbin Du if (fork() > 0) { 24771f198e22SChangbin Du int fd, ffd; 24781f198e22SChangbin Du char line[64]; 24791f198e22SChangbin Du int s; 24801f198e22SChangbin Du 24811f198e22SChangbin Du ffd = open(tracing_file("current_tracer"), O_WRONLY); 24821f198e22SChangbin Du if (ffd < 0) 24831f198e22SChangbin Du exit(-1); 24841f198e22SChangbin Du write(ffd, "nop", 3); 24851f198e22SChangbin Du 24861f198e22SChangbin Du fd = open(tracing_file("set_ftrace_pid"), O_WRONLY); 24871f198e22SChangbin Du s = sprintf(line, "%d\n", getpid()); 24881f198e22SChangbin Du write(fd, line, s); 24891f198e22SChangbin Du 24901f198e22SChangbin Du write(ffd, "function", 8); 24911f198e22SChangbin Du 24921f198e22SChangbin Du close(fd); 24931f198e22SChangbin Du close(ffd); 24941f198e22SChangbin Du 24951f198e22SChangbin Du execvp(argv[1], argv+1); 24961f198e22SChangbin Du } 24971f198e22SChangbin Du 24981f198e22SChangbin Du return 0; 24991f198e22SChangbin Du } 25001f198e22SChangbin Du 25011f198e22SChangbin DuOr this simple script! 25021f198e22SChangbin Du:: 25031f198e22SChangbin Du 25041f198e22SChangbin Du #!/bin/bash 25051f198e22SChangbin Du 25061f198e22SChangbin Du tracefs=`sed -ne 's/^tracefs \(.*\) tracefs.*/\1/p' /proc/mounts` 2507951e0d00SZhaoyu Liu echo 0 > $tracefs/tracing_on 2508951e0d00SZhaoyu Liu echo $$ > $tracefs/set_ftrace_pid 2509951e0d00SZhaoyu Liu echo function > $tracefs/current_tracer 2510951e0d00SZhaoyu Liu echo 1 > $tracefs/tracing_on 25111f198e22SChangbin Du exec "$@" 25121f198e22SChangbin Du 25131f198e22SChangbin Du 25141f198e22SChangbin Dufunction graph tracer 25151f198e22SChangbin Du--------------------------- 25161f198e22SChangbin Du 25171f198e22SChangbin DuThis tracer is similar to the function tracer except that it 25181f198e22SChangbin Duprobes a function on its entry and its exit. This is done by 25191f198e22SChangbin Duusing a dynamically allocated stack of return addresses in each 25201f198e22SChangbin Dutask_struct. On function entry the tracer overwrites the return 25211f198e22SChangbin Duaddress of each function traced to set a custom probe. Thus the 25221f198e22SChangbin Duoriginal return address is stored on the stack of return address 25231f198e22SChangbin Duin the task_struct. 25241f198e22SChangbin Du 25251f198e22SChangbin DuProbing on both ends of a function leads to special features 25261f198e22SChangbin Dusuch as: 25271f198e22SChangbin Du 25281f198e22SChangbin Du- measure of a function's time execution 25291f198e22SChangbin Du- having a reliable call stack to draw function calls graph 25301f198e22SChangbin Du 25311f198e22SChangbin DuThis tracer is useful in several situations: 25321f198e22SChangbin Du 25331f198e22SChangbin Du- you want to find the reason of a strange kernel behavior and 25341f198e22SChangbin Du need to see what happens in detail on any areas (or specific 25351f198e22SChangbin Du ones). 25361f198e22SChangbin Du 25371f198e22SChangbin Du- you are experiencing weird latencies but it's difficult to 25381f198e22SChangbin Du find its origin. 25391f198e22SChangbin Du 25401f198e22SChangbin Du- you want to find quickly which path is taken by a specific 25411f198e22SChangbin Du function 25421f198e22SChangbin Du 25431f198e22SChangbin Du- you just want to peek inside a working kernel and want to see 25441f198e22SChangbin Du what happens there. 25451f198e22SChangbin Du 25461f198e22SChangbin Du:: 25471f198e22SChangbin Du 25481f198e22SChangbin Du # tracer: function_graph 25491f198e22SChangbin Du # 25501f198e22SChangbin Du # CPU DURATION FUNCTION CALLS 25511f198e22SChangbin Du # | | | | | | | 25521f198e22SChangbin Du 25531f198e22SChangbin Du 0) | sys_open() { 25541f198e22SChangbin Du 0) | do_sys_open() { 25551f198e22SChangbin Du 0) | getname() { 25561f198e22SChangbin Du 0) | kmem_cache_alloc() { 25571f198e22SChangbin Du 0) 1.382 us | __might_sleep(); 25581f198e22SChangbin Du 0) 2.478 us | } 25591f198e22SChangbin Du 0) | strncpy_from_user() { 25601f198e22SChangbin Du 0) | might_fault() { 25611f198e22SChangbin Du 0) 1.389 us | __might_sleep(); 25621f198e22SChangbin Du 0) 2.553 us | } 25631f198e22SChangbin Du 0) 3.807 us | } 25641f198e22SChangbin Du 0) 7.876 us | } 25651f198e22SChangbin Du 0) | alloc_fd() { 25661f198e22SChangbin Du 0) 0.668 us | _spin_lock(); 25671f198e22SChangbin Du 0) 0.570 us | expand_files(); 25681f198e22SChangbin Du 0) 0.586 us | _spin_unlock(); 25691f198e22SChangbin Du 25701f198e22SChangbin Du 25711f198e22SChangbin DuThere are several columns that can be dynamically 25721f198e22SChangbin Duenabled/disabled. You can use every combination of options you 25731f198e22SChangbin Duwant, depending on your needs. 25741f198e22SChangbin Du 25751f198e22SChangbin Du- The cpu number on which the function executed is default 25761f198e22SChangbin Du enabled. It is sometimes better to only trace one cpu (see 25771f198e22SChangbin Du tracing_cpu_mask file) or you might sometimes see unordered 25781f198e22SChangbin Du function calls while cpu tracing switch. 25791f198e22SChangbin Du 25801f198e22SChangbin Du - hide: echo nofuncgraph-cpu > trace_options 25811f198e22SChangbin Du - show: echo funcgraph-cpu > trace_options 25821f198e22SChangbin Du 25831f198e22SChangbin Du- The duration (function's time of execution) is displayed on 25841f198e22SChangbin Du the closing bracket line of a function or on the same line 25851f198e22SChangbin Du than the current function in case of a leaf one. It is default 25861f198e22SChangbin Du enabled. 25871f198e22SChangbin Du 25881f198e22SChangbin Du - hide: echo nofuncgraph-duration > trace_options 25891f198e22SChangbin Du - show: echo funcgraph-duration > trace_options 25901f198e22SChangbin Du 25911f198e22SChangbin Du- The overhead field precedes the duration field in case of 25921f198e22SChangbin Du reached duration thresholds. 25931f198e22SChangbin Du 25941f198e22SChangbin Du - hide: echo nofuncgraph-overhead > trace_options 25951f198e22SChangbin Du - show: echo funcgraph-overhead > trace_options 25961f198e22SChangbin Du - depends on: funcgraph-duration 25971f198e22SChangbin Du 25981f198e22SChangbin Du ie:: 25991f198e22SChangbin Du 26001f198e22SChangbin Du 3) # 1837.709 us | } /* __switch_to */ 26011f198e22SChangbin Du 3) | finish_task_switch() { 26021f198e22SChangbin Du 3) 0.313 us | _raw_spin_unlock_irq(); 26031f198e22SChangbin Du 3) 3.177 us | } 26041f198e22SChangbin Du 3) # 1889.063 us | } /* __schedule */ 26051f198e22SChangbin Du 3) ! 140.417 us | } /* __schedule */ 26061f198e22SChangbin Du 3) # 2034.948 us | } /* schedule */ 26071f198e22SChangbin Du 3) * 33998.59 us | } /* schedule_preempt_disabled */ 26081f198e22SChangbin Du 26091f198e22SChangbin Du [...] 26101f198e22SChangbin Du 26111f198e22SChangbin Du 1) 0.260 us | msecs_to_jiffies(); 26121f198e22SChangbin Du 1) 0.313 us | __rcu_read_unlock(); 26131f198e22SChangbin Du 1) + 61.770 us | } 26141f198e22SChangbin Du 1) + 64.479 us | } 26151f198e22SChangbin Du 1) 0.313 us | rcu_bh_qs(); 26161f198e22SChangbin Du 1) 0.313 us | __local_bh_enable(); 26171f198e22SChangbin Du 1) ! 217.240 us | } 26181f198e22SChangbin Du 1) 0.365 us | idle_cpu(); 26191f198e22SChangbin Du 1) | rcu_irq_exit() { 26201f198e22SChangbin Du 1) 0.417 us | rcu_eqs_enter_common.isra.47(); 26211f198e22SChangbin Du 1) 3.125 us | } 26221f198e22SChangbin Du 1) ! 227.812 us | } 26231f198e22SChangbin Du 1) ! 457.395 us | } 26241f198e22SChangbin Du 1) @ 119760.2 us | } 26251f198e22SChangbin Du 26261f198e22SChangbin Du [...] 26271f198e22SChangbin Du 26281f198e22SChangbin Du 2) | handle_IPI() { 26291f198e22SChangbin Du 1) 6.979 us | } 26301f198e22SChangbin Du 2) 0.417 us | scheduler_ipi(); 26311f198e22SChangbin Du 1) 9.791 us | } 26321f198e22SChangbin Du 1) + 12.917 us | } 26331f198e22SChangbin Du 2) 3.490 us | } 26341f198e22SChangbin Du 1) + 15.729 us | } 26351f198e22SChangbin Du 1) + 18.542 us | } 26361f198e22SChangbin Du 2) $ 3594274 us | } 26371f198e22SChangbin Du 26381f198e22SChangbin DuFlags:: 26391f198e22SChangbin Du 26401f198e22SChangbin Du + means that the function exceeded 10 usecs. 26411f198e22SChangbin Du ! means that the function exceeded 100 usecs. 26421f198e22SChangbin Du # means that the function exceeded 1000 usecs. 26431f198e22SChangbin Du * means that the function exceeded 10 msecs. 26441f198e22SChangbin Du @ means that the function exceeded 100 msecs. 26451f198e22SChangbin Du $ means that the function exceeded 1 sec. 26461f198e22SChangbin Du 26471f198e22SChangbin Du 26481f198e22SChangbin Du- The task/pid field displays the thread cmdline and pid which 26491f198e22SChangbin Du executed the function. It is default disabled. 26501f198e22SChangbin Du 26511f198e22SChangbin Du - hide: echo nofuncgraph-proc > trace_options 26521f198e22SChangbin Du - show: echo funcgraph-proc > trace_options 26531f198e22SChangbin Du 26541f198e22SChangbin Du ie:: 26551f198e22SChangbin Du 26561f198e22SChangbin Du # tracer: function_graph 26571f198e22SChangbin Du # 26581f198e22SChangbin Du # CPU TASK/PID DURATION FUNCTION CALLS 26591f198e22SChangbin Du # | | | | | | | | | 26601f198e22SChangbin Du 0) sh-4802 | | d_free() { 26611f198e22SChangbin Du 0) sh-4802 | | call_rcu() { 26621f198e22SChangbin Du 0) sh-4802 | | __call_rcu() { 26631f198e22SChangbin Du 0) sh-4802 | 0.616 us | rcu_process_gp_end(); 26641f198e22SChangbin Du 0) sh-4802 | 0.586 us | check_for_new_grace_period(); 26651f198e22SChangbin Du 0) sh-4802 | 2.899 us | } 26661f198e22SChangbin Du 0) sh-4802 | 4.040 us | } 26671f198e22SChangbin Du 0) sh-4802 | 5.151 us | } 26681f198e22SChangbin Du 0) sh-4802 | + 49.370 us | } 26691f198e22SChangbin Du 26701f198e22SChangbin Du 26711f198e22SChangbin Du- The absolute time field is an absolute timestamp given by the 26721f198e22SChangbin Du system clock since it started. A snapshot of this time is 26731f198e22SChangbin Du given on each entry/exit of functions 26741f198e22SChangbin Du 26751f198e22SChangbin Du - hide: echo nofuncgraph-abstime > trace_options 26761f198e22SChangbin Du - show: echo funcgraph-abstime > trace_options 26771f198e22SChangbin Du 26781f198e22SChangbin Du ie:: 26791f198e22SChangbin Du 26801f198e22SChangbin Du # 26811f198e22SChangbin Du # TIME CPU DURATION FUNCTION CALLS 26821f198e22SChangbin Du # | | | | | | | | 26831f198e22SChangbin Du 360.774522 | 1) 0.541 us | } 26841f198e22SChangbin Du 360.774522 | 1) 4.663 us | } 26851f198e22SChangbin Du 360.774523 | 1) 0.541 us | __wake_up_bit(); 26861f198e22SChangbin Du 360.774524 | 1) 6.796 us | } 26871f198e22SChangbin Du 360.774524 | 1) 7.952 us | } 26881f198e22SChangbin Du 360.774525 | 1) 9.063 us | } 26891f198e22SChangbin Du 360.774525 | 1) 0.615 us | journal_mark_dirty(); 26901f198e22SChangbin Du 360.774527 | 1) 0.578 us | __brelse(); 26911f198e22SChangbin Du 360.774528 | 1) | reiserfs_prepare_for_journal() { 26921f198e22SChangbin Du 360.774528 | 1) | unlock_buffer() { 26931f198e22SChangbin Du 360.774529 | 1) | wake_up_bit() { 26941f198e22SChangbin Du 360.774529 | 1) | bit_waitqueue() { 26951f198e22SChangbin Du 360.774530 | 1) 0.594 us | __phys_addr(); 26961f198e22SChangbin Du 26971f198e22SChangbin Du 26981f198e22SChangbin DuThe function name is always displayed after the closing bracket 26991f198e22SChangbin Dufor a function if the start of that function is not in the 27001f198e22SChangbin Dutrace buffer. 27011f198e22SChangbin Du 27021f198e22SChangbin DuDisplay of the function name after the closing bracket may be 27031f198e22SChangbin Duenabled for functions whose start is in the trace buffer, 27041f198e22SChangbin Duallowing easier searching with grep for function durations. 27051f198e22SChangbin DuIt is default disabled. 27061f198e22SChangbin Du 27071f198e22SChangbin Du - hide: echo nofuncgraph-tail > trace_options 27081f198e22SChangbin Du - show: echo funcgraph-tail > trace_options 27091f198e22SChangbin Du 27101f198e22SChangbin Du Example with nofuncgraph-tail (default):: 27111f198e22SChangbin Du 27121f198e22SChangbin Du 0) | putname() { 27131f198e22SChangbin Du 0) | kmem_cache_free() { 27141f198e22SChangbin Du 0) 0.518 us | __phys_addr(); 27151f198e22SChangbin Du 0) 1.757 us | } 27161f198e22SChangbin Du 0) 2.861 us | } 27171f198e22SChangbin Du 27181f198e22SChangbin Du Example with funcgraph-tail:: 27191f198e22SChangbin Du 27201f198e22SChangbin Du 0) | putname() { 27211f198e22SChangbin Du 0) | kmem_cache_free() { 27221f198e22SChangbin Du 0) 0.518 us | __phys_addr(); 27231f198e22SChangbin Du 0) 1.757 us | } /* kmem_cache_free() */ 27241f198e22SChangbin Du 0) 2.861 us | } /* putname() */ 27251f198e22SChangbin Du 272621c094d3SDonglin PengThe return value of each traced function can be displayed after 272721c094d3SDonglin Pengan equal sign "=". When encountering system call failures, it 2728*d56b699dSBjorn Helgaascan be very helpful to quickly locate the function that first 272921c094d3SDonglin Pengreturns an error code. 273021c094d3SDonglin Peng 273121c094d3SDonglin Peng - hide: echo nofuncgraph-retval > trace_options 273221c094d3SDonglin Peng - show: echo funcgraph-retval > trace_options 273321c094d3SDonglin Peng 273421c094d3SDonglin Peng Example with funcgraph-retval:: 273521c094d3SDonglin Peng 273621c094d3SDonglin Peng 1) | cgroup_migrate() { 273721c094d3SDonglin Peng 1) 0.651 us | cgroup_migrate_add_task(); /* = 0xffff93fcfd346c00 */ 273821c094d3SDonglin Peng 1) | cgroup_migrate_execute() { 273921c094d3SDonglin Peng 1) | cpu_cgroup_can_attach() { 274021c094d3SDonglin Peng 1) | cgroup_taskset_first() { 274121c094d3SDonglin Peng 1) 0.732 us | cgroup_taskset_next(); /* = 0xffff93fc8fb20000 */ 274221c094d3SDonglin Peng 1) 1.232 us | } /* cgroup_taskset_first = 0xffff93fc8fb20000 */ 274321c094d3SDonglin Peng 1) 0.380 us | sched_rt_can_attach(); /* = 0x0 */ 274421c094d3SDonglin Peng 1) 2.335 us | } /* cpu_cgroup_can_attach = -22 */ 274521c094d3SDonglin Peng 1) 4.369 us | } /* cgroup_migrate_execute = -22 */ 274621c094d3SDonglin Peng 1) 7.143 us | } /* cgroup_migrate = -22 */ 274721c094d3SDonglin Peng 274821c094d3SDonglin PengThe above example shows that the function cpu_cgroup_can_attach 274921c094d3SDonglin Pengreturned the error code -22 firstly, then we can read the code 275021c094d3SDonglin Pengof this function to get the root cause. 275121c094d3SDonglin Peng 275221c094d3SDonglin PengWhen the option funcgraph-retval-hex is not set, the return value can 275321c094d3SDonglin Pengbe displayed in a smart way. Specifically, if it is an error code, 275421c094d3SDonglin Pengit will be printed in signed decimal format, otherwise it will 275521c094d3SDonglin Pengprinted in hexadecimal format. 275621c094d3SDonglin Peng 275721c094d3SDonglin Peng - smart: echo nofuncgraph-retval-hex > trace_options 275821c094d3SDonglin Peng - hexadecimal: echo funcgraph-retval-hex > trace_options 275921c094d3SDonglin Peng 276021c094d3SDonglin Peng Example with funcgraph-retval-hex:: 276121c094d3SDonglin Peng 276221c094d3SDonglin Peng 1) | cgroup_migrate() { 276321c094d3SDonglin Peng 1) 0.651 us | cgroup_migrate_add_task(); /* = 0xffff93fcfd346c00 */ 276421c094d3SDonglin Peng 1) | cgroup_migrate_execute() { 276521c094d3SDonglin Peng 1) | cpu_cgroup_can_attach() { 276621c094d3SDonglin Peng 1) | cgroup_taskset_first() { 276721c094d3SDonglin Peng 1) 0.732 us | cgroup_taskset_next(); /* = 0xffff93fc8fb20000 */ 276821c094d3SDonglin Peng 1) 1.232 us | } /* cgroup_taskset_first = 0xffff93fc8fb20000 */ 276921c094d3SDonglin Peng 1) 0.380 us | sched_rt_can_attach(); /* = 0x0 */ 277021c094d3SDonglin Peng 1) 2.335 us | } /* cpu_cgroup_can_attach = 0xffffffea */ 277121c094d3SDonglin Peng 1) 4.369 us | } /* cgroup_migrate_execute = 0xffffffea */ 277221c094d3SDonglin Peng 1) 7.143 us | } /* cgroup_migrate = 0xffffffea */ 277321c094d3SDonglin Peng 277421c094d3SDonglin PengAt present, there are some limitations when using the funcgraph-retval 277521c094d3SDonglin Pengoption, and these limitations will be eliminated in the future: 277621c094d3SDonglin Peng 277721c094d3SDonglin Peng- Even if the function return type is void, a return value will still 277821c094d3SDonglin Peng be printed, and you can just ignore it. 277921c094d3SDonglin Peng 278021c094d3SDonglin Peng- Even if return values are stored in multiple registers, only the 278121c094d3SDonglin Peng value contained in the first register will be recorded and printed. 278221c094d3SDonglin Peng To illustrate, in the x86 architecture, eax and edx are used to store 278321c094d3SDonglin Peng a 64-bit return value, with the lower 32 bits saved in eax and the 278421c094d3SDonglin Peng upper 32 bits saved in edx. However, only the value stored in eax 278521c094d3SDonglin Peng will be recorded and printed. 278621c094d3SDonglin Peng 278721c094d3SDonglin Peng- In certain procedure call standards, such as arm64's AAPCS64, when a 278821c094d3SDonglin Peng type is smaller than a GPR, it is the responsibility of the consumer 278921c094d3SDonglin Peng to perform the narrowing, and the upper bits may contain UNKNOWN values. 279021c094d3SDonglin Peng Therefore, it is advisable to check the code for such cases. For instance, 279121c094d3SDonglin Peng when using a u8 in a 64-bit GPR, bits [63:8] may contain arbitrary values, 279221c094d3SDonglin Peng especially when larger types are truncated, whether explicitly or implicitly. 279321c094d3SDonglin Peng Here are some specific cases to illustrate this point: 279421c094d3SDonglin Peng 2795fc30ace0SDonglin Peng **Case One**: 279621c094d3SDonglin Peng 279721c094d3SDonglin Peng The function narrow_to_u8 is defined as follows:: 279821c094d3SDonglin Peng 279921c094d3SDonglin Peng u8 narrow_to_u8(u64 val) 280021c094d3SDonglin Peng { 280121c094d3SDonglin Peng // implicitly truncated 280221c094d3SDonglin Peng return val; 280321c094d3SDonglin Peng } 280421c094d3SDonglin Peng 280521c094d3SDonglin Peng It may be compiled to:: 280621c094d3SDonglin Peng 280721c094d3SDonglin Peng narrow_to_u8: 280821c094d3SDonglin Peng < ... ftrace instrumentation ... > 280921c094d3SDonglin Peng RET 281021c094d3SDonglin Peng 281121c094d3SDonglin Peng If you pass 0x123456789abcdef to this function and want to narrow it, 281221c094d3SDonglin Peng it may be recorded as 0x123456789abcdef instead of 0xef. 281321c094d3SDonglin Peng 2814fc30ace0SDonglin Peng **Case Two**: 281521c094d3SDonglin Peng 281621c094d3SDonglin Peng The function error_if_not_4g_aligned is defined as follows:: 281721c094d3SDonglin Peng 281821c094d3SDonglin Peng int error_if_not_4g_aligned(u64 val) 281921c094d3SDonglin Peng { 282021c094d3SDonglin Peng if (val & GENMASK(31, 0)) 282121c094d3SDonglin Peng return -EINVAL; 282221c094d3SDonglin Peng 282321c094d3SDonglin Peng return 0; 282421c094d3SDonglin Peng } 282521c094d3SDonglin Peng 282621c094d3SDonglin Peng It could be compiled to:: 282721c094d3SDonglin Peng 282821c094d3SDonglin Peng error_if_not_4g_aligned: 282921c094d3SDonglin Peng CBNZ w0, .Lnot_aligned 283021c094d3SDonglin Peng RET // bits [31:0] are zero, bits 283121c094d3SDonglin Peng // [63:32] are UNKNOWN 283221c094d3SDonglin Peng .Lnot_aligned: 283321c094d3SDonglin Peng MOV x0, #-EINVAL 283421c094d3SDonglin Peng RET 283521c094d3SDonglin Peng 283621c094d3SDonglin Peng When passing 0x2_0000_0000 to it, the return value may be recorded as 283721c094d3SDonglin Peng 0x2_0000_0000 instead of 0. 283821c094d3SDonglin Peng 28391f198e22SChangbin DuYou can put some comments on specific functions by using 28401f198e22SChangbin Dutrace_printk() For example, if you want to put a comment inside 28411f198e22SChangbin Duthe __might_sleep() function, you just have to include 28421f198e22SChangbin Du<linux/ftrace.h> and call trace_printk() inside __might_sleep():: 28431f198e22SChangbin Du 28441f198e22SChangbin Du trace_printk("I'm a comment!\n") 28451f198e22SChangbin Du 28461f198e22SChangbin Duwill produce:: 28471f198e22SChangbin Du 28481f198e22SChangbin Du 1) | __might_sleep() { 28491f198e22SChangbin Du 1) | /* I'm a comment! */ 28501f198e22SChangbin Du 1) 1.449 us | } 28511f198e22SChangbin Du 28521f198e22SChangbin Du 28531f198e22SChangbin DuYou might find other useful features for this tracer in the 28541f198e22SChangbin Dufollowing "dynamic ftrace" section such as tracing only specific 28551f198e22SChangbin Dufunctions or tasks. 28561f198e22SChangbin Du 28571f198e22SChangbin Dudynamic ftrace 28581f198e22SChangbin Du-------------- 28591f198e22SChangbin Du 28601f198e22SChangbin DuIf CONFIG_DYNAMIC_FTRACE is set, the system will run with 28611f198e22SChangbin Duvirtually no overhead when function tracing is disabled. The way 28621f198e22SChangbin Duthis works is the mcount function call (placed at the start of 28631f198e22SChangbin Duevery kernel function, produced by the -pg switch in gcc), 28641f198e22SChangbin Dustarts of pointing to a simple return. (Enabling FTRACE will 28651f198e22SChangbin Duinclude the -pg switch in the compiling of the kernel.) 28661f198e22SChangbin Du 28671f198e22SChangbin DuAt compile time every C file object is run through the 28681f198e22SChangbin Durecordmcount program (located in the scripts directory). This 28691f198e22SChangbin Duprogram will parse the ELF headers in the C object to find all 28701f198e22SChangbin Duthe locations in the .text section that call mcount. Starting 28712a1e03caSAmir Livnehwith gcc version 4.6, the -mfentry has been added for x86, which 28721f198e22SChangbin Ducalls "__fentry__" instead of "mcount". Which is called before 28731f198e22SChangbin Duthe creation of the stack frame. 28741f198e22SChangbin Du 28751f198e22SChangbin DuNote, not all sections are traced. They may be prevented by either 28761f198e22SChangbin Dua notrace, or blocked another way and all inline functions are not 28771f198e22SChangbin Dutraced. Check the "available_filter_functions" file to see what functions 28781f198e22SChangbin Ducan be traced. 28791f198e22SChangbin Du 28801f198e22SChangbin DuA section called "__mcount_loc" is created that holds 28811f198e22SChangbin Dureferences to all the mcount/fentry call sites in the .text section. 28821f198e22SChangbin DuThe recordmcount program re-links this section back into the 28831f198e22SChangbin Duoriginal object. The final linking stage of the kernel will add all these 28841f198e22SChangbin Dureferences into a single table. 28851f198e22SChangbin Du 28861f198e22SChangbin DuOn boot up, before SMP is initialized, the dynamic ftrace code 28871f198e22SChangbin Duscans this table and updates all the locations into nops. It 28881f198e22SChangbin Dualso records the locations, which are added to the 28891f198e22SChangbin Duavailable_filter_functions list. Modules are processed as they 28901f198e22SChangbin Duare loaded and before they are executed. When a module is 28911f198e22SChangbin Duunloaded, it also removes its functions from the ftrace function 28921f198e22SChangbin Dulist. This is automatic in the module unload code, and the 28931f198e22SChangbin Dumodule author does not need to worry about it. 28941f198e22SChangbin Du 28951f198e22SChangbin DuWhen tracing is enabled, the process of modifying the function 28961f198e22SChangbin Dutracepoints is dependent on architecture. The old method is to use 28971f198e22SChangbin Dukstop_machine to prevent races with the CPUs executing code being 28981f198e22SChangbin Dumodified (which can cause the CPU to do undesirable things, especially 28991f198e22SChangbin Duif the modified code crosses cache (or page) boundaries), and the nops are 29001f198e22SChangbin Dupatched back to calls. But this time, they do not call mcount 29011f198e22SChangbin Du(which is just a function stub). They now call into the ftrace 29021f198e22SChangbin Duinfrastructure. 29031f198e22SChangbin Du 29041f198e22SChangbin DuThe new method of modifying the function tracepoints is to place 29051f198e22SChangbin Dua breakpoint at the location to be modified, sync all CPUs, modify 29061f198e22SChangbin Duthe rest of the instruction not covered by the breakpoint. Sync 29071f198e22SChangbin Duall CPUs again, and then remove the breakpoint with the finished 29081f198e22SChangbin Duversion to the ftrace call site. 29091f198e22SChangbin Du 29101f198e22SChangbin DuSome archs do not even need to monkey around with the synchronization, 29111f198e22SChangbin Duand can just slap the new code on top of the old without any 29121f198e22SChangbin Duproblems with other CPUs executing it at the same time. 29131f198e22SChangbin Du 29141f198e22SChangbin DuOne special side-effect to the recording of the functions being 29151f198e22SChangbin Dutraced is that we can now selectively choose which functions we 29161f198e22SChangbin Duwish to trace and which ones we want the mcount calls to remain 29171f198e22SChangbin Duas nops. 29181f198e22SChangbin Du 29191f198e22SChangbin DuTwo files are used, one for enabling and one for disabling the 29201f198e22SChangbin Dutracing of specified functions. They are: 29211f198e22SChangbin Du 29221f198e22SChangbin Du set_ftrace_filter 29231f198e22SChangbin Du 29241f198e22SChangbin Duand 29251f198e22SChangbin Du 29261f198e22SChangbin Du set_ftrace_notrace 29271f198e22SChangbin Du 29281f198e22SChangbin DuA list of available functions that you can add to these files is 29291f198e22SChangbin Dulisted in: 29301f198e22SChangbin Du 29311f198e22SChangbin Du available_filter_functions 29321f198e22SChangbin Du 29331f198e22SChangbin Du:: 29341f198e22SChangbin Du 29351f198e22SChangbin Du # cat available_filter_functions 29361f198e22SChangbin Du put_prev_task_idle 29371f198e22SChangbin Du kmem_cache_create 29381f198e22SChangbin Du pick_next_task_rt 2939c7483d82SSebastian Andrzej Siewior cpus_read_lock 29401f198e22SChangbin Du pick_next_task_fair 29411f198e22SChangbin Du mutex_lock 29421f198e22SChangbin Du [...] 29431f198e22SChangbin Du 29441f198e22SChangbin DuIf I am only interested in sys_nanosleep and hrtimer_interrupt:: 29451f198e22SChangbin Du 29461f198e22SChangbin Du # echo sys_nanosleep hrtimer_interrupt > set_ftrace_filter 29471f198e22SChangbin Du # echo function > current_tracer 29481f198e22SChangbin Du # echo 1 > tracing_on 29491f198e22SChangbin Du # usleep 1 29501f198e22SChangbin Du # echo 0 > tracing_on 29511f198e22SChangbin Du # cat trace 29521f198e22SChangbin Du # tracer: function 29531f198e22SChangbin Du # 29541f198e22SChangbin Du # entries-in-buffer/entries-written: 5/5 #P:4 29551f198e22SChangbin Du # 29561f198e22SChangbin Du # _-----=> irqs-off 29571f198e22SChangbin Du # / _----=> need-resched 29581f198e22SChangbin Du # | / _---=> hardirq/softirq 29591f198e22SChangbin Du # || / _--=> preempt-depth 29601f198e22SChangbin Du # ||| / delay 29611f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 29621f198e22SChangbin Du # | | | |||| | | 29631f198e22SChangbin Du usleep-2665 [001] .... 4186.475355: sys_nanosleep <-system_call_fastpath 29641f198e22SChangbin Du <idle>-0 [001] d.h1 4186.475409: hrtimer_interrupt <-smp_apic_timer_interrupt 29651f198e22SChangbin Du usleep-2665 [001] d.h1 4186.475426: hrtimer_interrupt <-smp_apic_timer_interrupt 29661f198e22SChangbin Du <idle>-0 [003] d.h1 4186.475426: hrtimer_interrupt <-smp_apic_timer_interrupt 29671f198e22SChangbin Du <idle>-0 [002] d.h1 4186.475427: hrtimer_interrupt <-smp_apic_timer_interrupt 29681f198e22SChangbin Du 29691f198e22SChangbin DuTo see which functions are being traced, you can cat the file: 29701f198e22SChangbin Du:: 29711f198e22SChangbin Du 29721f198e22SChangbin Du # cat set_ftrace_filter 29731f198e22SChangbin Du hrtimer_interrupt 29741f198e22SChangbin Du sys_nanosleep 29751f198e22SChangbin Du 29761f198e22SChangbin Du 29771f198e22SChangbin DuPerhaps this is not enough. The filters also allow glob(7) matching. 29781f198e22SChangbin Du 29796234c7bdSJonathan Corbet ``<match>*`` 29801f198e22SChangbin Du will match functions that begin with <match> 29816234c7bdSJonathan Corbet ``*<match>`` 29821f198e22SChangbin Du will match functions that end with <match> 29836234c7bdSJonathan Corbet ``*<match>*`` 29841f198e22SChangbin Du will match functions that have <match> in it 29856234c7bdSJonathan Corbet ``<match1>*<match2>`` 29861f198e22SChangbin Du will match functions that begin with <match1> and end with <match2> 29871f198e22SChangbin Du 29881f198e22SChangbin Du.. note:: 29891f198e22SChangbin Du It is better to use quotes to enclose the wild cards, 29901f198e22SChangbin Du otherwise the shell may expand the parameters into names 29911f198e22SChangbin Du of files in the local directory. 29921f198e22SChangbin Du 29931f198e22SChangbin Du:: 29941f198e22SChangbin Du 29951f198e22SChangbin Du # echo 'hrtimer_*' > set_ftrace_filter 29961f198e22SChangbin Du 29971f198e22SChangbin DuProduces:: 29981f198e22SChangbin Du 29991f198e22SChangbin Du # tracer: function 30001f198e22SChangbin Du # 30011f198e22SChangbin Du # entries-in-buffer/entries-written: 897/897 #P:4 30021f198e22SChangbin Du # 30031f198e22SChangbin Du # _-----=> irqs-off 30041f198e22SChangbin Du # / _----=> need-resched 30051f198e22SChangbin Du # | / _---=> hardirq/softirq 30061f198e22SChangbin Du # || / _--=> preempt-depth 30071f198e22SChangbin Du # ||| / delay 30081f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 30091f198e22SChangbin Du # | | | |||| | | 30101f198e22SChangbin Du <idle>-0 [003] dN.1 4228.547803: hrtimer_cancel <-tick_nohz_idle_exit 30111f198e22SChangbin Du <idle>-0 [003] dN.1 4228.547804: hrtimer_try_to_cancel <-hrtimer_cancel 30121f198e22SChangbin Du <idle>-0 [003] dN.2 4228.547805: hrtimer_force_reprogram <-__remove_hrtimer 30131f198e22SChangbin Du <idle>-0 [003] dN.1 4228.547805: hrtimer_forward <-tick_nohz_idle_exit 30141f198e22SChangbin Du <idle>-0 [003] dN.1 4228.547805: hrtimer_start_range_ns <-hrtimer_start_expires.constprop.11 30151f198e22SChangbin Du <idle>-0 [003] d..1 4228.547858: hrtimer_get_next_event <-get_next_timer_interrupt 30161f198e22SChangbin Du <idle>-0 [003] d..1 4228.547859: hrtimer_start <-__tick_nohz_idle_enter 30171f198e22SChangbin Du <idle>-0 [003] d..2 4228.547860: hrtimer_force_reprogram <-__rem 30181f198e22SChangbin Du 30191f198e22SChangbin DuNotice that we lost the sys_nanosleep. 30201f198e22SChangbin Du:: 30211f198e22SChangbin Du 30221f198e22SChangbin Du # cat set_ftrace_filter 30231f198e22SChangbin Du hrtimer_run_queues 30241f198e22SChangbin Du hrtimer_run_pending 30251f198e22SChangbin Du hrtimer_init 30261f198e22SChangbin Du hrtimer_cancel 30271f198e22SChangbin Du hrtimer_try_to_cancel 30281f198e22SChangbin Du hrtimer_forward 30291f198e22SChangbin Du hrtimer_start 30301f198e22SChangbin Du hrtimer_reprogram 30311f198e22SChangbin Du hrtimer_force_reprogram 30321f198e22SChangbin Du hrtimer_get_next_event 30331f198e22SChangbin Du hrtimer_interrupt 30341f198e22SChangbin Du hrtimer_nanosleep 30351f198e22SChangbin Du hrtimer_wakeup 30361f198e22SChangbin Du hrtimer_get_remaining 30371f198e22SChangbin Du hrtimer_get_res 30381f198e22SChangbin Du hrtimer_init_sleeper 30391f198e22SChangbin Du 30401f198e22SChangbin Du 30411f198e22SChangbin DuThis is because the '>' and '>>' act just like they do in bash. 30421f198e22SChangbin DuTo rewrite the filters, use '>' 30431f198e22SChangbin DuTo append to the filters, use '>>' 30441f198e22SChangbin Du 30451f198e22SChangbin DuTo clear out a filter so that all functions will be recorded 30461f198e22SChangbin Duagain:: 30471f198e22SChangbin Du 30481f198e22SChangbin Du # echo > set_ftrace_filter 30491f198e22SChangbin Du # cat set_ftrace_filter 30501f198e22SChangbin Du # 30511f198e22SChangbin Du 30521f198e22SChangbin DuAgain, now we want to append. 30531f198e22SChangbin Du 30541f198e22SChangbin Du:: 30551f198e22SChangbin Du 30561f198e22SChangbin Du # echo sys_nanosleep > set_ftrace_filter 30571f198e22SChangbin Du # cat set_ftrace_filter 30581f198e22SChangbin Du sys_nanosleep 30591f198e22SChangbin Du # echo 'hrtimer_*' >> set_ftrace_filter 30601f198e22SChangbin Du # cat set_ftrace_filter 30611f198e22SChangbin Du hrtimer_run_queues 30621f198e22SChangbin Du hrtimer_run_pending 30631f198e22SChangbin Du hrtimer_init 30641f198e22SChangbin Du hrtimer_cancel 30651f198e22SChangbin Du hrtimer_try_to_cancel 30661f198e22SChangbin Du hrtimer_forward 30671f198e22SChangbin Du hrtimer_start 30681f198e22SChangbin Du hrtimer_reprogram 30691f198e22SChangbin Du hrtimer_force_reprogram 30701f198e22SChangbin Du hrtimer_get_next_event 30711f198e22SChangbin Du hrtimer_interrupt 30721f198e22SChangbin Du sys_nanosleep 30731f198e22SChangbin Du hrtimer_nanosleep 30741f198e22SChangbin Du hrtimer_wakeup 30751f198e22SChangbin Du hrtimer_get_remaining 30761f198e22SChangbin Du hrtimer_get_res 30771f198e22SChangbin Du hrtimer_init_sleeper 30781f198e22SChangbin Du 30791f198e22SChangbin Du 30801f198e22SChangbin DuThe set_ftrace_notrace prevents those functions from being 30811f198e22SChangbin Dutraced. 30821f198e22SChangbin Du:: 30831f198e22SChangbin Du 30841f198e22SChangbin Du # echo '*preempt*' '*lock*' > set_ftrace_notrace 30851f198e22SChangbin Du 30861f198e22SChangbin DuProduces:: 30871f198e22SChangbin Du 30881f198e22SChangbin Du # tracer: function 30891f198e22SChangbin Du # 30901f198e22SChangbin Du # entries-in-buffer/entries-written: 39608/39608 #P:4 30911f198e22SChangbin Du # 30921f198e22SChangbin Du # _-----=> irqs-off 30931f198e22SChangbin Du # / _----=> need-resched 30941f198e22SChangbin Du # | / _---=> hardirq/softirq 30951f198e22SChangbin Du # || / _--=> preempt-depth 30961f198e22SChangbin Du # ||| / delay 30971f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 30981f198e22SChangbin Du # | | | |||| | | 30991f198e22SChangbin Du bash-1994 [000] .... 4342.324896: file_ra_state_init <-do_dentry_open 31001f198e22SChangbin Du bash-1994 [000] .... 4342.324897: open_check_o_direct <-do_last 31011f198e22SChangbin Du bash-1994 [000] .... 4342.324897: ima_file_check <-do_last 31021f198e22SChangbin Du bash-1994 [000] .... 4342.324898: process_measurement <-ima_file_check 31031f198e22SChangbin Du bash-1994 [000] .... 4342.324898: ima_get_action <-process_measurement 31041f198e22SChangbin Du bash-1994 [000] .... 4342.324898: ima_match_policy <-ima_get_action 31051f198e22SChangbin Du bash-1994 [000] .... 4342.324899: do_truncate <-do_last 3106ed5a7047SChristian Brauner bash-1994 [000] .... 4342.324899: setattr_should_drop_suidgid <-do_truncate 31071f198e22SChangbin Du bash-1994 [000] .... 4342.324899: notify_change <-do_truncate 31081f198e22SChangbin Du bash-1994 [000] .... 4342.324900: current_fs_time <-notify_change 31091f198e22SChangbin Du bash-1994 [000] .... 4342.324900: current_kernel_time <-current_fs_time 31101f198e22SChangbin Du bash-1994 [000] .... 4342.324900: timespec_trunc <-current_fs_time 31111f198e22SChangbin Du 31121f198e22SChangbin DuWe can see that there's no more lock or preempt tracing. 31131f198e22SChangbin Du 3114f79b3f33SSteven Rostedt (VMware)Selecting function filters via index 3115f79b3f33SSteven Rostedt (VMware)------------------------------------ 3116f79b3f33SSteven Rostedt (VMware) 3117f79b3f33SSteven Rostedt (VMware)Because processing of strings is expensive (the address of the function 3118f79b3f33SSteven Rostedt (VMware)needs to be looked up before comparing to the string being passed in), 3119f79b3f33SSteven Rostedt (VMware)an index can be used as well to enable functions. This is useful in the 3120f79b3f33SSteven Rostedt (VMware)case of setting thousands of specific functions at a time. By passing 3121f79b3f33SSteven Rostedt (VMware)in a list of numbers, no string processing will occur. Instead, the function 3122f79b3f33SSteven Rostedt (VMware)at the specific location in the internal array (which corresponds to the 3123f79b3f33SSteven Rostedt (VMware)functions in the "available_filter_functions" file), is selected. 3124f79b3f33SSteven Rostedt (VMware) 3125f79b3f33SSteven Rostedt (VMware):: 3126f79b3f33SSteven Rostedt (VMware) 3127f79b3f33SSteven Rostedt (VMware) # echo 1 > set_ftrace_filter 3128f79b3f33SSteven Rostedt (VMware) 3129f79b3f33SSteven Rostedt (VMware)Will select the first function listed in "available_filter_functions" 3130f79b3f33SSteven Rostedt (VMware) 3131f79b3f33SSteven Rostedt (VMware):: 3132f79b3f33SSteven Rostedt (VMware) 3133f79b3f33SSteven Rostedt (VMware) # head -1 available_filter_functions 3134f79b3f33SSteven Rostedt (VMware) trace_initcall_finish_cb 3135f79b3f33SSteven Rostedt (VMware) 3136f79b3f33SSteven Rostedt (VMware) # cat set_ftrace_filter 3137f79b3f33SSteven Rostedt (VMware) trace_initcall_finish_cb 3138f79b3f33SSteven Rostedt (VMware) 3139f79b3f33SSteven Rostedt (VMware) # head -50 available_filter_functions | tail -1 3140f79b3f33SSteven Rostedt (VMware) x86_pmu_commit_txn 3141f79b3f33SSteven Rostedt (VMware) 3142f79b3f33SSteven Rostedt (VMware) # echo 1 50 > set_ftrace_filter 3143f79b3f33SSteven Rostedt (VMware) # cat set_ftrace_filter 3144f79b3f33SSteven Rostedt (VMware) trace_initcall_finish_cb 3145f79b3f33SSteven Rostedt (VMware) x86_pmu_commit_txn 31461f198e22SChangbin Du 31471f198e22SChangbin DuDynamic ftrace with the function graph tracer 31481f198e22SChangbin Du--------------------------------------------- 31491f198e22SChangbin Du 31501f198e22SChangbin DuAlthough what has been explained above concerns both the 31511f198e22SChangbin Dufunction tracer and the function-graph-tracer, there are some 31521f198e22SChangbin Duspecial features only available in the function-graph tracer. 31531f198e22SChangbin Du 31541f198e22SChangbin DuIf you want to trace only one function and all of its children, 31551f198e22SChangbin Duyou just have to echo its name into set_graph_function:: 31561f198e22SChangbin Du 31571f198e22SChangbin Du echo __do_fault > set_graph_function 31581f198e22SChangbin Du 31591f198e22SChangbin Duwill produce the following "expanded" trace of the __do_fault() 31601f198e22SChangbin Dufunction:: 31611f198e22SChangbin Du 31621f198e22SChangbin Du 0) | __do_fault() { 31631f198e22SChangbin Du 0) | filemap_fault() { 31641f198e22SChangbin Du 0) | find_lock_page() { 31651f198e22SChangbin Du 0) 0.804 us | find_get_page(); 31661f198e22SChangbin Du 0) | __might_sleep() { 31671f198e22SChangbin Du 0) 1.329 us | } 31681f198e22SChangbin Du 0) 3.904 us | } 31691f198e22SChangbin Du 0) 4.979 us | } 31701f198e22SChangbin Du 0) 0.653 us | _spin_lock(); 31711f198e22SChangbin Du 0) 0.578 us | page_add_file_rmap(); 31721f198e22SChangbin Du 0) 0.525 us | native_set_pte_at(); 31731f198e22SChangbin Du 0) 0.585 us | _spin_unlock(); 31741f198e22SChangbin Du 0) | unlock_page() { 31751f198e22SChangbin Du 0) 0.541 us | page_waitqueue(); 31761f198e22SChangbin Du 0) 0.639 us | __wake_up_bit(); 31771f198e22SChangbin Du 0) 2.786 us | } 31781f198e22SChangbin Du 0) + 14.237 us | } 31791f198e22SChangbin Du 0) | __do_fault() { 31801f198e22SChangbin Du 0) | filemap_fault() { 31811f198e22SChangbin Du 0) | find_lock_page() { 31821f198e22SChangbin Du 0) 0.698 us | find_get_page(); 31831f198e22SChangbin Du 0) | __might_sleep() { 31841f198e22SChangbin Du 0) 1.412 us | } 31851f198e22SChangbin Du 0) 3.950 us | } 31861f198e22SChangbin Du 0) 5.098 us | } 31871f198e22SChangbin Du 0) 0.631 us | _spin_lock(); 31881f198e22SChangbin Du 0) 0.571 us | page_add_file_rmap(); 31891f198e22SChangbin Du 0) 0.526 us | native_set_pte_at(); 31901f198e22SChangbin Du 0) 0.586 us | _spin_unlock(); 31911f198e22SChangbin Du 0) | unlock_page() { 31921f198e22SChangbin Du 0) 0.533 us | page_waitqueue(); 31931f198e22SChangbin Du 0) 0.638 us | __wake_up_bit(); 31941f198e22SChangbin Du 0) 2.793 us | } 31951f198e22SChangbin Du 0) + 14.012 us | } 31961f198e22SChangbin Du 31971f198e22SChangbin DuYou can also expand several functions at once:: 31981f198e22SChangbin Du 31991f198e22SChangbin Du echo sys_open > set_graph_function 32001f198e22SChangbin Du echo sys_close >> set_graph_function 32011f198e22SChangbin Du 32021f198e22SChangbin DuNow if you want to go back to trace all functions you can clear 32031f198e22SChangbin Duthis special filter via:: 32041f198e22SChangbin Du 32051f198e22SChangbin Du echo > set_graph_function 32061f198e22SChangbin Du 32071f198e22SChangbin Du 32081f198e22SChangbin Duftrace_enabled 32091f198e22SChangbin Du-------------- 32101f198e22SChangbin Du 32111f198e22SChangbin DuNote, the proc sysctl ftrace_enable is a big on/off switch for the 32121f198e22SChangbin Dufunction tracer. By default it is enabled (when function tracing is 32131f198e22SChangbin Duenabled in the kernel). If it is disabled, all function tracing is 32141f198e22SChangbin Dudisabled. This includes not only the function tracers for ftrace, but 32157162431dSMiroslav Benesalso for any other uses (perf, kprobes, stack tracing, profiling, etc). It 32167162431dSMiroslav Benescannot be disabled if there is a callback with FTRACE_OPS_FL_PERMANENT set 32177162431dSMiroslav Benesregistered. 32181f198e22SChangbin Du 32191f198e22SChangbin DuPlease disable this with care. 32201f198e22SChangbin Du 32211f198e22SChangbin DuThis can be disable (and enabled) with:: 32221f198e22SChangbin Du 32231f198e22SChangbin Du sysctl kernel.ftrace_enabled=0 32241f198e22SChangbin Du sysctl kernel.ftrace_enabled=1 32251f198e22SChangbin Du 32261f198e22SChangbin Du or 32271f198e22SChangbin Du 32281f198e22SChangbin Du echo 0 > /proc/sys/kernel/ftrace_enabled 32291f198e22SChangbin Du echo 1 > /proc/sys/kernel/ftrace_enabled 32301f198e22SChangbin Du 32311f198e22SChangbin Du 32321f198e22SChangbin DuFilter commands 32331f198e22SChangbin Du--------------- 32341f198e22SChangbin Du 32351f198e22SChangbin DuA few commands are supported by the set_ftrace_filter interface. 32361f198e22SChangbin DuTrace commands have the following format:: 32371f198e22SChangbin Du 32381f198e22SChangbin Du <function>:<command>:<parameter> 32391f198e22SChangbin Du 32401f198e22SChangbin DuThe following commands are supported: 32411f198e22SChangbin Du 32421f198e22SChangbin Du- mod: 32431f198e22SChangbin Du This command enables function filtering per module. The 32441f198e22SChangbin Du parameter defines the module. For example, if only the write* 32451f198e22SChangbin Du functions in the ext3 module are desired, run: 32461f198e22SChangbin Du 32471f198e22SChangbin Du echo 'write*:mod:ext3' > set_ftrace_filter 32481f198e22SChangbin Du 32491f198e22SChangbin Du This command interacts with the filter in the same way as 32501f198e22SChangbin Du filtering based on function names. Thus, adding more functions 32511f198e22SChangbin Du in a different module is accomplished by appending (>>) to the 32521f198e22SChangbin Du filter file. Remove specific module functions by prepending 32531f198e22SChangbin Du '!':: 32541f198e22SChangbin Du 32551f198e22SChangbin Du echo '!writeback*:mod:ext3' >> set_ftrace_filter 32561f198e22SChangbin Du 32571f198e22SChangbin Du Mod command supports module globbing. Disable tracing for all 32581f198e22SChangbin Du functions except a specific module:: 32591f198e22SChangbin Du 32601f198e22SChangbin Du echo '!*:mod:!ext3' >> set_ftrace_filter 32611f198e22SChangbin Du 32621f198e22SChangbin Du Disable tracing for all modules, but still trace kernel:: 32631f198e22SChangbin Du 32641f198e22SChangbin Du echo '!*:mod:*' >> set_ftrace_filter 32651f198e22SChangbin Du 32661f198e22SChangbin Du Enable filter only for kernel:: 32671f198e22SChangbin Du 32681f198e22SChangbin Du echo '*write*:mod:!*' >> set_ftrace_filter 32691f198e22SChangbin Du 32701f198e22SChangbin Du Enable filter for module globbing:: 32711f198e22SChangbin Du 32721f198e22SChangbin Du echo '*write*:mod:*snd*' >> set_ftrace_filter 32731f198e22SChangbin Du 32741f198e22SChangbin Du- traceon/traceoff: 32751f198e22SChangbin Du These commands turn tracing on and off when the specified 32761f198e22SChangbin Du functions are hit. The parameter determines how many times the 32771f198e22SChangbin Du tracing system is turned on and off. If unspecified, there is 32781f198e22SChangbin Du no limit. For example, to disable tracing when a schedule bug 32791f198e22SChangbin Du is hit the first 5 times, run:: 32801f198e22SChangbin Du 32811f198e22SChangbin Du echo '__schedule_bug:traceoff:5' > set_ftrace_filter 32821f198e22SChangbin Du 32831f198e22SChangbin Du To always disable tracing when __schedule_bug is hit:: 32841f198e22SChangbin Du 32851f198e22SChangbin Du echo '__schedule_bug:traceoff' > set_ftrace_filter 32861f198e22SChangbin Du 32871f198e22SChangbin Du These commands are cumulative whether or not they are appended 32881f198e22SChangbin Du to set_ftrace_filter. To remove a command, prepend it by '!' 32891f198e22SChangbin Du and drop the parameter:: 32901f198e22SChangbin Du 32911f198e22SChangbin Du echo '!__schedule_bug:traceoff:0' > set_ftrace_filter 32921f198e22SChangbin Du 32931f198e22SChangbin Du The above removes the traceoff command for __schedule_bug 32941f198e22SChangbin Du that have a counter. To remove commands without counters:: 32951f198e22SChangbin Du 32961f198e22SChangbin Du echo '!__schedule_bug:traceoff' > set_ftrace_filter 32971f198e22SChangbin Du 32981f198e22SChangbin Du- snapshot: 32991f198e22SChangbin Du Will cause a snapshot to be triggered when the function is hit. 33001f198e22SChangbin Du :: 33011f198e22SChangbin Du 33021f198e22SChangbin Du echo 'native_flush_tlb_others:snapshot' > set_ftrace_filter 33031f198e22SChangbin Du 33041f198e22SChangbin Du To only snapshot once: 33051f198e22SChangbin Du :: 33061f198e22SChangbin Du 33071f198e22SChangbin Du echo 'native_flush_tlb_others:snapshot:1' > set_ftrace_filter 33081f198e22SChangbin Du 33091f198e22SChangbin Du To remove the above commands:: 33101f198e22SChangbin Du 33111f198e22SChangbin Du echo '!native_flush_tlb_others:snapshot' > set_ftrace_filter 33121f198e22SChangbin Du echo '!native_flush_tlb_others:snapshot:0' > set_ftrace_filter 33131f198e22SChangbin Du 33141f198e22SChangbin Du- enable_event/disable_event: 33151f198e22SChangbin Du These commands can enable or disable a trace event. Note, because 33161f198e22SChangbin Du function tracing callbacks are very sensitive, when these commands 33171f198e22SChangbin Du are registered, the trace point is activated, but disabled in 33181f198e22SChangbin Du a "soft" mode. That is, the tracepoint will be called, but 33191f198e22SChangbin Du just will not be traced. The event tracepoint stays in this mode 33201f198e22SChangbin Du as long as there's a command that triggers it. 33211f198e22SChangbin Du :: 33221f198e22SChangbin Du 33231f198e22SChangbin Du echo 'try_to_wake_up:enable_event:sched:sched_switch:2' > \ 33241f198e22SChangbin Du set_ftrace_filter 33251f198e22SChangbin Du 33261f198e22SChangbin Du The format is:: 33271f198e22SChangbin Du 33281f198e22SChangbin Du <function>:enable_event:<system>:<event>[:count] 33291f198e22SChangbin Du <function>:disable_event:<system>:<event>[:count] 33301f198e22SChangbin Du 33311f198e22SChangbin Du To remove the events commands:: 33321f198e22SChangbin Du 33331f198e22SChangbin Du echo '!try_to_wake_up:enable_event:sched:sched_switch:0' > \ 33341f198e22SChangbin Du set_ftrace_filter 33351f198e22SChangbin Du echo '!schedule:disable_event:sched:sched_switch' > \ 33361f198e22SChangbin Du set_ftrace_filter 33371f198e22SChangbin Du 33381f198e22SChangbin Du- dump: 33391f198e22SChangbin Du When the function is hit, it will dump the contents of the ftrace 33401f198e22SChangbin Du ring buffer to the console. This is useful if you need to debug 33411f198e22SChangbin Du something, and want to dump the trace when a certain function 33422a1e03caSAmir Livneh is hit. Perhaps it's a function that is called before a triple 33431f198e22SChangbin Du fault happens and does not allow you to get a regular dump. 33441f198e22SChangbin Du 33451f198e22SChangbin Du- cpudump: 33461f198e22SChangbin Du When the function is hit, it will dump the contents of the ftrace 33471f198e22SChangbin Du ring buffer for the current CPU to the console. Unlike the "dump" 33481f198e22SChangbin Du command, it only prints out the contents of the ring buffer for the 33491f198e22SChangbin Du CPU that executed the function that triggered the dump. 33501f198e22SChangbin Du 33518a2933cfSMasami Hiramatsu- stacktrace: 33528a2933cfSMasami Hiramatsu When the function is hit, a stack trace is recorded. 33538a2933cfSMasami Hiramatsu 33541f198e22SChangbin Dutrace_pipe 33551f198e22SChangbin Du---------- 33561f198e22SChangbin Du 33571f198e22SChangbin DuThe trace_pipe outputs the same content as the trace file, but 33581f198e22SChangbin Duthe effect on the tracing is different. Every read from 33591f198e22SChangbin Dutrace_pipe is consumed. This means that subsequent reads will be 33601f198e22SChangbin Dudifferent. The trace is live. 33611f198e22SChangbin Du:: 33621f198e22SChangbin Du 33631f198e22SChangbin Du # echo function > current_tracer 33641f198e22SChangbin Du # cat trace_pipe > /tmp/trace.out & 33651f198e22SChangbin Du [1] 4153 33661f198e22SChangbin Du # echo 1 > tracing_on 33671f198e22SChangbin Du # usleep 1 33681f198e22SChangbin Du # echo 0 > tracing_on 33691f198e22SChangbin Du # cat trace 33701f198e22SChangbin Du # tracer: function 33711f198e22SChangbin Du # 33721f198e22SChangbin Du # entries-in-buffer/entries-written: 0/0 #P:4 33731f198e22SChangbin Du # 33741f198e22SChangbin Du # _-----=> irqs-off 33751f198e22SChangbin Du # / _----=> need-resched 33761f198e22SChangbin Du # | / _---=> hardirq/softirq 33771f198e22SChangbin Du # || / _--=> preempt-depth 33781f198e22SChangbin Du # ||| / delay 33791f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 33801f198e22SChangbin Du # | | | |||| | | 33811f198e22SChangbin Du 33821f198e22SChangbin Du # 33831f198e22SChangbin Du # cat /tmp/trace.out 33841f198e22SChangbin Du bash-1994 [000] .... 5281.568961: mutex_unlock <-rb_simple_write 33851f198e22SChangbin Du bash-1994 [000] .... 5281.568963: __mutex_unlock_slowpath <-mutex_unlock 33861f198e22SChangbin Du bash-1994 [000] .... 5281.568963: __fsnotify_parent <-fsnotify_modify 33871f198e22SChangbin Du bash-1994 [000] .... 5281.568964: fsnotify <-fsnotify_modify 33881f198e22SChangbin Du bash-1994 [000] .... 5281.568964: __srcu_read_lock <-fsnotify 33891f198e22SChangbin Du bash-1994 [000] .... 5281.568964: add_preempt_count <-__srcu_read_lock 33901f198e22SChangbin Du bash-1994 [000] ...1 5281.568965: sub_preempt_count <-__srcu_read_lock 33911f198e22SChangbin Du bash-1994 [000] .... 5281.568965: __srcu_read_unlock <-fsnotify 33921f198e22SChangbin Du bash-1994 [000] .... 5281.568967: sys_dup2 <-system_call_fastpath 33931f198e22SChangbin Du 33941f198e22SChangbin Du 33951f198e22SChangbin DuNote, reading the trace_pipe file will block until more input is 3396f12fcca6SPeter Wuadded. This is contrary to the trace file. If any process opened 3397f12fcca6SPeter Wuthe trace file for reading, it will actually disable tracing and 3398f12fcca6SPeter Wuprevent new entries from being added. The trace_pipe file does 3399f12fcca6SPeter Wunot have this limitation. 34001f198e22SChangbin Du 34011f198e22SChangbin Dutrace entries 34021f198e22SChangbin Du------------- 34031f198e22SChangbin Du 34041f198e22SChangbin DuHaving too much or not enough data can be troublesome in 34051f198e22SChangbin Dudiagnosing an issue in the kernel. The file buffer_size_kb is 34061f198e22SChangbin Duused to modify the size of the internal trace buffers. The 34071f198e22SChangbin Dunumber listed is the number of entries that can be recorded per 34081f198e22SChangbin DuCPU. To know the full size, multiply the number of possible CPUs 34091f198e22SChangbin Duwith the number of entries. 34101f198e22SChangbin Du:: 34111f198e22SChangbin Du 34121f198e22SChangbin Du # cat buffer_size_kb 34131f198e22SChangbin Du 1408 (units kilobytes) 34141f198e22SChangbin Du 34151f198e22SChangbin DuOr simply read buffer_total_size_kb 34161f198e22SChangbin Du:: 34171f198e22SChangbin Du 34181f198e22SChangbin Du # cat buffer_total_size_kb 34191f198e22SChangbin Du 5632 34201f198e22SChangbin Du 34211f198e22SChangbin DuTo modify the buffer, simple echo in a number (in 1024 byte segments). 34221f198e22SChangbin Du:: 34231f198e22SChangbin Du 34241f198e22SChangbin Du # echo 10000 > buffer_size_kb 34251f198e22SChangbin Du # cat buffer_size_kb 34261f198e22SChangbin Du 10000 (units kilobytes) 34271f198e22SChangbin Du 34281f198e22SChangbin DuIt will try to allocate as much as possible. If you allocate too 34291f198e22SChangbin Dumuch, it can cause Out-Of-Memory to trigger. 34301f198e22SChangbin Du:: 34311f198e22SChangbin Du 34321f198e22SChangbin Du # echo 1000000000000 > buffer_size_kb 34331f198e22SChangbin Du -bash: echo: write error: Cannot allocate memory 34341f198e22SChangbin Du # cat buffer_size_kb 34351f198e22SChangbin Du 85 34361f198e22SChangbin Du 34371f198e22SChangbin DuThe per_cpu buffers can be changed individually as well: 34381f198e22SChangbin Du:: 34391f198e22SChangbin Du 34401f198e22SChangbin Du # echo 10000 > per_cpu/cpu0/buffer_size_kb 34411f198e22SChangbin Du # echo 100 > per_cpu/cpu1/buffer_size_kb 34421f198e22SChangbin Du 34431f198e22SChangbin DuWhen the per_cpu buffers are not the same, the buffer_size_kb 34441f198e22SChangbin Duat the top level will just show an X 34451f198e22SChangbin Du:: 34461f198e22SChangbin Du 34471f198e22SChangbin Du # cat buffer_size_kb 34481f198e22SChangbin Du X 34491f198e22SChangbin Du 34501f198e22SChangbin DuThis is where the buffer_total_size_kb is useful: 34511f198e22SChangbin Du:: 34521f198e22SChangbin Du 34531f198e22SChangbin Du # cat buffer_total_size_kb 34541f198e22SChangbin Du 12916 34551f198e22SChangbin Du 34561f198e22SChangbin DuWriting to the top level buffer_size_kb will reset all the buffers 34571f198e22SChangbin Duto be the same again. 34581f198e22SChangbin Du 34591f198e22SChangbin DuSnapshot 34601f198e22SChangbin Du-------- 34611f198e22SChangbin DuCONFIG_TRACER_SNAPSHOT makes a generic snapshot feature 34621f198e22SChangbin Duavailable to all non latency tracers. (Latency tracers which 34631f198e22SChangbin Durecord max latency, such as "irqsoff" or "wakeup", can't use 34641f198e22SChangbin Duthis feature, since those are already using the snapshot 34651f198e22SChangbin Dumechanism internally.) 34661f198e22SChangbin Du 34671f198e22SChangbin DuSnapshot preserves a current trace buffer at a particular point 34681f198e22SChangbin Duin time without stopping tracing. Ftrace swaps the current 34691f198e22SChangbin Dubuffer with a spare buffer, and tracing continues in the new 34701f198e22SChangbin Ducurrent (=previous spare) buffer. 34711f198e22SChangbin Du 34721f198e22SChangbin DuThe following tracefs files in "tracing" are related to this 34731f198e22SChangbin Dufeature: 34741f198e22SChangbin Du 34751f198e22SChangbin Du snapshot: 34761f198e22SChangbin Du 34771f198e22SChangbin Du This is used to take a snapshot and to read the output 34781f198e22SChangbin Du of the snapshot. Echo 1 into this file to allocate a 34791f198e22SChangbin Du spare buffer and to take a snapshot (swap), then read 34801f198e22SChangbin Du the snapshot from this file in the same format as 34811f198e22SChangbin Du "trace" (described above in the section "The File 34821f198e22SChangbin Du System"). Both reads snapshot and tracing are executable 34831f198e22SChangbin Du in parallel. When the spare buffer is allocated, echoing 34841f198e22SChangbin Du 0 frees it, and echoing else (positive) values clear the 34851f198e22SChangbin Du snapshot contents. 34861f198e22SChangbin Du More details are shown in the table below. 34871f198e22SChangbin Du 34881f198e22SChangbin Du +--------------+------------+------------+------------+ 34891f198e22SChangbin Du |status\\input | 0 | 1 | else | 34901f198e22SChangbin Du +==============+============+============+============+ 34911f198e22SChangbin Du |not allocated |(do nothing)| alloc+swap |(do nothing)| 34921f198e22SChangbin Du +--------------+------------+------------+------------+ 34931f198e22SChangbin Du |allocated | free | swap | clear | 34941f198e22SChangbin Du +--------------+------------+------------+------------+ 34951f198e22SChangbin Du 34961f198e22SChangbin DuHere is an example of using the snapshot feature. 34971f198e22SChangbin Du:: 34981f198e22SChangbin Du 34991f198e22SChangbin Du # echo 1 > events/sched/enable 35001f198e22SChangbin Du # echo 1 > snapshot 35011f198e22SChangbin Du # cat snapshot 35021f198e22SChangbin Du # tracer: nop 35031f198e22SChangbin Du # 35041f198e22SChangbin Du # entries-in-buffer/entries-written: 71/71 #P:8 35051f198e22SChangbin Du # 35061f198e22SChangbin Du # _-----=> irqs-off 35071f198e22SChangbin Du # / _----=> need-resched 35081f198e22SChangbin Du # | / _---=> hardirq/softirq 35091f198e22SChangbin Du # || / _--=> preempt-depth 35101f198e22SChangbin Du # ||| / delay 35111f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 35121f198e22SChangbin Du # | | | |||| | | 35131f198e22SChangbin Du <idle>-0 [005] d... 2440.603828: sched_switch: prev_comm=swapper/5 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=snapshot-test-2 next_pid=2242 next_prio=120 35141f198e22SChangbin Du sleep-2242 [005] d... 2440.603846: sched_switch: prev_comm=snapshot-test-2 prev_pid=2242 prev_prio=120 prev_state=R ==> next_comm=kworker/5:1 next_pid=60 next_prio=120 35151f198e22SChangbin Du [...] 35161f198e22SChangbin Du <idle>-0 [002] d... 2440.707230: sched_switch: prev_comm=swapper/2 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=snapshot-test-2 next_pid=2229 next_prio=120 35171f198e22SChangbin Du 35181f198e22SChangbin Du # cat trace 35191f198e22SChangbin Du # tracer: nop 35201f198e22SChangbin Du # 35211f198e22SChangbin Du # entries-in-buffer/entries-written: 77/77 #P:8 35221f198e22SChangbin Du # 35231f198e22SChangbin Du # _-----=> irqs-off 35241f198e22SChangbin Du # / _----=> need-resched 35251f198e22SChangbin Du # | / _---=> hardirq/softirq 35261f198e22SChangbin Du # || / _--=> preempt-depth 35271f198e22SChangbin Du # ||| / delay 35281f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 35291f198e22SChangbin Du # | | | |||| | | 35301f198e22SChangbin Du <idle>-0 [007] d... 2440.707395: sched_switch: prev_comm=swapper/7 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=snapshot-test-2 next_pid=2243 next_prio=120 35311f198e22SChangbin Du snapshot-test-2-2229 [002] d... 2440.707438: sched_switch: prev_comm=snapshot-test-2 prev_pid=2229 prev_prio=120 prev_state=S ==> next_comm=swapper/2 next_pid=0 next_prio=120 35321f198e22SChangbin Du [...] 35331f198e22SChangbin Du 35341f198e22SChangbin Du 35351f198e22SChangbin DuIf you try to use this snapshot feature when current tracer is 35361f198e22SChangbin Duone of the latency tracers, you will get the following results. 35371f198e22SChangbin Du:: 35381f198e22SChangbin Du 35391f198e22SChangbin Du # echo wakeup > current_tracer 35401f198e22SChangbin Du # echo 1 > snapshot 35411f198e22SChangbin Du bash: echo: write error: Device or resource busy 35421f198e22SChangbin Du # cat snapshot 35431f198e22SChangbin Du cat: snapshot: Device or resource busy 35441f198e22SChangbin Du 35451f198e22SChangbin Du 35461f198e22SChangbin DuInstances 35471f198e22SChangbin Du--------- 3548cc2cf679SHuichun FengIn the tracefs tracing directory, there is a directory called "instances". 35491f198e22SChangbin DuThis directory can have new directories created inside of it using 35501f198e22SChangbin Dumkdir, and removing directories with rmdir. The directory created 35511f198e22SChangbin Duwith mkdir in this directory will already contain files and other 35521f198e22SChangbin Dudirectories after it is created. 35531f198e22SChangbin Du:: 35541f198e22SChangbin Du 35551f198e22SChangbin Du # mkdir instances/foo 35561f198e22SChangbin Du # ls instances/foo 35571f198e22SChangbin Du buffer_size_kb buffer_total_size_kb events free_buffer per_cpu 35581f198e22SChangbin Du set_event snapshot trace trace_clock trace_marker trace_options 35591f198e22SChangbin Du trace_pipe tracing_on 35601f198e22SChangbin Du 35611f198e22SChangbin DuAs you can see, the new directory looks similar to the tracing directory 35621f198e22SChangbin Duitself. In fact, it is very similar, except that the buffer and 35635b8914a6SFrank A. Cancio Belloevents are agnostic from the main directory, or from any other 35641f198e22SChangbin Duinstances that are created. 35651f198e22SChangbin Du 35661f198e22SChangbin DuThe files in the new directory work just like the files with the 35671f198e22SChangbin Dusame name in the tracing directory except the buffer that is used 35681f198e22SChangbin Duis a separate and new buffer. The files affect that buffer but do not 35691f198e22SChangbin Duaffect the main buffer with the exception of trace_options. Currently, 35701f198e22SChangbin Duthe trace_options affect all instances and the top level buffer 35711f198e22SChangbin Duthe same, but this may change in future releases. That is, options 35721f198e22SChangbin Dumay become specific to the instance they reside in. 35731f198e22SChangbin Du 35741f198e22SChangbin DuNotice that none of the function tracer files are there, nor is 35751f198e22SChangbin Ducurrent_tracer and available_tracers. This is because the buffers 35761f198e22SChangbin Ducan currently only have events enabled for them. 35771f198e22SChangbin Du:: 35781f198e22SChangbin Du 35791f198e22SChangbin Du # mkdir instances/foo 35801f198e22SChangbin Du # mkdir instances/bar 35811f198e22SChangbin Du # mkdir instances/zoot 35821f198e22SChangbin Du # echo 100000 > buffer_size_kb 35831f198e22SChangbin Du # echo 1000 > instances/foo/buffer_size_kb 35841f198e22SChangbin Du # echo 5000 > instances/bar/per_cpu/cpu1/buffer_size_kb 35851f198e22SChangbin Du # echo function > current_trace 35861f198e22SChangbin Du # echo 1 > instances/foo/events/sched/sched_wakeup/enable 35871f198e22SChangbin Du # echo 1 > instances/foo/events/sched/sched_wakeup_new/enable 35881f198e22SChangbin Du # echo 1 > instances/foo/events/sched/sched_switch/enable 35891f198e22SChangbin Du # echo 1 > instances/bar/events/irq/enable 35901f198e22SChangbin Du # echo 1 > instances/zoot/events/syscalls/enable 35911f198e22SChangbin Du # cat trace_pipe 35921f198e22SChangbin Du CPU:2 [LOST 11745 EVENTS] 35931f198e22SChangbin Du bash-2044 [002] .... 10594.481032: _raw_spin_lock_irqsave <-get_page_from_freelist 35941f198e22SChangbin Du bash-2044 [002] d... 10594.481032: add_preempt_count <-_raw_spin_lock_irqsave 35951f198e22SChangbin Du bash-2044 [002] d..1 10594.481032: __rmqueue <-get_page_from_freelist 35961f198e22SChangbin Du bash-2044 [002] d..1 10594.481033: _raw_spin_unlock <-get_page_from_freelist 35971f198e22SChangbin Du bash-2044 [002] d..1 10594.481033: sub_preempt_count <-_raw_spin_unlock 35981f198e22SChangbin Du bash-2044 [002] d... 10594.481033: get_pageblock_flags_group <-get_pageblock_migratetype 35991f198e22SChangbin Du bash-2044 [002] d... 10594.481034: __mod_zone_page_state <-get_page_from_freelist 36001f198e22SChangbin Du bash-2044 [002] d... 10594.481034: zone_statistics <-get_page_from_freelist 36011f198e22SChangbin Du bash-2044 [002] d... 10594.481034: __inc_zone_state <-zone_statistics 36021f198e22SChangbin Du bash-2044 [002] d... 10594.481034: __inc_zone_state <-zone_statistics 36031f198e22SChangbin Du bash-2044 [002] .... 10594.481035: arch_dup_task_struct <-copy_process 36041f198e22SChangbin Du [...] 36051f198e22SChangbin Du 36061f198e22SChangbin Du # cat instances/foo/trace_pipe 36071f198e22SChangbin Du bash-1998 [000] d..4 136.676759: sched_wakeup: comm=kworker/0:1 pid=59 prio=120 success=1 target_cpu=000 36081f198e22SChangbin Du bash-1998 [000] dN.4 136.676760: sched_wakeup: comm=bash pid=1998 prio=120 success=1 target_cpu=000 36091f198e22SChangbin Du <idle>-0 [003] d.h3 136.676906: sched_wakeup: comm=rcu_preempt pid=9 prio=120 success=1 target_cpu=003 36101f198e22SChangbin Du <idle>-0 [003] d..3 136.676909: sched_switch: prev_comm=swapper/3 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=rcu_preempt next_pid=9 next_prio=120 36111f198e22SChangbin Du rcu_preempt-9 [003] d..3 136.676916: sched_switch: prev_comm=rcu_preempt prev_pid=9 prev_prio=120 prev_state=S ==> next_comm=swapper/3 next_pid=0 next_prio=120 36121f198e22SChangbin Du bash-1998 [000] d..4 136.677014: sched_wakeup: comm=kworker/0:1 pid=59 prio=120 success=1 target_cpu=000 36131f198e22SChangbin Du bash-1998 [000] dN.4 136.677016: sched_wakeup: comm=bash pid=1998 prio=120 success=1 target_cpu=000 36141f198e22SChangbin Du bash-1998 [000] d..3 136.677018: sched_switch: prev_comm=bash prev_pid=1998 prev_prio=120 prev_state=R+ ==> next_comm=kworker/0:1 next_pid=59 next_prio=120 36151f198e22SChangbin Du kworker/0:1-59 [000] d..4 136.677022: sched_wakeup: comm=sshd pid=1995 prio=120 success=1 target_cpu=001 36161f198e22SChangbin Du kworker/0:1-59 [000] d..3 136.677025: sched_switch: prev_comm=kworker/0:1 prev_pid=59 prev_prio=120 prev_state=S ==> next_comm=bash next_pid=1998 next_prio=120 36171f198e22SChangbin Du [...] 36181f198e22SChangbin Du 36191f198e22SChangbin Du # cat instances/bar/trace_pipe 36201f198e22SChangbin Du migration/1-14 [001] d.h3 138.732674: softirq_raise: vec=3 [action=NET_RX] 36211f198e22SChangbin Du <idle>-0 [001] dNh3 138.732725: softirq_raise: vec=3 [action=NET_RX] 36221f198e22SChangbin Du bash-1998 [000] d.h1 138.733101: softirq_raise: vec=1 [action=TIMER] 36231f198e22SChangbin Du bash-1998 [000] d.h1 138.733102: softirq_raise: vec=9 [action=RCU] 36241f198e22SChangbin Du bash-1998 [000] ..s2 138.733105: softirq_entry: vec=1 [action=TIMER] 36251f198e22SChangbin Du bash-1998 [000] ..s2 138.733106: softirq_exit: vec=1 [action=TIMER] 36261f198e22SChangbin Du bash-1998 [000] ..s2 138.733106: softirq_entry: vec=9 [action=RCU] 36271f198e22SChangbin Du bash-1998 [000] ..s2 138.733109: softirq_exit: vec=9 [action=RCU] 36281f198e22SChangbin Du sshd-1995 [001] d.h1 138.733278: irq_handler_entry: irq=21 name=uhci_hcd:usb4 36291f198e22SChangbin Du sshd-1995 [001] d.h1 138.733280: irq_handler_exit: irq=21 ret=unhandled 36301f198e22SChangbin Du sshd-1995 [001] d.h1 138.733281: irq_handler_entry: irq=21 name=eth0 36311f198e22SChangbin Du sshd-1995 [001] d.h1 138.733283: irq_handler_exit: irq=21 ret=handled 36321f198e22SChangbin Du [...] 36331f198e22SChangbin Du 36341f198e22SChangbin Du # cat instances/zoot/trace 36351f198e22SChangbin Du # tracer: nop 36361f198e22SChangbin Du # 36371f198e22SChangbin Du # entries-in-buffer/entries-written: 18996/18996 #P:4 36381f198e22SChangbin Du # 36391f198e22SChangbin Du # _-----=> irqs-off 36401f198e22SChangbin Du # / _----=> need-resched 36411f198e22SChangbin Du # | / _---=> hardirq/softirq 36421f198e22SChangbin Du # || / _--=> preempt-depth 36431f198e22SChangbin Du # ||| / delay 36441f198e22SChangbin Du # TASK-PID CPU# |||| TIMESTAMP FUNCTION 36451f198e22SChangbin Du # | | | |||| | | 36461f198e22SChangbin Du bash-1998 [000] d... 140.733501: sys_write -> 0x2 36471f198e22SChangbin Du bash-1998 [000] d... 140.733504: sys_dup2(oldfd: a, newfd: 1) 36481f198e22SChangbin Du bash-1998 [000] d... 140.733506: sys_dup2 -> 0x1 36491f198e22SChangbin Du bash-1998 [000] d... 140.733508: sys_fcntl(fd: a, cmd: 1, arg: 0) 36501f198e22SChangbin Du bash-1998 [000] d... 140.733509: sys_fcntl -> 0x1 36511f198e22SChangbin Du bash-1998 [000] d... 140.733510: sys_close(fd: a) 36521f198e22SChangbin Du bash-1998 [000] d... 140.733510: sys_close -> 0x0 36531f198e22SChangbin Du bash-1998 [000] d... 140.733514: sys_rt_sigprocmask(how: 0, nset: 0, oset: 6e2768, sigsetsize: 8) 36541f198e22SChangbin Du bash-1998 [000] d... 140.733515: sys_rt_sigprocmask -> 0x0 36551f198e22SChangbin Du bash-1998 [000] d... 140.733516: sys_rt_sigaction(sig: 2, act: 7fff718846f0, oact: 7fff71884650, sigsetsize: 8) 36561f198e22SChangbin Du bash-1998 [000] d... 140.733516: sys_rt_sigaction -> 0x0 36571f198e22SChangbin Du 36581f198e22SChangbin DuYou can see that the trace of the top most trace buffer shows only 36591f198e22SChangbin Duthe function tracing. The foo instance displays wakeups and task 36601f198e22SChangbin Duswitches. 36611f198e22SChangbin Du 36621f198e22SChangbin DuTo remove the instances, simply delete their directories: 36631f198e22SChangbin Du:: 36641f198e22SChangbin Du 36651f198e22SChangbin Du # rmdir instances/foo 36661f198e22SChangbin Du # rmdir instances/bar 36671f198e22SChangbin Du # rmdir instances/zoot 36681f198e22SChangbin Du 36691f198e22SChangbin DuNote, if a process has a trace file open in one of the instance 36701f198e22SChangbin Dudirectories, the rmdir will fail with EBUSY. 36711f198e22SChangbin Du 36721f198e22SChangbin Du 36731f198e22SChangbin DuStack trace 36741f198e22SChangbin Du----------- 36751f198e22SChangbin DuSince the kernel has a fixed sized stack, it is important not to 3676c9b951c3SLin Yu Chenwaste it in functions. A kernel developer must be conscious of 36771f198e22SChangbin Duwhat they allocate on the stack. If they add too much, the system 36781f198e22SChangbin Ducan be in danger of a stack overflow, and corruption will occur, 36791f198e22SChangbin Duusually leading to a system panic. 36801f198e22SChangbin Du 36811f198e22SChangbin DuThere are some tools that check this, usually with interrupts 36821f198e22SChangbin Duperiodically checking usage. But if you can perform a check 36831f198e22SChangbin Duat every function call that will become very useful. As ftrace provides 36841f198e22SChangbin Dua function tracer, it makes it convenient to check the stack size 36851f198e22SChangbin Duat every function call. This is enabled via the stack tracer. 36861f198e22SChangbin Du 36871f198e22SChangbin DuCONFIG_STACK_TRACER enables the ftrace stack tracing functionality. 36881f198e22SChangbin DuTo enable it, write a '1' into /proc/sys/kernel/stack_tracer_enabled. 36891f198e22SChangbin Du:: 36901f198e22SChangbin Du 36911f198e22SChangbin Du # echo 1 > /proc/sys/kernel/stack_tracer_enabled 36921f198e22SChangbin Du 36931f198e22SChangbin DuYou can also enable it from the kernel command line to trace 36941f198e22SChangbin Duthe stack size of the kernel during boot up, by adding "stacktrace" 36951f198e22SChangbin Duto the kernel command line parameter. 36961f198e22SChangbin Du 36971f198e22SChangbin DuAfter running it for a few minutes, the output looks like: 36981f198e22SChangbin Du:: 36991f198e22SChangbin Du 37001f198e22SChangbin Du # cat stack_max_size 37011f198e22SChangbin Du 2928 37021f198e22SChangbin Du 37031f198e22SChangbin Du # cat stack_trace 37041f198e22SChangbin Du Depth Size Location (18 entries) 37051f198e22SChangbin Du ----- ---- -------- 37061f198e22SChangbin Du 0) 2928 224 update_sd_lb_stats+0xbc/0x4ac 37071f198e22SChangbin Du 1) 2704 160 find_busiest_group+0x31/0x1f1 37081f198e22SChangbin Du 2) 2544 256 load_balance+0xd9/0x662 37091f198e22SChangbin Du 3) 2288 80 idle_balance+0xbb/0x130 37101f198e22SChangbin Du 4) 2208 128 __schedule+0x26e/0x5b9 37111f198e22SChangbin Du 5) 2080 16 schedule+0x64/0x66 37121f198e22SChangbin Du 6) 2064 128 schedule_timeout+0x34/0xe0 37131f198e22SChangbin Du 7) 1936 112 wait_for_common+0x97/0xf1 37141f198e22SChangbin Du 8) 1824 16 wait_for_completion+0x1d/0x1f 37151f198e22SChangbin Du 9) 1808 128 flush_work+0xfe/0x119 37161f198e22SChangbin Du 10) 1680 16 tty_flush_to_ldisc+0x1e/0x20 37171f198e22SChangbin Du 11) 1664 48 input_available_p+0x1d/0x5c 37181f198e22SChangbin Du 12) 1616 48 n_tty_poll+0x6d/0x134 37191f198e22SChangbin Du 13) 1568 64 tty_poll+0x64/0x7f 37201f198e22SChangbin Du 14) 1504 880 do_select+0x31e/0x511 37211f198e22SChangbin Du 15) 624 400 core_sys_select+0x177/0x216 37221f198e22SChangbin Du 16) 224 96 sys_select+0x91/0xb9 37231f198e22SChangbin Du 17) 128 128 system_call_fastpath+0x16/0x1b 37241f198e22SChangbin Du 37251f198e22SChangbin DuNote, if -mfentry is being used by gcc, functions get traced before 37261f198e22SChangbin Duthey set up the stack frame. This means that leaf level functions 37271f198e22SChangbin Duare not tested by the stack tracer when -mfentry is used. 37281f198e22SChangbin Du 37291f198e22SChangbin DuCurrently, -mfentry is used by gcc 4.6.0 and above on x86 only. 37301f198e22SChangbin Du 37311f198e22SChangbin DuMore 37321f198e22SChangbin Du---- 37331f198e22SChangbin DuMore details can be found in the source code, in the `kernel/trace/*.c` files. 3734