trace.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379
  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 | TRACE_ITER_PRINTK;
  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. register_tracer(&boot_tracer);
  2745. current_trace = &boot_tracer;
  2746. current_trace->init(&global_trace);
  2747. #else
  2748. current_trace = &nop_trace;
  2749. #endif
  2750. /* All seems OK, enable tracing */
  2751. global_trace.ctrl = 1;
  2752. tracing_disabled = 0;
  2753. atomic_notifier_chain_register(&panic_notifier_list,
  2754. &trace_panic_notifier);
  2755. register_die_notifier(&trace_die_notifier);
  2756. return 0;
  2757. }
  2758. early_initcall(tracer_alloc_buffers);
  2759. fs_initcall(tracer_init_debugfs);