ftrace.rst 131 KB

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