ftrace.rst 142 KB

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