{"id":148,"date":"2010-12-19T11:20:28","date_gmt":"2010-12-19T11:20:28","guid":{"rendered":"http:\/\/wp.neependra.net\/?p=148"},"modified":"2010-12-19T11:20:28","modified_gmt":"2010-12-19T11:20:28","slug":"ftrace-fedora-mini-conf-session-at-foss-in10","status":"publish","type":"post","link":"https:\/\/neependra.net\/index.php\/2010\/12\/19\/ftrace-fedora-mini-conf-session-at-foss-in10\/","title":{"rendered":"Ftrace:  Fedora Mini-Conf Session at FOSS.in\u201910"},"content":{"rendered":"<p>I gave a talk on Ftrace in <a href=\"https:\/\/fedoraproject.org\/wiki\/FOSSin_2010#Mini_Conf_Sessions\">Fedora Mini-Conf\u00a0 at FOSS.in&#8217;10.<\/a><\/p>\n<p>The slides are at<a href=\"https:\/\/fedoraproject.org\/wiki\/File:Fedora_Ftrace.pdf\"> https:\/\/fedoraproject.org\/wiki\/File:Fedora_Ftrace.pdf<\/a><\/p>\n<p>I started my presentation with an example. I setup<em><strong> function_ftrace<\/strong><\/em> as\u00a0 <em><strong>current_tracer <\/strong><\/em>and set<\/p>\n<p>the trace filter for all the <em><strong>ext3<\/strong><\/em> functions and started the tracing:<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]<\/p>\n<p>$ echo function_ftrace &gt; \/sys\/kernel\/debug\/tracing\/current_tracer<\/p>\n<p>$ echo ext3* &gt; \/sys\/kernel\/debug\/tracing\/set_ftrace_filter<\/p>\n<p>$ echo 1\u00a0 &gt; \/sys\/kernel\/debug\/tracing\/tracing_on<\/p>\n<p>[\/sourcecode]<\/p>\n<p>Then after creating a ext3 filesystem, I created a directory on it.<\/p>\n<p>We got a trace in the \/sys\/kernel\/debug\/tracing\/trace file. A snippet from it :-<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]<br \/>\n1) ! 23988.06 us |\u00a0\u00a0\u00a0 } \/* ext3_new_inode *\/<br \/>\n1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 |\u00a0\u00a0\u00a0 ext3_bread() {<br \/>\n1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_getblk() {<br \/>\n1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_get_blocks_handle() {<br \/>\n1)\u00a0\u00a0 0.461 us \u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_block_to_path();<br \/>\n1)\u00a0\u00a0 0.365 us\u00a0\u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_get_branch();<br \/>\n1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_new_blocks() {<br \/>\n1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_dirty_inode() {<br \/>\n1)\u00a0\u00a0 0.602 us \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_journal_start_sb();<br \/>\n1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_mark_inode_dirty() {<br \/>\n1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext3_reserve_inode_write() {<br \/>\n[\/sourcecode]<\/p>\n<p>This kind of stuff helps when you try to understand the kernel code because you know what functions are getting called.<\/p>\n<p>Second example I took to get the function trace when the system system OOPs. I did following setting to get the trace:-<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]<br \/>\necho function_graph &gt; \/sys\/kernel\/debug\/tracing\/current_tracer<br \/>\necho 5 &gt; \/sys\/kernel\/debug\/tracing\/buffer_size_kb<br \/>\necho 1 &gt; \/sys\/kernel\/debug\/tracing\/tracing_on<br \/>\necho 1 &gt; \/proc\/sys\/kernel\/ftrace_dump_on_oops<br \/>\n[\/sourcecode]<\/p>\n<p>I used one\u00a0 simple character driver for that. It can be downloaded from<\/p>\n<p><a href=\"http:\/\/wp.neependra.net\/kernel\/char-dev-read-write-oop.tar.gz\">http:\/\/wp.neependra.net\/kernel\/char-dev-read-write-oop.tar.gz<\/a><\/p>\n<p>I had following for the read operation<\/p>\n<p>[sourcecode language=&#8221;cpp&#8221; gutter=&#8221;false&#8221;]<br \/>\nstatic ssize_t mycdrv1_read (struct file *file, char __user * buf, size_t lbuf, loff_t * ppos)<br \/>\n{<br \/>\n*(int *)0 = 0;<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p>After inserting the module I created the character device<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]<br \/>\ninsmod char-read-write.ko<br \/>\nmknod \/dev\/mycdrv1 c 700 0<\/p>\n<p>[\/sourcecode]<\/p>\n<p>Just after doing the read to the device OOPs happened and got\u00a0 following in the in the <strong>\/var\/log\/messages<\/strong> file<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]<br \/>\nmycdrv1_read() {<br \/>\n raw_local_irq_enable();<br \/>\n &#8230;&#8230;&#8230;..<br \/>\n find_vma();<br \/>\n bad_area() {<br \/>\n up_read();<br \/>\n &#8230;&#8230;&#8230;&#8230;<br \/>\n is_prefetch.clone.13() {<br \/>\n convert_ip_to_linear();<br \/>\n pagefault_disable();<br \/>\n pagefault_enable();<br \/>\n }<br \/>\n oops_enter() {<br \/>\n[\/sourcecode]<\/p>\n<p>Then I showed an example with <em><strong>sched_switch<\/strong><\/em> tracer and showed how we can trace all the function of a particular module.<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]&lt;\/pre&gt;<br \/>\n$ echo sched_switch &gt; \/sys\/kernel\/debug\/tracing\/current_tracer<\/p>\n<p>$ echo :mod:zfs &gt; \/sys\/kernel\/debug\/tracing\/set_ftrace_filter<br \/>\n[\/sourcecode]<\/p>\n<p>I also also showed how to look at the stack usage.\u00a0 To enable stack strace<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]<br \/>\necho 1 &gt; \/proc\/sys\/kernel\/stack_tracer_enabled<br \/>\n[\/sourcecode]<\/p>\n<p>and\u00a0 look at \/sys\/kernel\/debug\/tracing\/stack_trace file, which will have something like.<\/p>\n<p>[sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;]<br \/>\nDepth\u00a0\u00a0\u00a0 Size\u00a0\u00a0 Location\u00a0\u00a0\u00a0 (15 entries)<br \/>\n&#8212;&#8211;\u00a0\u00a0\u00a0 &#8212;-\u00a0\u00a0 &#8212;&#8212;&#8211;<br \/>\n0)\u00a0\u00a0\u00a0\u00a0 1544\u00a0\u00a0\u00a0\u00a0 352\u00a0\u00a0 ext3_get_blocks_handle+0xa0\/0x920<br \/>\n1)\u00a0\u00a0\u00a0\u00a0 1192\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0 return_to_handler+0x0\/0x2f<br \/>\n2)\u00a0\u00a0\u00a0\u00a0 1192\u00a0\u00a0\u00a0\u00a0\u00a0 96\u00a0\u00a0 ext3_get_block+0xbb\/0xf8<br \/>\n3)\u00a0\u00a0\u00a0\u00a0 1096\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0 return_to_handler+0x0\/0x2f<br \/>\n4)\u00a0\u00a0\u00a0\u00a0 1096\u00a0\u00a0\u00a0\u00a0 128\u00a0\u00a0 generic_block_bmap+0x3c\/0x42<br \/>\n[\/sourcecode]<\/p>\n<p>It tells you how much kernel stack is used and usage from\u00a0 each function. This was very helpful for me while doing the port<\/p>\n<p>of<a href=\"http:\/\/zfs.kqinfotech.com\/\"> <em><strong>ZFS on Linux<\/strong><\/em>.<\/a> We have limited kernel stack on Linux but this not the case in Solaris.<\/p>\n<p>I then talked about <em><strong>trace-cmd<\/strong><\/em> and <em><strong>kernelshark<\/strong><\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I gave a talk on Ftrace in Fedora Mini-Conf\u00a0 at FOSS.in&#8217;10. The slides are at https:\/\/fedoraproject.org\/wiki\/File:Fedora_Ftrace.pdf I started my presentation with an example. I setup function_ftrace as\u00a0 current_tracer and set the trace filter for all the ext3 functions and started the tracing: [sourcecode language=&#8221;text&#8221; gutter=&#8221;false&#8221;] $ echo function_ftrace &gt; \/sys\/kernel\/debug\/tracing\/current_tracer $ echo ext3* &gt; \/sys\/kernel\/debug\/tracing\/set_ftrace_filter &#8230; <a title=\"Ftrace:  Fedora Mini-Conf Session at FOSS.in\u201910\" class=\"read-more\" href=\"https:\/\/neependra.net\/index.php\/2010\/12\/19\/ftrace-fedora-mini-conf-session-at-foss-in10\/\" aria-label=\"Read more about Ftrace:  Fedora Mini-Conf Session at FOSS.in\u201910\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[48],"tags":[84,86,88,101],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-fedora","tag-foss","tag-ftrace","tag-kernel"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":0,"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"wp:attachment":[{"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neependra.net\/index.php\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}