ftrace.rst 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366
  1. ========================
  2. ftrace - Function Tracer
  3. ========================
  4. Copyright 2008 Red Hat Inc.
  5. :Author: Steven Rostedt <srostedt@redhat.com>
  6. :License: The GNU Free Documentation License, Version 1.2
  7. (dual licensed under the GPL v2)
  8. :Original Reviewers: Elias Oltmanns, Randy Dunlap, Andrew Morton,
  9. John Kacur, and David Teigland.
  10. - Written for: 2.6.28-rc2
  11. - Updated for: 3.10
  12. - Updated for: 4.13 - Copyright 2017 VMware Inc. Steven Rostedt
  13. - Converted to rst format - Changbin Du <changbin.du@intel.com>
  14. Introduction
  15. ------------
  16. Ftrace is an internal tracer designed to help out developers and
  17. designers of systems to find what is going on inside the kernel.
  18. It can be used for debugging or analyzing latencies and
  19. performance issues that take place outside of user-space.
  20. Although ftrace is typically considered the function tracer, it
  21. is really a frame work of several assorted tracing utilities.
  22. There's latency tracing to examine what occurs between interrupts
  23. disabled and enabled, as well as for preemption and from a time
  24. a task is woken to the task is actually scheduled in.
  25. One of the most common uses of ftrace is the event tracing.
  26. Through out the kernel is hundreds of static event points that
  27. can be enabled via the tracefs file system to see what is
  28. going on in certain parts of the kernel.
  29. See events.txt for more information.
  30. Implementation Details
  31. ----------------------
  32. See :doc:`ftrace-design` for details for arch porters and such.
  33. The File System
  34. ---------------
  35. Ftrace uses the tracefs file system to hold the control files as
  36. well as the files to display output.
  37. When tracefs is configured into the kernel (which selecting any ftrace
  38. option will do) the directory /sys/kernel/tracing will be created. To mount
  39. this directory, you can add to your /etc/fstab file::
  40. tracefs /sys/kernel/tracing tracefs defaults 0 0
  41. Or you can mount it at run time with::
  42. mount -t tracefs nodev /sys/kernel/tracing
  43. For quicker access to that directory you may want to make a soft link to
  44. it::
  45. ln -s /sys/kernel/tracing /tracing
  46. .. attention::
  47. Before 4.1, all ftrace tracing control files were within the debugfs
  48. file system, which is typically located at /sys/kernel/debug/tracing.
  49. For backward compatibility, when mounting the debugfs file system,
  50. the tracefs file system will be automatically mounted at:
  51. /sys/kernel/debug/tracing
  52. All files located in the tracefs file system will be located in that
  53. debugfs file system directory as well.
  54. .. attention::
  55. Any selected ftrace option will also create the tracefs file system.
  56. The rest of the document will assume that you are in the ftrace directory
  57. (cd /sys/kernel/tracing) and will only concentrate on the files within that
  58. directory and not distract from the content with the extended
  59. "/sys/kernel/tracing" path name.
  60. That's it! (assuming that you have ftrace configured into your kernel)
  61. After mounting tracefs you will have access to the control and output files
  62. of ftrace. Here is a list of some of the key files:
  63. Note: all time values are in microseconds.
  64. current_tracer:
  65. This is used to set or display the current tracer
  66. that is configured.
  67. available_tracers:
  68. This holds the different types of tracers that
  69. have been compiled into the kernel. The
  70. tracers listed here can be configured by
  71. echoing their name into current_tracer.
  72. tracing_on:
  73. This sets or displays whether writing to the trace
  74. ring buffer is enabled. Echo 0 into this file to disable
  75. the tracer or 1 to enable it. Note, this only disables
  76. writing to the ring buffer, the tracing overhead may
  77. still be occurring.
  78. The kernel function tracing_off() can be used within the
  79. kernel to disable writing to the ring buffer, which will
  80. set this file to "0". User space can re-enable tracing by
  81. echoing "1" into the file.
  82. Note, the function and event trigger "traceoff" will also
  83. set this file to zero and stop tracing. Which can also
  84. be re-enabled by user space using this file.
  85. trace:
  86. This file holds the output of the trace in a human
  87. readable format (described below). Note, tracing is temporarily
  88. disabled while this file is being read (opened).
  89. trace_pipe:
  90. The output is the same as the "trace" file but this
  91. file is meant to be streamed with live tracing.
  92. Reads from this file will block until new data is
  93. retrieved. Unlike the "trace" file, this file is a
  94. consumer. This means reading from this file causes
  95. sequential reads to display more current data. Once
  96. data is read from this file, it is consumed, and
  97. will not be read again with a sequential read. The
  98. "trace" file is static, and if the tracer is not
  99. adding more data, it will display the same
  100. information every time it is read. This file will not
  101. disable tracing while being read.
  102. trace_options:
  103. This file lets the user control the amount of data
  104. that is displayed in one of the above output
  105. files. Options also exist to modify how a tracer
  106. or events work (stack traces, timestamps, etc).
  107. options:
  108. This is a directory that has a file for every available
  109. trace option (also in trace_options). Options may also be set
  110. or cleared by writing a "1" or "0" respectively into the
  111. corresponding file with the option name.
  112. tracing_max_latency:
  113. Some of the tracers record the max latency.
  114. For example, the maximum time that interrupts are disabled.
  115. The maximum time is saved in this file. The max trace will also be
  116. stored, and displayed by "trace". A new max trace will only be
  117. recorded if the latency is greater than the value in this file
  118. (in microseconds).
  119. By echoing in a time into this file, no latency will be recorded
  120. unless it is greater than the time in this file.
  121. tracing_thresh:
  122. Some latency tracers will record a trace whenever the
  123. latency is greater than the number in this file.
  124. Only active when the file contains a number greater than 0.
  125. (in microseconds)
  126. buffer_size_kb:
  127. This sets or displays the number of kilobytes each CPU
  128. buffer holds. By default, the trace buffers are the same size
  129. for each CPU. The displayed number is the size of the
  130. CPU buffer and not total size of all buffers. The
  131. trace buffers are allocated in pages (blocks of memory
  132. that the kernel uses for allocation, usually 4 KB in size).
  133. If the last page allocated has room for more bytes
  134. than requested, the rest of the page will be used,
  135. making the actual allocation bigger than requested or shown.
  136. ( Note, the size may not be a multiple of the page size
  137. due to buffer management meta-data. )
  138. Buffer sizes for individual CPUs may vary
  139. (see "per_cpu/cpu0/buffer_size_kb" below), and if they do
  140. this file will show "X".
  141. buffer_total_size_kb:
  142. This displays the total combined size of all the trace buffers.
  143. free_buffer:
  144. If a process is performing tracing, and the ring buffer should be
  145. shrunk "freed" when the process is finished, even if it were to be
  146. killed by a signal, this file can be used for that purpose. On close
  147. of this file, the ring buffer will be resized to its minimum size.
  148. Having a process that is tracing also open this file, when the process
  149. exits its file descriptor for this file will be closed, and in doing so,
  150. the ring buffer will be "freed".
  151. It may also stop tracing if disable_on_free option is set.
  152. tracing_cpumask:
  153. This is a mask that lets the user only trace on specified CPUs.
  154. The format is a hex string representing the CPUs.
  155. set_ftrace_filter:
  156. When dynamic ftrace is configured in (see the
  157. section below "dynamic ftrace"), the code is dynamically
  158. modified (code text rewrite) to disable calling of the
  159. function profiler (mcount). This lets tracing be configured
  160. in with practically no overhead in performance. This also
  161. has a side effect of enabling or disabling specific functions
  162. to be traced. Echoing names of functions into this file
  163. will limit the trace to only those functions.
  164. This influences the tracers "function" and "function_graph"
  165. and thus also function profiling (see "function_profile_enabled").
  166. The functions listed in "available_filter_functions" are what
  167. can be written into this file.
  168. This interface also allows for commands to be used. See the
  169. "Filter commands" section for more details.
  170. set_ftrace_notrace:
  171. This has an effect opposite to that of
  172. set_ftrace_filter. Any function that is added here will not
  173. be traced. If a function exists in both set_ftrace_filter
  174. and set_ftrace_notrace, the function will _not_ be traced.
  175. set_ftrace_pid:
  176. Have the function tracer only trace the threads whose PID are
  177. listed in this file.
  178. If the "function-fork" option is set, then when a task whose
  179. PID is listed in this file forks, the child's PID will
  180. automatically be added to this file, and the child will be
  181. traced by the function tracer as well. This option will also
  182. cause PIDs of tasks that exit to be removed from the file.
  183. set_event_pid:
  184. Have the events only trace a task with a PID listed in this file.
  185. Note, sched_switch and sched_wake_up will also trace events
  186. listed in this file.
  187. To have the PIDs of children of tasks with their PID in this file
  188. added on fork, enable the "event-fork" option. That option will also
  189. cause the PIDs of tasks to be removed from this file when the task
  190. exits.
  191. set_graph_function:
  192. Functions listed in this file will cause the function graph
  193. tracer to only trace these functions and the functions that
  194. they call. (See the section "dynamic ftrace" for more details).
  195. Note, set_ftrace_filter and set_ftrace_notrace still affects
  196. what functions are being traced.
  197. set_graph_notrace:
  198. Similar to set_graph_function, but will disable function graph
  199. tracing when the function is hit until it exits the function.
  200. This makes it possible to ignore tracing functions that are called
  201. by a specific function.
  202. available_filter_functions:
  203. This lists the functions that ftrace has processed and can trace.
  204. These are the function names that you can pass to
  205. "set_ftrace_filter", "set_ftrace_notrace",
  206. "set_graph_function", or "set_graph_notrace".
  207. (See the section "dynamic ftrace" below for more details.)
  208. dyn_ftrace_total_info:
  209. This file is for debugging purposes. The number of functions that
  210. have been converted to nops and are available to be traced.
  211. enabled_functions:
  212. This file is more for debugging ftrace, but can also be useful
  213. in seeing if any function has a callback attached to it.
  214. Not only does the trace infrastructure use ftrace function
  215. trace utility, but other subsystems might too. This file
  216. displays all functions that have a callback attached to them
  217. as well as the number of callbacks that have been attached.
  218. Note, a callback may also call multiple functions which will
  219. not be listed in this count.
  220. If the callback registered to be traced by a function with
  221. the "save regs" attribute (thus even more overhead), a 'R'
  222. will be displayed on the same line as the function that
  223. is returning registers.
  224. If the callback registered to be traced by a function with
  225. the "ip modify" attribute (thus the regs->ip can be changed),
  226. an 'I' will be displayed on the same line as the function that
  227. can be overridden.
  228. If the architecture supports it, it will also show what callback
  229. is being directly called by the function. If the count is greater
  230. than 1 it most likely will be ftrace_ops_list_func().
  231. If the callback of the function jumps to a trampoline that is
  232. specific to a the callback and not the standard trampoline,
  233. its address will be printed as well as the function that the
  234. trampoline calls.
  235. function_profile_enabled:
  236. When set it will enable all functions with either the function
  237. tracer, or if configured, the function graph tracer. It will
  238. keep a histogram of the number of functions that were called
  239. and if the function graph tracer was configured, it will also keep
  240. track of the time spent in those functions. The histogram
  241. content can be displayed in the files:
  242. trace_stat/function<cpu> ( function0, function1, etc).
  243. trace_stat:
  244. A directory that holds different tracing stats.
  245. kprobe_events:
  246. Enable dynamic trace points. See kprobetrace.txt.
  247. kprobe_profile:
  248. Dynamic trace points stats. See kprobetrace.txt.
  249. max_graph_depth:
  250. Used with the function graph tracer. This is the max depth
  251. it will trace into a function. Setting this to a value of
  252. one will show only the first kernel function that is called
  253. from user space.
  254. printk_formats:
  255. This is for tools that read the raw format files. If an event in
  256. the ring buffer references a string, only a pointer to the string
  257. is recorded into the buffer and not the string itself. This prevents
  258. tools from knowing what that string was. This file displays the string
  259. and address for the string allowing tools to map the pointers to what
  260. the strings were.
  261. saved_cmdlines:
  262. Only the pid of the task is recorded in a trace event unless
  263. the event specifically saves the task comm as well. Ftrace
  264. makes a cache of pid mappings to comms to try to display
  265. comms for events. If a pid for a comm is not listed, then
  266. "<...>" is displayed in the output.
  267. If the option "record-cmd" is set to "0", then comms of tasks
  268. will not be saved during recording. By default, it is enabled.
  269. saved_cmdlines_size:
  270. By default, 128 comms are saved (see "saved_cmdlines" above). To
  271. increase or decrease the amount of comms that are cached, echo
  272. in a the number of comms to cache, into this file.
  273. saved_tgids:
  274. If the option "record-tgid" is set, on each scheduling context switch
  275. the Task Group ID of a task is saved in a table mapping the PID of
  276. the thread to its TGID. By default, the "record-tgid" option is
  277. disabled.
  278. snapshot:
  279. This displays the "snapshot" buffer and also lets the user
  280. take a snapshot of the current running trace.
  281. See the "Snapshot" section below for more details.
  282. stack_max_size:
  283. When the stack tracer is activated, this will display the
  284. maximum stack size it has encountered.
  285. See the "Stack Trace" section below.
  286. stack_trace:
  287. This displays the stack back trace of the largest stack
  288. that was encountered when the stack tracer is activated.
  289. See the "Stack Trace" section below.
  290. stack_trace_filter:
  291. This is similar to "set_ftrace_filter" but it limits what
  292. functions the stack tracer will check.
  293. trace_clock:
  294. Whenever an event is recorded into the ring buffer, a
  295. "timestamp" is added. This stamp comes from a specified
  296. clock. By default, ftrace uses the "local" clock. This
  297. clock is very fast and strictly per cpu, but on some
  298. systems it may not be monotonic with respect to other
  299. CPUs. In other words, the local clocks may not be in sync
  300. with local clocks on other CPUs.
  301. Usual clocks for tracing::
  302. # cat trace_clock
  303. [local] global counter x86-tsc
  304. The clock with the square brackets around it is the one in effect.
  305. local:
  306. Default clock, but may not be in sync across CPUs
  307. global:
  308. This clock is in sync with all CPUs but may
  309. be a bit slower than the local clock.
  310. counter:
  311. This is not a clock at all, but literally an atomic
  312. counter. It counts up one by one, but is in sync
  313. with all CPUs. This is useful when you need to
  314. know exactly the order events occurred with respect to
  315. each other on different CPUs.
  316. uptime:
  317. This uses the jiffies counter and the time stamp
  318. is relative to the time since boot up.
  319. perf:
  320. This makes ftrace use the same clock that perf uses.
  321. Eventually perf will be able to read ftrace buffers
  322. and this will help out in interleaving the data.
  323. x86-tsc:
  324. Architectures may define their own clocks. For
  325. example, x86 uses its own TSC cycle clock here.
  326. ppc-tb:
  327. This uses the powerpc timebase register value.
  328. This is in sync across CPUs and can also be used
  329. to correlate events across hypervisor/guest if
  330. tb_offset is known.
  331. mono:
  332. This uses the fast monotonic clock (CLOCK_MONOTONIC)
  333. which is monotonic and is subject to NTP rate adjustments.
  334. mono_raw:
  335. This is the raw monotonic clock (CLOCK_MONOTONIC_RAW)
  336. which is montonic but is not subject to any rate adjustments
  337. and ticks at the same rate as the hardware clocksource.
  338. boot:
  339. This is the boot clock (CLOCK_BOOTTIME) and is based on the
  340. fast monotonic clock, but also accounts for time spent in
  341. suspend. Since the clock access is designed for use in
  342. tracing in the suspend path, some side effects are possible
  343. if clock is accessed after the suspend time is accounted before
  344. the fast mono clock is updated. In this case, the clock update
  345. appears to happen slightly sooner than it normally would have.
  346. Also on 32-bit systems, it's possible that the 64-bit boot offset
  347. sees a partial update. These effects are rare and post
  348. processing should be able to handle them. See comments in the
  349. ktime_get_boot_fast_ns() function for more information.
  350. To set a clock, simply echo the clock name into this file::
  351. # echo global > trace_clock
  352. trace_marker:
  353. This is a very useful file for synchronizing user space
  354. with events happening in the kernel. Writing strings into
  355. this file will be written into the ftrace buffer.
  356. It is useful in applications to open this file at the start
  357. of the application and just reference the file descriptor
  358. for the file::
  359. void trace_write(const char *fmt, ...)
  360. {
  361. va_list ap;
  362. char buf[256];
  363. int n;
  364. if (trace_fd < 0)
  365. return;
  366. va_start(ap, fmt);
  367. n = vsnprintf(buf, 256, fmt, ap);
  368. va_end(ap);
  369. write(trace_fd, buf, n);
  370. }
  371. start::
  372. trace_fd = open("trace_marker", WR_ONLY);
  373. Note: Writing into the trace_marker file can also initiate triggers
  374. that are written into /sys/kernel/tracing/events/ftrace/print/trigger
  375. See "Event triggers" in Documentation/trace/events.rst and an
  376. example in Documentation/trace/histogram.rst (Section 3.)
  377. trace_marker_raw:
  378. This is similar to trace_marker above, but is meant for for binary data
  379. to be written to it, where a tool can be used to parse the data
  380. from trace_pipe_raw.
  381. uprobe_events:
  382. Add dynamic tracepoints in programs.
  383. See uprobetracer.txt
  384. uprobe_profile:
  385. Uprobe statistics. See uprobetrace.txt
  386. instances:
  387. This is a way to make multiple trace buffers where different
  388. events can be recorded in different buffers.
  389. See "Instances" section below.
  390. events:
  391. This is the trace event directory. It holds event tracepoints
  392. (also known as static tracepoints) that have been compiled
  393. into the kernel. It shows what event tracepoints exist
  394. and how they are grouped by system. There are "enable"
  395. files at various levels that can enable the tracepoints
  396. when a "1" is written to them.
  397. See events.txt for more information.
  398. set_event:
  399. By echoing in the event into this file, will enable that event.
  400. See events.txt for more information.
  401. available_events:
  402. A list of events that can be enabled in tracing.
  403. See events.txt for more information.
  404. timestamp_mode:
  405. Certain tracers may change the timestamp mode used when
  406. logging trace events into the event buffer. Events with
  407. different modes can coexist within a buffer but the mode in
  408. effect when an event is logged determines which timestamp mode
  409. is used for that event. The default timestamp mode is
  410. 'delta'.
  411. Usual timestamp modes for tracing:
  412. # cat timestamp_mode
  413. [delta] absolute
  414. The timestamp mode with the square brackets around it is the
  415. one in effect.
  416. delta: Default timestamp mode - timestamp is a delta against
  417. a per-buffer timestamp.
  418. absolute: The timestamp is a full timestamp, not a delta
  419. against some other value. As such it takes up more
  420. space and is less efficient.
  421. hwlat_detector:
  422. Directory for the Hardware Latency Detector.
  423. See "Hardware Latency Detector" section below.
  424. per_cpu:
  425. This is a directory that contains the trace per_cpu information.
  426. per_cpu/cpu0/buffer_size_kb:
  427. The ftrace buffer is defined per_cpu. That is, there's a separate
  428. buffer for each CPU to allow writes to be done atomically,
  429. and free from cache bouncing. These buffers may have different
  430. size buffers. This file is similar to the buffer_size_kb
  431. file, but it only displays or sets the buffer size for the
  432. specific CPU. (here cpu0).
  433. per_cpu/cpu0/trace:
  434. This is similar to the "trace" file, but it will only display
  435. the data specific for the CPU. If written to, it only clears
  436. the specific CPU buffer.
  437. per_cpu/cpu0/trace_pipe
  438. This is similar to the "trace_pipe" file, and is a consuming
  439. read, but it will only display (and consume) the data specific
  440. for the CPU.
  441. per_cpu/cpu0/trace_pipe_raw
  442. For tools that can parse the ftrace ring buffer binary format,
  443. the trace_pipe_raw file can be used to extract the data
  444. from the ring buffer directly. With the use of the splice()
  445. system call, the buffer data can be quickly transferred to
  446. a file or to the network where a server is collecting the
  447. data.
  448. Like trace_pipe, this is a consuming reader, where multiple
  449. reads will always produce different data.
  450. per_cpu/cpu0/snapshot:
  451. This is similar to the main "snapshot" file, but will only
  452. snapshot the current CPU (if supported). It only displays
  453. the content of the snapshot for a given CPU, and if
  454. written to, only clears this CPU buffer.
  455. per_cpu/cpu0/snapshot_raw:
  456. Similar to the trace_pipe_raw, but will read the binary format
  457. from the snapshot buffer for the given CPU.
  458. per_cpu/cpu0/stats:
  459. This displays certain stats about the ring buffer:
  460. entries:
  461. The number of events that are still in the buffer.
  462. overrun:
  463. The number of lost events due to overwriting when
  464. the buffer was full.
  465. commit overrun:
  466. Should always be zero.
  467. This gets set if so many events happened within a nested
  468. event (ring buffer is re-entrant), that it fills the
  469. buffer and starts dropping events.
  470. bytes:
  471. Bytes actually read (not overwritten).
  472. oldest event ts:
  473. The oldest timestamp in the buffer
  474. now ts:
  475. The current timestamp
  476. dropped events:
  477. Events lost due to overwrite option being off.
  478. read events:
  479. The number of events read.
  480. The Tracers
  481. -----------
  482. Here is the list of current tracers that may be configured.
  483. "function"
  484. Function call tracer to trace all kernel functions.
  485. "function_graph"
  486. Similar to the function tracer except that the
  487. function tracer probes the functions on their entry
  488. whereas the function graph tracer traces on both entry
  489. and exit of the functions. It then provides the ability
  490. to draw a graph of function calls similar to C code
  491. source.
  492. "blk"
  493. The block tracer. The tracer used by the blktrace user
  494. application.
  495. "hwlat"
  496. The Hardware Latency tracer is used to detect if the hardware
  497. produces any latency. See "Hardware Latency Detector" section
  498. below.
  499. "irqsoff"
  500. Traces the areas that disable interrupts and saves
  501. the trace with the longest max latency.
  502. See tracing_max_latency. When a new max is recorded,
  503. it replaces the old trace. It is best to view this
  504. trace with the latency-format option enabled, which
  505. happens automatically when the tracer is selected.
  506. "preemptoff"
  507. Similar to irqsoff but traces and records the amount of
  508. time for which preemption is disabled.
  509. "preemptirqsoff"
  510. Similar to irqsoff and preemptoff, but traces and
  511. records the largest time for which irqs and/or preemption
  512. is disabled.
  513. "wakeup"
  514. Traces and records the max latency that it takes for
  515. the highest priority task to get scheduled after
  516. it has been woken up.
  517. Traces all tasks as an average developer would expect.
  518. "wakeup_rt"
  519. Traces and records the max latency that it takes for just
  520. RT tasks (as the current "wakeup" does). This is useful
  521. for those interested in wake up timings of RT tasks.
  522. "wakeup_dl"
  523. Traces and records the max latency that it takes for
  524. a SCHED_DEADLINE task to be woken (as the "wakeup" and
  525. "wakeup_rt" does).
  526. "mmiotrace"
  527. A special tracer that is used to trace binary module.
  528. It will trace all the calls that a module makes to the
  529. hardware. Everything it writes and reads from the I/O
  530. as well.
  531. "branch"
  532. This tracer can be configured when tracing likely/unlikely
  533. calls within the kernel. It will trace when a likely and
  534. unlikely branch is hit and if it was correct in its prediction
  535. of being correct.
  536. "nop"
  537. This is the "trace nothing" tracer. To remove all
  538. tracers from tracing simply echo "nop" into
  539. current_tracer.
  540. Examples of using the tracer
  541. ----------------------------
  542. Here are typical examples of using the tracers when controlling
  543. them only with the tracefs interface (without using any
  544. user-land utilities).
  545. Output format:
  546. --------------
  547. Here is an example of the output format of the file "trace"::
  548. # tracer: function
  549. #
  550. # entries-in-buffer/entries-written: 140080/250280 #P:4
  551. #
  552. # _-----=> irqs-off
  553. # / _----=> need-resched
  554. # | / _---=> hardirq/softirq
  555. # || / _--=> preempt-depth
  556. # ||| / delay
  557. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  558. # | | | |||| | |
  559. bash-1977 [000] .... 17284.993652: sys_close <-system_call_fastpath
  560. bash-1977 [000] .... 17284.993653: __close_fd <-sys_close
  561. bash-1977 [000] .... 17284.993653: _raw_spin_lock <-__close_fd
  562. sshd-1974 [003] .... 17284.993653: __srcu_read_unlock <-fsnotify
  563. bash-1977 [000] .... 17284.993654: add_preempt_count <-_raw_spin_lock
  564. bash-1977 [000] ...1 17284.993655: _raw_spin_unlock <-__close_fd
  565. bash-1977 [000] ...1 17284.993656: sub_preempt_count <-_raw_spin_unlock
  566. bash-1977 [000] .... 17284.993657: filp_close <-__close_fd
  567. bash-1977 [000] .... 17284.993657: dnotify_flush <-filp_close
  568. sshd-1974 [003] .... 17284.993658: sys_select <-system_call_fastpath
  569. ....
  570. A header is printed with the tracer name that is represented by
  571. the trace. In this case the tracer is "function". Then it shows the
  572. number of events in the buffer as well as the total number of entries
  573. that were written. The difference is the number of entries that were
  574. lost due to the buffer filling up (250280 - 140080 = 110200 events
  575. lost).
  576. The header explains the content of the events. Task name "bash", the task
  577. PID "1977", the CPU that it was running on "000", the latency format
  578. (explained below), the timestamp in <secs>.<usecs> format, the
  579. function name that was traced "sys_close" and the parent function that
  580. called this function "system_call_fastpath". The timestamp is the time
  581. at which the function was entered.
  582. Latency trace format
  583. --------------------
  584. When the latency-format option is enabled or when one of the latency
  585. tracers is set, the trace file gives somewhat more information to see
  586. why a latency happened. Here is a typical trace::
  587. # tracer: irqsoff
  588. #
  589. # irqsoff latency trace v1.1.5 on 3.8.0-test+
  590. # --------------------------------------------------------------------
  591. # latency: 259 us, #4/4, CPU#2 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  592. # -----------------
  593. # | task: ps-6143 (uid:0 nice:0 policy:0 rt_prio:0)
  594. # -----------------
  595. # => started at: __lock_task_sighand
  596. # => ended at: _raw_spin_unlock_irqrestore
  597. #
  598. #
  599. # _------=> CPU#
  600. # / _-----=> irqs-off
  601. # | / _----=> need-resched
  602. # || / _---=> hardirq/softirq
  603. # ||| / _--=> preempt-depth
  604. # |||| / delay
  605. # cmd pid ||||| time | caller
  606. # \ / ||||| \ | /
  607. ps-6143 2d... 0us!: trace_hardirqs_off <-__lock_task_sighand
  608. ps-6143 2d..1 259us+: trace_hardirqs_on <-_raw_spin_unlock_irqrestore
  609. ps-6143 2d..1 263us+: time_hardirqs_on <-_raw_spin_unlock_irqrestore
  610. ps-6143 2d..1 306us : <stack trace>
  611. => trace_hardirqs_on_caller
  612. => trace_hardirqs_on
  613. => _raw_spin_unlock_irqrestore
  614. => do_task_stat
  615. => proc_tgid_stat
  616. => proc_single_show
  617. => seq_read
  618. => vfs_read
  619. => sys_read
  620. => system_call_fastpath
  621. This shows that the current tracer is "irqsoff" tracing the time
  622. for which interrupts were disabled. It gives the trace version (which
  623. never changes) and the version of the kernel upon which this was executed on
  624. (3.8). Then it displays the max latency in microseconds (259 us). The number
  625. of trace entries displayed and the total number (both are four: #4/4).
  626. VP, KP, SP, and HP are always zero and are reserved for later use.
  627. #P is the number of online CPUs (#P:4).
  628. The task is the process that was running when the latency
  629. occurred. (ps pid: 6143).
  630. The start and stop (the functions in which the interrupts were
  631. disabled and enabled respectively) that caused the latencies:
  632. - __lock_task_sighand is where the interrupts were disabled.
  633. - _raw_spin_unlock_irqrestore is where they were enabled again.
  634. The next lines after the header are the trace itself. The header
  635. explains which is which.
  636. cmd: The name of the process in the trace.
  637. pid: The PID of that process.
  638. CPU#: The CPU which the process was running on.
  639. irqs-off: 'd' interrupts are disabled. '.' otherwise.
  640. .. caution:: If the architecture does not support a way to
  641. read the irq flags variable, an 'X' will always
  642. be printed here.
  643. need-resched:
  644. - 'N' both TIF_NEED_RESCHED and PREEMPT_NEED_RESCHED is set,
  645. - 'n' only TIF_NEED_RESCHED is set,
  646. - 'p' only PREEMPT_NEED_RESCHED is set,
  647. - '.' otherwise.
  648. hardirq/softirq:
  649. - 'Z' - NMI occurred inside a hardirq
  650. - 'z' - NMI is running
  651. - 'H' - hard irq occurred inside a softirq.
  652. - 'h' - hard irq is running
  653. - 's' - soft irq is running
  654. - '.' - normal context.
  655. preempt-depth: The level of preempt_disabled
  656. The above is mostly meaningful for kernel developers.
  657. time:
  658. When the latency-format option is enabled, the trace file
  659. output includes a timestamp relative to the start of the
  660. trace. This differs from the output when latency-format
  661. is disabled, which includes an absolute timestamp.
  662. delay:
  663. This is just to help catch your eye a bit better. And
  664. needs to be fixed to be only relative to the same CPU.
  665. The marks are determined by the difference between this
  666. current trace and the next trace.
  667. - '$' - greater than 1 second
  668. - '@' - greater than 100 milisecond
  669. - '*' - greater than 10 milisecond
  670. - '#' - greater than 1000 microsecond
  671. - '!' - greater than 100 microsecond
  672. - '+' - greater than 10 microsecond
  673. - ' ' - less than or equal to 10 microsecond.
  674. The rest is the same as the 'trace' file.
  675. Note, the latency tracers will usually end with a back trace
  676. to easily find where the latency occurred.
  677. trace_options
  678. -------------
  679. The trace_options file (or the options directory) is used to control
  680. what gets printed in the trace output, or manipulate the tracers.
  681. To see what is available, simply cat the file::
  682. cat trace_options
  683. print-parent
  684. nosym-offset
  685. nosym-addr
  686. noverbose
  687. noraw
  688. nohex
  689. nobin
  690. noblock
  691. trace_printk
  692. annotate
  693. nouserstacktrace
  694. nosym-userobj
  695. noprintk-msg-only
  696. context-info
  697. nolatency-format
  698. record-cmd
  699. norecord-tgid
  700. overwrite
  701. nodisable_on_free
  702. irq-info
  703. markers
  704. noevent-fork
  705. function-trace
  706. nofunction-fork
  707. nodisplay-graph
  708. nostacktrace
  709. nobranch
  710. To disable one of the options, echo in the option prepended with
  711. "no"::
  712. echo noprint-parent > trace_options
  713. To enable an option, leave off the "no"::
  714. echo sym-offset > trace_options
  715. Here are the available options:
  716. print-parent
  717. On function traces, display the calling (parent)
  718. function as well as the function being traced.
  719. ::
  720. print-parent:
  721. bash-4000 [01] 1477.606694: simple_strtoul <-kstrtoul
  722. noprint-parent:
  723. bash-4000 [01] 1477.606694: simple_strtoul
  724. sym-offset
  725. Display not only the function name, but also the
  726. offset in the function. For example, instead of
  727. seeing just "ktime_get", you will see
  728. "ktime_get+0xb/0x20".
  729. ::
  730. sym-offset:
  731. bash-4000 [01] 1477.606694: simple_strtoul+0x6/0xa0
  732. sym-addr
  733. This will also display the function address as well
  734. as the function name.
  735. ::
  736. sym-addr:
  737. bash-4000 [01] 1477.606694: simple_strtoul <c0339346>
  738. verbose
  739. This deals with the trace file when the
  740. latency-format option is enabled.
  741. ::
  742. bash 4000 1 0 00000000 00010a95 [58127d26] 1720.415ms \
  743. (+0.000ms): simple_strtoul (kstrtoul)
  744. raw
  745. This will display raw numbers. This option is best for
  746. use with user applications that can translate the raw
  747. numbers better than having it done in the kernel.
  748. hex
  749. Similar to raw, but the numbers will be in a hexadecimal format.
  750. bin
  751. This will print out the formats in raw binary.
  752. block
  753. When set, reading trace_pipe will not block when polled.
  754. trace_printk
  755. Can disable trace_printk() from writing into the buffer.
  756. annotate
  757. It is sometimes confusing when the CPU buffers are full
  758. and one CPU buffer had a lot of events recently, thus
  759. a shorter time frame, were another CPU may have only had
  760. a few events, which lets it have older events. When
  761. the trace is reported, it shows the oldest events first,
  762. and it may look like only one CPU ran (the one with the
  763. oldest events). When the annotate option is set, it will
  764. display when a new CPU buffer started::
  765. <idle>-0 [001] dNs4 21169.031481: wake_up_idle_cpu <-add_timer_on
  766. <idle>-0 [001] dNs4 21169.031482: _raw_spin_unlock_irqrestore <-add_timer_on
  767. <idle>-0 [001] .Ns4 21169.031484: sub_preempt_count <-_raw_spin_unlock_irqrestore
  768. ##### CPU 2 buffer started ####
  769. <idle>-0 [002] .N.1 21169.031484: rcu_idle_exit <-cpu_idle
  770. <idle>-0 [001] .Ns3 21169.031484: _raw_spin_unlock <-clocksource_watchdog
  771. <idle>-0 [001] .Ns3 21169.031485: sub_preempt_count <-_raw_spin_unlock
  772. userstacktrace
  773. This option changes the trace. It records a
  774. stacktrace of the current user space thread after
  775. each trace event.
  776. sym-userobj
  777. when user stacktrace are enabled, look up which
  778. object the address belongs to, and print a
  779. relative address. This is especially useful when
  780. ASLR is on, otherwise you don't get a chance to
  781. resolve the address to object/file/line after
  782. the app is no longer running
  783. The lookup is performed when you read
  784. trace,trace_pipe. Example::
  785. a.out-1623 [000] 40874.465068: /root/a.out[+0x480] <-/root/a.out[+0
  786. x494] <- /root/a.out[+0x4a8] <- /lib/libc-2.7.so[+0x1e1a6]
  787. printk-msg-only
  788. When set, trace_printk()s will only show the format
  789. and not their parameters (if trace_bprintk() or
  790. trace_bputs() was used to save the trace_printk()).
  791. context-info
  792. Show only the event data. Hides the comm, PID,
  793. timestamp, CPU, and other useful data.
  794. latency-format
  795. This option changes the trace output. When it is enabled,
  796. the trace displays additional information about the
  797. latency, as described in "Latency trace format".
  798. record-cmd
  799. When any event or tracer is enabled, a hook is enabled
  800. in the sched_switch trace point to fill comm cache
  801. with mapped pids and comms. But this may cause some
  802. overhead, and if you only care about pids, and not the
  803. name of the task, disabling this option can lower the
  804. impact of tracing. See "saved_cmdlines".
  805. record-tgid
  806. When any event or tracer is enabled, a hook is enabled
  807. in the sched_switch trace point to fill the cache of
  808. mapped Thread Group IDs (TGID) mapping to pids. See
  809. "saved_tgids".
  810. overwrite
  811. This controls what happens when the trace buffer is
  812. full. If "1" (default), the oldest events are
  813. discarded and overwritten. If "0", then the newest
  814. events are discarded.
  815. (see per_cpu/cpu0/stats for overrun and dropped)
  816. disable_on_free
  817. When the free_buffer is closed, tracing will
  818. stop (tracing_on set to 0).
  819. irq-info
  820. Shows the interrupt, preempt count, need resched data.
  821. When disabled, the trace looks like::
  822. # tracer: function
  823. #
  824. # entries-in-buffer/entries-written: 144405/9452052 #P:4
  825. #
  826. # TASK-PID CPU# TIMESTAMP FUNCTION
  827. # | | | | |
  828. <idle>-0 [002] 23636.756054: ttwu_do_activate.constprop.89 <-try_to_wake_up
  829. <idle>-0 [002] 23636.756054: activate_task <-ttwu_do_activate.constprop.89
  830. <idle>-0 [002] 23636.756055: enqueue_task <-activate_task
  831. markers
  832. When set, the trace_marker is writable (only by root).
  833. When disabled, the trace_marker will error with EINVAL
  834. on write.
  835. event-fork
  836. When set, tasks with PIDs listed in set_event_pid will have
  837. the PIDs of their children added to set_event_pid when those
  838. tasks fork. Also, when tasks with PIDs in set_event_pid exit,
  839. their PIDs will be removed from the file.
  840. function-trace
  841. The latency tracers will enable function tracing
  842. if this option is enabled (default it is). When
  843. it is disabled, the latency tracers do not trace
  844. functions. This keeps the overhead of the tracer down
  845. when performing latency tests.
  846. function-fork
  847. When set, tasks with PIDs listed in set_ftrace_pid will
  848. have the PIDs of their children added to set_ftrace_pid
  849. when those tasks fork. Also, when tasks with PIDs in
  850. set_ftrace_pid exit, their PIDs will be removed from the
  851. file.
  852. display-graph
  853. When set, the latency tracers (irqsoff, wakeup, etc) will
  854. use function graph tracing instead of function tracing.
  855. stacktrace
  856. When set, a stack trace is recorded after any trace event
  857. is recorded.
  858. branch
  859. Enable branch tracing with the tracer. This enables branch
  860. tracer along with the currently set tracer. Enabling this
  861. with the "nop" tracer is the same as just enabling the
  862. "branch" tracer.
  863. .. tip:: Some tracers have their own options. They only appear in this
  864. file when the tracer is active. They always appear in the
  865. options directory.
  866. Here are the per tracer options:
  867. Options for function tracer:
  868. func_stack_trace
  869. When set, a stack trace is recorded after every
  870. function that is recorded. NOTE! Limit the functions
  871. that are recorded before enabling this, with
  872. "set_ftrace_filter" otherwise the system performance
  873. will be critically degraded. Remember to disable
  874. this option before clearing the function filter.
  875. Options for function_graph tracer:
  876. Since the function_graph tracer has a slightly different output
  877. it has its own options to control what is displayed.
  878. funcgraph-overrun
  879. When set, the "overrun" of the graph stack is
  880. displayed after each function traced. The
  881. overrun, is when the stack depth of the calls
  882. is greater than what is reserved for each task.
  883. Each task has a fixed array of functions to
  884. trace in the call graph. If the depth of the
  885. calls exceeds that, the function is not traced.
  886. The overrun is the number of functions missed
  887. due to exceeding this array.
  888. funcgraph-cpu
  889. When set, the CPU number of the CPU where the trace
  890. occurred is displayed.
  891. funcgraph-overhead
  892. When set, if the function takes longer than
  893. A certain amount, then a delay marker is
  894. displayed. See "delay" above, under the
  895. header description.
  896. funcgraph-proc
  897. Unlike other tracers, the process' command line
  898. is not displayed by default, but instead only
  899. when a task is traced in and out during a context
  900. switch. Enabling this options has the command
  901. of each process displayed at every line.
  902. funcgraph-duration
  903. At the end of each function (the return)
  904. the duration of the amount of time in the
  905. function is displayed in microseconds.
  906. funcgraph-abstime
  907. When set, the timestamp is displayed at each line.
  908. funcgraph-irqs
  909. When disabled, functions that happen inside an
  910. interrupt will not be traced.
  911. funcgraph-tail
  912. When set, the return event will include the function
  913. that it represents. By default this is off, and
  914. only a closing curly bracket "}" is displayed for
  915. the return of a function.
  916. sleep-time
  917. When running function graph tracer, to include
  918. the time a task schedules out in its function.
  919. When enabled, it will account time the task has been
  920. scheduled out as part of the function call.
  921. graph-time
  922. When running function profiler with function graph tracer,
  923. to include the time to call nested functions. When this is
  924. not set, the time reported for the function will only
  925. include the time the function itself executed for, not the
  926. time for functions that it called.
  927. Options for blk tracer:
  928. blk_classic
  929. Shows a more minimalistic output.
  930. irqsoff
  931. -------
  932. When interrupts are disabled, the CPU can not react to any other
  933. external event (besides NMIs and SMIs). This prevents the timer
  934. interrupt from triggering or the mouse interrupt from letting
  935. the kernel know of a new mouse event. The result is a latency
  936. with the reaction time.
  937. The irqsoff tracer tracks the time for which interrupts are
  938. disabled. When a new maximum latency is hit, the tracer saves
  939. the trace leading up to that latency point so that every time a
  940. new maximum is reached, the old saved trace is discarded and the
  941. new trace is saved.
  942. To reset the maximum, echo 0 into tracing_max_latency. Here is
  943. an example::
  944. # echo 0 > options/function-trace
  945. # echo irqsoff > current_tracer
  946. # echo 1 > tracing_on
  947. # echo 0 > tracing_max_latency
  948. # ls -ltr
  949. [...]
  950. # echo 0 > tracing_on
  951. # cat trace
  952. # tracer: irqsoff
  953. #
  954. # irqsoff latency trace v1.1.5 on 3.8.0-test+
  955. # --------------------------------------------------------------------
  956. # latency: 16 us, #4/4, CPU#0 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  957. # -----------------
  958. # | task: swapper/0-0 (uid:0 nice:0 policy:0 rt_prio:0)
  959. # -----------------
  960. # => started at: run_timer_softirq
  961. # => ended at: run_timer_softirq
  962. #
  963. #
  964. # _------=> CPU#
  965. # / _-----=> irqs-off
  966. # | / _----=> need-resched
  967. # || / _---=> hardirq/softirq
  968. # ||| / _--=> preempt-depth
  969. # |||| / delay
  970. # cmd pid ||||| time | caller
  971. # \ / ||||| \ | /
  972. <idle>-0 0d.s2 0us+: _raw_spin_lock_irq <-run_timer_softirq
  973. <idle>-0 0dNs3 17us : _raw_spin_unlock_irq <-run_timer_softirq
  974. <idle>-0 0dNs3 17us+: trace_hardirqs_on <-run_timer_softirq
  975. <idle>-0 0dNs3 25us : <stack trace>
  976. => _raw_spin_unlock_irq
  977. => run_timer_softirq
  978. => __do_softirq
  979. => call_softirq
  980. => do_softirq
  981. => irq_exit
  982. => smp_apic_timer_interrupt
  983. => apic_timer_interrupt
  984. => rcu_idle_exit
  985. => cpu_idle
  986. => rest_init
  987. => start_kernel
  988. => x86_64_start_reservations
  989. => x86_64_start_kernel
  990. Here we see that that we had a latency of 16 microseconds (which is
  991. very good). The _raw_spin_lock_irq in run_timer_softirq disabled
  992. interrupts. The difference between the 16 and the displayed
  993. timestamp 25us occurred because the clock was incremented
  994. between the time of recording the max latency and the time of
  995. recording the function that had that latency.
  996. Note the above example had function-trace not set. If we set
  997. function-trace, we get a much larger output::
  998. with echo 1 > options/function-trace
  999. # tracer: irqsoff
  1000. #
  1001. # irqsoff latency trace v1.1.5 on 3.8.0-test+
  1002. # --------------------------------------------------------------------
  1003. # latency: 71 us, #168/168, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1004. # -----------------
  1005. # | task: bash-2042 (uid:0 nice:0 policy:0 rt_prio:0)
  1006. # -----------------
  1007. # => started at: ata_scsi_queuecmd
  1008. # => ended at: ata_scsi_queuecmd
  1009. #
  1010. #
  1011. # _------=> CPU#
  1012. # / _-----=> irqs-off
  1013. # | / _----=> need-resched
  1014. # || / _---=> hardirq/softirq
  1015. # ||| / _--=> preempt-depth
  1016. # |||| / delay
  1017. # cmd pid ||||| time | caller
  1018. # \ / ||||| \ | /
  1019. bash-2042 3d... 0us : _raw_spin_lock_irqsave <-ata_scsi_queuecmd
  1020. bash-2042 3d... 0us : add_preempt_count <-_raw_spin_lock_irqsave
  1021. bash-2042 3d..1 1us : ata_scsi_find_dev <-ata_scsi_queuecmd
  1022. bash-2042 3d..1 1us : __ata_scsi_find_dev <-ata_scsi_find_dev
  1023. bash-2042 3d..1 2us : ata_find_dev.part.14 <-__ata_scsi_find_dev
  1024. bash-2042 3d..1 2us : ata_qc_new_init <-__ata_scsi_queuecmd
  1025. bash-2042 3d..1 3us : ata_sg_init <-__ata_scsi_queuecmd
  1026. bash-2042 3d..1 4us : ata_scsi_rw_xlat <-__ata_scsi_queuecmd
  1027. bash-2042 3d..1 4us : ata_build_rw_tf <-ata_scsi_rw_xlat
  1028. [...]
  1029. bash-2042 3d..1 67us : delay_tsc <-__delay
  1030. bash-2042 3d..1 67us : add_preempt_count <-delay_tsc
  1031. bash-2042 3d..2 67us : sub_preempt_count <-delay_tsc
  1032. bash-2042 3d..1 67us : add_preempt_count <-delay_tsc
  1033. bash-2042 3d..2 68us : sub_preempt_count <-delay_tsc
  1034. bash-2042 3d..1 68us+: ata_bmdma_start <-ata_bmdma_qc_issue
  1035. bash-2042 3d..1 71us : _raw_spin_unlock_irqrestore <-ata_scsi_queuecmd
  1036. bash-2042 3d..1 71us : _raw_spin_unlock_irqrestore <-ata_scsi_queuecmd
  1037. bash-2042 3d..1 72us+: trace_hardirqs_on <-ata_scsi_queuecmd
  1038. bash-2042 3d..1 120us : <stack trace>
  1039. => _raw_spin_unlock_irqrestore
  1040. => ata_scsi_queuecmd
  1041. => scsi_dispatch_cmd
  1042. => scsi_request_fn
  1043. => __blk_run_queue_uncond
  1044. => __blk_run_queue
  1045. => blk_queue_bio
  1046. => generic_make_request
  1047. => submit_bio
  1048. => submit_bh
  1049. => __ext3_get_inode_loc
  1050. => ext3_iget
  1051. => ext3_lookup
  1052. => lookup_real
  1053. => __lookup_hash
  1054. => walk_component
  1055. => lookup_last
  1056. => path_lookupat
  1057. => filename_lookup
  1058. => user_path_at_empty
  1059. => user_path_at
  1060. => vfs_fstatat
  1061. => vfs_stat
  1062. => sys_newstat
  1063. => system_call_fastpath
  1064. Here we traced a 71 microsecond latency. But we also see all the
  1065. functions that were called during that time. Note that by
  1066. enabling function tracing, we incur an added overhead. This
  1067. overhead may extend the latency times. But nevertheless, this
  1068. trace has provided some very helpful debugging information.
  1069. preemptoff
  1070. ----------
  1071. When preemption is disabled, we may be able to receive
  1072. interrupts but the task cannot be preempted and a higher
  1073. priority task must wait for preemption to be enabled again
  1074. before it can preempt a lower priority task.
  1075. The preemptoff tracer traces the places that disable preemption.
  1076. Like the irqsoff tracer, it records the maximum latency for
  1077. which preemption was disabled. The control of preemptoff tracer
  1078. is much like the irqsoff tracer.
  1079. ::
  1080. # echo 0 > options/function-trace
  1081. # echo preemptoff > current_tracer
  1082. # echo 1 > tracing_on
  1083. # echo 0 > tracing_max_latency
  1084. # ls -ltr
  1085. [...]
  1086. # echo 0 > tracing_on
  1087. # cat trace
  1088. # tracer: preemptoff
  1089. #
  1090. # preemptoff latency trace v1.1.5 on 3.8.0-test+
  1091. # --------------------------------------------------------------------
  1092. # latency: 46 us, #4/4, CPU#1 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1093. # -----------------
  1094. # | task: sshd-1991 (uid:0 nice:0 policy:0 rt_prio:0)
  1095. # -----------------
  1096. # => started at: do_IRQ
  1097. # => ended at: do_IRQ
  1098. #
  1099. #
  1100. # _------=> CPU#
  1101. # / _-----=> irqs-off
  1102. # | / _----=> need-resched
  1103. # || / _---=> hardirq/softirq
  1104. # ||| / _--=> preempt-depth
  1105. # |||| / delay
  1106. # cmd pid ||||| time | caller
  1107. # \ / ||||| \ | /
  1108. sshd-1991 1d.h. 0us+: irq_enter <-do_IRQ
  1109. sshd-1991 1d..1 46us : irq_exit <-do_IRQ
  1110. sshd-1991 1d..1 47us+: trace_preempt_on <-do_IRQ
  1111. sshd-1991 1d..1 52us : <stack trace>
  1112. => sub_preempt_count
  1113. => irq_exit
  1114. => do_IRQ
  1115. => ret_from_intr
  1116. This has some more changes. Preemption was disabled when an
  1117. interrupt came in (notice the 'h'), and was enabled on exit.
  1118. But we also see that interrupts have been disabled when entering
  1119. the preempt off section and leaving it (the 'd'). We do not know if
  1120. interrupts were enabled in the mean time or shortly after this
  1121. was over.
  1122. ::
  1123. # tracer: preemptoff
  1124. #
  1125. # preemptoff latency trace v1.1.5 on 3.8.0-test+
  1126. # --------------------------------------------------------------------
  1127. # latency: 83 us, #241/241, CPU#1 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1128. # -----------------
  1129. # | task: bash-1994 (uid:0 nice:0 policy:0 rt_prio:0)
  1130. # -----------------
  1131. # => started at: wake_up_new_task
  1132. # => ended at: task_rq_unlock
  1133. #
  1134. #
  1135. # _------=> CPU#
  1136. # / _-----=> irqs-off
  1137. # | / _----=> need-resched
  1138. # || / _---=> hardirq/softirq
  1139. # ||| / _--=> preempt-depth
  1140. # |||| / delay
  1141. # cmd pid ||||| time | caller
  1142. # \ / ||||| \ | /
  1143. bash-1994 1d..1 0us : _raw_spin_lock_irqsave <-wake_up_new_task
  1144. bash-1994 1d..1 0us : select_task_rq_fair <-select_task_rq
  1145. bash-1994 1d..1 1us : __rcu_read_lock <-select_task_rq_fair
  1146. bash-1994 1d..1 1us : source_load <-select_task_rq_fair
  1147. bash-1994 1d..1 1us : source_load <-select_task_rq_fair
  1148. [...]
  1149. bash-1994 1d..1 12us : irq_enter <-smp_apic_timer_interrupt
  1150. bash-1994 1d..1 12us : rcu_irq_enter <-irq_enter
  1151. bash-1994 1d..1 13us : add_preempt_count <-irq_enter
  1152. bash-1994 1d.h1 13us : exit_idle <-smp_apic_timer_interrupt
  1153. bash-1994 1d.h1 13us : hrtimer_interrupt <-smp_apic_timer_interrupt
  1154. bash-1994 1d.h1 13us : _raw_spin_lock <-hrtimer_interrupt
  1155. bash-1994 1d.h1 14us : add_preempt_count <-_raw_spin_lock
  1156. bash-1994 1d.h2 14us : ktime_get_update_offsets <-hrtimer_interrupt
  1157. [...]
  1158. bash-1994 1d.h1 35us : lapic_next_event <-clockevents_program_event
  1159. bash-1994 1d.h1 35us : irq_exit <-smp_apic_timer_interrupt
  1160. bash-1994 1d.h1 36us : sub_preempt_count <-irq_exit
  1161. bash-1994 1d..2 36us : do_softirq <-irq_exit
  1162. bash-1994 1d..2 36us : __do_softirq <-call_softirq
  1163. bash-1994 1d..2 36us : __local_bh_disable <-__do_softirq
  1164. bash-1994 1d.s2 37us : add_preempt_count <-_raw_spin_lock_irq
  1165. bash-1994 1d.s3 38us : _raw_spin_unlock <-run_timer_softirq
  1166. bash-1994 1d.s3 39us : sub_preempt_count <-_raw_spin_unlock
  1167. bash-1994 1d.s2 39us : call_timer_fn <-run_timer_softirq
  1168. [...]
  1169. bash-1994 1dNs2 81us : cpu_needs_another_gp <-rcu_process_callbacks
  1170. bash-1994 1dNs2 82us : __local_bh_enable <-__do_softirq
  1171. bash-1994 1dNs2 82us : sub_preempt_count <-__local_bh_enable
  1172. bash-1994 1dN.2 82us : idle_cpu <-irq_exit
  1173. bash-1994 1dN.2 83us : rcu_irq_exit <-irq_exit
  1174. bash-1994 1dN.2 83us : sub_preempt_count <-irq_exit
  1175. bash-1994 1.N.1 84us : _raw_spin_unlock_irqrestore <-task_rq_unlock
  1176. bash-1994 1.N.1 84us+: trace_preempt_on <-task_rq_unlock
  1177. bash-1994 1.N.1 104us : <stack trace>
  1178. => sub_preempt_count
  1179. => _raw_spin_unlock_irqrestore
  1180. => task_rq_unlock
  1181. => wake_up_new_task
  1182. => do_fork
  1183. => sys_clone
  1184. => stub_clone
  1185. The above is an example of the preemptoff trace with
  1186. function-trace set. Here we see that interrupts were not disabled
  1187. the entire time. The irq_enter code lets us know that we entered
  1188. an interrupt 'h'. Before that, the functions being traced still
  1189. show that it is not in an interrupt, but we can see from the
  1190. functions themselves that this is not the case.
  1191. preemptirqsoff
  1192. --------------
  1193. Knowing the locations that have interrupts disabled or
  1194. preemption disabled for the longest times is helpful. But
  1195. sometimes we would like to know when either preemption and/or
  1196. interrupts are disabled.
  1197. Consider the following code::
  1198. local_irq_disable();
  1199. call_function_with_irqs_off();
  1200. preempt_disable();
  1201. call_function_with_irqs_and_preemption_off();
  1202. local_irq_enable();
  1203. call_function_with_preemption_off();
  1204. preempt_enable();
  1205. The irqsoff tracer will record the total length of
  1206. call_function_with_irqs_off() and
  1207. call_function_with_irqs_and_preemption_off().
  1208. The preemptoff tracer will record the total length of
  1209. call_function_with_irqs_and_preemption_off() and
  1210. call_function_with_preemption_off().
  1211. But neither will trace the time that interrupts and/or
  1212. preemption is disabled. This total time is the time that we can
  1213. not schedule. To record this time, use the preemptirqsoff
  1214. tracer.
  1215. Again, using this trace is much like the irqsoff and preemptoff
  1216. tracers.
  1217. ::
  1218. # echo 0 > options/function-trace
  1219. # echo preemptirqsoff > current_tracer
  1220. # echo 1 > tracing_on
  1221. # echo 0 > tracing_max_latency
  1222. # ls -ltr
  1223. [...]
  1224. # echo 0 > tracing_on
  1225. # cat trace
  1226. # tracer: preemptirqsoff
  1227. #
  1228. # preemptirqsoff latency trace v1.1.5 on 3.8.0-test+
  1229. # --------------------------------------------------------------------
  1230. # latency: 100 us, #4/4, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1231. # -----------------
  1232. # | task: ls-2230 (uid:0 nice:0 policy:0 rt_prio:0)
  1233. # -----------------
  1234. # => started at: ata_scsi_queuecmd
  1235. # => ended at: ata_scsi_queuecmd
  1236. #
  1237. #
  1238. # _------=> CPU#
  1239. # / _-----=> irqs-off
  1240. # | / _----=> need-resched
  1241. # || / _---=> hardirq/softirq
  1242. # ||| / _--=> preempt-depth
  1243. # |||| / delay
  1244. # cmd pid ||||| time | caller
  1245. # \ / ||||| \ | /
  1246. ls-2230 3d... 0us+: _raw_spin_lock_irqsave <-ata_scsi_queuecmd
  1247. ls-2230 3...1 100us : _raw_spin_unlock_irqrestore <-ata_scsi_queuecmd
  1248. ls-2230 3...1 101us+: trace_preempt_on <-ata_scsi_queuecmd
  1249. ls-2230 3...1 111us : <stack trace>
  1250. => sub_preempt_count
  1251. => _raw_spin_unlock_irqrestore
  1252. => ata_scsi_queuecmd
  1253. => scsi_dispatch_cmd
  1254. => scsi_request_fn
  1255. => __blk_run_queue_uncond
  1256. => __blk_run_queue
  1257. => blk_queue_bio
  1258. => generic_make_request
  1259. => submit_bio
  1260. => submit_bh
  1261. => ext3_bread
  1262. => ext3_dir_bread
  1263. => htree_dirblock_to_tree
  1264. => ext3_htree_fill_tree
  1265. => ext3_readdir
  1266. => vfs_readdir
  1267. => sys_getdents
  1268. => system_call_fastpath
  1269. The trace_hardirqs_off_thunk is called from assembly on x86 when
  1270. interrupts are disabled in the assembly code. Without the
  1271. function tracing, we do not know if interrupts were enabled
  1272. within the preemption points. We do see that it started with
  1273. preemption enabled.
  1274. Here is a trace with function-trace set::
  1275. # tracer: preemptirqsoff
  1276. #
  1277. # preemptirqsoff latency trace v1.1.5 on 3.8.0-test+
  1278. # --------------------------------------------------------------------
  1279. # latency: 161 us, #339/339, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1280. # -----------------
  1281. # | task: ls-2269 (uid:0 nice:0 policy:0 rt_prio:0)
  1282. # -----------------
  1283. # => started at: schedule
  1284. # => ended at: mutex_unlock
  1285. #
  1286. #
  1287. # _------=> CPU#
  1288. # / _-----=> irqs-off
  1289. # | / _----=> need-resched
  1290. # || / _---=> hardirq/softirq
  1291. # ||| / _--=> preempt-depth
  1292. # |||| / delay
  1293. # cmd pid ||||| time | caller
  1294. # \ / ||||| \ | /
  1295. kworker/-59 3...1 0us : __schedule <-schedule
  1296. kworker/-59 3d..1 0us : rcu_preempt_qs <-rcu_note_context_switch
  1297. kworker/-59 3d..1 1us : add_preempt_count <-_raw_spin_lock_irq
  1298. kworker/-59 3d..2 1us : deactivate_task <-__schedule
  1299. kworker/-59 3d..2 1us : dequeue_task <-deactivate_task
  1300. kworker/-59 3d..2 2us : update_rq_clock <-dequeue_task
  1301. kworker/-59 3d..2 2us : dequeue_task_fair <-dequeue_task
  1302. kworker/-59 3d..2 2us : update_curr <-dequeue_task_fair
  1303. kworker/-59 3d..2 2us : update_min_vruntime <-update_curr
  1304. kworker/-59 3d..2 3us : cpuacct_charge <-update_curr
  1305. kworker/-59 3d..2 3us : __rcu_read_lock <-cpuacct_charge
  1306. kworker/-59 3d..2 3us : __rcu_read_unlock <-cpuacct_charge
  1307. kworker/-59 3d..2 3us : update_cfs_rq_blocked_load <-dequeue_task_fair
  1308. kworker/-59 3d..2 4us : clear_buddies <-dequeue_task_fair
  1309. kworker/-59 3d..2 4us : account_entity_dequeue <-dequeue_task_fair
  1310. kworker/-59 3d..2 4us : update_min_vruntime <-dequeue_task_fair
  1311. kworker/-59 3d..2 4us : update_cfs_shares <-dequeue_task_fair
  1312. kworker/-59 3d..2 5us : hrtick_update <-dequeue_task_fair
  1313. kworker/-59 3d..2 5us : wq_worker_sleeping <-__schedule
  1314. kworker/-59 3d..2 5us : kthread_data <-wq_worker_sleeping
  1315. kworker/-59 3d..2 5us : put_prev_task_fair <-__schedule
  1316. kworker/-59 3d..2 6us : pick_next_task_fair <-pick_next_task
  1317. kworker/-59 3d..2 6us : clear_buddies <-pick_next_task_fair
  1318. kworker/-59 3d..2 6us : set_next_entity <-pick_next_task_fair
  1319. kworker/-59 3d..2 6us : update_stats_wait_end <-set_next_entity
  1320. ls-2269 3d..2 7us : finish_task_switch <-__schedule
  1321. ls-2269 3d..2 7us : _raw_spin_unlock_irq <-finish_task_switch
  1322. ls-2269 3d..2 8us : do_IRQ <-ret_from_intr
  1323. ls-2269 3d..2 8us : irq_enter <-do_IRQ
  1324. ls-2269 3d..2 8us : rcu_irq_enter <-irq_enter
  1325. ls-2269 3d..2 9us : add_preempt_count <-irq_enter
  1326. ls-2269 3d.h2 9us : exit_idle <-do_IRQ
  1327. [...]
  1328. ls-2269 3d.h3 20us : sub_preempt_count <-_raw_spin_unlock
  1329. ls-2269 3d.h2 20us : irq_exit <-do_IRQ
  1330. ls-2269 3d.h2 21us : sub_preempt_count <-irq_exit
  1331. ls-2269 3d..3 21us : do_softirq <-irq_exit
  1332. ls-2269 3d..3 21us : __do_softirq <-call_softirq
  1333. ls-2269 3d..3 21us+: __local_bh_disable <-__do_softirq
  1334. ls-2269 3d.s4 29us : sub_preempt_count <-_local_bh_enable_ip
  1335. ls-2269 3d.s5 29us : sub_preempt_count <-_local_bh_enable_ip
  1336. ls-2269 3d.s5 31us : do_IRQ <-ret_from_intr
  1337. ls-2269 3d.s5 31us : irq_enter <-do_IRQ
  1338. ls-2269 3d.s5 31us : rcu_irq_enter <-irq_enter
  1339. [...]
  1340. ls-2269 3d.s5 31us : rcu_irq_enter <-irq_enter
  1341. ls-2269 3d.s5 32us : add_preempt_count <-irq_enter
  1342. ls-2269 3d.H5 32us : exit_idle <-do_IRQ
  1343. ls-2269 3d.H5 32us : handle_irq <-do_IRQ
  1344. ls-2269 3d.H5 32us : irq_to_desc <-handle_irq
  1345. ls-2269 3d.H5 33us : handle_fasteoi_irq <-handle_irq
  1346. [...]
  1347. ls-2269 3d.s5 158us : _raw_spin_unlock_irqrestore <-rtl8139_poll
  1348. ls-2269 3d.s3 158us : net_rps_action_and_irq_enable.isra.65 <-net_rx_action
  1349. ls-2269 3d.s3 159us : __local_bh_enable <-__do_softirq
  1350. ls-2269 3d.s3 159us : sub_preempt_count <-__local_bh_enable
  1351. ls-2269 3d..3 159us : idle_cpu <-irq_exit
  1352. ls-2269 3d..3 159us : rcu_irq_exit <-irq_exit
  1353. ls-2269 3d..3 160us : sub_preempt_count <-irq_exit
  1354. ls-2269 3d... 161us : __mutex_unlock_slowpath <-mutex_unlock
  1355. ls-2269 3d... 162us+: trace_hardirqs_on <-mutex_unlock
  1356. ls-2269 3d... 186us : <stack trace>
  1357. => __mutex_unlock_slowpath
  1358. => mutex_unlock
  1359. => process_output
  1360. => n_tty_write
  1361. => tty_write
  1362. => vfs_write
  1363. => sys_write
  1364. => system_call_fastpath
  1365. This is an interesting trace. It started with kworker running and
  1366. scheduling out and ls taking over. But as soon as ls released the
  1367. rq lock and enabled interrupts (but not preemption) an interrupt
  1368. triggered. When the interrupt finished, it started running softirqs.
  1369. But while the softirq was running, another interrupt triggered.
  1370. When an interrupt is running inside a softirq, the annotation is 'H'.
  1371. wakeup
  1372. ------
  1373. One common case that people are interested in tracing is the
  1374. time it takes for a task that is woken to actually wake up.
  1375. Now for non Real-Time tasks, this can be arbitrary. But tracing
  1376. it none the less can be interesting.
  1377. Without function tracing::
  1378. # echo 0 > options/function-trace
  1379. # echo wakeup > current_tracer
  1380. # echo 1 > tracing_on
  1381. # echo 0 > tracing_max_latency
  1382. # chrt -f 5 sleep 1
  1383. # echo 0 > tracing_on
  1384. # cat trace
  1385. # tracer: wakeup
  1386. #
  1387. # wakeup latency trace v1.1.5 on 3.8.0-test+
  1388. # --------------------------------------------------------------------
  1389. # latency: 15 us, #4/4, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1390. # -----------------
  1391. # | task: kworker/3:1H-312 (uid:0 nice:-20 policy:0 rt_prio:0)
  1392. # -----------------
  1393. #
  1394. # _------=> CPU#
  1395. # / _-----=> irqs-off
  1396. # | / _----=> need-resched
  1397. # || / _---=> hardirq/softirq
  1398. # ||| / _--=> preempt-depth
  1399. # |||| / delay
  1400. # cmd pid ||||| time | caller
  1401. # \ / ||||| \ | /
  1402. <idle>-0 3dNs7 0us : 0:120:R + [003] 312:100:R kworker/3:1H
  1403. <idle>-0 3dNs7 1us+: ttwu_do_activate.constprop.87 <-try_to_wake_up
  1404. <idle>-0 3d..3 15us : __schedule <-schedule
  1405. <idle>-0 3d..3 15us : 0:120:R ==> [003] 312:100:R kworker/3:1H
  1406. The tracer only traces the highest priority task in the system
  1407. to avoid tracing the normal circumstances. Here we see that
  1408. the kworker with a nice priority of -20 (not very nice), took
  1409. just 15 microseconds from the time it woke up, to the time it
  1410. ran.
  1411. Non Real-Time tasks are not that interesting. A more interesting
  1412. trace is to concentrate only on Real-Time tasks.
  1413. wakeup_rt
  1414. ---------
  1415. In a Real-Time environment it is very important to know the
  1416. wakeup time it takes for the highest priority task that is woken
  1417. up to the time that it executes. This is also known as "schedule
  1418. latency". I stress the point that this is about RT tasks. It is
  1419. also important to know the scheduling latency of non-RT tasks,
  1420. but the average schedule latency is better for non-RT tasks.
  1421. Tools like LatencyTop are more appropriate for such
  1422. measurements.
  1423. Real-Time environments are interested in the worst case latency.
  1424. That is the longest latency it takes for something to happen,
  1425. and not the average. We can have a very fast scheduler that may
  1426. only have a large latency once in a while, but that would not
  1427. work well with Real-Time tasks. The wakeup_rt tracer was designed
  1428. to record the worst case wakeups of RT tasks. Non-RT tasks are
  1429. not recorded because the tracer only records one worst case and
  1430. tracing non-RT tasks that are unpredictable will overwrite the
  1431. worst case latency of RT tasks (just run the normal wakeup
  1432. tracer for a while to see that effect).
  1433. Since this tracer only deals with RT tasks, we will run this
  1434. slightly differently than we did with the previous tracers.
  1435. Instead of performing an 'ls', we will run 'sleep 1' under
  1436. 'chrt' which changes the priority of the task.
  1437. ::
  1438. # echo 0 > options/function-trace
  1439. # echo wakeup_rt > current_tracer
  1440. # echo 1 > tracing_on
  1441. # echo 0 > tracing_max_latency
  1442. # chrt -f 5 sleep 1
  1443. # echo 0 > tracing_on
  1444. # cat trace
  1445. # tracer: wakeup
  1446. #
  1447. # tracer: wakeup_rt
  1448. #
  1449. # wakeup_rt latency trace v1.1.5 on 3.8.0-test+
  1450. # --------------------------------------------------------------------
  1451. # latency: 5 us, #4/4, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1452. # -----------------
  1453. # | task: sleep-2389 (uid:0 nice:0 policy:1 rt_prio:5)
  1454. # -----------------
  1455. #
  1456. # _------=> CPU#
  1457. # / _-----=> irqs-off
  1458. # | / _----=> need-resched
  1459. # || / _---=> hardirq/softirq
  1460. # ||| / _--=> preempt-depth
  1461. # |||| / delay
  1462. # cmd pid ||||| time | caller
  1463. # \ / ||||| \ | /
  1464. <idle>-0 3d.h4 0us : 0:120:R + [003] 2389: 94:R sleep
  1465. <idle>-0 3d.h4 1us+: ttwu_do_activate.constprop.87 <-try_to_wake_up
  1466. <idle>-0 3d..3 5us : __schedule <-schedule
  1467. <idle>-0 3d..3 5us : 0:120:R ==> [003] 2389: 94:R sleep
  1468. Running this on an idle system, we see that it only took 5 microseconds
  1469. to perform the task switch. Note, since the trace point in the schedule
  1470. is before the actual "switch", we stop the tracing when the recorded task
  1471. is about to schedule in. This may change if we add a new marker at the
  1472. end of the scheduler.
  1473. Notice that the recorded task is 'sleep' with the PID of 2389
  1474. and it has an rt_prio of 5. This priority is user-space priority
  1475. and not the internal kernel priority. The policy is 1 for
  1476. SCHED_FIFO and 2 for SCHED_RR.
  1477. Note, that the trace data shows the internal priority (99 - rtprio).
  1478. ::
  1479. <idle>-0 3d..3 5us : 0:120:R ==> [003] 2389: 94:R sleep
  1480. The 0:120:R means idle was running with a nice priority of 0 (120 - 120)
  1481. and in the running state 'R'. The sleep task was scheduled in with
  1482. 2389: 94:R. That is the priority is the kernel rtprio (99 - 5 = 94)
  1483. and it too is in the running state.
  1484. Doing the same with chrt -r 5 and function-trace set.
  1485. ::
  1486. echo 1 > options/function-trace
  1487. # tracer: wakeup_rt
  1488. #
  1489. # wakeup_rt latency trace v1.1.5 on 3.8.0-test+
  1490. # --------------------------------------------------------------------
  1491. # latency: 29 us, #85/85, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1492. # -----------------
  1493. # | task: sleep-2448 (uid:0 nice:0 policy:1 rt_prio:5)
  1494. # -----------------
  1495. #
  1496. # _------=> CPU#
  1497. # / _-----=> irqs-off
  1498. # | / _----=> need-resched
  1499. # || / _---=> hardirq/softirq
  1500. # ||| / _--=> preempt-depth
  1501. # |||| / delay
  1502. # cmd pid ||||| time | caller
  1503. # \ / ||||| \ | /
  1504. <idle>-0 3d.h4 1us+: 0:120:R + [003] 2448: 94:R sleep
  1505. <idle>-0 3d.h4 2us : ttwu_do_activate.constprop.87 <-try_to_wake_up
  1506. <idle>-0 3d.h3 3us : check_preempt_curr <-ttwu_do_wakeup
  1507. <idle>-0 3d.h3 3us : resched_curr <-check_preempt_curr
  1508. <idle>-0 3dNh3 4us : task_woken_rt <-ttwu_do_wakeup
  1509. <idle>-0 3dNh3 4us : _raw_spin_unlock <-try_to_wake_up
  1510. <idle>-0 3dNh3 4us : sub_preempt_count <-_raw_spin_unlock
  1511. <idle>-0 3dNh2 5us : ttwu_stat <-try_to_wake_up
  1512. <idle>-0 3dNh2 5us : _raw_spin_unlock_irqrestore <-try_to_wake_up
  1513. <idle>-0 3dNh2 6us : sub_preempt_count <-_raw_spin_unlock_irqrestore
  1514. <idle>-0 3dNh1 6us : _raw_spin_lock <-__run_hrtimer
  1515. <idle>-0 3dNh1 6us : add_preempt_count <-_raw_spin_lock
  1516. <idle>-0 3dNh2 7us : _raw_spin_unlock <-hrtimer_interrupt
  1517. <idle>-0 3dNh2 7us : sub_preempt_count <-_raw_spin_unlock
  1518. <idle>-0 3dNh1 7us : tick_program_event <-hrtimer_interrupt
  1519. <idle>-0 3dNh1 7us : clockevents_program_event <-tick_program_event
  1520. <idle>-0 3dNh1 8us : ktime_get <-clockevents_program_event
  1521. <idle>-0 3dNh1 8us : lapic_next_event <-clockevents_program_event
  1522. <idle>-0 3dNh1 8us : irq_exit <-smp_apic_timer_interrupt
  1523. <idle>-0 3dNh1 9us : sub_preempt_count <-irq_exit
  1524. <idle>-0 3dN.2 9us : idle_cpu <-irq_exit
  1525. <idle>-0 3dN.2 9us : rcu_irq_exit <-irq_exit
  1526. <idle>-0 3dN.2 10us : rcu_eqs_enter_common.isra.45 <-rcu_irq_exit
  1527. <idle>-0 3dN.2 10us : sub_preempt_count <-irq_exit
  1528. <idle>-0 3.N.1 11us : rcu_idle_exit <-cpu_idle
  1529. <idle>-0 3dN.1 11us : rcu_eqs_exit_common.isra.43 <-rcu_idle_exit
  1530. <idle>-0 3.N.1 11us : tick_nohz_idle_exit <-cpu_idle
  1531. <idle>-0 3dN.1 12us : menu_hrtimer_cancel <-tick_nohz_idle_exit
  1532. <idle>-0 3dN.1 12us : ktime_get <-tick_nohz_idle_exit
  1533. <idle>-0 3dN.1 12us : tick_do_update_jiffies64 <-tick_nohz_idle_exit
  1534. <idle>-0 3dN.1 13us : cpu_load_update_nohz <-tick_nohz_idle_exit
  1535. <idle>-0 3dN.1 13us : _raw_spin_lock <-cpu_load_update_nohz
  1536. <idle>-0 3dN.1 13us : add_preempt_count <-_raw_spin_lock
  1537. <idle>-0 3dN.2 13us : __cpu_load_update <-cpu_load_update_nohz
  1538. <idle>-0 3dN.2 14us : sched_avg_update <-__cpu_load_update
  1539. <idle>-0 3dN.2 14us : _raw_spin_unlock <-cpu_load_update_nohz
  1540. <idle>-0 3dN.2 14us : sub_preempt_count <-_raw_spin_unlock
  1541. <idle>-0 3dN.1 15us : calc_load_nohz_stop <-tick_nohz_idle_exit
  1542. <idle>-0 3dN.1 15us : touch_softlockup_watchdog <-tick_nohz_idle_exit
  1543. <idle>-0 3dN.1 15us : hrtimer_cancel <-tick_nohz_idle_exit
  1544. <idle>-0 3dN.1 15us : hrtimer_try_to_cancel <-hrtimer_cancel
  1545. <idle>-0 3dN.1 16us : lock_hrtimer_base.isra.18 <-hrtimer_try_to_cancel
  1546. <idle>-0 3dN.1 16us : _raw_spin_lock_irqsave <-lock_hrtimer_base.isra.18
  1547. <idle>-0 3dN.1 16us : add_preempt_count <-_raw_spin_lock_irqsave
  1548. <idle>-0 3dN.2 17us : __remove_hrtimer <-remove_hrtimer.part.16
  1549. <idle>-0 3dN.2 17us : hrtimer_force_reprogram <-__remove_hrtimer
  1550. <idle>-0 3dN.2 17us : tick_program_event <-hrtimer_force_reprogram
  1551. <idle>-0 3dN.2 18us : clockevents_program_event <-tick_program_event
  1552. <idle>-0 3dN.2 18us : ktime_get <-clockevents_program_event
  1553. <idle>-0 3dN.2 18us : lapic_next_event <-clockevents_program_event
  1554. <idle>-0 3dN.2 19us : _raw_spin_unlock_irqrestore <-hrtimer_try_to_cancel
  1555. <idle>-0 3dN.2 19us : sub_preempt_count <-_raw_spin_unlock_irqrestore
  1556. <idle>-0 3dN.1 19us : hrtimer_forward <-tick_nohz_idle_exit
  1557. <idle>-0 3dN.1 20us : ktime_add_safe <-hrtimer_forward
  1558. <idle>-0 3dN.1 20us : ktime_add_safe <-hrtimer_forward
  1559. <idle>-0 3dN.1 20us : hrtimer_start_range_ns <-hrtimer_start_expires.constprop.11
  1560. <idle>-0 3dN.1 20us : __hrtimer_start_range_ns <-hrtimer_start_range_ns
  1561. <idle>-0 3dN.1 21us : lock_hrtimer_base.isra.18 <-__hrtimer_start_range_ns
  1562. <idle>-0 3dN.1 21us : _raw_spin_lock_irqsave <-lock_hrtimer_base.isra.18
  1563. <idle>-0 3dN.1 21us : add_preempt_count <-_raw_spin_lock_irqsave
  1564. <idle>-0 3dN.2 22us : ktime_add_safe <-__hrtimer_start_range_ns
  1565. <idle>-0 3dN.2 22us : enqueue_hrtimer <-__hrtimer_start_range_ns
  1566. <idle>-0 3dN.2 22us : tick_program_event <-__hrtimer_start_range_ns
  1567. <idle>-0 3dN.2 23us : clockevents_program_event <-tick_program_event
  1568. <idle>-0 3dN.2 23us : ktime_get <-clockevents_program_event
  1569. <idle>-0 3dN.2 23us : lapic_next_event <-clockevents_program_event
  1570. <idle>-0 3dN.2 24us : _raw_spin_unlock_irqrestore <-__hrtimer_start_range_ns
  1571. <idle>-0 3dN.2 24us : sub_preempt_count <-_raw_spin_unlock_irqrestore
  1572. <idle>-0 3dN.1 24us : account_idle_ticks <-tick_nohz_idle_exit
  1573. <idle>-0 3dN.1 24us : account_idle_time <-account_idle_ticks
  1574. <idle>-0 3.N.1 25us : sub_preempt_count <-cpu_idle
  1575. <idle>-0 3.N.. 25us : schedule <-cpu_idle
  1576. <idle>-0 3.N.. 25us : __schedule <-preempt_schedule
  1577. <idle>-0 3.N.. 26us : add_preempt_count <-__schedule
  1578. <idle>-0 3.N.1 26us : rcu_note_context_switch <-__schedule
  1579. <idle>-0 3.N.1 26us : rcu_sched_qs <-rcu_note_context_switch
  1580. <idle>-0 3dN.1 27us : rcu_preempt_qs <-rcu_note_context_switch
  1581. <idle>-0 3.N.1 27us : _raw_spin_lock_irq <-__schedule
  1582. <idle>-0 3dN.1 27us : add_preempt_count <-_raw_spin_lock_irq
  1583. <idle>-0 3dN.2 28us : put_prev_task_idle <-__schedule
  1584. <idle>-0 3dN.2 28us : pick_next_task_stop <-pick_next_task
  1585. <idle>-0 3dN.2 28us : pick_next_task_rt <-pick_next_task
  1586. <idle>-0 3dN.2 29us : dequeue_pushable_task <-pick_next_task_rt
  1587. <idle>-0 3d..3 29us : __schedule <-preempt_schedule
  1588. <idle>-0 3d..3 30us : 0:120:R ==> [003] 2448: 94:R sleep
  1589. This isn't that big of a trace, even with function tracing enabled,
  1590. so I included the entire trace.
  1591. The interrupt went off while when the system was idle. Somewhere
  1592. before task_woken_rt() was called, the NEED_RESCHED flag was set,
  1593. this is indicated by the first occurrence of the 'N' flag.
  1594. Latency tracing and events
  1595. --------------------------
  1596. As function tracing can induce a much larger latency, but without
  1597. seeing what happens within the latency it is hard to know what
  1598. caused it. There is a middle ground, and that is with enabling
  1599. events.
  1600. ::
  1601. # echo 0 > options/function-trace
  1602. # echo wakeup_rt > current_tracer
  1603. # echo 1 > events/enable
  1604. # echo 1 > tracing_on
  1605. # echo 0 > tracing_max_latency
  1606. # chrt -f 5 sleep 1
  1607. # echo 0 > tracing_on
  1608. # cat trace
  1609. # tracer: wakeup_rt
  1610. #
  1611. # wakeup_rt latency trace v1.1.5 on 3.8.0-test+
  1612. # --------------------------------------------------------------------
  1613. # latency: 6 us, #12/12, CPU#2 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
  1614. # -----------------
  1615. # | task: sleep-5882 (uid:0 nice:0 policy:1 rt_prio:5)
  1616. # -----------------
  1617. #
  1618. # _------=> CPU#
  1619. # / _-----=> irqs-off
  1620. # | / _----=> need-resched
  1621. # || / _---=> hardirq/softirq
  1622. # ||| / _--=> preempt-depth
  1623. # |||| / delay
  1624. # cmd pid ||||| time | caller
  1625. # \ / ||||| \ | /
  1626. <idle>-0 2d.h4 0us : 0:120:R + [002] 5882: 94:R sleep
  1627. <idle>-0 2d.h4 0us : ttwu_do_activate.constprop.87 <-try_to_wake_up
  1628. <idle>-0 2d.h4 1us : sched_wakeup: comm=sleep pid=5882 prio=94 success=1 target_cpu=002
  1629. <idle>-0 2dNh2 1us : hrtimer_expire_exit: hrtimer=ffff88007796feb8
  1630. <idle>-0 2.N.2 2us : power_end: cpu_id=2
  1631. <idle>-0 2.N.2 3us : cpu_idle: state=4294967295 cpu_id=2
  1632. <idle>-0 2dN.3 4us : hrtimer_cancel: hrtimer=ffff88007d50d5e0
  1633. <idle>-0 2dN.3 4us : hrtimer_start: hrtimer=ffff88007d50d5e0 function=tick_sched_timer expires=34311211000000 softexpires=34311211000000
  1634. <idle>-0 2.N.2 5us : rcu_utilization: Start context switch
  1635. <idle>-0 2.N.2 5us : rcu_utilization: End context switch
  1636. <idle>-0 2d..3 6us : __schedule <-schedule
  1637. <idle>-0 2d..3 6us : 0:120:R ==> [002] 5882: 94:R sleep
  1638. Hardware Latency Detector
  1639. -------------------------
  1640. The hardware latency detector is executed by enabling the "hwlat" tracer.
  1641. NOTE, this tracer will affect the performance of the system as it will
  1642. periodically make a CPU constantly busy with interrupts disabled.
  1643. ::
  1644. # echo hwlat > current_tracer
  1645. # sleep 100
  1646. # cat trace
  1647. # tracer: hwlat
  1648. #
  1649. # _-----=> irqs-off
  1650. # / _----=> need-resched
  1651. # | / _---=> hardirq/softirq
  1652. # || / _--=> preempt-depth
  1653. # ||| / delay
  1654. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  1655. # | | | |||| | |
  1656. <...>-3638 [001] d... 19452.055471: #1 inner/outer(us): 12/14 ts:1499801089.066141940
  1657. <...>-3638 [003] d... 19454.071354: #2 inner/outer(us): 11/9 ts:1499801091.082164365
  1658. <...>-3638 [002] dn.. 19461.126852: #3 inner/outer(us): 12/9 ts:1499801098.138150062
  1659. <...>-3638 [001] d... 19488.340960: #4 inner/outer(us): 8/12 ts:1499801125.354139633
  1660. <...>-3638 [003] d... 19494.388553: #5 inner/outer(us): 8/12 ts:1499801131.402150961
  1661. <...>-3638 [003] d... 19501.283419: #6 inner/outer(us): 0/12 ts:1499801138.297435289 nmi-total:4 nmi-count:1
  1662. The above output is somewhat the same in the header. All events will have
  1663. interrupts disabled 'd'. Under the FUNCTION title there is:
  1664. #1
  1665. This is the count of events recorded that were greater than the
  1666. tracing_threshold (See below).
  1667. inner/outer(us): 12/14
  1668. This shows two numbers as "inner latency" and "outer latency". The test
  1669. runs in a loop checking a timestamp twice. The latency detected within
  1670. the two timestamps is the "inner latency" and the latency detected
  1671. after the previous timestamp and the next timestamp in the loop is
  1672. the "outer latency".
  1673. ts:1499801089.066141940
  1674. The absolute timestamp that the event happened.
  1675. nmi-total:4 nmi-count:1
  1676. On architectures that support it, if an NMI comes in during the
  1677. test, the time spent in NMI is reported in "nmi-total" (in
  1678. microseconds).
  1679. All architectures that have NMIs will show the "nmi-count" if an
  1680. NMI comes in during the test.
  1681. hwlat files:
  1682. tracing_threshold
  1683. This gets automatically set to "10" to represent 10
  1684. microseconds. This is the threshold of latency that
  1685. needs to be detected before the trace will be recorded.
  1686. Note, when hwlat tracer is finished (another tracer is
  1687. written into "current_tracer"), the original value for
  1688. tracing_threshold is placed back into this file.
  1689. hwlat_detector/width
  1690. The length of time the test runs with interrupts disabled.
  1691. hwlat_detector/window
  1692. The length of time of the window which the test
  1693. runs. That is, the test will run for "width"
  1694. microseconds per "window" microseconds
  1695. tracing_cpumask
  1696. When the test is started. A kernel thread is created that
  1697. runs the test. This thread will alternate between CPUs
  1698. listed in the tracing_cpumask between each period
  1699. (one "window"). To limit the test to specific CPUs
  1700. set the mask in this file to only the CPUs that the test
  1701. should run on.
  1702. function
  1703. --------
  1704. This tracer is the function tracer. Enabling the function tracer
  1705. can be done from the debug file system. Make sure the
  1706. ftrace_enabled is set; otherwise this tracer is a nop.
  1707. See the "ftrace_enabled" section below.
  1708. ::
  1709. # sysctl kernel.ftrace_enabled=1
  1710. # echo function > current_tracer
  1711. # echo 1 > tracing_on
  1712. # usleep 1
  1713. # echo 0 > tracing_on
  1714. # cat trace
  1715. # tracer: function
  1716. #
  1717. # entries-in-buffer/entries-written: 24799/24799 #P:4
  1718. #
  1719. # _-----=> irqs-off
  1720. # / _----=> need-resched
  1721. # | / _---=> hardirq/softirq
  1722. # || / _--=> preempt-depth
  1723. # ||| / delay
  1724. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  1725. # | | | |||| | |
  1726. bash-1994 [002] .... 3082.063030: mutex_unlock <-rb_simple_write
  1727. bash-1994 [002] .... 3082.063031: __mutex_unlock_slowpath <-mutex_unlock
  1728. bash-1994 [002] .... 3082.063031: __fsnotify_parent <-fsnotify_modify
  1729. bash-1994 [002] .... 3082.063032: fsnotify <-fsnotify_modify
  1730. bash-1994 [002] .... 3082.063032: __srcu_read_lock <-fsnotify
  1731. bash-1994 [002] .... 3082.063032: add_preempt_count <-__srcu_read_lock
  1732. bash-1994 [002] ...1 3082.063032: sub_preempt_count <-__srcu_read_lock
  1733. bash-1994 [002] .... 3082.063033: __srcu_read_unlock <-fsnotify
  1734. [...]
  1735. Note: function tracer uses ring buffers to store the above
  1736. entries. The newest data may overwrite the oldest data.
  1737. Sometimes using echo to stop the trace is not sufficient because
  1738. the tracing could have overwritten the data that you wanted to
  1739. record. For this reason, it is sometimes better to disable
  1740. tracing directly from a program. This allows you to stop the
  1741. tracing at the point that you hit the part that you are
  1742. interested in. To disable the tracing directly from a C program,
  1743. something like following code snippet can be used::
  1744. int trace_fd;
  1745. [...]
  1746. int main(int argc, char *argv[]) {
  1747. [...]
  1748. trace_fd = open(tracing_file("tracing_on"), O_WRONLY);
  1749. [...]
  1750. if (condition_hit()) {
  1751. write(trace_fd, "0", 1);
  1752. }
  1753. [...]
  1754. }
  1755. Single thread tracing
  1756. ---------------------
  1757. By writing into set_ftrace_pid you can trace a
  1758. single thread. For example::
  1759. # cat set_ftrace_pid
  1760. no pid
  1761. # echo 3111 > set_ftrace_pid
  1762. # cat set_ftrace_pid
  1763. 3111
  1764. # echo function > current_tracer
  1765. # cat trace | head
  1766. # tracer: function
  1767. #
  1768. # TASK-PID CPU# TIMESTAMP FUNCTION
  1769. # | | | | |
  1770. yum-updatesd-3111 [003] 1637.254676: finish_task_switch <-thread_return
  1771. yum-updatesd-3111 [003] 1637.254681: hrtimer_cancel <-schedule_hrtimeout_range
  1772. yum-updatesd-3111 [003] 1637.254682: hrtimer_try_to_cancel <-hrtimer_cancel
  1773. yum-updatesd-3111 [003] 1637.254683: lock_hrtimer_base <-hrtimer_try_to_cancel
  1774. yum-updatesd-3111 [003] 1637.254685: fget_light <-do_sys_poll
  1775. yum-updatesd-3111 [003] 1637.254686: pipe_poll <-do_sys_poll
  1776. # echo > set_ftrace_pid
  1777. # cat trace |head
  1778. # tracer: function
  1779. #
  1780. # TASK-PID CPU# TIMESTAMP FUNCTION
  1781. # | | | | |
  1782. ##### CPU 3 buffer started ####
  1783. yum-updatesd-3111 [003] 1701.957688: free_poll_entry <-poll_freewait
  1784. yum-updatesd-3111 [003] 1701.957689: remove_wait_queue <-free_poll_entry
  1785. yum-updatesd-3111 [003] 1701.957691: fput <-free_poll_entry
  1786. yum-updatesd-3111 [003] 1701.957692: audit_syscall_exit <-sysret_audit
  1787. yum-updatesd-3111 [003] 1701.957693: path_put <-audit_syscall_exit
  1788. If you want to trace a function when executing, you could use
  1789. something like this simple program.
  1790. ::
  1791. #include <stdio.h>
  1792. #include <stdlib.h>
  1793. #include <sys/types.h>
  1794. #include <sys/stat.h>
  1795. #include <fcntl.h>
  1796. #include <unistd.h>
  1797. #include <string.h>
  1798. #define _STR(x) #x
  1799. #define STR(x) _STR(x)
  1800. #define MAX_PATH 256
  1801. const char *find_tracefs(void)
  1802. {
  1803. static char tracefs[MAX_PATH+1];
  1804. static int tracefs_found;
  1805. char type[100];
  1806. FILE *fp;
  1807. if (tracefs_found)
  1808. return tracefs;
  1809. if ((fp = fopen("/proc/mounts","r")) == NULL) {
  1810. perror("/proc/mounts");
  1811. return NULL;
  1812. }
  1813. while (fscanf(fp, "%*s %"
  1814. STR(MAX_PATH)
  1815. "s %99s %*s %*d %*d\n",
  1816. tracefs, type) == 2) {
  1817. if (strcmp(type, "tracefs") == 0)
  1818. break;
  1819. }
  1820. fclose(fp);
  1821. if (strcmp(type, "tracefs") != 0) {
  1822. fprintf(stderr, "tracefs not mounted");
  1823. return NULL;
  1824. }
  1825. strcat(tracefs, "/tracing/");
  1826. tracefs_found = 1;
  1827. return tracefs;
  1828. }
  1829. const char *tracing_file(const char *file_name)
  1830. {
  1831. static char trace_file[MAX_PATH+1];
  1832. snprintf(trace_file, MAX_PATH, "%s/%s", find_tracefs(), file_name);
  1833. return trace_file;
  1834. }
  1835. int main (int argc, char **argv)
  1836. {
  1837. if (argc < 1)
  1838. exit(-1);
  1839. if (fork() > 0) {
  1840. int fd, ffd;
  1841. char line[64];
  1842. int s;
  1843. ffd = open(tracing_file("current_tracer"), O_WRONLY);
  1844. if (ffd < 0)
  1845. exit(-1);
  1846. write(ffd, "nop", 3);
  1847. fd = open(tracing_file("set_ftrace_pid"), O_WRONLY);
  1848. s = sprintf(line, "%d\n", getpid());
  1849. write(fd, line, s);
  1850. write(ffd, "function", 8);
  1851. close(fd);
  1852. close(ffd);
  1853. execvp(argv[1], argv+1);
  1854. }
  1855. return 0;
  1856. }
  1857. Or this simple script!
  1858. ::
  1859. #!/bin/bash
  1860. tracefs=`sed -ne 's/^tracefs \(.*\) tracefs.*/\1/p' /proc/mounts`
  1861. echo nop > $tracefs/tracing/current_tracer
  1862. echo 0 > $tracefs/tracing/tracing_on
  1863. echo $$ > $tracefs/tracing/set_ftrace_pid
  1864. echo function > $tracefs/tracing/current_tracer
  1865. echo 1 > $tracefs/tracing/tracing_on
  1866. exec "$@"
  1867. function graph tracer
  1868. ---------------------------
  1869. This tracer is similar to the function tracer except that it
  1870. probes a function on its entry and its exit. This is done by
  1871. using a dynamically allocated stack of return addresses in each
  1872. task_struct. On function entry the tracer overwrites the return
  1873. address of each function traced to set a custom probe. Thus the
  1874. original return address is stored on the stack of return address
  1875. in the task_struct.
  1876. Probing on both ends of a function leads to special features
  1877. such as:
  1878. - measure of a function's time execution
  1879. - having a reliable call stack to draw function calls graph
  1880. This tracer is useful in several situations:
  1881. - you want to find the reason of a strange kernel behavior and
  1882. need to see what happens in detail on any areas (or specific
  1883. ones).
  1884. - you are experiencing weird latencies but it's difficult to
  1885. find its origin.
  1886. - you want to find quickly which path is taken by a specific
  1887. function
  1888. - you just want to peek inside a working kernel and want to see
  1889. what happens there.
  1890. ::
  1891. # tracer: function_graph
  1892. #
  1893. # CPU DURATION FUNCTION CALLS
  1894. # | | | | | | |
  1895. 0) | sys_open() {
  1896. 0) | do_sys_open() {
  1897. 0) | getname() {
  1898. 0) | kmem_cache_alloc() {
  1899. 0) 1.382 us | __might_sleep();
  1900. 0) 2.478 us | }
  1901. 0) | strncpy_from_user() {
  1902. 0) | might_fault() {
  1903. 0) 1.389 us | __might_sleep();
  1904. 0) 2.553 us | }
  1905. 0) 3.807 us | }
  1906. 0) 7.876 us | }
  1907. 0) | alloc_fd() {
  1908. 0) 0.668 us | _spin_lock();
  1909. 0) 0.570 us | expand_files();
  1910. 0) 0.586 us | _spin_unlock();
  1911. There are several columns that can be dynamically
  1912. enabled/disabled. You can use every combination of options you
  1913. want, depending on your needs.
  1914. - The cpu number on which the function executed is default
  1915. enabled. It is sometimes better to only trace one cpu (see
  1916. tracing_cpu_mask file) or you might sometimes see unordered
  1917. function calls while cpu tracing switch.
  1918. - hide: echo nofuncgraph-cpu > trace_options
  1919. - show: echo funcgraph-cpu > trace_options
  1920. - The duration (function's time of execution) is displayed on
  1921. the closing bracket line of a function or on the same line
  1922. than the current function in case of a leaf one. It is default
  1923. enabled.
  1924. - hide: echo nofuncgraph-duration > trace_options
  1925. - show: echo funcgraph-duration > trace_options
  1926. - The overhead field precedes the duration field in case of
  1927. reached duration thresholds.
  1928. - hide: echo nofuncgraph-overhead > trace_options
  1929. - show: echo funcgraph-overhead > trace_options
  1930. - depends on: funcgraph-duration
  1931. ie::
  1932. 3) # 1837.709 us | } /* __switch_to */
  1933. 3) | finish_task_switch() {
  1934. 3) 0.313 us | _raw_spin_unlock_irq();
  1935. 3) 3.177 us | }
  1936. 3) # 1889.063 us | } /* __schedule */
  1937. 3) ! 140.417 us | } /* __schedule */
  1938. 3) # 2034.948 us | } /* schedule */
  1939. 3) * 33998.59 us | } /* schedule_preempt_disabled */
  1940. [...]
  1941. 1) 0.260 us | msecs_to_jiffies();
  1942. 1) 0.313 us | __rcu_read_unlock();
  1943. 1) + 61.770 us | }
  1944. 1) + 64.479 us | }
  1945. 1) 0.313 us | rcu_bh_qs();
  1946. 1) 0.313 us | __local_bh_enable();
  1947. 1) ! 217.240 us | }
  1948. 1) 0.365 us | idle_cpu();
  1949. 1) | rcu_irq_exit() {
  1950. 1) 0.417 us | rcu_eqs_enter_common.isra.47();
  1951. 1) 3.125 us | }
  1952. 1) ! 227.812 us | }
  1953. 1) ! 457.395 us | }
  1954. 1) @ 119760.2 us | }
  1955. [...]
  1956. 2) | handle_IPI() {
  1957. 1) 6.979 us | }
  1958. 2) 0.417 us | scheduler_ipi();
  1959. 1) 9.791 us | }
  1960. 1) + 12.917 us | }
  1961. 2) 3.490 us | }
  1962. 1) + 15.729 us | }
  1963. 1) + 18.542 us | }
  1964. 2) $ 3594274 us | }
  1965. Flags::
  1966. + means that the function exceeded 10 usecs.
  1967. ! means that the function exceeded 100 usecs.
  1968. # means that the function exceeded 1000 usecs.
  1969. * means that the function exceeded 10 msecs.
  1970. @ means that the function exceeded 100 msecs.
  1971. $ means that the function exceeded 1 sec.
  1972. - The task/pid field displays the thread cmdline and pid which
  1973. executed the function. It is default disabled.
  1974. - hide: echo nofuncgraph-proc > trace_options
  1975. - show: echo funcgraph-proc > trace_options
  1976. ie::
  1977. # tracer: function_graph
  1978. #
  1979. # CPU TASK/PID DURATION FUNCTION CALLS
  1980. # | | | | | | | | |
  1981. 0) sh-4802 | | d_free() {
  1982. 0) sh-4802 | | call_rcu() {
  1983. 0) sh-4802 | | __call_rcu() {
  1984. 0) sh-4802 | 0.616 us | rcu_process_gp_end();
  1985. 0) sh-4802 | 0.586 us | check_for_new_grace_period();
  1986. 0) sh-4802 | 2.899 us | }
  1987. 0) sh-4802 | 4.040 us | }
  1988. 0) sh-4802 | 5.151 us | }
  1989. 0) sh-4802 | + 49.370 us | }
  1990. - The absolute time field is an absolute timestamp given by the
  1991. system clock since it started. A snapshot of this time is
  1992. given on each entry/exit of functions
  1993. - hide: echo nofuncgraph-abstime > trace_options
  1994. - show: echo funcgraph-abstime > trace_options
  1995. ie::
  1996. #
  1997. # TIME CPU DURATION FUNCTION CALLS
  1998. # | | | | | | | |
  1999. 360.774522 | 1) 0.541 us | }
  2000. 360.774522 | 1) 4.663 us | }
  2001. 360.774523 | 1) 0.541 us | __wake_up_bit();
  2002. 360.774524 | 1) 6.796 us | }
  2003. 360.774524 | 1) 7.952 us | }
  2004. 360.774525 | 1) 9.063 us | }
  2005. 360.774525 | 1) 0.615 us | journal_mark_dirty();
  2006. 360.774527 | 1) 0.578 us | __brelse();
  2007. 360.774528 | 1) | reiserfs_prepare_for_journal() {
  2008. 360.774528 | 1) | unlock_buffer() {
  2009. 360.774529 | 1) | wake_up_bit() {
  2010. 360.774529 | 1) | bit_waitqueue() {
  2011. 360.774530 | 1) 0.594 us | __phys_addr();
  2012. The function name is always displayed after the closing bracket
  2013. for a function if the start of that function is not in the
  2014. trace buffer.
  2015. Display of the function name after the closing bracket may be
  2016. enabled for functions whose start is in the trace buffer,
  2017. allowing easier searching with grep for function durations.
  2018. It is default disabled.
  2019. - hide: echo nofuncgraph-tail > trace_options
  2020. - show: echo funcgraph-tail > trace_options
  2021. Example with nofuncgraph-tail (default)::
  2022. 0) | putname() {
  2023. 0) | kmem_cache_free() {
  2024. 0) 0.518 us | __phys_addr();
  2025. 0) 1.757 us | }
  2026. 0) 2.861 us | }
  2027. Example with funcgraph-tail::
  2028. 0) | putname() {
  2029. 0) | kmem_cache_free() {
  2030. 0) 0.518 us | __phys_addr();
  2031. 0) 1.757 us | } /* kmem_cache_free() */
  2032. 0) 2.861 us | } /* putname() */
  2033. You can put some comments on specific functions by using
  2034. trace_printk() For example, if you want to put a comment inside
  2035. the __might_sleep() function, you just have to include
  2036. <linux/ftrace.h> and call trace_printk() inside __might_sleep()::
  2037. trace_printk("I'm a comment!\n")
  2038. will produce::
  2039. 1) | __might_sleep() {
  2040. 1) | /* I'm a comment! */
  2041. 1) 1.449 us | }
  2042. You might find other useful features for this tracer in the
  2043. following "dynamic ftrace" section such as tracing only specific
  2044. functions or tasks.
  2045. dynamic ftrace
  2046. --------------
  2047. If CONFIG_DYNAMIC_FTRACE is set, the system will run with
  2048. virtually no overhead when function tracing is disabled. The way
  2049. this works is the mcount function call (placed at the start of
  2050. every kernel function, produced by the -pg switch in gcc),
  2051. starts of pointing to a simple return. (Enabling FTRACE will
  2052. include the -pg switch in the compiling of the kernel.)
  2053. At compile time every C file object is run through the
  2054. recordmcount program (located in the scripts directory). This
  2055. program will parse the ELF headers in the C object to find all
  2056. the locations in the .text section that call mcount. Starting
  2057. with gcc verson 4.6, the -mfentry has been added for x86, which
  2058. calls "__fentry__" instead of "mcount". Which is called before
  2059. the creation of the stack frame.
  2060. Note, not all sections are traced. They may be prevented by either
  2061. a notrace, or blocked another way and all inline functions are not
  2062. traced. Check the "available_filter_functions" file to see what functions
  2063. can be traced.
  2064. A section called "__mcount_loc" is created that holds
  2065. references to all the mcount/fentry call sites in the .text section.
  2066. The recordmcount program re-links this section back into the
  2067. original object. The final linking stage of the kernel will add all these
  2068. references into a single table.
  2069. On boot up, before SMP is initialized, the dynamic ftrace code
  2070. scans this table and updates all the locations into nops. It
  2071. also records the locations, which are added to the
  2072. available_filter_functions list. Modules are processed as they
  2073. are loaded and before they are executed. When a module is
  2074. unloaded, it also removes its functions from the ftrace function
  2075. list. This is automatic in the module unload code, and the
  2076. module author does not need to worry about it.
  2077. When tracing is enabled, the process of modifying the function
  2078. tracepoints is dependent on architecture. The old method is to use
  2079. kstop_machine to prevent races with the CPUs executing code being
  2080. modified (which can cause the CPU to do undesirable things, especially
  2081. if the modified code crosses cache (or page) boundaries), and the nops are
  2082. patched back to calls. But this time, they do not call mcount
  2083. (which is just a function stub). They now call into the ftrace
  2084. infrastructure.
  2085. The new method of modifying the function tracepoints is to place
  2086. a breakpoint at the location to be modified, sync all CPUs, modify
  2087. the rest of the instruction not covered by the breakpoint. Sync
  2088. all CPUs again, and then remove the breakpoint with the finished
  2089. version to the ftrace call site.
  2090. Some archs do not even need to monkey around with the synchronization,
  2091. and can just slap the new code on top of the old without any
  2092. problems with other CPUs executing it at the same time.
  2093. One special side-effect to the recording of the functions being
  2094. traced is that we can now selectively choose which functions we
  2095. wish to trace and which ones we want the mcount calls to remain
  2096. as nops.
  2097. Two files are used, one for enabling and one for disabling the
  2098. tracing of specified functions. They are:
  2099. set_ftrace_filter
  2100. and
  2101. set_ftrace_notrace
  2102. A list of available functions that you can add to these files is
  2103. listed in:
  2104. available_filter_functions
  2105. ::
  2106. # cat available_filter_functions
  2107. put_prev_task_idle
  2108. kmem_cache_create
  2109. pick_next_task_rt
  2110. get_online_cpus
  2111. pick_next_task_fair
  2112. mutex_lock
  2113. [...]
  2114. If I am only interested in sys_nanosleep and hrtimer_interrupt::
  2115. # echo sys_nanosleep hrtimer_interrupt > set_ftrace_filter
  2116. # echo function > current_tracer
  2117. # echo 1 > tracing_on
  2118. # usleep 1
  2119. # echo 0 > tracing_on
  2120. # cat trace
  2121. # tracer: function
  2122. #
  2123. # entries-in-buffer/entries-written: 5/5 #P:4
  2124. #
  2125. # _-----=> irqs-off
  2126. # / _----=> need-resched
  2127. # | / _---=> hardirq/softirq
  2128. # || / _--=> preempt-depth
  2129. # ||| / delay
  2130. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  2131. # | | | |||| | |
  2132. usleep-2665 [001] .... 4186.475355: sys_nanosleep <-system_call_fastpath
  2133. <idle>-0 [001] d.h1 4186.475409: hrtimer_interrupt <-smp_apic_timer_interrupt
  2134. usleep-2665 [001] d.h1 4186.475426: hrtimer_interrupt <-smp_apic_timer_interrupt
  2135. <idle>-0 [003] d.h1 4186.475426: hrtimer_interrupt <-smp_apic_timer_interrupt
  2136. <idle>-0 [002] d.h1 4186.475427: hrtimer_interrupt <-smp_apic_timer_interrupt
  2137. To see which functions are being traced, you can cat the file:
  2138. ::
  2139. # cat set_ftrace_filter
  2140. hrtimer_interrupt
  2141. sys_nanosleep
  2142. Perhaps this is not enough. The filters also allow glob(7) matching.
  2143. ``<match>*``
  2144. will match functions that begin with <match>
  2145. ``*<match>``
  2146. will match functions that end with <match>
  2147. ``*<match>*``
  2148. will match functions that have <match> in it
  2149. ``<match1>*<match2>``
  2150. will match functions that begin with <match1> and end with <match2>
  2151. .. note::
  2152. It is better to use quotes to enclose the wild cards,
  2153. otherwise the shell may expand the parameters into names
  2154. of files in the local directory.
  2155. ::
  2156. # echo 'hrtimer_*' > set_ftrace_filter
  2157. Produces::
  2158. # tracer: function
  2159. #
  2160. # entries-in-buffer/entries-written: 897/897 #P:4
  2161. #
  2162. # _-----=> irqs-off
  2163. # / _----=> need-resched
  2164. # | / _---=> hardirq/softirq
  2165. # || / _--=> preempt-depth
  2166. # ||| / delay
  2167. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  2168. # | | | |||| | |
  2169. <idle>-0 [003] dN.1 4228.547803: hrtimer_cancel <-tick_nohz_idle_exit
  2170. <idle>-0 [003] dN.1 4228.547804: hrtimer_try_to_cancel <-hrtimer_cancel
  2171. <idle>-0 [003] dN.2 4228.547805: hrtimer_force_reprogram <-__remove_hrtimer
  2172. <idle>-0 [003] dN.1 4228.547805: hrtimer_forward <-tick_nohz_idle_exit
  2173. <idle>-0 [003] dN.1 4228.547805: hrtimer_start_range_ns <-hrtimer_start_expires.constprop.11
  2174. <idle>-0 [003] d..1 4228.547858: hrtimer_get_next_event <-get_next_timer_interrupt
  2175. <idle>-0 [003] d..1 4228.547859: hrtimer_start <-__tick_nohz_idle_enter
  2176. <idle>-0 [003] d..2 4228.547860: hrtimer_force_reprogram <-__rem
  2177. Notice that we lost the sys_nanosleep.
  2178. ::
  2179. # cat set_ftrace_filter
  2180. hrtimer_run_queues
  2181. hrtimer_run_pending
  2182. hrtimer_init
  2183. hrtimer_cancel
  2184. hrtimer_try_to_cancel
  2185. hrtimer_forward
  2186. hrtimer_start
  2187. hrtimer_reprogram
  2188. hrtimer_force_reprogram
  2189. hrtimer_get_next_event
  2190. hrtimer_interrupt
  2191. hrtimer_nanosleep
  2192. hrtimer_wakeup
  2193. hrtimer_get_remaining
  2194. hrtimer_get_res
  2195. hrtimer_init_sleeper
  2196. This is because the '>' and '>>' act just like they do in bash.
  2197. To rewrite the filters, use '>'
  2198. To append to the filters, use '>>'
  2199. To clear out a filter so that all functions will be recorded
  2200. again::
  2201. # echo > set_ftrace_filter
  2202. # cat set_ftrace_filter
  2203. #
  2204. Again, now we want to append.
  2205. ::
  2206. # echo sys_nanosleep > set_ftrace_filter
  2207. # cat set_ftrace_filter
  2208. sys_nanosleep
  2209. # echo 'hrtimer_*' >> set_ftrace_filter
  2210. # cat set_ftrace_filter
  2211. hrtimer_run_queues
  2212. hrtimer_run_pending
  2213. hrtimer_init
  2214. hrtimer_cancel
  2215. hrtimer_try_to_cancel
  2216. hrtimer_forward
  2217. hrtimer_start
  2218. hrtimer_reprogram
  2219. hrtimer_force_reprogram
  2220. hrtimer_get_next_event
  2221. hrtimer_interrupt
  2222. sys_nanosleep
  2223. hrtimer_nanosleep
  2224. hrtimer_wakeup
  2225. hrtimer_get_remaining
  2226. hrtimer_get_res
  2227. hrtimer_init_sleeper
  2228. The set_ftrace_notrace prevents those functions from being
  2229. traced.
  2230. ::
  2231. # echo '*preempt*' '*lock*' > set_ftrace_notrace
  2232. Produces::
  2233. # tracer: function
  2234. #
  2235. # entries-in-buffer/entries-written: 39608/39608 #P:4
  2236. #
  2237. # _-----=> irqs-off
  2238. # / _----=> need-resched
  2239. # | / _---=> hardirq/softirq
  2240. # || / _--=> preempt-depth
  2241. # ||| / delay
  2242. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  2243. # | | | |||| | |
  2244. bash-1994 [000] .... 4342.324896: file_ra_state_init <-do_dentry_open
  2245. bash-1994 [000] .... 4342.324897: open_check_o_direct <-do_last
  2246. bash-1994 [000] .... 4342.324897: ima_file_check <-do_last
  2247. bash-1994 [000] .... 4342.324898: process_measurement <-ima_file_check
  2248. bash-1994 [000] .... 4342.324898: ima_get_action <-process_measurement
  2249. bash-1994 [000] .... 4342.324898: ima_match_policy <-ima_get_action
  2250. bash-1994 [000] .... 4342.324899: do_truncate <-do_last
  2251. bash-1994 [000] .... 4342.324899: should_remove_suid <-do_truncate
  2252. bash-1994 [000] .... 4342.324899: notify_change <-do_truncate
  2253. bash-1994 [000] .... 4342.324900: current_fs_time <-notify_change
  2254. bash-1994 [000] .... 4342.324900: current_kernel_time <-current_fs_time
  2255. bash-1994 [000] .... 4342.324900: timespec_trunc <-current_fs_time
  2256. We can see that there's no more lock or preempt tracing.
  2257. Dynamic ftrace with the function graph tracer
  2258. ---------------------------------------------
  2259. Although what has been explained above concerns both the
  2260. function tracer and the function-graph-tracer, there are some
  2261. special features only available in the function-graph tracer.
  2262. If you want to trace only one function and all of its children,
  2263. you just have to echo its name into set_graph_function::
  2264. echo __do_fault > set_graph_function
  2265. will produce the following "expanded" trace of the __do_fault()
  2266. function::
  2267. 0) | __do_fault() {
  2268. 0) | filemap_fault() {
  2269. 0) | find_lock_page() {
  2270. 0) 0.804 us | find_get_page();
  2271. 0) | __might_sleep() {
  2272. 0) 1.329 us | }
  2273. 0) 3.904 us | }
  2274. 0) 4.979 us | }
  2275. 0) 0.653 us | _spin_lock();
  2276. 0) 0.578 us | page_add_file_rmap();
  2277. 0) 0.525 us | native_set_pte_at();
  2278. 0) 0.585 us | _spin_unlock();
  2279. 0) | unlock_page() {
  2280. 0) 0.541 us | page_waitqueue();
  2281. 0) 0.639 us | __wake_up_bit();
  2282. 0) 2.786 us | }
  2283. 0) + 14.237 us | }
  2284. 0) | __do_fault() {
  2285. 0) | filemap_fault() {
  2286. 0) | find_lock_page() {
  2287. 0) 0.698 us | find_get_page();
  2288. 0) | __might_sleep() {
  2289. 0) 1.412 us | }
  2290. 0) 3.950 us | }
  2291. 0) 5.098 us | }
  2292. 0) 0.631 us | _spin_lock();
  2293. 0) 0.571 us | page_add_file_rmap();
  2294. 0) 0.526 us | native_set_pte_at();
  2295. 0) 0.586 us | _spin_unlock();
  2296. 0) | unlock_page() {
  2297. 0) 0.533 us | page_waitqueue();
  2298. 0) 0.638 us | __wake_up_bit();
  2299. 0) 2.793 us | }
  2300. 0) + 14.012 us | }
  2301. You can also expand several functions at once::
  2302. echo sys_open > set_graph_function
  2303. echo sys_close >> set_graph_function
  2304. Now if you want to go back to trace all functions you can clear
  2305. this special filter via::
  2306. echo > set_graph_function
  2307. ftrace_enabled
  2308. --------------
  2309. Note, the proc sysctl ftrace_enable is a big on/off switch for the
  2310. function tracer. By default it is enabled (when function tracing is
  2311. enabled in the kernel). If it is disabled, all function tracing is
  2312. disabled. This includes not only the function tracers for ftrace, but
  2313. also for any other uses (perf, kprobes, stack tracing, profiling, etc).
  2314. Please disable this with care.
  2315. This can be disable (and enabled) with::
  2316. sysctl kernel.ftrace_enabled=0
  2317. sysctl kernel.ftrace_enabled=1
  2318. or
  2319. echo 0 > /proc/sys/kernel/ftrace_enabled
  2320. echo 1 > /proc/sys/kernel/ftrace_enabled
  2321. Filter commands
  2322. ---------------
  2323. A few commands are supported by the set_ftrace_filter interface.
  2324. Trace commands have the following format::
  2325. <function>:<command>:<parameter>
  2326. The following commands are supported:
  2327. - mod:
  2328. This command enables function filtering per module. The
  2329. parameter defines the module. For example, if only the write*
  2330. functions in the ext3 module are desired, run:
  2331. echo 'write*:mod:ext3' > set_ftrace_filter
  2332. This command interacts with the filter in the same way as
  2333. filtering based on function names. Thus, adding more functions
  2334. in a different module is accomplished by appending (>>) to the
  2335. filter file. Remove specific module functions by prepending
  2336. '!'::
  2337. echo '!writeback*:mod:ext3' >> set_ftrace_filter
  2338. Mod command supports module globbing. Disable tracing for all
  2339. functions except a specific module::
  2340. echo '!*:mod:!ext3' >> set_ftrace_filter
  2341. Disable tracing for all modules, but still trace kernel::
  2342. echo '!*:mod:*' >> set_ftrace_filter
  2343. Enable filter only for kernel::
  2344. echo '*write*:mod:!*' >> set_ftrace_filter
  2345. Enable filter for module globbing::
  2346. echo '*write*:mod:*snd*' >> set_ftrace_filter
  2347. - traceon/traceoff:
  2348. These commands turn tracing on and off when the specified
  2349. functions are hit. The parameter determines how many times the
  2350. tracing system is turned on and off. If unspecified, there is
  2351. no limit. For example, to disable tracing when a schedule bug
  2352. is hit the first 5 times, run::
  2353. echo '__schedule_bug:traceoff:5' > set_ftrace_filter
  2354. To always disable tracing when __schedule_bug is hit::
  2355. echo '__schedule_bug:traceoff' > set_ftrace_filter
  2356. These commands are cumulative whether or not they are appended
  2357. to set_ftrace_filter. To remove a command, prepend it by '!'
  2358. and drop the parameter::
  2359. echo '!__schedule_bug:traceoff:0' > set_ftrace_filter
  2360. The above removes the traceoff command for __schedule_bug
  2361. that have a counter. To remove commands without counters::
  2362. echo '!__schedule_bug:traceoff' > set_ftrace_filter
  2363. - snapshot:
  2364. Will cause a snapshot to be triggered when the function is hit.
  2365. ::
  2366. echo 'native_flush_tlb_others:snapshot' > set_ftrace_filter
  2367. To only snapshot once:
  2368. ::
  2369. echo 'native_flush_tlb_others:snapshot:1' > set_ftrace_filter
  2370. To remove the above commands::
  2371. echo '!native_flush_tlb_others:snapshot' > set_ftrace_filter
  2372. echo '!native_flush_tlb_others:snapshot:0' > set_ftrace_filter
  2373. - enable_event/disable_event:
  2374. These commands can enable or disable a trace event. Note, because
  2375. function tracing callbacks are very sensitive, when these commands
  2376. are registered, the trace point is activated, but disabled in
  2377. a "soft" mode. That is, the tracepoint will be called, but
  2378. just will not be traced. The event tracepoint stays in this mode
  2379. as long as there's a command that triggers it.
  2380. ::
  2381. echo 'try_to_wake_up:enable_event:sched:sched_switch:2' > \
  2382. set_ftrace_filter
  2383. The format is::
  2384. <function>:enable_event:<system>:<event>[:count]
  2385. <function>:disable_event:<system>:<event>[:count]
  2386. To remove the events commands::
  2387. echo '!try_to_wake_up:enable_event:sched:sched_switch:0' > \
  2388. set_ftrace_filter
  2389. echo '!schedule:disable_event:sched:sched_switch' > \
  2390. set_ftrace_filter
  2391. - dump:
  2392. When the function is hit, it will dump the contents of the ftrace
  2393. ring buffer to the console. This is useful if you need to debug
  2394. something, and want to dump the trace when a certain function
  2395. is hit. Perhaps its a function that is called before a tripple
  2396. fault happens and does not allow you to get a regular dump.
  2397. - cpudump:
  2398. When the function is hit, it will dump the contents of the ftrace
  2399. ring buffer for the current CPU to the console. Unlike the "dump"
  2400. command, it only prints out the contents of the ring buffer for the
  2401. CPU that executed the function that triggered the dump.
  2402. trace_pipe
  2403. ----------
  2404. The trace_pipe outputs the same content as the trace file, but
  2405. the effect on the tracing is different. Every read from
  2406. trace_pipe is consumed. This means that subsequent reads will be
  2407. different. The trace is live.
  2408. ::
  2409. # echo function > current_tracer
  2410. # cat trace_pipe > /tmp/trace.out &
  2411. [1] 4153
  2412. # echo 1 > tracing_on
  2413. # usleep 1
  2414. # echo 0 > tracing_on
  2415. # cat trace
  2416. # tracer: function
  2417. #
  2418. # entries-in-buffer/entries-written: 0/0 #P:4
  2419. #
  2420. # _-----=> irqs-off
  2421. # / _----=> need-resched
  2422. # | / _---=> hardirq/softirq
  2423. # || / _--=> preempt-depth
  2424. # ||| / delay
  2425. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  2426. # | | | |||| | |
  2427. #
  2428. # cat /tmp/trace.out
  2429. bash-1994 [000] .... 5281.568961: mutex_unlock <-rb_simple_write
  2430. bash-1994 [000] .... 5281.568963: __mutex_unlock_slowpath <-mutex_unlock
  2431. bash-1994 [000] .... 5281.568963: __fsnotify_parent <-fsnotify_modify
  2432. bash-1994 [000] .... 5281.568964: fsnotify <-fsnotify_modify
  2433. bash-1994 [000] .... 5281.568964: __srcu_read_lock <-fsnotify
  2434. bash-1994 [000] .... 5281.568964: add_preempt_count <-__srcu_read_lock
  2435. bash-1994 [000] ...1 5281.568965: sub_preempt_count <-__srcu_read_lock
  2436. bash-1994 [000] .... 5281.568965: __srcu_read_unlock <-fsnotify
  2437. bash-1994 [000] .... 5281.568967: sys_dup2 <-system_call_fastpath
  2438. Note, reading the trace_pipe file will block until more input is
  2439. added.
  2440. trace entries
  2441. -------------
  2442. Having too much or not enough data can be troublesome in
  2443. diagnosing an issue in the kernel. The file buffer_size_kb is
  2444. used to modify the size of the internal trace buffers. The
  2445. number listed is the number of entries that can be recorded per
  2446. CPU. To know the full size, multiply the number of possible CPUs
  2447. with the number of entries.
  2448. ::
  2449. # cat buffer_size_kb
  2450. 1408 (units kilobytes)
  2451. Or simply read buffer_total_size_kb
  2452. ::
  2453. # cat buffer_total_size_kb
  2454. 5632
  2455. To modify the buffer, simple echo in a number (in 1024 byte segments).
  2456. ::
  2457. # echo 10000 > buffer_size_kb
  2458. # cat buffer_size_kb
  2459. 10000 (units kilobytes)
  2460. It will try to allocate as much as possible. If you allocate too
  2461. much, it can cause Out-Of-Memory to trigger.
  2462. ::
  2463. # echo 1000000000000 > buffer_size_kb
  2464. -bash: echo: write error: Cannot allocate memory
  2465. # cat buffer_size_kb
  2466. 85
  2467. The per_cpu buffers can be changed individually as well:
  2468. ::
  2469. # echo 10000 > per_cpu/cpu0/buffer_size_kb
  2470. # echo 100 > per_cpu/cpu1/buffer_size_kb
  2471. When the per_cpu buffers are not the same, the buffer_size_kb
  2472. at the top level will just show an X
  2473. ::
  2474. # cat buffer_size_kb
  2475. X
  2476. This is where the buffer_total_size_kb is useful:
  2477. ::
  2478. # cat buffer_total_size_kb
  2479. 12916
  2480. Writing to the top level buffer_size_kb will reset all the buffers
  2481. to be the same again.
  2482. Snapshot
  2483. --------
  2484. CONFIG_TRACER_SNAPSHOT makes a generic snapshot feature
  2485. available to all non latency tracers. (Latency tracers which
  2486. record max latency, such as "irqsoff" or "wakeup", can't use
  2487. this feature, since those are already using the snapshot
  2488. mechanism internally.)
  2489. Snapshot preserves a current trace buffer at a particular point
  2490. in time without stopping tracing. Ftrace swaps the current
  2491. buffer with a spare buffer, and tracing continues in the new
  2492. current (=previous spare) buffer.
  2493. The following tracefs files in "tracing" are related to this
  2494. feature:
  2495. snapshot:
  2496. This is used to take a snapshot and to read the output
  2497. of the snapshot. Echo 1 into this file to allocate a
  2498. spare buffer and to take a snapshot (swap), then read
  2499. the snapshot from this file in the same format as
  2500. "trace" (described above in the section "The File
  2501. System"). Both reads snapshot and tracing are executable
  2502. in parallel. When the spare buffer is allocated, echoing
  2503. 0 frees it, and echoing else (positive) values clear the
  2504. snapshot contents.
  2505. More details are shown in the table below.
  2506. +--------------+------------+------------+------------+
  2507. |status\\input | 0 | 1 | else |
  2508. +==============+============+============+============+
  2509. |not allocated |(do nothing)| alloc+swap |(do nothing)|
  2510. +--------------+------------+------------+------------+
  2511. |allocated | free | swap | clear |
  2512. +--------------+------------+------------+------------+
  2513. Here is an example of using the snapshot feature.
  2514. ::
  2515. # echo 1 > events/sched/enable
  2516. # echo 1 > snapshot
  2517. # cat snapshot
  2518. # tracer: nop
  2519. #
  2520. # entries-in-buffer/entries-written: 71/71 #P:8
  2521. #
  2522. # _-----=> irqs-off
  2523. # / _----=> need-resched
  2524. # | / _---=> hardirq/softirq
  2525. # || / _--=> preempt-depth
  2526. # ||| / delay
  2527. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  2528. # | | | |||| | |
  2529. <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
  2530. 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
  2531. [...]
  2532. <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
  2533. # cat trace
  2534. # tracer: nop
  2535. #
  2536. # entries-in-buffer/entries-written: 77/77 #P:8
  2537. #
  2538. # _-----=> irqs-off
  2539. # / _----=> need-resched
  2540. # | / _---=> hardirq/softirq
  2541. # || / _--=> preempt-depth
  2542. # ||| / delay
  2543. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  2544. # | | | |||| | |
  2545. <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
  2546. 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
  2547. [...]
  2548. If you try to use this snapshot feature when current tracer is
  2549. one of the latency tracers, you will get the following results.
  2550. ::
  2551. # echo wakeup > current_tracer
  2552. # echo 1 > snapshot
  2553. bash: echo: write error: Device or resource busy
  2554. # cat snapshot
  2555. cat: snapshot: Device or resource busy
  2556. Instances
  2557. ---------
  2558. In the tracefs tracing directory is a directory called "instances".
  2559. This directory can have new directories created inside of it using
  2560. mkdir, and removing directories with rmdir. The directory created
  2561. with mkdir in this directory will already contain files and other
  2562. directories after it is created.
  2563. ::
  2564. # mkdir instances/foo
  2565. # ls instances/foo
  2566. buffer_size_kb buffer_total_size_kb events free_buffer per_cpu
  2567. set_event snapshot trace trace_clock trace_marker trace_options
  2568. trace_pipe tracing_on
  2569. As you can see, the new directory looks similar to the tracing directory
  2570. itself. In fact, it is very similar, except that the buffer and
  2571. events are agnostic from the main director, or from any other
  2572. instances that are created.
  2573. The files in the new directory work just like the files with the
  2574. same name in the tracing directory except the buffer that is used
  2575. is a separate and new buffer. The files affect that buffer but do not
  2576. affect the main buffer with the exception of trace_options. Currently,
  2577. the trace_options affect all instances and the top level buffer
  2578. the same, but this may change in future releases. That is, options
  2579. may become specific to the instance they reside in.
  2580. Notice that none of the function tracer files are there, nor is
  2581. current_tracer and available_tracers. This is because the buffers
  2582. can currently only have events enabled for them.
  2583. ::
  2584. # mkdir instances/foo
  2585. # mkdir instances/bar
  2586. # mkdir instances/zoot
  2587. # echo 100000 > buffer_size_kb
  2588. # echo 1000 > instances/foo/buffer_size_kb
  2589. # echo 5000 > instances/bar/per_cpu/cpu1/buffer_size_kb
  2590. # echo function > current_trace
  2591. # echo 1 > instances/foo/events/sched/sched_wakeup/enable
  2592. # echo 1 > instances/foo/events/sched/sched_wakeup_new/enable
  2593. # echo 1 > instances/foo/events/sched/sched_switch/enable
  2594. # echo 1 > instances/bar/events/irq/enable
  2595. # echo 1 > instances/zoot/events/syscalls/enable
  2596. # cat trace_pipe
  2597. CPU:2 [LOST 11745 EVENTS]
  2598. bash-2044 [002] .... 10594.481032: _raw_spin_lock_irqsave <-get_page_from_freelist
  2599. bash-2044 [002] d... 10594.481032: add_preempt_count <-_raw_spin_lock_irqsave
  2600. bash-2044 [002] d..1 10594.481032: __rmqueue <-get_page_from_freelist
  2601. bash-2044 [002] d..1 10594.481033: _raw_spin_unlock <-get_page_from_freelist
  2602. bash-2044 [002] d..1 10594.481033: sub_preempt_count <-_raw_spin_unlock
  2603. bash-2044 [002] d... 10594.481033: get_pageblock_flags_group <-get_pageblock_migratetype
  2604. bash-2044 [002] d... 10594.481034: __mod_zone_page_state <-get_page_from_freelist
  2605. bash-2044 [002] d... 10594.481034: zone_statistics <-get_page_from_freelist
  2606. bash-2044 [002] d... 10594.481034: __inc_zone_state <-zone_statistics
  2607. bash-2044 [002] d... 10594.481034: __inc_zone_state <-zone_statistics
  2608. bash-2044 [002] .... 10594.481035: arch_dup_task_struct <-copy_process
  2609. [...]
  2610. # cat instances/foo/trace_pipe
  2611. bash-1998 [000] d..4 136.676759: sched_wakeup: comm=kworker/0:1 pid=59 prio=120 success=1 target_cpu=000
  2612. bash-1998 [000] dN.4 136.676760: sched_wakeup: comm=bash pid=1998 prio=120 success=1 target_cpu=000
  2613. <idle>-0 [003] d.h3 136.676906: sched_wakeup: comm=rcu_preempt pid=9 prio=120 success=1 target_cpu=003
  2614. <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
  2615. 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
  2616. bash-1998 [000] d..4 136.677014: sched_wakeup: comm=kworker/0:1 pid=59 prio=120 success=1 target_cpu=000
  2617. bash-1998 [000] dN.4 136.677016: sched_wakeup: comm=bash pid=1998 prio=120 success=1 target_cpu=000
  2618. 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
  2619. kworker/0:1-59 [000] d..4 136.677022: sched_wakeup: comm=sshd pid=1995 prio=120 success=1 target_cpu=001
  2620. 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
  2621. [...]
  2622. # cat instances/bar/trace_pipe
  2623. migration/1-14 [001] d.h3 138.732674: softirq_raise: vec=3 [action=NET_RX]
  2624. <idle>-0 [001] dNh3 138.732725: softirq_raise: vec=3 [action=NET_RX]
  2625. bash-1998 [000] d.h1 138.733101: softirq_raise: vec=1 [action=TIMER]
  2626. bash-1998 [000] d.h1 138.733102: softirq_raise: vec=9 [action=RCU]
  2627. bash-1998 [000] ..s2 138.733105: softirq_entry: vec=1 [action=TIMER]
  2628. bash-1998 [000] ..s2 138.733106: softirq_exit: vec=1 [action=TIMER]
  2629. bash-1998 [000] ..s2 138.733106: softirq_entry: vec=9 [action=RCU]
  2630. bash-1998 [000] ..s2 138.733109: softirq_exit: vec=9 [action=RCU]
  2631. sshd-1995 [001] d.h1 138.733278: irq_handler_entry: irq=21 name=uhci_hcd:usb4
  2632. sshd-1995 [001] d.h1 138.733280: irq_handler_exit: irq=21 ret=unhandled
  2633. sshd-1995 [001] d.h1 138.733281: irq_handler_entry: irq=21 name=eth0
  2634. sshd-1995 [001] d.h1 138.733283: irq_handler_exit: irq=21 ret=handled
  2635. [...]
  2636. # cat instances/zoot/trace
  2637. # tracer: nop
  2638. #
  2639. # entries-in-buffer/entries-written: 18996/18996 #P:4
  2640. #
  2641. # _-----=> irqs-off
  2642. # / _----=> need-resched
  2643. # | / _---=> hardirq/softirq
  2644. # || / _--=> preempt-depth
  2645. # ||| / delay
  2646. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  2647. # | | | |||| | |
  2648. bash-1998 [000] d... 140.733501: sys_write -> 0x2
  2649. bash-1998 [000] d... 140.733504: sys_dup2(oldfd: a, newfd: 1)
  2650. bash-1998 [000] d... 140.733506: sys_dup2 -> 0x1
  2651. bash-1998 [000] d... 140.733508: sys_fcntl(fd: a, cmd: 1, arg: 0)
  2652. bash-1998 [000] d... 140.733509: sys_fcntl -> 0x1
  2653. bash-1998 [000] d... 140.733510: sys_close(fd: a)
  2654. bash-1998 [000] d... 140.733510: sys_close -> 0x0
  2655. bash-1998 [000] d... 140.733514: sys_rt_sigprocmask(how: 0, nset: 0, oset: 6e2768, sigsetsize: 8)
  2656. bash-1998 [000] d... 140.733515: sys_rt_sigprocmask -> 0x0
  2657. bash-1998 [000] d... 140.733516: sys_rt_sigaction(sig: 2, act: 7fff718846f0, oact: 7fff71884650, sigsetsize: 8)
  2658. bash-1998 [000] d... 140.733516: sys_rt_sigaction -> 0x0
  2659. You can see that the trace of the top most trace buffer shows only
  2660. the function tracing. The foo instance displays wakeups and task
  2661. switches.
  2662. To remove the instances, simply delete their directories:
  2663. ::
  2664. # rmdir instances/foo
  2665. # rmdir instances/bar
  2666. # rmdir instances/zoot
  2667. Note, if a process has a trace file open in one of the instance
  2668. directories, the rmdir will fail with EBUSY.
  2669. Stack trace
  2670. -----------
  2671. Since the kernel has a fixed sized stack, it is important not to
  2672. waste it in functions. A kernel developer must be conscience of
  2673. what they allocate on the stack. If they add too much, the system
  2674. can be in danger of a stack overflow, and corruption will occur,
  2675. usually leading to a system panic.
  2676. There are some tools that check this, usually with interrupts
  2677. periodically checking usage. But if you can perform a check
  2678. at every function call that will become very useful. As ftrace provides
  2679. a function tracer, it makes it convenient to check the stack size
  2680. at every function call. This is enabled via the stack tracer.
  2681. CONFIG_STACK_TRACER enables the ftrace stack tracing functionality.
  2682. To enable it, write a '1' into /proc/sys/kernel/stack_tracer_enabled.
  2683. ::
  2684. # echo 1 > /proc/sys/kernel/stack_tracer_enabled
  2685. You can also enable it from the kernel command line to trace
  2686. the stack size of the kernel during boot up, by adding "stacktrace"
  2687. to the kernel command line parameter.
  2688. After running it for a few minutes, the output looks like:
  2689. ::
  2690. # cat stack_max_size
  2691. 2928
  2692. # cat stack_trace
  2693. Depth Size Location (18 entries)
  2694. ----- ---- --------
  2695. 0) 2928 224 update_sd_lb_stats+0xbc/0x4ac
  2696. 1) 2704 160 find_busiest_group+0x31/0x1f1
  2697. 2) 2544 256 load_balance+0xd9/0x662
  2698. 3) 2288 80 idle_balance+0xbb/0x130
  2699. 4) 2208 128 __schedule+0x26e/0x5b9
  2700. 5) 2080 16 schedule+0x64/0x66
  2701. 6) 2064 128 schedule_timeout+0x34/0xe0
  2702. 7) 1936 112 wait_for_common+0x97/0xf1
  2703. 8) 1824 16 wait_for_completion+0x1d/0x1f
  2704. 9) 1808 128 flush_work+0xfe/0x119
  2705. 10) 1680 16 tty_flush_to_ldisc+0x1e/0x20
  2706. 11) 1664 48 input_available_p+0x1d/0x5c
  2707. 12) 1616 48 n_tty_poll+0x6d/0x134
  2708. 13) 1568 64 tty_poll+0x64/0x7f
  2709. 14) 1504 880 do_select+0x31e/0x511
  2710. 15) 624 400 core_sys_select+0x177/0x216
  2711. 16) 224 96 sys_select+0x91/0xb9
  2712. 17) 128 128 system_call_fastpath+0x16/0x1b
  2713. Note, if -mfentry is being used by gcc, functions get traced before
  2714. they set up the stack frame. This means that leaf level functions
  2715. are not tested by the stack tracer when -mfentry is used.
  2716. Currently, -mfentry is used by gcc 4.6.0 and above on x86 only.
  2717. More
  2718. ----
  2719. More details can be found in the source code, in the `kernel/trace/*.c` files.