红联Linux门户
Linux帮助

Linux Kernel启动时间调试

发布时间:2016-12-18 09:54:17来源:linux网站作者:9527zyj
要观察Kernel各个模块启动时间,并且针对性的进行优化,一般用Initcall Debug来进行调试,我的调试笔记如下:
 
1.u-boot修改
首先修改u-boot的启动参数,在bootargs参数后添加参数printk.time=y initcall_debug,这样可以使kernel启动时详细打印各个部分启动的时间戳,以下截取片段仅供参考:
[    0.001035] pid_max: default: 32768 minimum: 301
[    0.001210] Mount-cache hash table entries: 512
[    0.001930] CPU: Testing write buffer coherency: ok
[    0.002203] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[    0.002264] Setting up static identity map for 0x806221b8 - 0x80622210
[    0.040358] Brought up 1 CPUs
[    0.040367] SMP: Total of 1 processors activated (1581.05 BogoMIPS).
 
2.kernel修改
如果kernel配置了如下内容,u-boot参数可以不增加printk.time=y
Kernel hacking
----->Show timing information on printks
此外,为了增加启动log所prink内容的缓冲区大小,建议把内核中的CONFIG_LOG_BUF_SHIFT配置从默认的14修改为18,这样就吧默认的缓冲区从16k增加到256k
 
3.查看log
进入文件系统后,用如下命令可以进行调试:
dmesg -s 256000 | grep "initcall"
这可以查看内核的initcall的各个模块,参考以下截取片段:
[    0.159235] initcall key_proc_init+0x0/0x4c returned 0 after 8 usecs
[    0.159263] initcall crypto_algapi_init+0x0/0x10 returned 0 after 6 usecs
[    0.159288] initcall skcipher_module_init+0x0/0x48 returned 0 after 1 usecs
[    0.159316] initcall chainiv_module_init+0x0/0xc returned 0 after 4 usecs
[    0.159340] initcall eseqiv_module_init+0x0/0xc returned 0 after 2 usecs
此外
dmesg -s 256000 | grep "initcall" | sed "s/\(.*\)after\(.*\)/\2 \1/g" | sort -n
(不知道怎么回事上面的英文括号打不出来,因此用中文括号代替了)
这条命令可以对initcall的log进行排序,更加方便的查看各个模块加载所消耗的实际,参考以下截取片段:
343 usecs [    0.158440] initcall init_jffs2_fs+0x0/0xdc returned 0
348 usecs [    1.876173] initcall imx_tef6638_driver_init+0x0/0xc returned 0
351 usecs [    1.173609] initcall mxs_viim_driver_init+0x0/0xc returned 0
361 usecs [    0.159030] initcall fuse_init+0x0/0x1c4 returned 0
每行的第一列即是该模块加载消耗的时间
这样,大家就可以对没有用的模块进行裁剪,耗时较大的模块进行优化啦!
 
本文永久更新地址:http://www.linuxdiyf.com/linux/26995.html