<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Erlang非业余研究 &#187; global</title>
	<atom:link href="http://blog.yufeng.info/archives/tag/global/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.yufeng.info</link>
	<description>Erlang系统深度探索和应用</description>
	<lastBuildDate>Tue, 17 Jan 2012 06:05:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>用systemtap来修改下linux内核变量的值</title>
		<link>http://blog.yufeng.info/archives/102</link>
		<comments>http://blog.yufeng.info/archives/102#comments</comments>
		<pubDate>Thu, 29 Oct 2009 11:07:20 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[网络编程]]></category>
		<category><![CDATA[调优]]></category>
		<category><![CDATA[-g]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[global]]></category>
		<category><![CDATA[guru]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[stap]]></category>
		<category><![CDATA[systemtap]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=102</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: 用systemtap来修改下linux内核变量的值 我们在探索linux内核的时候，经常需要调整下变量的值，看它对系统的影响。如果这个值没有透过/proc来修改的话，那只能编译内核。这个步骤是非常繁琐的。现在我们有systemtap这个利器来帮忙了。 演示如下： 我们通过修改过 extern int sysctl_tcp_fin_timeout;的值来达到目的。是因为这个值是proc导出的 我们好验证是否成功。 这个时候 stap在运行， 只是还没有触发do_tcp_setsockopt. 现在我们来触发 Ok,这时候回头可以看到stap打出来以下： sysctl_tcp_fin_timeout = 18000 我们来验证下： OK,成功。 Tips： 1. stap对全局变量的写需要-g guru模式。 2. 全局变量必须在一个单元内的函数里面才可以修改， 而且必须是在内核上下文。 PS. 这样写的话会更好,因为这个变量是单元可见的,这个模块里面的任何函数被触发都可以看到这个变量. 因为这是tcp的核心模块随时都会被出发的,免除了以上的麻烦! Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/102">用systemtap来修改下linux内核变量的值</a></p>
</div>
<p>我们在探索linux内核的时候，经常需要调整下变量的值，看它对系统的影响。如果这个值没有透过/proc来修改的话，那只能编译内核。这个步骤是非常繁琐的。现在我们有systemtap这个利器来帮忙了。</p>
<p>演示如下：<br />
我们通过修改过<br />
extern int sysctl_tcp_fin_timeout;的值来达到目的。是因为这个值是proc导出的 我们好验证是否成功。</p>
<pre class="brush: bash; title: ; notranslate">
root@localhost ~]# cat /proc/sys/net/ipv4/tcp_fin_timeout
15000
[root@localhost ~]# cat test.stp
probe begin
{
        printf(&quot;ready go\n&quot;);
}

probe kernel.function(&quot;do_tcp_setsockopt&quot;)
{
        $sysctl_tcp_fin_timeout = $1
        printf(&quot;sysctl_tcp_fin_timeout = %d\n&quot;, $sysctl_tcp_fin_timeout);
        exit()
}

[root@localhost ~]# stap -g test.stp 18000
ready go
</pre>
<p>这个时候 stap在运行， 只是还没有触发do_tcp_setsockopt.<br />
现在我们来触发</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# erl
Erlang R13B02 (erts-5.7.3) 1 [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.3  (abort with ^G)
1&gt; {ok, LSock} = gen_tcp:listen(0, []).
{ok,#Port&lt;0.437&gt;}
2&gt;
2&gt; inet:setopts(LSock, [{nodelay,true}]).
ok
3&gt;
</pre>
<p>Ok,这时候回头可以看到stap打出来以下：<br />
sysctl_tcp_fin_timeout = 18000</p>
<p>我们来验证下：</p>
<pre class="brush: bash; title: ; notranslate">
root@localhost ~]# cat /proc/sys/net/ipv4/tcp_fin_timeout
18000
</pre>
<p>OK,成功。</p>
<p>Tips：<br />
1. stap对全局变量的写需要-g guru模式。<br />
2. 全局变量必须在一个单元内的函数里面才可以修改， 而且必须是在内核上下文。 </p>
<p>PS. 这样写的话会更好,因为这个变量是单元可见的,这个模块里面的任何函数被触发都可以看到这个变量. 因为这是tcp的核心模块随时都会被出发的,免除了以上的麻烦!</p>
<pre class="brush: bash; title: ; notranslate">
$ cat test.stp
probe begin
{
        printf(&quot;ready go\n&quot;);
}
probe kernel.function(&quot;*@net/ipv4/tcp.c&quot;)
//probe kernel.function(&quot;do_tcp_setsockopt&quot;)
{
        $sysctl_tcp_fin_timeout = $1
        printf(&quot;sysctl_tcp_fin_timeout = %d\n&quot;, $sysctl_tcp_fin_timeout);
        exit()
}
</pre>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/102/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

