trace.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381
  1. /*
  2. * ring buffer based function tracer
  3. *
  4. * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
  5. * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
  6. *
  7. * Originally taken from the RT patch by:
  8. * Arnaldo Carvalho de Melo <acme@redhat.com>
  9. *
  10. * Based on code from the latency_tracer, that is:
  11. * Copyright (C) 2004-2006 Ingo Molnar
  12. * Copyright (C) 2004 William Lee Irwin III
  13. */
  14. #include <linux/utsrelease.h>
  15. #include <linux/kallsyms.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/notifier.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/hardirq.h>
  21. #include <linux/linkage.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/ftrace.h>
  24. #include <linux/module.h>
  25. #include <linux/percpu.h>
  26. #include <linux/kdebug.h>
  27. #include <linux/ctype.h>
  28. #include <linux/init.h>
  29. #include <linux/poll.h>
  30. #include <linux/gfp.h>
  31. #include <linux/fs.h>
  32. #include <linux/kprobes.h>
  33. #include <linux/writeback.h>
  34. #include <linux/stacktrace.h>
  35. #include <linux/ring_buffer.h>
  36. #include <linux/irqflags.h>
  37. #include "trace.h"
  38. #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
  39. unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX;
  40. unsigned long __read_mostly tracing_thresh;
  41. /*
  42. * Kill all tracing for good (never come back).
  43. * It is initialized to 1 but will turn to zero if the initialization
  44. * of the tracer is successful. But that is the only place that sets
  45. * this back to zero.
  46. */
  47. int tracing_disabled = 1;
  48. static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled);
  49. static inline void ftrace_disable_cpu(void)
  50. {
  51. preempt_disable();
  52. local_inc(&__get_cpu_var(ftrace_cpu_disabled));
  53. }
  54. static inline void ftrace_enable_cpu(void)
  55. {
  56. local_dec(&__get_cpu_var(ftrace_cpu_disabled));
  57. preempt_enable();
  58. }
  59. static cpumask_t __read_mostly tracing_buffer_mask;
  60. #define for_each_tracing_cpu(cpu) \
  61. for_each_cpu_mask(cpu, tracing_buffer_mask)
  62. /*
  63. * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
  64. *
  65. * If there is an oops (or kernel panic) and the ftrace_dump_on_oops
  66. * is set, then ftrace_dump is called. This will output the contents
  67. * of the ftrace buffers to the console. This is very useful for
  68. * capturing traces that lead to crashes and outputing it to a
  69. * serial console.
  70. *
  71. * It is default off, but you can enable it with either specifying
  72. * "ftrace_dump_on_oops" in the kernel command line, or setting
  73. * /proc/sys/kernel/ftrace_dump_on_oops to true.
  74. */
  75. int ftrace_dump_on_oops;
  76. static int tracing_set_tracer(char *buf);
  77. static int __init set_ftrace(char *str)
  78. {
  79. tracing_set_tracer(str);
  80. return 1;
  81. }
  82. __setup("ftrace", set_ftrace);
  83. static int __init set_ftrace_dump_on_oops(char *str)
  84. {
  85. ftrace_dump_on_oops = 1;
  86. return 1;
  87. }
  88. __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
  89. long
  90. ns2usecs(cycle_t nsec)
  91. {
  92. nsec += 500;
  93. do_div(nsec, 1000);
  94. return nsec;
  95. }
  96. cycle_t ftrace_now(int cpu)
  97. {
  98. u64 ts = ring_buffer_time_stamp(cpu);
  99. ring_buffer_normalize_time_stamp(cpu, &ts);
  100. return ts;
  101. }
  102. /*
  103. * The global_trace is the descriptor that holds the tracing
  104. * buffers for the live tracing. For each CPU, it contains
  105. * a link list of pages that will store trace entries. The
  106. * page descriptor of the pages in the memory is used to hold
  107. * the link list by linking the lru item in the page descriptor
  108. * to each of the pages in the buffer per CPU.
  109. *
  110. * For each active CPU there is a data field that holds the
  111. * pages for the buffer for that CPU. Each CPU has the same number
  112. * of pages allocated for its buffer.
  113. */
  114. static struct trace_array global_trace;
  115. static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu);
  116. /*
  117. * The max_tr is used to snapshot the global_trace when a maximum
  118. * latency is reached. Some tracers will use this to store a maximum
  119. * trace while it continues examining live traces.
  120. *
  121. * The buffers for the max_tr are set up the same as the global_trace.
  122. * When a snapshot is taken, the link list of the max_tr is swapped
  123. * with the link list of the global_trace and the buffers are reset for
  124. * the global_trace so the tracing can continue.
  125. */
  126. static struct trace_array max_tr;
  127. static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
  128. /* tracer_enabled is used to toggle activation of a tracer */
  129. static int tracer_enabled = 1;
  130. /**
  131. * tracing_is_enabled - return tracer_enabled status
  132. *
  133. * This function is used by other tracers to know the status
  134. * of the tracer_enabled flag. Tracers may use this function
  135. * to know if it should enable their features when starting
  136. * up. See irqsoff tracer for an example (start_irqsoff_tracer).
  137. */
  138. int tracing_is_enabled(void)
  139. {
  140. return tracer_enabled;
  141. }
  142. /* function tracing enabled */
  143. int ftrace_function_enabled;
  144. /*
  145. * trace_buf_size is the size in bytes that is allocated
  146. * for a buffer. Note, the number of bytes is always rounded
  147. * to page size.
  148. *
  149. * This number is purposely set to a low number of 16384.
  150. * If the dump on oops happens, it will be much appreciated
  151. * to not have to wait for all that output. Anyway this can be
  152. * boot time and run time configurable.
  153. */
  154. #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */
  155. static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT;
  156. /* trace_types holds a link list of available tracers. */
  157. static struct tracer *trace_types __read_mostly;
  158. /* current_trace points to the tracer that is currently active */
  159. static struct tracer *current_trace __read_mostly;
  160. /*
  161. * max_tracer_type_len is used to simplify the allocating of
  162. * buffers to read userspace tracer names. We keep track of
  163. * the longest tracer name registered.
  164. */
  165. static int max_tracer_type_len;
  166. /*
  167. * trace_types_lock is used to protect the trace_types list.
  168. * This lock is also used to keep user access serialized.
  169. * Accesses from userspace will grab this lock while userspace
  170. * activities happen inside the kernel.
  171. */
  172. static DEFINE_MUTEX(trace_types_lock);
  173. /* trace_wait is a waitqueue for tasks blocked on trace_poll */
  174. static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
  175. /* trace_flags holds iter_ctrl options */
  176. unsigned long trace_flags = TRACE_ITER_PRINT_PARENT;
  177. /**
  178. * trace_wake_up - wake up tasks waiting for trace input
  179. *
  180. * Simply wakes up any task that is blocked on the trace_wait
  181. * queue. These is used with trace_poll for tasks polling the trace.
  182. */
  183. void trace_wake_up(void)
  184. {
  185. /*
  186. * The runqueue_is_locked() can fail, but this is the best we
  187. * have for now:
  188. */
  189. if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
  190. wake_up(&trace_wait);
  191. }
  192. static int __init set_buf_size(char *str)
  193. {
  194. unsigned long buf_size;
  195. int ret;
  196. if (!str)
  197. return 0;
  198. ret = strict_strtoul(str, 0, &buf_size);
  199. /* nr_entries can not be zero */
  200. if (ret < 0 || buf_size == 0)
  201. return 0;
  202. trace_buf_size = buf_size;
  203. return 1;
  204. }
  205. __setup("trace_buf_size=", set_buf_size);
  206. unsigned long nsecs_to_usecs(unsigned long nsecs)
  207. {
  208. return nsecs / 1000;
  209. }
  210. /*
  211. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  212. * control the output of kernel symbols.
  213. */
  214. #define TRACE_ITER_SYM_MASK \
  215. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  216. /* These must match the bit postions in trace_iterator_flags */
  217. static const char *trace_options[] = {
  218. "print-parent",
  219. "sym-offset",
  220. "sym-addr",
  221. "verbose",
  222. "raw",
  223. "hex",
  224. "bin",
  225. "block",
  226. "stacktrace",
  227. "sched-tree",
  228. "ftrace_printk",
  229. "ftrace_preempt",
  230. NULL
  231. };
  232. /*
  233. * ftrace_max_lock is used to protect the swapping of buffers
  234. * when taking a max snapshot. The buffers themselves are
  235. * protected by per_cpu spinlocks. But the action of the swap
  236. * needs its own lock.
  237. *
  238. * This is defined as a raw_spinlock_t in order to help
  239. * with performance when lockdep debugging is enabled.
  240. */
  241. static raw_spinlock_t ftrace_max_lock =
  242. (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
  243. /*
  244. * Copy the new maximum trace into the separate maximum-trace
  245. * structure. (this way the maximum trace is permanently saved,
  246. * for later retrieval via /debugfs/tracing/latency_trace)
  247. */
  248. static void
  249. __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
  250. {
  251. struct trace_array_cpu *data = tr->data[cpu];
  252. max_tr.cpu = cpu;
  253. max_tr.time_start = data->preempt_timestamp;
  254. data = max_tr.data[cpu];
  255. data->saved_latency = tracing_max_latency;
  256. memcpy(data->comm, tsk->comm, TASK_COMM_LEN);
  257. data->pid = tsk->pid;
  258. data->uid = tsk->uid;
  259. data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
  260. data->policy = tsk->policy;
  261. data->rt_priority = tsk->rt_priority;
  262. /* record this tasks comm */
  263. tracing_record_cmdline(current);
  264. }
  265. /**
  266. * trace_seq_printf - sequence printing of trace information
  267. * @s: trace sequence descriptor
  268. * @fmt: printf format string
  269. *
  270. * The tracer may use either sequence operations or its own
  271. * copy to user routines. To simplify formating of a trace
  272. * trace_seq_printf is used to store strings into a special
  273. * buffer (@s). Then the output may be either used by
  274. * the sequencer or pulled into another buffer.
  275. */
  276. int
  277. trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
  278. {
  279. int len = (PAGE_SIZE - 1) - s->len;
  280. va_list ap;
  281. int ret;
  282. if (!len)
  283. return 0;
  284. va_start(ap, fmt);
  285. ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
  286. va_end(ap);
  287. /* If we can't write it all, don't bother writing anything */
  288. if (ret >= len)
  289. return 0;
  290. s->len += ret;
  291. return len;
  292. }
  293. /**
  294. * trace_seq_puts - trace sequence printing of simple string
  295. * @s: trace sequence descriptor
  296. * @str: simple string to record
  297. *
  298. * The tracer may use either the sequence operations or its own
  299. * copy to user routines. This function records a simple string
  300. * into a special buffer (@s) for later retrieval by a sequencer
  301. * or other mechanism.
  302. */
  303. static int
  304. trace_seq_puts(struct trace_seq *s, const char *str)
  305. {
  306. int len = strlen(str);
  307. if (len > ((PAGE_SIZE - 1) - s->len))
  308. return 0;
  309. memcpy(s->buffer + s->len, str, len);
  310. s->len += len;
  311. return len;
  312. }
  313. static int
  314. trace_seq_putc(struct trace_seq *s, unsigned char c)
  315. {
  316. if (s->len >= (PAGE_SIZE - 1))
  317. return 0;
  318. s->buffer[s->len++] = c;
  319. return 1;
  320. }
  321. static int
  322. trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
  323. {
  324. if (len > ((PAGE_SIZE - 1) - s->len))
  325. return 0;
  326. memcpy(s->buffer + s->len, mem, len);
  327. s->len += len;
  328. return len;
  329. }
  330. #define MAX_MEMHEX_BYTES 8
  331. #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1)
  332. static int
  333. trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
  334. {
  335. unsigned char hex[HEX_CHARS];
  336. unsigned char *data = mem;
  337. int i, j;
  338. #ifdef __BIG_ENDIAN
  339. for (i = 0, j = 0; i < len; i++) {
  340. #else
  341. for (i = len-1, j = 0; i >= 0; i--) {
  342. #endif
  343. hex[j++] = hex_asc_hi(data[i]);
  344. hex[j++] = hex_asc_lo(data[i]);
  345. }
  346. hex[j++] = ' ';
  347. return trace_seq_putmem(s, hex, j);
  348. }
  349. static void
  350. trace_seq_reset(struct trace_seq *s)
  351. {
  352. s->len = 0;
  353. s->readpos = 0;
  354. }
  355. ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
  356. {
  357. int len;
  358. int ret;
  359. if (s->len <= s->readpos)
  360. return -EBUSY;
  361. len = s->len - s->readpos;
  362. if (cnt > len)
  363. cnt = len;
  364. ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
  365. if (ret)
  366. return -EFAULT;
  367. s->readpos += len;
  368. return cnt;
  369. }
  370. static void
  371. trace_print_seq(struct seq_file *m, struct trace_seq *s)
  372. {
  373. int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
  374. s->buffer[len] = 0;
  375. seq_puts(m, s->buffer);
  376. trace_seq_reset(s);
  377. }
  378. /**
  379. * update_max_tr - snapshot all trace buffers from global_trace to max_tr
  380. * @tr: tracer
  381. * @tsk: the task with the latency
  382. * @cpu: The cpu that initiated the trace.
  383. *
  384. * Flip the buffers between the @tr and the max_tr and record information
  385. * about which task was the cause of this latency.
  386. */
  387. void
  388. update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
  389. {
  390. struct ring_buffer *buf = tr->buffer;
  391. WARN_ON_ONCE(!irqs_disabled());
  392. __raw_spin_lock(&ftrace_max_lock);
  393. tr->buffer = max_tr.buffer;
  394. max_tr.buffer = buf;
  395. ftrace_disable_cpu();
  396. ring_buffer_reset(tr->buffer);
  397. ftrace_enable_cpu();
  398. __update_max_tr(tr, tsk, cpu);
  399. __raw_spin_unlock(&ftrace_max_lock);
  400. }
  401. /**
  402. * update_max_tr_single - only copy one trace over, and reset the rest
  403. * @tr - tracer
  404. * @tsk - task with the latency
  405. * @cpu - the cpu of the buffer to copy.
  406. *
  407. * Flip the trace of a single CPU buffer between the @tr and the max_tr.
  408. */
  409. void
  410. update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
  411. {
  412. int ret;
  413. WARN_ON_ONCE(!irqs_disabled());
  414. __raw_spin_lock(&ftrace_max_lock);
  415. ftrace_disable_cpu();
  416. ring_buffer_reset(max_tr.buffer);
  417. ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu);
  418. ftrace_enable_cpu();
  419. WARN_ON_ONCE(ret);
  420. __update_max_tr(tr, tsk, cpu);
  421. __raw_spin_unlock(&ftrace_max_lock);
  422. }
  423. /**
  424. * register_tracer - register a tracer with the ftrace system.
  425. * @type - the plugin for the tracer
  426. *
  427. * Register a new plugin tracer.
  428. */
  429. int register_tracer(struct tracer *type)
  430. {
  431. struct tracer *t;
  432. int len;
  433. int ret = 0;
  434. if (!type->name) {
  435. pr_info("Tracer must have a name\n");
  436. return -1;
  437. }
  438. mutex_lock(&trace_types_lock);
  439. for (t = trace_types; t; t = t->next) {
  440. if (strcmp(type->name, t->name) == 0) {
  441. /* already found */
  442. pr_info("Trace %s already registered\n",
  443. type->name);
  444. ret = -1;
  445. goto out;
  446. }
  447. }
  448. #ifdef CONFIG_FTRACE_STARTUP_TEST
  449. if (type->selftest) {
  450. struct tracer *saved_tracer = current_trace;
  451. struct trace_array *tr = &global_trace;
  452. int saved_ctrl = tr->ctrl;
  453. int i;
  454. /*
  455. * Run a selftest on this tracer.
  456. * Here we reset the trace buffer, and set the current
  457. * tracer to be this tracer. The tracer can then run some
  458. * internal tracing to verify that everything is in order.
  459. * If we fail, we do not register this tracer.
  460. */
  461. for_each_tracing_cpu(i) {
  462. tracing_reset(tr, i);
  463. }
  464. current_trace = type;
  465. tr->ctrl = 0;
  466. /* the test is responsible for initializing and enabling */
  467. pr_info("Testing tracer %s: ", type->name);
  468. ret = type->selftest(type, tr);
  469. /* the test is responsible for resetting too */
  470. current_trace = saved_tracer;
  471. tr->ctrl = saved_ctrl;
  472. if (ret) {
  473. printk(KERN_CONT "FAILED!\n");
  474. goto out;
  475. }
  476. /* Only reset on passing, to avoid touching corrupted buffers */
  477. for_each_tracing_cpu(i) {
  478. tracing_reset(tr, i);
  479. }
  480. printk(KERN_CONT "PASSED\n");
  481. }
  482. #endif
  483. type->next = trace_types;
  484. trace_types = type;
  485. len = strlen(type->name);
  486. if (len > max_tracer_type_len)
  487. max_tracer_type_len = len;
  488. out:
  489. mutex_unlock(&trace_types_lock);
  490. return ret;
  491. }
  492. void unregister_tracer(struct tracer *type)
  493. {
  494. struct tracer **t;
  495. int len;
  496. mutex_lock(&trace_types_lock);
  497. for (t = &trace_types; *t; t = &(*t)->next) {
  498. if (*t == type)
  499. goto found;
  500. }
  501. pr_info("Trace %s not registered\n", type->name);
  502. goto out;
  503. found:
  504. *t = (*t)->next;
  505. if (strlen(type->name) != max_tracer_type_len)
  506. goto out;
  507. max_tracer_type_len = 0;
  508. for (t = &trace_types; *t; t = &(*t)->next) {
  509. len = strlen((*t)->name);
  510. if (len > max_tracer_type_len)
  511. max_tracer_type_len = len;
  512. }
  513. out:
  514. mutex_unlock(&trace_types_lock);
  515. }
  516. void tracing_reset(struct trace_array *tr, int cpu)
  517. {
  518. ftrace_disable_cpu();
  519. ring_buffer_reset_cpu(tr->buffer, cpu);
  520. ftrace_enable_cpu();
  521. }
  522. #define SAVED_CMDLINES 128
  523. static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
  524. static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
  525. static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
  526. static int cmdline_idx;
  527. static DEFINE_SPINLOCK(trace_cmdline_lock);
  528. /* temporary disable recording */
  529. atomic_t trace_record_cmdline_disabled __read_mostly;
  530. static void trace_init_cmdlines(void)
  531. {
  532. memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
  533. memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
  534. cmdline_idx = 0;
  535. }
  536. static int trace_stop_count;
  537. static DEFINE_SPINLOCK(tracing_start_lock);
  538. /**
  539. * tracing_start - quick start of the tracer
  540. *
  541. * If tracing is enabled but was stopped by tracing_stop,
  542. * this will start the tracer back up.
  543. */
  544. void tracing_start(void)
  545. {
  546. struct ring_buffer *buffer;
  547. unsigned long flags;
  548. if (tracing_disabled)
  549. return;
  550. spin_lock_irqsave(&tracing_start_lock, flags);
  551. if (--trace_stop_count)
  552. goto out;
  553. if (trace_stop_count < 0) {
  554. /* Someone screwed up their debugging */
  555. WARN_ON_ONCE(1);
  556. trace_stop_count = 0;
  557. goto out;
  558. }
  559. buffer = global_trace.buffer;
  560. if (buffer)
  561. ring_buffer_record_enable(buffer);
  562. buffer = max_tr.buffer;
  563. if (buffer)
  564. ring_buffer_record_enable(buffer);
  565. ftrace_start();
  566. out:
  567. spin_unlock_irqrestore(&tracing_start_lock, flags);
  568. }
  569. /**
  570. * tracing_stop - quick stop of the tracer
  571. *
  572. * Light weight way to stop tracing. Use in conjunction with
  573. * tracing_start.
  574. */
  575. void tracing_stop(void)
  576. {
  577. struct ring_buffer *buffer;
  578. unsigned long flags;
  579. ftrace_stop();
  580. spin_lock_irqsave(&tracing_start_lock, flags);
  581. if (trace_stop_count++)
  582. goto out;
  583. buffer = global_trace.buffer;
  584. if (buffer)
  585. ring_buffer_record_disable(buffer);
  586. buffer = max_tr.buffer;
  587. if (buffer)
  588. ring_buffer_record_disable(buffer);
  589. out:
  590. spin_unlock_irqrestore(&tracing_start_lock, flags);
  591. }
  592. void trace_stop_cmdline_recording(void);
  593. static void trace_save_cmdline(struct task_struct *tsk)
  594. {
  595. unsigned map;
  596. unsigned idx;
  597. if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
  598. return;
  599. /*
  600. * It's not the end of the world if we don't get
  601. * the lock, but we also don't want to spin
  602. * nor do we want to disable interrupts,
  603. * so if we miss here, then better luck next time.
  604. */
  605. if (!spin_trylock(&trace_cmdline_lock))
  606. return;
  607. idx = map_pid_to_cmdline[tsk->pid];
  608. if (idx >= SAVED_CMDLINES) {
  609. idx = (cmdline_idx + 1) % SAVED_CMDLINES;
  610. map = map_cmdline_to_pid[idx];
  611. if (map <= PID_MAX_DEFAULT)
  612. map_pid_to_cmdline[map] = (unsigned)-1;
  613. map_pid_to_cmdline[tsk->pid] = idx;
  614. cmdline_idx = idx;
  615. }
  616. memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
  617. spin_unlock(&trace_cmdline_lock);
  618. }
  619. static char *trace_find_cmdline(int pid)
  620. {
  621. char *cmdline = "<...>";
  622. unsigned map;
  623. if (!pid)
  624. return "<idle>";
  625. if (pid > PID_MAX_DEFAULT)
  626. goto out;
  627. map = map_pid_to_cmdline[pid];
  628. if (map >= SAVED_CMDLINES)
  629. goto out;
  630. cmdline = saved_cmdlines[map];
  631. out:
  632. return cmdline;
  633. }
  634. void tracing_record_cmdline(struct task_struct *tsk)
  635. {
  636. if (atomic_read(&trace_record_cmdline_disabled))
  637. return;
  638. trace_save_cmdline(tsk);
  639. }
  640. void
  641. tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
  642. int pc)
  643. {
  644. struct task_struct *tsk = current;
  645. entry->preempt_count = pc & 0xff;
  646. entry->pid = (tsk) ? tsk->pid : 0;
  647. entry->flags =
  648. #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
  649. (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
  650. #else
  651. TRACE_FLAG_IRQS_NOSUPPORT |
  652. #endif
  653. ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
  654. ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
  655. (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
  656. }
  657. void
  658. trace_function(struct trace_array *tr, struct trace_array_cpu *data,
  659. unsigned long ip, unsigned long parent_ip, unsigned long flags,
  660. int pc)
  661. {
  662. struct ring_buffer_event *event;
  663. struct ftrace_entry *entry;
  664. unsigned long irq_flags;
  665. /* If we are reading the ring buffer, don't trace */
  666. if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled))))
  667. return;
  668. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  669. &irq_flags);
  670. if (!event)
  671. return;
  672. entry = ring_buffer_event_data(event);
  673. tracing_generic_entry_update(&entry->ent, flags, pc);
  674. entry->ent.type = TRACE_FN;
  675. entry->ip = ip;
  676. entry->parent_ip = parent_ip;
  677. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  678. }
  679. void
  680. ftrace(struct trace_array *tr, struct trace_array_cpu *data,
  681. unsigned long ip, unsigned long parent_ip, unsigned long flags,
  682. int pc)
  683. {
  684. if (likely(!atomic_read(&data->disabled)))
  685. trace_function(tr, data, ip, parent_ip, flags, pc);
  686. }
  687. static void ftrace_trace_stack(struct trace_array *tr,
  688. struct trace_array_cpu *data,
  689. unsigned long flags,
  690. int skip, int pc)
  691. {
  692. #ifdef CONFIG_STACKTRACE
  693. struct ring_buffer_event *event;
  694. struct stack_entry *entry;
  695. struct stack_trace trace;
  696. unsigned long irq_flags;
  697. if (!(trace_flags & TRACE_ITER_STACKTRACE))
  698. return;
  699. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  700. &irq_flags);
  701. if (!event)
  702. return;
  703. entry = ring_buffer_event_data(event);
  704. tracing_generic_entry_update(&entry->ent, flags, pc);
  705. entry->ent.type = TRACE_STACK;
  706. memset(&entry->caller, 0, sizeof(entry->caller));
  707. trace.nr_entries = 0;
  708. trace.max_entries = FTRACE_STACK_ENTRIES;
  709. trace.skip = skip;
  710. trace.entries = entry->caller;
  711. save_stack_trace(&trace);
  712. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  713. #endif
  714. }
  715. void __trace_stack(struct trace_array *tr,
  716. struct trace_array_cpu *data,
  717. unsigned long flags,
  718. int skip)
  719. {
  720. ftrace_trace_stack(tr, data, flags, skip, preempt_count());
  721. }
  722. static void
  723. ftrace_trace_special(void *__tr, void *__data,
  724. unsigned long arg1, unsigned long arg2, unsigned long arg3,
  725. int pc)
  726. {
  727. struct ring_buffer_event *event;
  728. struct trace_array_cpu *data = __data;
  729. struct trace_array *tr = __tr;
  730. struct special_entry *entry;
  731. unsigned long irq_flags;
  732. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  733. &irq_flags);
  734. if (!event)
  735. return;
  736. entry = ring_buffer_event_data(event);
  737. tracing_generic_entry_update(&entry->ent, 0, pc);
  738. entry->ent.type = TRACE_SPECIAL;
  739. entry->arg1 = arg1;
  740. entry->arg2 = arg2;
  741. entry->arg3 = arg3;
  742. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  743. ftrace_trace_stack(tr, data, irq_flags, 4, pc);
  744. trace_wake_up();
  745. }
  746. void
  747. __trace_special(void *__tr, void *__data,
  748. unsigned long arg1, unsigned long arg2, unsigned long arg3)
  749. {
  750. ftrace_trace_special(__tr, __data, arg1, arg2, arg3, preempt_count());
  751. }
  752. void
  753. tracing_sched_switch_trace(struct trace_array *tr,
  754. struct trace_array_cpu *data,
  755. struct task_struct *prev,
  756. struct task_struct *next,
  757. unsigned long flags, int pc)
  758. {
  759. struct ring_buffer_event *event;
  760. struct ctx_switch_entry *entry;
  761. unsigned long irq_flags;
  762. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  763. &irq_flags);
  764. if (!event)
  765. return;
  766. entry = ring_buffer_event_data(event);
  767. tracing_generic_entry_update(&entry->ent, flags, pc);
  768. entry->ent.type = TRACE_CTX;
  769. entry->prev_pid = prev->pid;
  770. entry->prev_prio = prev->prio;
  771. entry->prev_state = prev->state;
  772. entry->next_pid = next->pid;
  773. entry->next_prio = next->prio;
  774. entry->next_state = next->state;
  775. entry->next_cpu = task_cpu(next);
  776. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  777. ftrace_trace_stack(tr, data, flags, 5, pc);
  778. }
  779. void
  780. tracing_sched_wakeup_trace(struct trace_array *tr,
  781. struct trace_array_cpu *data,
  782. struct task_struct *wakee,
  783. struct task_struct *curr,
  784. unsigned long flags, int pc)
  785. {
  786. struct ring_buffer_event *event;
  787. struct ctx_switch_entry *entry;
  788. unsigned long irq_flags;
  789. event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
  790. &irq_flags);
  791. if (!event)
  792. return;
  793. entry = ring_buffer_event_data(event);
  794. tracing_generic_entry_update(&entry->ent, flags, pc);
  795. entry->ent.type = TRACE_WAKE;
  796. entry->prev_pid = curr->pid;
  797. entry->prev_prio = curr->prio;
  798. entry->prev_state = curr->state;
  799. entry->next_pid = wakee->pid;
  800. entry->next_prio = wakee->prio;
  801. entry->next_state = wakee->state;
  802. entry->next_cpu = task_cpu(wakee);
  803. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  804. ftrace_trace_stack(tr, data, flags, 6, pc);
  805. trace_wake_up();
  806. }
  807. void
  808. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
  809. {
  810. struct trace_array *tr = &global_trace;
  811. struct trace_array_cpu *data;
  812. int cpu;
  813. int pc;
  814. if (tracing_disabled || !tr->ctrl)
  815. return;
  816. pc = preempt_count();
  817. preempt_disable_notrace();
  818. cpu = raw_smp_processor_id();
  819. data = tr->data[cpu];
  820. if (likely(!atomic_read(&data->disabled)))
  821. ftrace_trace_special(tr, data, arg1, arg2, arg3, pc);
  822. preempt_enable_notrace();
  823. }
  824. #ifdef CONFIG_FUNCTION_TRACER
  825. static void
  826. function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip)
  827. {
  828. struct trace_array *tr = &global_trace;
  829. struct trace_array_cpu *data;
  830. unsigned long flags;
  831. long disabled;
  832. int cpu, resched;
  833. int pc;
  834. if (unlikely(!ftrace_function_enabled))
  835. return;
  836. pc = preempt_count();
  837. resched = ftrace_preempt_disable();
  838. local_save_flags(flags);
  839. cpu = raw_smp_processor_id();
  840. data = tr->data[cpu];
  841. disabled = atomic_inc_return(&data->disabled);
  842. if (likely(disabled == 1))
  843. trace_function(tr, data, ip, parent_ip, flags, pc);
  844. atomic_dec(&data->disabled);
  845. ftrace_preempt_enable(resched);
  846. }
  847. static void
  848. function_trace_call(unsigned long ip, unsigned long parent_ip)
  849. {
  850. struct trace_array *tr = &global_trace;
  851. struct trace_array_cpu *data;
  852. unsigned long flags;
  853. long disabled;
  854. int cpu;
  855. int pc;
  856. if (unlikely(!ftrace_function_enabled))
  857. return;
  858. /*
  859. * Need to use raw, since this must be called before the
  860. * recursive protection is performed.
  861. */
  862. raw_local_irq_save(flags);
  863. cpu = raw_smp_processor_id();
  864. data = tr->data[cpu];
  865. disabled = atomic_inc_return(&data->disabled);
  866. if (likely(disabled == 1)) {
  867. pc = preempt_count();
  868. trace_function(tr, data, ip, parent_ip, flags, pc);
  869. }
  870. atomic_dec(&data->disabled);
  871. raw_local_irq_restore(flags);
  872. }
  873. static struct ftrace_ops trace_ops __read_mostly =
  874. {
  875. .func = function_trace_call,
  876. };
  877. void tracing_start_function_trace(void)
  878. {
  879. ftrace_function_enabled = 0;
  880. if (trace_flags & TRACE_ITER_PREEMPTONLY)
  881. trace_ops.func = function_trace_call_preempt_only;
  882. else
  883. trace_ops.func = function_trace_call;
  884. register_ftrace_function(&trace_ops);
  885. ftrace_function_enabled = 1;
  886. }
  887. void tracing_stop_function_trace(void)
  888. {
  889. ftrace_function_enabled = 0;
  890. unregister_ftrace_function(&trace_ops);
  891. }
  892. #endif
  893. enum trace_file_type {
  894. TRACE_FILE_LAT_FMT = 1,
  895. };
  896. static void trace_iterator_increment(struct trace_iterator *iter, int cpu)
  897. {
  898. /* Don't allow ftrace to trace into the ring buffers */
  899. ftrace_disable_cpu();
  900. iter->idx++;
  901. if (iter->buffer_iter[iter->cpu])
  902. ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
  903. ftrace_enable_cpu();
  904. }
  905. static struct trace_entry *
  906. peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts)
  907. {
  908. struct ring_buffer_event *event;
  909. struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu];
  910. /* Don't allow ftrace to trace into the ring buffers */
  911. ftrace_disable_cpu();
  912. if (buf_iter)
  913. event = ring_buffer_iter_peek(buf_iter, ts);
  914. else
  915. event = ring_buffer_peek(iter->tr->buffer, cpu, ts);
  916. ftrace_enable_cpu();
  917. return event ? ring_buffer_event_data(event) : NULL;
  918. }
  919. static struct trace_entry *
  920. __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
  921. {
  922. struct ring_buffer *buffer = iter->tr->buffer;
  923. struct trace_entry *ent, *next = NULL;
  924. u64 next_ts = 0, ts;
  925. int next_cpu = -1;
  926. int cpu;
  927. for_each_tracing_cpu(cpu) {
  928. if (ring_buffer_empty_cpu(buffer, cpu))
  929. continue;
  930. ent = peek_next_entry(iter, cpu, &ts);
  931. /*
  932. * Pick the entry with the smallest timestamp:
  933. */
  934. if (ent && (!next || ts < next_ts)) {
  935. next = ent;
  936. next_cpu = cpu;
  937. next_ts = ts;
  938. }
  939. }
  940. if (ent_cpu)
  941. *ent_cpu = next_cpu;
  942. if (ent_ts)
  943. *ent_ts = next_ts;
  944. return next;
  945. }
  946. /* Find the next real entry, without updating the iterator itself */
  947. static struct trace_entry *
  948. find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
  949. {
  950. return __find_next_entry(iter, ent_cpu, ent_ts);
  951. }
  952. /* Find the next real entry, and increment the iterator to the next entry */
  953. static void *find_next_entry_inc(struct trace_iterator *iter)
  954. {
  955. iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts);
  956. if (iter->ent)
  957. trace_iterator_increment(iter, iter->cpu);
  958. return iter->ent ? iter : NULL;
  959. }
  960. static void trace_consume(struct trace_iterator *iter)
  961. {
  962. /* Don't allow ftrace to trace into the ring buffers */
  963. ftrace_disable_cpu();
  964. ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts);
  965. ftrace_enable_cpu();
  966. }
  967. static void *s_next(struct seq_file *m, void *v, loff_t *pos)
  968. {
  969. struct trace_iterator *iter = m->private;
  970. int i = (int)*pos;
  971. void *ent;
  972. (*pos)++;
  973. /* can't go backwards */
  974. if (iter->idx > i)
  975. return NULL;
  976. if (iter->idx < 0)
  977. ent = find_next_entry_inc(iter);
  978. else
  979. ent = iter;
  980. while (ent && iter->idx < i)
  981. ent = find_next_entry_inc(iter);
  982. iter->pos = *pos;
  983. return ent;
  984. }
  985. static void *s_start(struct seq_file *m, loff_t *pos)
  986. {
  987. struct trace_iterator *iter = m->private;
  988. void *p = NULL;
  989. loff_t l = 0;
  990. int cpu;
  991. mutex_lock(&trace_types_lock);
  992. if (!current_trace || current_trace != iter->trace) {
  993. mutex_unlock(&trace_types_lock);
  994. return NULL;
  995. }
  996. atomic_inc(&trace_record_cmdline_disabled);
  997. if (*pos != iter->pos) {
  998. iter->ent = NULL;
  999. iter->cpu = 0;
  1000. iter->idx = -1;
  1001. ftrace_disable_cpu();
  1002. for_each_tracing_cpu(cpu) {
  1003. ring_buffer_iter_reset(iter->buffer_iter[cpu]);
  1004. }
  1005. ftrace_enable_cpu();
  1006. for (p = iter; p && l < *pos; p = s_next(m, p, &l))
  1007. ;
  1008. } else {
  1009. l = *pos - 1;
  1010. p = s_next(m, p, &l);
  1011. }
  1012. return p;
  1013. }
  1014. static void s_stop(struct seq_file *m, void *p)
  1015. {
  1016. atomic_dec(&trace_record_cmdline_disabled);
  1017. mutex_unlock(&trace_types_lock);
  1018. }
  1019. #ifdef CONFIG_KRETPROBES
  1020. static inline const char *kretprobed(const char *name)
  1021. {
  1022. static const char tramp_name[] = "kretprobe_trampoline";
  1023. int size = sizeof(tramp_name);
  1024. if (strncmp(tramp_name, name, size) == 0)
  1025. return "[unknown/kretprobe'd]";
  1026. return name;
  1027. }
  1028. #else
  1029. static inline const char *kretprobed(const char *name)
  1030. {
  1031. return name;
  1032. }
  1033. #endif /* CONFIG_KRETPROBES */
  1034. static int
  1035. seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
  1036. {
  1037. #ifdef CONFIG_KALLSYMS
  1038. char str[KSYM_SYMBOL_LEN];
  1039. const char *name;
  1040. kallsyms_lookup(address, NULL, NULL, NULL, str);
  1041. name = kretprobed(str);
  1042. return trace_seq_printf(s, fmt, name);
  1043. #endif
  1044. return 1;
  1045. }
  1046. static int
  1047. seq_print_sym_offset(struct trace_seq *s, const char *fmt,
  1048. unsigned long address)
  1049. {
  1050. #ifdef CONFIG_KALLSYMS
  1051. char str[KSYM_SYMBOL_LEN];
  1052. const char *name;
  1053. sprint_symbol(str, address);
  1054. name = kretprobed(str);
  1055. return trace_seq_printf(s, fmt, name);
  1056. #endif
  1057. return 1;
  1058. }
  1059. #ifndef CONFIG_64BIT
  1060. # define IP_FMT "%08lx"
  1061. #else
  1062. # define IP_FMT "%016lx"
  1063. #endif
  1064. static int
  1065. seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
  1066. {
  1067. int ret;
  1068. if (!ip)
  1069. return trace_seq_printf(s, "0");
  1070. if (sym_flags & TRACE_ITER_SYM_OFFSET)
  1071. ret = seq_print_sym_offset(s, "%s", ip);
  1072. else
  1073. ret = seq_print_sym_short(s, "%s", ip);
  1074. if (!ret)
  1075. return 0;
  1076. if (sym_flags & TRACE_ITER_SYM_ADDR)
  1077. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  1078. return ret;
  1079. }
  1080. static void print_lat_help_header(struct seq_file *m)
  1081. {
  1082. seq_puts(m, "# _------=> CPU# \n");
  1083. seq_puts(m, "# / _-----=> irqs-off \n");
  1084. seq_puts(m, "# | / _----=> need-resched \n");
  1085. seq_puts(m, "# || / _---=> hardirq/softirq \n");
  1086. seq_puts(m, "# ||| / _--=> preempt-depth \n");
  1087. seq_puts(m, "# |||| / \n");
  1088. seq_puts(m, "# ||||| delay \n");
  1089. seq_puts(m, "# cmd pid ||||| time | caller \n");
  1090. seq_puts(m, "# \\ / ||||| \\ | / \n");
  1091. }
  1092. static void print_func_help_header(struct seq_file *m)
  1093. {
  1094. seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
  1095. seq_puts(m, "# | | | | |\n");
  1096. }
  1097. static void
  1098. print_trace_header(struct seq_file *m, struct trace_iterator *iter)
  1099. {
  1100. unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
  1101. struct trace_array *tr = iter->tr;
  1102. struct trace_array_cpu *data = tr->data[tr->cpu];
  1103. struct tracer *type = current_trace;
  1104. unsigned long total;
  1105. unsigned long entries;
  1106. const char *name = "preemption";
  1107. if (type)
  1108. name = type->name;
  1109. entries = ring_buffer_entries(iter->tr->buffer);
  1110. total = entries +
  1111. ring_buffer_overruns(iter->tr->buffer);
  1112. seq_printf(m, "%s latency trace v1.1.5 on %s\n",
  1113. name, UTS_RELEASE);
  1114. seq_puts(m, "-----------------------------------"
  1115. "---------------------------------\n");
  1116. seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |"
  1117. " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
  1118. nsecs_to_usecs(data->saved_latency),
  1119. entries,
  1120. total,
  1121. tr->cpu,
  1122. #if defined(CONFIG_PREEMPT_NONE)
  1123. "server",
  1124. #elif defined(CONFIG_PREEMPT_VOLUNTARY)
  1125. "desktop",
  1126. #elif defined(CONFIG_PREEMPT)
  1127. "preempt",
  1128. #else
  1129. "unknown",
  1130. #endif
  1131. /* These are reserved for later use */
  1132. 0, 0, 0, 0);
  1133. #ifdef CONFIG_SMP
  1134. seq_printf(m, " #P:%d)\n", num_online_cpus());
  1135. #else
  1136. seq_puts(m, ")\n");
  1137. #endif
  1138. seq_puts(m, " -----------------\n");
  1139. seq_printf(m, " | task: %.16s-%d "
  1140. "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
  1141. data->comm, data->pid, data->uid, data->nice,
  1142. data->policy, data->rt_priority);
  1143. seq_puts(m, " -----------------\n");
  1144. if (data->critical_start) {
  1145. seq_puts(m, " => started at: ");
  1146. seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
  1147. trace_print_seq(m, &iter->seq);
  1148. seq_puts(m, "\n => ended at: ");
  1149. seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
  1150. trace_print_seq(m, &iter->seq);
  1151. seq_puts(m, "\n");
  1152. }
  1153. seq_puts(m, "\n");
  1154. }
  1155. static void
  1156. lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
  1157. {
  1158. int hardirq, softirq;
  1159. char *comm;
  1160. comm = trace_find_cmdline(entry->pid);
  1161. trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
  1162. trace_seq_printf(s, "%3d", cpu);
  1163. trace_seq_printf(s, "%c%c",
  1164. (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
  1165. (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
  1166. ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
  1167. hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
  1168. softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
  1169. if (hardirq && softirq) {
  1170. trace_seq_putc(s, 'H');
  1171. } else {
  1172. if (hardirq) {
  1173. trace_seq_putc(s, 'h');
  1174. } else {
  1175. if (softirq)
  1176. trace_seq_putc(s, 's');
  1177. else
  1178. trace_seq_putc(s, '.');
  1179. }
  1180. }
  1181. if (entry->preempt_count)
  1182. trace_seq_printf(s, "%x", entry->preempt_count);
  1183. else
  1184. trace_seq_puts(s, ".");
  1185. }
  1186. unsigned long preempt_mark_thresh = 100;
  1187. static void
  1188. lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
  1189. unsigned long rel_usecs)
  1190. {
  1191. trace_seq_printf(s, " %4lldus", abs_usecs);
  1192. if (rel_usecs > preempt_mark_thresh)
  1193. trace_seq_puts(s, "!: ");
  1194. else if (rel_usecs > 1)
  1195. trace_seq_puts(s, "+: ");
  1196. else
  1197. trace_seq_puts(s, " : ");
  1198. }
  1199. static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
  1200. /*
  1201. * The message is supposed to contain an ending newline.
  1202. * If the printing stops prematurely, try to add a newline of our own.
  1203. */
  1204. void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter)
  1205. {
  1206. struct trace_entry *ent;
  1207. struct trace_field_cont *cont;
  1208. bool ok = true;
  1209. ent = peek_next_entry(iter, iter->cpu, NULL);
  1210. if (!ent || ent->type != TRACE_CONT) {
  1211. trace_seq_putc(s, '\n');
  1212. return;
  1213. }
  1214. do {
  1215. cont = (struct trace_field_cont *)ent;
  1216. if (ok)
  1217. ok = (trace_seq_printf(s, "%s", cont->buf) > 0);
  1218. ftrace_disable_cpu();
  1219. if (iter->buffer_iter[iter->cpu])
  1220. ring_buffer_read(iter->buffer_iter[iter->cpu], NULL);
  1221. else
  1222. ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL);
  1223. ftrace_enable_cpu();
  1224. ent = peek_next_entry(iter, iter->cpu, NULL);
  1225. } while (ent && ent->type == TRACE_CONT);
  1226. if (!ok)
  1227. trace_seq_putc(s, '\n');
  1228. }
  1229. static enum print_line_t
  1230. print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
  1231. {
  1232. struct trace_seq *s = &iter->seq;
  1233. unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
  1234. struct trace_entry *next_entry;
  1235. unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
  1236. struct trace_entry *entry = iter->ent;
  1237. unsigned long abs_usecs;
  1238. unsigned long rel_usecs;
  1239. u64 next_ts;
  1240. char *comm;
  1241. int S, T;
  1242. int i;
  1243. unsigned state;
  1244. if (entry->type == TRACE_CONT)
  1245. return TRACE_TYPE_HANDLED;
  1246. next_entry = find_next_entry(iter, NULL, &next_ts);
  1247. if (!next_entry)
  1248. next_ts = iter->ts;
  1249. rel_usecs = ns2usecs(next_ts - iter->ts);
  1250. abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
  1251. if (verbose) {
  1252. comm = trace_find_cmdline(entry->pid);
  1253. trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]"
  1254. " %ld.%03ldms (+%ld.%03ldms): ",
  1255. comm,
  1256. entry->pid, cpu, entry->flags,
  1257. entry->preempt_count, trace_idx,
  1258. ns2usecs(iter->ts),
  1259. abs_usecs/1000,
  1260. abs_usecs % 1000, rel_usecs/1000,
  1261. rel_usecs % 1000);
  1262. } else {
  1263. lat_print_generic(s, entry, cpu);
  1264. lat_print_timestamp(s, abs_usecs, rel_usecs);
  1265. }
  1266. switch (entry->type) {
  1267. case TRACE_FN: {
  1268. struct ftrace_entry *field;
  1269. trace_assign_type(field, entry);
  1270. seq_print_ip_sym(s, field->ip, sym_flags);
  1271. trace_seq_puts(s, " (");
  1272. seq_print_ip_sym(s, field->parent_ip, sym_flags);
  1273. trace_seq_puts(s, ")\n");
  1274. break;
  1275. }
  1276. case TRACE_CTX:
  1277. case TRACE_WAKE: {
  1278. struct ctx_switch_entry *field;
  1279. trace_assign_type(field, entry);
  1280. T = field->next_state < sizeof(state_to_char) ?
  1281. state_to_char[field->next_state] : 'X';
  1282. state = field->prev_state ?
  1283. __ffs(field->prev_state) + 1 : 0;
  1284. S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X';
  1285. comm = trace_find_cmdline(field->next_pid);
  1286. trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  1287. field->prev_pid,
  1288. field->prev_prio,
  1289. S, entry->type == TRACE_CTX ? "==>" : " +",
  1290. field->next_cpu,
  1291. field->next_pid,
  1292. field->next_prio,
  1293. T, comm);
  1294. break;
  1295. }
  1296. case TRACE_SPECIAL: {
  1297. struct special_entry *field;
  1298. trace_assign_type(field, entry);
  1299. trace_seq_printf(s, "# %ld %ld %ld\n",
  1300. field->arg1,
  1301. field->arg2,
  1302. field->arg3);
  1303. break;
  1304. }
  1305. case TRACE_STACK: {
  1306. struct stack_entry *field;
  1307. trace_assign_type(field, entry);
  1308. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  1309. if (i)
  1310. trace_seq_puts(s, " <= ");
  1311. seq_print_ip_sym(s, field->caller[i], sym_flags);
  1312. }
  1313. trace_seq_puts(s, "\n");
  1314. break;
  1315. }
  1316. case TRACE_PRINT: {
  1317. struct print_entry *field;
  1318. trace_assign_type(field, entry);
  1319. seq_print_ip_sym(s, field->ip, sym_flags);
  1320. trace_seq_printf(s, ": %s", field->buf);
  1321. if (entry->flags & TRACE_FLAG_CONT)
  1322. trace_seq_print_cont(s, iter);
  1323. break;
  1324. }
  1325. default:
  1326. trace_seq_printf(s, "Unknown type %d\n", entry->type);
  1327. }
  1328. return TRACE_TYPE_HANDLED;
  1329. }
  1330. static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
  1331. {
  1332. struct trace_seq *s = &iter->seq;
  1333. unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
  1334. struct trace_entry *entry;
  1335. unsigned long usec_rem;
  1336. unsigned long long t;
  1337. unsigned long secs;
  1338. char *comm;
  1339. int ret;
  1340. int S, T;
  1341. int i;
  1342. entry = iter->ent;
  1343. if (entry->type == TRACE_CONT)
  1344. return TRACE_TYPE_HANDLED;
  1345. comm = trace_find_cmdline(iter->ent->pid);
  1346. t = ns2usecs(iter->ts);
  1347. usec_rem = do_div(t, 1000000ULL);
  1348. secs = (unsigned long)t;
  1349. ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
  1350. if (!ret)
  1351. return TRACE_TYPE_PARTIAL_LINE;
  1352. ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
  1353. if (!ret)
  1354. return TRACE_TYPE_PARTIAL_LINE;
  1355. ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
  1356. if (!ret)
  1357. return TRACE_TYPE_PARTIAL_LINE;
  1358. switch (entry->type) {
  1359. case TRACE_FN: {
  1360. struct ftrace_entry *field;
  1361. trace_assign_type(field, entry);
  1362. ret = seq_print_ip_sym(s, field->ip, sym_flags);
  1363. if (!ret)
  1364. return TRACE_TYPE_PARTIAL_LINE;
  1365. if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
  1366. field->parent_ip) {
  1367. ret = trace_seq_printf(s, " <-");
  1368. if (!ret)
  1369. return TRACE_TYPE_PARTIAL_LINE;
  1370. ret = seq_print_ip_sym(s,
  1371. field->parent_ip,
  1372. sym_flags);
  1373. if (!ret)
  1374. return TRACE_TYPE_PARTIAL_LINE;
  1375. }
  1376. ret = trace_seq_printf(s, "\n");
  1377. if (!ret)
  1378. return TRACE_TYPE_PARTIAL_LINE;
  1379. break;
  1380. }
  1381. case TRACE_CTX:
  1382. case TRACE_WAKE: {
  1383. struct ctx_switch_entry *field;
  1384. trace_assign_type(field, entry);
  1385. S = field->prev_state < sizeof(state_to_char) ?
  1386. state_to_char[field->prev_state] : 'X';
  1387. T = field->next_state < sizeof(state_to_char) ?
  1388. state_to_char[field->next_state] : 'X';
  1389. ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n",
  1390. field->prev_pid,
  1391. field->prev_prio,
  1392. S,
  1393. entry->type == TRACE_CTX ? "==>" : " +",
  1394. field->next_cpu,
  1395. field->next_pid,
  1396. field->next_prio,
  1397. T);
  1398. if (!ret)
  1399. return TRACE_TYPE_PARTIAL_LINE;
  1400. break;
  1401. }
  1402. case TRACE_SPECIAL: {
  1403. struct special_entry *field;
  1404. trace_assign_type(field, entry);
  1405. ret = trace_seq_printf(s, "# %ld %ld %ld\n",
  1406. field->arg1,
  1407. field->arg2,
  1408. field->arg3);
  1409. if (!ret)
  1410. return TRACE_TYPE_PARTIAL_LINE;
  1411. break;
  1412. }
  1413. case TRACE_STACK: {
  1414. struct stack_entry *field;
  1415. trace_assign_type(field, entry);
  1416. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  1417. if (i) {
  1418. ret = trace_seq_puts(s, " <= ");
  1419. if (!ret)
  1420. return TRACE_TYPE_PARTIAL_LINE;
  1421. }
  1422. ret = seq_print_ip_sym(s, field->caller[i],
  1423. sym_flags);
  1424. if (!ret)
  1425. return TRACE_TYPE_PARTIAL_LINE;
  1426. }
  1427. ret = trace_seq_puts(s, "\n");
  1428. if (!ret)
  1429. return TRACE_TYPE_PARTIAL_LINE;
  1430. break;
  1431. }
  1432. case TRACE_PRINT: {
  1433. struct print_entry *field;
  1434. trace_assign_type(field, entry);
  1435. seq_print_ip_sym(s, field->ip, sym_flags);
  1436. trace_seq_printf(s, ": %s", field->buf);
  1437. if (entry->flags & TRACE_FLAG_CONT)
  1438. trace_seq_print_cont(s, iter);
  1439. break;
  1440. }
  1441. }
  1442. return TRACE_TYPE_HANDLED;
  1443. }
  1444. static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
  1445. {
  1446. struct trace_seq *s = &iter->seq;
  1447. struct trace_entry *entry;
  1448. int ret;
  1449. int S, T;
  1450. entry = iter->ent;
  1451. if (entry->type == TRACE_CONT)
  1452. return TRACE_TYPE_HANDLED;
  1453. ret = trace_seq_printf(s, "%d %d %llu ",
  1454. entry->pid, iter->cpu, iter->ts);
  1455. if (!ret)
  1456. return TRACE_TYPE_PARTIAL_LINE;
  1457. switch (entry->type) {
  1458. case TRACE_FN: {
  1459. struct ftrace_entry *field;
  1460. trace_assign_type(field, entry);
  1461. ret = trace_seq_printf(s, "%x %x\n",
  1462. field->ip,
  1463. field->parent_ip);
  1464. if (!ret)
  1465. return TRACE_TYPE_PARTIAL_LINE;
  1466. break;
  1467. }
  1468. case TRACE_CTX:
  1469. case TRACE_WAKE: {
  1470. struct ctx_switch_entry *field;
  1471. trace_assign_type(field, entry);
  1472. S = field->prev_state < sizeof(state_to_char) ?
  1473. state_to_char[field->prev_state] : 'X';
  1474. T = field->next_state < sizeof(state_to_char) ?
  1475. state_to_char[field->next_state] : 'X';
  1476. if (entry->type == TRACE_WAKE)
  1477. S = '+';
  1478. ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n",
  1479. field->prev_pid,
  1480. field->prev_prio,
  1481. S,
  1482. field->next_cpu,
  1483. field->next_pid,
  1484. field->next_prio,
  1485. T);
  1486. if (!ret)
  1487. return TRACE_TYPE_PARTIAL_LINE;
  1488. break;
  1489. }
  1490. case TRACE_SPECIAL:
  1491. case TRACE_STACK: {
  1492. struct special_entry *field;
  1493. trace_assign_type(field, entry);
  1494. ret = trace_seq_printf(s, "# %ld %ld %ld\n",
  1495. field->arg1,
  1496. field->arg2,
  1497. field->arg3);
  1498. if (!ret)
  1499. return TRACE_TYPE_PARTIAL_LINE;
  1500. break;
  1501. }
  1502. case TRACE_PRINT: {
  1503. struct print_entry *field;
  1504. trace_assign_type(field, entry);
  1505. trace_seq_printf(s, "# %lx %s", field->ip, field->buf);
  1506. if (entry->flags & TRACE_FLAG_CONT)
  1507. trace_seq_print_cont(s, iter);
  1508. break;
  1509. }
  1510. }
  1511. return TRACE_TYPE_HANDLED;
  1512. }
  1513. #define SEQ_PUT_FIELD_RET(s, x) \
  1514. do { \
  1515. if (!trace_seq_putmem(s, &(x), sizeof(x))) \
  1516. return 0; \
  1517. } while (0)
  1518. #define SEQ_PUT_HEX_FIELD_RET(s, x) \
  1519. do { \
  1520. BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \
  1521. if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \
  1522. return 0; \
  1523. } while (0)
  1524. static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
  1525. {
  1526. struct trace_seq *s = &iter->seq;
  1527. unsigned char newline = '\n';
  1528. struct trace_entry *entry;
  1529. int S, T;
  1530. entry = iter->ent;
  1531. if (entry->type == TRACE_CONT)
  1532. return TRACE_TYPE_HANDLED;
  1533. SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
  1534. SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
  1535. SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
  1536. switch (entry->type) {
  1537. case TRACE_FN: {
  1538. struct ftrace_entry *field;
  1539. trace_assign_type(field, entry);
  1540. SEQ_PUT_HEX_FIELD_RET(s, field->ip);
  1541. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  1542. break;
  1543. }
  1544. case TRACE_CTX:
  1545. case TRACE_WAKE: {
  1546. struct ctx_switch_entry *field;
  1547. trace_assign_type(field, entry);
  1548. S = field->prev_state < sizeof(state_to_char) ?
  1549. state_to_char[field->prev_state] : 'X';
  1550. T = field->next_state < sizeof(state_to_char) ?
  1551. state_to_char[field->next_state] : 'X';
  1552. if (entry->type == TRACE_WAKE)
  1553. S = '+';
  1554. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  1555. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  1556. SEQ_PUT_HEX_FIELD_RET(s, S);
  1557. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  1558. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  1559. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  1560. SEQ_PUT_HEX_FIELD_RET(s, T);
  1561. break;
  1562. }
  1563. case TRACE_SPECIAL:
  1564. case TRACE_STACK: {
  1565. struct special_entry *field;
  1566. trace_assign_type(field, entry);
  1567. SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
  1568. SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
  1569. SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
  1570. break;
  1571. }
  1572. }
  1573. SEQ_PUT_FIELD_RET(s, newline);
  1574. return TRACE_TYPE_HANDLED;
  1575. }
  1576. static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
  1577. {
  1578. struct trace_seq *s = &iter->seq;
  1579. struct trace_entry *entry;
  1580. entry = iter->ent;
  1581. if (entry->type == TRACE_CONT)
  1582. return TRACE_TYPE_HANDLED;
  1583. SEQ_PUT_FIELD_RET(s, entry->pid);
  1584. SEQ_PUT_FIELD_RET(s, entry->cpu);
  1585. SEQ_PUT_FIELD_RET(s, iter->ts);
  1586. switch (entry->type) {
  1587. case TRACE_FN: {
  1588. struct ftrace_entry *field;
  1589. trace_assign_type(field, entry);
  1590. SEQ_PUT_FIELD_RET(s, field->ip);
  1591. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  1592. break;
  1593. }
  1594. case TRACE_CTX: {
  1595. struct ctx_switch_entry *field;
  1596. trace_assign_type(field, entry);
  1597. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  1598. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  1599. SEQ_PUT_FIELD_RET(s, field->prev_state);
  1600. SEQ_PUT_FIELD_RET(s, field->next_pid);
  1601. SEQ_PUT_FIELD_RET(s, field->next_prio);
  1602. SEQ_PUT_FIELD_RET(s, field->next_state);
  1603. break;
  1604. }
  1605. case TRACE_SPECIAL:
  1606. case TRACE_STACK: {
  1607. struct special_entry *field;
  1608. trace_assign_type(field, entry);
  1609. SEQ_PUT_FIELD_RET(s, field->arg1);
  1610. SEQ_PUT_FIELD_RET(s, field->arg2);
  1611. SEQ_PUT_FIELD_RET(s, field->arg3);
  1612. break;
  1613. }
  1614. }
  1615. return 1;
  1616. }
  1617. static int trace_empty(struct trace_iterator *iter)
  1618. {
  1619. int cpu;
  1620. for_each_tracing_cpu(cpu) {
  1621. if (iter->buffer_iter[cpu]) {
  1622. if (!ring_buffer_iter_empty(iter->buffer_iter[cpu]))
  1623. return 0;
  1624. } else {
  1625. if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu))
  1626. return 0;
  1627. }
  1628. }
  1629. return 1;
  1630. }
  1631. static enum print_line_t print_trace_line(struct trace_iterator *iter)
  1632. {
  1633. enum print_line_t ret;
  1634. if (iter->trace && iter->trace->print_line) {
  1635. ret = iter->trace->print_line(iter);
  1636. if (ret != TRACE_TYPE_UNHANDLED)
  1637. return ret;
  1638. }
  1639. if (trace_flags & TRACE_ITER_BIN)
  1640. return print_bin_fmt(iter);
  1641. if (trace_flags & TRACE_ITER_HEX)
  1642. return print_hex_fmt(iter);
  1643. if (trace_flags & TRACE_ITER_RAW)
  1644. return print_raw_fmt(iter);
  1645. if (iter->iter_flags & TRACE_FILE_LAT_FMT)
  1646. return print_lat_fmt(iter, iter->idx, iter->cpu);
  1647. return print_trace_fmt(iter);
  1648. }
  1649. static int s_show(struct seq_file *m, void *v)
  1650. {
  1651. struct trace_iterator *iter = v;
  1652. if (iter->ent == NULL) {
  1653. if (iter->tr) {
  1654. seq_printf(m, "# tracer: %s\n", iter->trace->name);
  1655. seq_puts(m, "#\n");
  1656. }
  1657. if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
  1658. /* print nothing if the buffers are empty */
  1659. if (trace_empty(iter))
  1660. return 0;
  1661. print_trace_header(m, iter);
  1662. if (!(trace_flags & TRACE_ITER_VERBOSE))
  1663. print_lat_help_header(m);
  1664. } else {
  1665. if (!(trace_flags & TRACE_ITER_VERBOSE))
  1666. print_func_help_header(m);
  1667. }
  1668. } else {
  1669. print_trace_line(iter);
  1670. trace_print_seq(m, &iter->seq);
  1671. }
  1672. return 0;
  1673. }
  1674. static struct seq_operations tracer_seq_ops = {
  1675. .start = s_start,
  1676. .next = s_next,
  1677. .stop = s_stop,
  1678. .show = s_show,
  1679. };
  1680. static struct trace_iterator *
  1681. __tracing_open(struct inode *inode, struct file *file, int *ret)
  1682. {
  1683. struct trace_iterator *iter;
  1684. struct seq_file *m;
  1685. int cpu;
  1686. if (tracing_disabled) {
  1687. *ret = -ENODEV;
  1688. return NULL;
  1689. }
  1690. iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  1691. if (!iter) {
  1692. *ret = -ENOMEM;
  1693. goto out;
  1694. }
  1695. mutex_lock(&trace_types_lock);
  1696. if (current_trace && current_trace->print_max)
  1697. iter->tr = &max_tr;
  1698. else
  1699. iter->tr = inode->i_private;
  1700. iter->trace = current_trace;
  1701. iter->pos = -1;
  1702. for_each_tracing_cpu(cpu) {
  1703. iter->buffer_iter[cpu] =
  1704. ring_buffer_read_start(iter->tr->buffer, cpu);
  1705. if (!iter->buffer_iter[cpu])
  1706. goto fail_buffer;
  1707. }
  1708. /* TODO stop tracer */
  1709. *ret = seq_open(file, &tracer_seq_ops);
  1710. if (*ret)
  1711. goto fail_buffer;
  1712. m = file->private_data;
  1713. m->private = iter;
  1714. /* stop the trace while dumping */
  1715. tracing_stop();
  1716. if (iter->trace && iter->trace->open)
  1717. iter->trace->open(iter);
  1718. mutex_unlock(&trace_types_lock);
  1719. out:
  1720. return iter;
  1721. fail_buffer:
  1722. for_each_tracing_cpu(cpu) {
  1723. if (iter->buffer_iter[cpu])
  1724. ring_buffer_read_finish(iter->buffer_iter[cpu]);
  1725. }
  1726. mutex_unlock(&trace_types_lock);
  1727. return ERR_PTR(-ENOMEM);
  1728. }
  1729. int tracing_open_generic(struct inode *inode, struct file *filp)
  1730. {
  1731. if (tracing_disabled)
  1732. return -ENODEV;
  1733. filp->private_data = inode->i_private;
  1734. return 0;
  1735. }
  1736. int tracing_release(struct inode *inode, struct file *file)
  1737. {
  1738. struct seq_file *m = (struct seq_file *)file->private_data;
  1739. struct trace_iterator *iter = m->private;
  1740. int cpu;
  1741. mutex_lock(&trace_types_lock);
  1742. for_each_tracing_cpu(cpu) {
  1743. if (iter->buffer_iter[cpu])
  1744. ring_buffer_read_finish(iter->buffer_iter[cpu]);
  1745. }
  1746. if (iter->trace && iter->trace->close)
  1747. iter->trace->close(iter);
  1748. /* reenable tracing if it was previously enabled */
  1749. tracing_start();
  1750. mutex_unlock(&trace_types_lock);
  1751. seq_release(inode, file);
  1752. kfree(iter);
  1753. return 0;
  1754. }
  1755. static int tracing_open(struct inode *inode, struct file *file)
  1756. {
  1757. int ret;
  1758. __tracing_open(inode, file, &ret);
  1759. return ret;
  1760. }
  1761. static int tracing_lt_open(struct inode *inode, struct file *file)
  1762. {
  1763. struct trace_iterator *iter;
  1764. int ret;
  1765. iter = __tracing_open(inode, file, &ret);
  1766. if (!ret)
  1767. iter->iter_flags |= TRACE_FILE_LAT_FMT;
  1768. return ret;
  1769. }
  1770. static void *
  1771. t_next(struct seq_file *m, void *v, loff_t *pos)
  1772. {
  1773. struct tracer *t = m->private;
  1774. (*pos)++;
  1775. if (t)
  1776. t = t->next;
  1777. m->private = t;
  1778. return t;
  1779. }
  1780. static void *t_start(struct seq_file *m, loff_t *pos)
  1781. {
  1782. struct tracer *t = m->private;
  1783. loff_t l = 0;
  1784. mutex_lock(&trace_types_lock);
  1785. for (; t && l < *pos; t = t_next(m, t, &l))
  1786. ;
  1787. return t;
  1788. }
  1789. static void t_stop(struct seq_file *m, void *p)
  1790. {
  1791. mutex_unlock(&trace_types_lock);
  1792. }
  1793. static int t_show(struct seq_file *m, void *v)
  1794. {
  1795. struct tracer *t = v;
  1796. if (!t)
  1797. return 0;
  1798. seq_printf(m, "%s", t->name);
  1799. if (t->next)
  1800. seq_putc(m, ' ');
  1801. else
  1802. seq_putc(m, '\n');
  1803. return 0;
  1804. }
  1805. static struct seq_operations show_traces_seq_ops = {
  1806. .start = t_start,
  1807. .next = t_next,
  1808. .stop = t_stop,
  1809. .show = t_show,
  1810. };
  1811. static int show_traces_open(struct inode *inode, struct file *file)
  1812. {
  1813. int ret;
  1814. if (tracing_disabled)
  1815. return -ENODEV;
  1816. ret = seq_open(file, &show_traces_seq_ops);
  1817. if (!ret) {
  1818. struct seq_file *m = file->private_data;
  1819. m->private = trace_types;
  1820. }
  1821. return ret;
  1822. }
  1823. static struct file_operations tracing_fops = {
  1824. .open = tracing_open,
  1825. .read = seq_read,
  1826. .llseek = seq_lseek,
  1827. .release = tracing_release,
  1828. };
  1829. static struct file_operations tracing_lt_fops = {
  1830. .open = tracing_lt_open,
  1831. .read = seq_read,
  1832. .llseek = seq_lseek,
  1833. .release = tracing_release,
  1834. };
  1835. static struct file_operations show_traces_fops = {
  1836. .open = show_traces_open,
  1837. .read = seq_read,
  1838. .release = seq_release,
  1839. };
  1840. /*
  1841. * Only trace on a CPU if the bitmask is set:
  1842. */
  1843. static cpumask_t tracing_cpumask = CPU_MASK_ALL;
  1844. /*
  1845. * When tracing/tracing_cpu_mask is modified then this holds
  1846. * the new bitmask we are about to install:
  1847. */
  1848. static cpumask_t tracing_cpumask_new;
  1849. /*
  1850. * The tracer itself will not take this lock, but still we want
  1851. * to provide a consistent cpumask to user-space:
  1852. */
  1853. static DEFINE_MUTEX(tracing_cpumask_update_lock);
  1854. /*
  1855. * Temporary storage for the character representation of the
  1856. * CPU bitmask (and one more byte for the newline):
  1857. */
  1858. static char mask_str[NR_CPUS + 1];
  1859. static ssize_t
  1860. tracing_cpumask_read(struct file *filp, char __user *ubuf,
  1861. size_t count, loff_t *ppos)
  1862. {
  1863. int len;
  1864. mutex_lock(&tracing_cpumask_update_lock);
  1865. len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
  1866. if (count - len < 2) {
  1867. count = -EINVAL;
  1868. goto out_err;
  1869. }
  1870. len += sprintf(mask_str + len, "\n");
  1871. count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
  1872. out_err:
  1873. mutex_unlock(&tracing_cpumask_update_lock);
  1874. return count;
  1875. }
  1876. static ssize_t
  1877. tracing_cpumask_write(struct file *filp, const char __user *ubuf,
  1878. size_t count, loff_t *ppos)
  1879. {
  1880. int err, cpu;
  1881. mutex_lock(&tracing_cpumask_update_lock);
  1882. err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
  1883. if (err)
  1884. goto err_unlock;
  1885. raw_local_irq_disable();
  1886. __raw_spin_lock(&ftrace_max_lock);
  1887. for_each_tracing_cpu(cpu) {
  1888. /*
  1889. * Increase/decrease the disabled counter if we are
  1890. * about to flip a bit in the cpumask:
  1891. */
  1892. if (cpu_isset(cpu, tracing_cpumask) &&
  1893. !cpu_isset(cpu, tracing_cpumask_new)) {
  1894. atomic_inc(&global_trace.data[cpu]->disabled);
  1895. }
  1896. if (!cpu_isset(cpu, tracing_cpumask) &&
  1897. cpu_isset(cpu, tracing_cpumask_new)) {
  1898. atomic_dec(&global_trace.data[cpu]->disabled);
  1899. }
  1900. }
  1901. __raw_spin_unlock(&ftrace_max_lock);
  1902. raw_local_irq_enable();
  1903. tracing_cpumask = tracing_cpumask_new;
  1904. mutex_unlock(&tracing_cpumask_update_lock);
  1905. return count;
  1906. err_unlock:
  1907. mutex_unlock(&tracing_cpumask_update_lock);
  1908. return err;
  1909. }
  1910. static struct file_operations tracing_cpumask_fops = {
  1911. .open = tracing_open_generic,
  1912. .read = tracing_cpumask_read,
  1913. .write = tracing_cpumask_write,
  1914. };
  1915. static ssize_t
  1916. tracing_iter_ctrl_read(struct file *filp, char __user *ubuf,
  1917. size_t cnt, loff_t *ppos)
  1918. {
  1919. char *buf;
  1920. int r = 0;
  1921. int len = 0;
  1922. int i;
  1923. /* calulate max size */
  1924. for (i = 0; trace_options[i]; i++) {
  1925. len += strlen(trace_options[i]);
  1926. len += 3; /* "no" and space */
  1927. }
  1928. /* +2 for \n and \0 */
  1929. buf = kmalloc(len + 2, GFP_KERNEL);
  1930. if (!buf)
  1931. return -ENOMEM;
  1932. for (i = 0; trace_options[i]; i++) {
  1933. if (trace_flags & (1 << i))
  1934. r += sprintf(buf + r, "%s ", trace_options[i]);
  1935. else
  1936. r += sprintf(buf + r, "no%s ", trace_options[i]);
  1937. }
  1938. r += sprintf(buf + r, "\n");
  1939. WARN_ON(r >= len + 2);
  1940. r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  1941. kfree(buf);
  1942. return r;
  1943. }
  1944. static ssize_t
  1945. tracing_iter_ctrl_write(struct file *filp, const char __user *ubuf,
  1946. size_t cnt, loff_t *ppos)
  1947. {
  1948. char buf[64];
  1949. char *cmp = buf;
  1950. int neg = 0;
  1951. int i;
  1952. if (cnt >= sizeof(buf))
  1953. return -EINVAL;
  1954. if (copy_from_user(&buf, ubuf, cnt))
  1955. return -EFAULT;
  1956. buf[cnt] = 0;
  1957. if (strncmp(buf, "no", 2) == 0) {
  1958. neg = 1;
  1959. cmp += 2;
  1960. }
  1961. for (i = 0; trace_options[i]; i++) {
  1962. int len = strlen(trace_options[i]);
  1963. if (strncmp(cmp, trace_options[i], len) == 0) {
  1964. if (neg)
  1965. trace_flags &= ~(1 << i);
  1966. else
  1967. trace_flags |= (1 << i);
  1968. break;
  1969. }
  1970. }
  1971. /*
  1972. * If no option could be set, return an error:
  1973. */
  1974. if (!trace_options[i])
  1975. return -EINVAL;
  1976. filp->f_pos += cnt;
  1977. return cnt;
  1978. }
  1979. static struct file_operations tracing_iter_fops = {
  1980. .open = tracing_open_generic,
  1981. .read = tracing_iter_ctrl_read,
  1982. .write = tracing_iter_ctrl_write,
  1983. };
  1984. static const char readme_msg[] =
  1985. "tracing mini-HOWTO:\n\n"
  1986. "# mkdir /debug\n"
  1987. "# mount -t debugfs nodev /debug\n\n"
  1988. "# cat /debug/tracing/available_tracers\n"
  1989. "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
  1990. "# cat /debug/tracing/current_tracer\n"
  1991. "none\n"
  1992. "# echo sched_switch > /debug/tracing/current_tracer\n"
  1993. "# cat /debug/tracing/current_tracer\n"
  1994. "sched_switch\n"
  1995. "# cat /debug/tracing/iter_ctrl\n"
  1996. "noprint-parent nosym-offset nosym-addr noverbose\n"
  1997. "# echo print-parent > /debug/tracing/iter_ctrl\n"
  1998. "# echo 1 > /debug/tracing/tracing_enabled\n"
  1999. "# cat /debug/tracing/trace > /tmp/trace.txt\n"
  2000. "echo 0 > /debug/tracing/tracing_enabled\n"
  2001. ;
  2002. static ssize_t
  2003. tracing_readme_read(struct file *filp, char __user *ubuf,
  2004. size_t cnt, loff_t *ppos)
  2005. {
  2006. return simple_read_from_buffer(ubuf, cnt, ppos,
  2007. readme_msg, strlen(readme_msg));
  2008. }
  2009. static struct file_operations tracing_readme_fops = {
  2010. .open = tracing_open_generic,
  2011. .read = tracing_readme_read,
  2012. };
  2013. static ssize_t
  2014. tracing_ctrl_read(struct file *filp, char __user *ubuf,
  2015. size_t cnt, loff_t *ppos)
  2016. {
  2017. char buf[64];
  2018. int r;
  2019. r = sprintf(buf, "%u\n", tracer_enabled);
  2020. return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  2021. }
  2022. static ssize_t
  2023. tracing_ctrl_write(struct file *filp, const char __user *ubuf,
  2024. size_t cnt, loff_t *ppos)
  2025. {
  2026. struct trace_array *tr = filp->private_data;
  2027. char buf[64];
  2028. long val;
  2029. int ret;
  2030. if (cnt >= sizeof(buf))
  2031. return -EINVAL;
  2032. if (copy_from_user(&buf, ubuf, cnt))
  2033. return -EFAULT;
  2034. buf[cnt] = 0;
  2035. ret = strict_strtoul(buf, 10, &val);
  2036. if (ret < 0)
  2037. return ret;
  2038. val = !!val;
  2039. mutex_lock(&trace_types_lock);
  2040. if (tracer_enabled ^ val) {
  2041. if (val) {
  2042. tracer_enabled = 1;
  2043. if (current_trace->start)
  2044. current_trace->start(tr);
  2045. tracing_start();
  2046. } else {
  2047. tracer_enabled = 0;
  2048. tracing_stop();
  2049. if (current_trace->stop)
  2050. current_trace->stop(tr);
  2051. }
  2052. }
  2053. mutex_unlock(&trace_types_lock);
  2054. filp->f_pos += cnt;
  2055. return cnt;
  2056. }
  2057. static ssize_t
  2058. tracing_set_trace_read(struct file *filp, char __user *ubuf,
  2059. size_t cnt, loff_t *ppos)
  2060. {
  2061. char buf[max_tracer_type_len+2];
  2062. int r;
  2063. mutex_lock(&trace_types_lock);
  2064. if (current_trace)
  2065. r = sprintf(buf, "%s\n", current_trace->name);
  2066. else
  2067. r = sprintf(buf, "\n");
  2068. mutex_unlock(&trace_types_lock);
  2069. return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  2070. }
  2071. static int tracing_set_tracer(char *buf)
  2072. {
  2073. struct trace_array *tr = &global_trace;
  2074. struct tracer *t;
  2075. int ret = 0;
  2076. mutex_lock(&trace_types_lock);
  2077. for (t = trace_types; t; t = t->next) {
  2078. if (strcmp(t->name, buf) == 0)
  2079. break;
  2080. }
  2081. if (!t) {
  2082. ret = -EINVAL;
  2083. goto out;
  2084. }
  2085. if (t == current_trace)
  2086. goto out;
  2087. if (current_trace && current_trace->reset)
  2088. current_trace->reset(tr);
  2089. current_trace = t;
  2090. if (t->init)
  2091. t->init(tr);
  2092. out:
  2093. mutex_unlock(&trace_types_lock);
  2094. return ret;
  2095. }
  2096. static ssize_t
  2097. tracing_set_trace_write(struct file *filp, const char __user *ubuf,
  2098. size_t cnt, loff_t *ppos)
  2099. {
  2100. char buf[max_tracer_type_len+1];
  2101. int i;
  2102. size_t ret;
  2103. if (cnt > max_tracer_type_len)
  2104. cnt = max_tracer_type_len;
  2105. if (copy_from_user(&buf, ubuf, cnt))
  2106. return -EFAULT;
  2107. buf[cnt] = 0;
  2108. /* strip ending whitespace. */
  2109. for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
  2110. buf[i] = 0;
  2111. ret = tracing_set_tracer(buf);
  2112. if (!ret)
  2113. ret = cnt;
  2114. if (ret > 0)
  2115. filp->f_pos += ret;
  2116. return ret;
  2117. }
  2118. static ssize_t
  2119. tracing_max_lat_read(struct file *filp, char __user *ubuf,
  2120. size_t cnt, loff_t *ppos)
  2121. {
  2122. unsigned long *ptr = filp->private_data;
  2123. char buf[64];
  2124. int r;
  2125. r = snprintf(buf, sizeof(buf), "%ld\n",
  2126. *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
  2127. if (r > sizeof(buf))
  2128. r = sizeof(buf);
  2129. return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  2130. }
  2131. static ssize_t
  2132. tracing_max_lat_write(struct file *filp, const char __user *ubuf,
  2133. size_t cnt, loff_t *ppos)
  2134. {
  2135. long *ptr = filp->private_data;
  2136. char buf[64];
  2137. long val;
  2138. int ret;
  2139. if (cnt >= sizeof(buf))
  2140. return -EINVAL;
  2141. if (copy_from_user(&buf, ubuf, cnt))
  2142. return -EFAULT;
  2143. buf[cnt] = 0;
  2144. ret = strict_strtoul(buf, 10, &val);
  2145. if (ret < 0)
  2146. return ret;
  2147. *ptr = val * 1000;
  2148. return cnt;
  2149. }
  2150. static atomic_t tracing_reader;
  2151. static int tracing_open_pipe(struct inode *inode, struct file *filp)
  2152. {
  2153. struct trace_iterator *iter;
  2154. if (tracing_disabled)
  2155. return -ENODEV;
  2156. /* We only allow for reader of the pipe */
  2157. if (atomic_inc_return(&tracing_reader) != 1) {
  2158. atomic_dec(&tracing_reader);
  2159. return -EBUSY;
  2160. }
  2161. /* create a buffer to store the information to pass to userspace */
  2162. iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  2163. if (!iter)
  2164. return -ENOMEM;
  2165. mutex_lock(&trace_types_lock);
  2166. iter->tr = &global_trace;
  2167. iter->trace = current_trace;
  2168. filp->private_data = iter;
  2169. if (iter->trace->pipe_open)
  2170. iter->trace->pipe_open(iter);
  2171. mutex_unlock(&trace_types_lock);
  2172. return 0;
  2173. }
  2174. static int tracing_release_pipe(struct inode *inode, struct file *file)
  2175. {
  2176. struct trace_iterator *iter = file->private_data;
  2177. kfree(iter);
  2178. atomic_dec(&tracing_reader);
  2179. return 0;
  2180. }
  2181. static unsigned int
  2182. tracing_poll_pipe(struct file *filp, poll_table *poll_table)
  2183. {
  2184. struct trace_iterator *iter = filp->private_data;
  2185. if (trace_flags & TRACE_ITER_BLOCK) {
  2186. /*
  2187. * Always select as readable when in blocking mode
  2188. */
  2189. return POLLIN | POLLRDNORM;
  2190. } else {
  2191. if (!trace_empty(iter))
  2192. return POLLIN | POLLRDNORM;
  2193. poll_wait(filp, &trace_wait, poll_table);
  2194. if (!trace_empty(iter))
  2195. return POLLIN | POLLRDNORM;
  2196. return 0;
  2197. }
  2198. }
  2199. /*
  2200. * Consumer reader.
  2201. */
  2202. static ssize_t
  2203. tracing_read_pipe(struct file *filp, char __user *ubuf,
  2204. size_t cnt, loff_t *ppos)
  2205. {
  2206. struct trace_iterator *iter = filp->private_data;
  2207. ssize_t sret;
  2208. /* return any leftover data */
  2209. sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
  2210. if (sret != -EBUSY)
  2211. return sret;
  2212. trace_seq_reset(&iter->seq);
  2213. mutex_lock(&trace_types_lock);
  2214. if (iter->trace->read) {
  2215. sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
  2216. if (sret)
  2217. goto out;
  2218. }
  2219. waitagain:
  2220. sret = 0;
  2221. while (trace_empty(iter)) {
  2222. if ((filp->f_flags & O_NONBLOCK)) {
  2223. sret = -EAGAIN;
  2224. goto out;
  2225. }
  2226. /*
  2227. * This is a make-shift waitqueue. The reason we don't use
  2228. * an actual wait queue is because:
  2229. * 1) we only ever have one waiter
  2230. * 2) the tracing, traces all functions, we don't want
  2231. * the overhead of calling wake_up and friends
  2232. * (and tracing them too)
  2233. * Anyway, this is really very primitive wakeup.
  2234. */
  2235. set_current_state(TASK_INTERRUPTIBLE);
  2236. iter->tr->waiter = current;
  2237. mutex_unlock(&trace_types_lock);
  2238. /* sleep for 100 msecs, and try again. */
  2239. schedule_timeout(HZ/10);
  2240. mutex_lock(&trace_types_lock);
  2241. iter->tr->waiter = NULL;
  2242. if (signal_pending(current)) {
  2243. sret = -EINTR;
  2244. goto out;
  2245. }
  2246. if (iter->trace != current_trace)
  2247. goto out;
  2248. /*
  2249. * We block until we read something and tracing is disabled.
  2250. * We still block if tracing is disabled, but we have never
  2251. * read anything. This allows a user to cat this file, and
  2252. * then enable tracing. But after we have read something,
  2253. * we give an EOF when tracing is again disabled.
  2254. *
  2255. * iter->pos will be 0 if we haven't read anything.
  2256. */
  2257. if (!tracer_enabled && iter->pos)
  2258. break;
  2259. continue;
  2260. }
  2261. /* stop when tracing is finished */
  2262. if (trace_empty(iter))
  2263. goto out;
  2264. if (cnt >= PAGE_SIZE)
  2265. cnt = PAGE_SIZE - 1;
  2266. /* reset all but tr, trace, and overruns */
  2267. memset(&iter->seq, 0,
  2268. sizeof(struct trace_iterator) -
  2269. offsetof(struct trace_iterator, seq));
  2270. iter->pos = -1;
  2271. while (find_next_entry_inc(iter) != NULL) {
  2272. enum print_line_t ret;
  2273. int len = iter->seq.len;
  2274. ret = print_trace_line(iter);
  2275. if (ret == TRACE_TYPE_PARTIAL_LINE) {
  2276. /* don't print partial lines */
  2277. iter->seq.len = len;
  2278. break;
  2279. }
  2280. trace_consume(iter);
  2281. if (iter->seq.len >= cnt)
  2282. break;
  2283. }
  2284. /* Now copy what we have to the user */
  2285. sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
  2286. if (iter->seq.readpos >= iter->seq.len)
  2287. trace_seq_reset(&iter->seq);
  2288. /*
  2289. * If there was nothing to send to user, inspite of consuming trace
  2290. * entries, go back to wait for more entries.
  2291. */
  2292. if (sret == -EBUSY)
  2293. goto waitagain;
  2294. out:
  2295. mutex_unlock(&trace_types_lock);
  2296. return sret;
  2297. }
  2298. static ssize_t
  2299. tracing_entries_read(struct file *filp, char __user *ubuf,
  2300. size_t cnt, loff_t *ppos)
  2301. {
  2302. struct trace_array *tr = filp->private_data;
  2303. char buf[64];
  2304. int r;
  2305. r = sprintf(buf, "%lu\n", tr->entries);
  2306. return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  2307. }
  2308. static ssize_t
  2309. tracing_entries_write(struct file *filp, const char __user *ubuf,
  2310. size_t cnt, loff_t *ppos)
  2311. {
  2312. unsigned long val;
  2313. char buf[64];
  2314. int ret;
  2315. struct trace_array *tr = filp->private_data;
  2316. if (cnt >= sizeof(buf))
  2317. return -EINVAL;
  2318. if (copy_from_user(&buf, ubuf, cnt))
  2319. return -EFAULT;
  2320. buf[cnt] = 0;
  2321. ret = strict_strtoul(buf, 10, &val);
  2322. if (ret < 0)
  2323. return ret;
  2324. /* must have at least 1 entry */
  2325. if (!val)
  2326. return -EINVAL;
  2327. mutex_lock(&trace_types_lock);
  2328. if (tr->ctrl) {
  2329. cnt = -EBUSY;
  2330. pr_info("ftrace: please disable tracing"
  2331. " before modifying buffer size\n");
  2332. goto out;
  2333. }
  2334. if (val != global_trace.entries) {
  2335. ret = ring_buffer_resize(global_trace.buffer, val);
  2336. if (ret < 0) {
  2337. cnt = ret;
  2338. goto out;
  2339. }
  2340. ret = ring_buffer_resize(max_tr.buffer, val);
  2341. if (ret < 0) {
  2342. int r;
  2343. cnt = ret;
  2344. r = ring_buffer_resize(global_trace.buffer,
  2345. global_trace.entries);
  2346. if (r < 0) {
  2347. /* AARGH! We are left with different
  2348. * size max buffer!!!! */
  2349. WARN_ON(1);
  2350. tracing_disabled = 1;
  2351. }
  2352. goto out;
  2353. }
  2354. global_trace.entries = val;
  2355. }
  2356. filp->f_pos += cnt;
  2357. /* If check pages failed, return ENOMEM */
  2358. if (tracing_disabled)
  2359. cnt = -ENOMEM;
  2360. out:
  2361. max_tr.entries = global_trace.entries;
  2362. mutex_unlock(&trace_types_lock);
  2363. return cnt;
  2364. }
  2365. static int mark_printk(const char *fmt, ...)
  2366. {
  2367. int ret;
  2368. va_list args;
  2369. va_start(args, fmt);
  2370. ret = trace_vprintk(0, fmt, args);
  2371. va_end(args);
  2372. return ret;
  2373. }
  2374. static ssize_t
  2375. tracing_mark_write(struct file *filp, const char __user *ubuf,
  2376. size_t cnt, loff_t *fpos)
  2377. {
  2378. char *buf;
  2379. char *end;
  2380. struct trace_array *tr = &global_trace;
  2381. if (!tr->ctrl || tracing_disabled)
  2382. return -EINVAL;
  2383. if (cnt > TRACE_BUF_SIZE)
  2384. cnt = TRACE_BUF_SIZE;
  2385. buf = kmalloc(cnt + 1, GFP_KERNEL);
  2386. if (buf == NULL)
  2387. return -ENOMEM;
  2388. if (copy_from_user(buf, ubuf, cnt)) {
  2389. kfree(buf);
  2390. return -EFAULT;
  2391. }
  2392. /* Cut from the first nil or newline. */
  2393. buf[cnt] = '\0';
  2394. end = strchr(buf, '\n');
  2395. if (end)
  2396. *end = '\0';
  2397. cnt = mark_printk("%s\n", buf);
  2398. kfree(buf);
  2399. *fpos += cnt;
  2400. return cnt;
  2401. }
  2402. static struct file_operations tracing_max_lat_fops = {
  2403. .open = tracing_open_generic,
  2404. .read = tracing_max_lat_read,
  2405. .write = tracing_max_lat_write,
  2406. };
  2407. static struct file_operations tracing_ctrl_fops = {
  2408. .open = tracing_open_generic,
  2409. .read = tracing_ctrl_read,
  2410. .write = tracing_ctrl_write,
  2411. };
  2412. static struct file_operations set_tracer_fops = {
  2413. .open = tracing_open_generic,
  2414. .read = tracing_set_trace_read,
  2415. .write = tracing_set_trace_write,
  2416. };
  2417. static struct file_operations tracing_pipe_fops = {
  2418. .open = tracing_open_pipe,
  2419. .poll = tracing_poll_pipe,
  2420. .read = tracing_read_pipe,
  2421. .release = tracing_release_pipe,
  2422. };
  2423. static struct file_operations tracing_entries_fops = {
  2424. .open = tracing_open_generic,
  2425. .read = tracing_entries_read,
  2426. .write = tracing_entries_write,
  2427. };
  2428. static struct file_operations tracing_mark_fops = {
  2429. .open = tracing_open_generic,
  2430. .write = tracing_mark_write,
  2431. };
  2432. #ifdef CONFIG_DYNAMIC_FTRACE
  2433. int __weak ftrace_arch_read_dyn_info(char *buf, int size)
  2434. {
  2435. return 0;
  2436. }
  2437. static ssize_t
  2438. tracing_read_dyn_info(struct file *filp, char __user *ubuf,
  2439. size_t cnt, loff_t *ppos)
  2440. {
  2441. static char ftrace_dyn_info_buffer[1024];
  2442. static DEFINE_MUTEX(dyn_info_mutex);
  2443. unsigned long *p = filp->private_data;
  2444. char *buf = ftrace_dyn_info_buffer;
  2445. int size = ARRAY_SIZE(ftrace_dyn_info_buffer);
  2446. int r;
  2447. mutex_lock(&dyn_info_mutex);
  2448. r = sprintf(buf, "%ld ", *p);
  2449. r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r);
  2450. buf[r++] = '\n';
  2451. r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  2452. mutex_unlock(&dyn_info_mutex);
  2453. return r;
  2454. }
  2455. static struct file_operations tracing_dyn_info_fops = {
  2456. .open = tracing_open_generic,
  2457. .read = tracing_read_dyn_info,
  2458. };
  2459. #endif
  2460. static struct dentry *d_tracer;
  2461. struct dentry *tracing_init_dentry(void)
  2462. {
  2463. static int once;
  2464. if (d_tracer)
  2465. return d_tracer;
  2466. d_tracer = debugfs_create_dir("tracing", NULL);
  2467. if (!d_tracer && !once) {
  2468. once = 1;
  2469. pr_warning("Could not create debugfs directory 'tracing'\n");
  2470. return NULL;
  2471. }
  2472. return d_tracer;
  2473. }
  2474. #ifdef CONFIG_FTRACE_SELFTEST
  2475. /* Let selftest have access to static functions in this file */
  2476. #include "trace_selftest.c"
  2477. #endif
  2478. static __init int tracer_init_debugfs(void)
  2479. {
  2480. struct dentry *d_tracer;
  2481. struct dentry *entry;
  2482. d_tracer = tracing_init_dentry();
  2483. entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
  2484. &global_trace, &tracing_ctrl_fops);
  2485. if (!entry)
  2486. pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
  2487. entry = debugfs_create_file("iter_ctrl", 0644, d_tracer,
  2488. NULL, &tracing_iter_fops);
  2489. if (!entry)
  2490. pr_warning("Could not create debugfs 'iter_ctrl' entry\n");
  2491. entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
  2492. NULL, &tracing_cpumask_fops);
  2493. if (!entry)
  2494. pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
  2495. entry = debugfs_create_file("latency_trace", 0444, d_tracer,
  2496. &global_trace, &tracing_lt_fops);
  2497. if (!entry)
  2498. pr_warning("Could not create debugfs 'latency_trace' entry\n");
  2499. entry = debugfs_create_file("trace", 0444, d_tracer,
  2500. &global_trace, &tracing_fops);
  2501. if (!entry)
  2502. pr_warning("Could not create debugfs 'trace' entry\n");
  2503. entry = debugfs_create_file("available_tracers", 0444, d_tracer,
  2504. &global_trace, &show_traces_fops);
  2505. if (!entry)
  2506. pr_warning("Could not create debugfs 'available_tracers' entry\n");
  2507. entry = debugfs_create_file("current_tracer", 0444, d_tracer,
  2508. &global_trace, &set_tracer_fops);
  2509. if (!entry)
  2510. pr_warning("Could not create debugfs 'current_tracer' entry\n");
  2511. entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
  2512. &tracing_max_latency,
  2513. &tracing_max_lat_fops);
  2514. if (!entry)
  2515. pr_warning("Could not create debugfs "
  2516. "'tracing_max_latency' entry\n");
  2517. entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
  2518. &tracing_thresh, &tracing_max_lat_fops);
  2519. if (!entry)
  2520. pr_warning("Could not create debugfs "
  2521. "'tracing_thresh' entry\n");
  2522. entry = debugfs_create_file("README", 0644, d_tracer,
  2523. NULL, &tracing_readme_fops);
  2524. if (!entry)
  2525. pr_warning("Could not create debugfs 'README' entry\n");
  2526. entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
  2527. NULL, &tracing_pipe_fops);
  2528. if (!entry)
  2529. pr_warning("Could not create debugfs "
  2530. "'trace_pipe' entry\n");
  2531. entry = debugfs_create_file("trace_entries", 0644, d_tracer,
  2532. &global_trace, &tracing_entries_fops);
  2533. if (!entry)
  2534. pr_warning("Could not create debugfs "
  2535. "'trace_entries' entry\n");
  2536. entry = debugfs_create_file("trace_marker", 0220, d_tracer,
  2537. NULL, &tracing_mark_fops);
  2538. if (!entry)
  2539. pr_warning("Could not create debugfs "
  2540. "'trace_marker' entry\n");
  2541. #ifdef CONFIG_DYNAMIC_FTRACE
  2542. entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
  2543. &ftrace_update_tot_cnt,
  2544. &tracing_dyn_info_fops);
  2545. if (!entry)
  2546. pr_warning("Could not create debugfs "
  2547. "'dyn_ftrace_total_info' entry\n");
  2548. #endif
  2549. #ifdef CONFIG_SYSPROF_TRACER
  2550. init_tracer_sysprof_debugfs(d_tracer);
  2551. #endif
  2552. return 0;
  2553. }
  2554. int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
  2555. {
  2556. static DEFINE_SPINLOCK(trace_buf_lock);
  2557. static char trace_buf[TRACE_BUF_SIZE];
  2558. struct ring_buffer_event *event;
  2559. struct trace_array *tr = &global_trace;
  2560. struct trace_array_cpu *data;
  2561. struct print_entry *entry;
  2562. unsigned long flags, irq_flags;
  2563. int cpu, len = 0, size, pc;
  2564. if (!tr->ctrl || tracing_disabled)
  2565. return 0;
  2566. pc = preempt_count();
  2567. preempt_disable_notrace();
  2568. cpu = raw_smp_processor_id();
  2569. data = tr->data[cpu];
  2570. if (unlikely(atomic_read(&data->disabled)))
  2571. goto out;
  2572. spin_lock_irqsave(&trace_buf_lock, flags);
  2573. len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args);
  2574. len = min(len, TRACE_BUF_SIZE-1);
  2575. trace_buf[len] = 0;
  2576. size = sizeof(*entry) + len + 1;
  2577. event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags);
  2578. if (!event)
  2579. goto out_unlock;
  2580. entry = ring_buffer_event_data(event);
  2581. tracing_generic_entry_update(&entry->ent, flags, pc);
  2582. entry->ent.type = TRACE_PRINT;
  2583. entry->ip = ip;
  2584. memcpy(&entry->buf, trace_buf, len);
  2585. entry->buf[len] = 0;
  2586. ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
  2587. out_unlock:
  2588. spin_unlock_irqrestore(&trace_buf_lock, flags);
  2589. out:
  2590. preempt_enable_notrace();
  2591. return len;
  2592. }
  2593. EXPORT_SYMBOL_GPL(trace_vprintk);
  2594. int __ftrace_printk(unsigned long ip, const char *fmt, ...)
  2595. {
  2596. int ret;
  2597. va_list ap;
  2598. if (!(trace_flags & TRACE_ITER_PRINTK))
  2599. return 0;
  2600. va_start(ap, fmt);
  2601. ret = trace_vprintk(ip, fmt, ap);
  2602. va_end(ap);
  2603. return ret;
  2604. }
  2605. EXPORT_SYMBOL_GPL(__ftrace_printk);
  2606. static int trace_panic_handler(struct notifier_block *this,
  2607. unsigned long event, void *unused)
  2608. {
  2609. if (ftrace_dump_on_oops)
  2610. ftrace_dump();
  2611. return NOTIFY_OK;
  2612. }
  2613. static struct notifier_block trace_panic_notifier = {
  2614. .notifier_call = trace_panic_handler,
  2615. .next = NULL,
  2616. .priority = 150 /* priority: INT_MAX >= x >= 0 */
  2617. };
  2618. static int trace_die_handler(struct notifier_block *self,
  2619. unsigned long val,
  2620. void *data)
  2621. {
  2622. switch (val) {
  2623. case DIE_OOPS:
  2624. if (ftrace_dump_on_oops)
  2625. ftrace_dump();
  2626. break;
  2627. default:
  2628. break;
  2629. }
  2630. return NOTIFY_OK;
  2631. }
  2632. static struct notifier_block trace_die_notifier = {
  2633. .notifier_call = trace_die_handler,
  2634. .priority = 200
  2635. };
  2636. /*
  2637. * printk is set to max of 1024, we really don't need it that big.
  2638. * Nothing should be printing 1000 characters anyway.
  2639. */
  2640. #define TRACE_MAX_PRINT 1000
  2641. /*
  2642. * Define here KERN_TRACE so that we have one place to modify
  2643. * it if we decide to change what log level the ftrace dump
  2644. * should be at.
  2645. */
  2646. #define KERN_TRACE KERN_INFO
  2647. static void
  2648. trace_printk_seq(struct trace_seq *s)
  2649. {
  2650. /* Probably should print a warning here. */
  2651. if (s->len >= 1000)
  2652. s->len = 1000;
  2653. /* should be zero ended, but we are paranoid. */
  2654. s->buffer[s->len] = 0;
  2655. printk(KERN_TRACE "%s", s->buffer);
  2656. trace_seq_reset(s);
  2657. }
  2658. void ftrace_dump(void)
  2659. {
  2660. static DEFINE_SPINLOCK(ftrace_dump_lock);
  2661. /* use static because iter can be a bit big for the stack */
  2662. static struct trace_iterator iter;
  2663. static cpumask_t mask;
  2664. static int dump_ran;
  2665. unsigned long flags;
  2666. int cnt = 0, cpu;
  2667. /* only one dump */
  2668. spin_lock_irqsave(&ftrace_dump_lock, flags);
  2669. if (dump_ran)
  2670. goto out;
  2671. dump_ran = 1;
  2672. /* No turning back! */
  2673. ftrace_kill();
  2674. for_each_tracing_cpu(cpu) {
  2675. atomic_inc(&global_trace.data[cpu]->disabled);
  2676. }
  2677. printk(KERN_TRACE "Dumping ftrace buffer:\n");
  2678. iter.tr = &global_trace;
  2679. iter.trace = current_trace;
  2680. /*
  2681. * We need to stop all tracing on all CPUS to read the
  2682. * the next buffer. This is a bit expensive, but is
  2683. * not done often. We fill all what we can read,
  2684. * and then release the locks again.
  2685. */
  2686. cpus_clear(mask);
  2687. while (!trace_empty(&iter)) {
  2688. if (!cnt)
  2689. printk(KERN_TRACE "---------------------------------\n");
  2690. cnt++;
  2691. /* reset all but tr, trace, and overruns */
  2692. memset(&iter.seq, 0,
  2693. sizeof(struct trace_iterator) -
  2694. offsetof(struct trace_iterator, seq));
  2695. iter.iter_flags |= TRACE_FILE_LAT_FMT;
  2696. iter.pos = -1;
  2697. if (find_next_entry_inc(&iter) != NULL) {
  2698. print_trace_line(&iter);
  2699. trace_consume(&iter);
  2700. }
  2701. trace_printk_seq(&iter.seq);
  2702. }
  2703. if (!cnt)
  2704. printk(KERN_TRACE " (ftrace buffer empty)\n");
  2705. else
  2706. printk(KERN_TRACE "---------------------------------\n");
  2707. out:
  2708. spin_unlock_irqrestore(&ftrace_dump_lock, flags);
  2709. }
  2710. __init static int tracer_alloc_buffers(void)
  2711. {
  2712. struct trace_array_cpu *data;
  2713. int i;
  2714. /* TODO: make the number of buffers hot pluggable with CPUS */
  2715. tracing_buffer_mask = cpu_possible_map;
  2716. global_trace.buffer = ring_buffer_alloc(trace_buf_size,
  2717. TRACE_BUFFER_FLAGS);
  2718. if (!global_trace.buffer) {
  2719. printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
  2720. WARN_ON(1);
  2721. return 0;
  2722. }
  2723. global_trace.entries = ring_buffer_size(global_trace.buffer);
  2724. #ifdef CONFIG_TRACER_MAX_TRACE
  2725. max_tr.buffer = ring_buffer_alloc(trace_buf_size,
  2726. TRACE_BUFFER_FLAGS);
  2727. if (!max_tr.buffer) {
  2728. printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
  2729. WARN_ON(1);
  2730. ring_buffer_free(global_trace.buffer);
  2731. return 0;
  2732. }
  2733. max_tr.entries = ring_buffer_size(max_tr.buffer);
  2734. WARN_ON(max_tr.entries != global_trace.entries);
  2735. #endif
  2736. /* Allocate the first page for all buffers */
  2737. for_each_tracing_cpu(i) {
  2738. data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
  2739. max_tr.data[i] = &per_cpu(max_data, i);
  2740. }
  2741. trace_init_cmdlines();
  2742. register_tracer(&nop_trace);
  2743. #ifdef CONFIG_BOOT_TRACER
  2744. /* We don't want to launch sched_switch tracer yet */
  2745. global_trace.ctrl = 0;
  2746. register_tracer(&boot_tracer);
  2747. current_trace = &boot_tracer;
  2748. current_trace->init(&global_trace);
  2749. #else
  2750. current_trace = &nop_trace;
  2751. #endif
  2752. /* All seems OK, enable tracing */
  2753. global_trace.ctrl = 1;
  2754. tracing_disabled = 0;
  2755. atomic_notifier_chain_register(&panic_notifier_list,
  2756. &trace_panic_notifier);
  2757. register_die_notifier(&trace_die_notifier);
  2758. return 0;
  2759. }
  2760. early_initcall(tracer_alloc_buffers);
  2761. fs_initcall(tracer_init_debugfs);