Linux Bootup Timephp
英文原文地址:http://elinux.org/Boot_Timehtml
1. 简介
启动时间这一话题包括不少子话题,好比启动时间的衡量、启动时间的分析、人为因素分析、初始化技术和还原技术等等。node
在消费类领域,不管电子设备设计是多么的精心,多么的吸引人,这个产品品所需的启动时间始终是直接影响最终用户体验的第一感知。移动设备达到一个互动的、可用的状态是相当重要的用户体验。所以开机时第一个用户用例。linux
启动一个设备,包括多个步骤和有序的事件。为了使用一致的术语,CELF工做组提出了一系列的术语和能够被普遍接受的定义。请参阅如下页面:开机时间术语定义列表android
2. 技术/项目
下面就介绍与linux系统启动时间有关的技术也项目。git
2.1 Bootup Time度量
1. Printk Times – 为启动过程当中的多有printk信息加入时间日志。web
2. Kernel Function Trace – 用于报告函数执行时间内核函数跟踪系统。算法
3. Linux Trace Toolkit –针对特定内核和特定事件的时间数据通知系统。shell
4. Oprofile - linux系统上系统框架内的剖析工具。swift
5. Bootchart – 针对linux启动过程的性能分析的可视化工具,搜集启动过程当中用户空间部分的资源利用率和进程信息等相关数据,而后经过PNG、SVG或者EPS呈现出图表。
6. Bootprobe - System Tap 的一组脚本,用于分析系统启动过过程。
7. "cat /proc/uptime" 也能够收集系统启动信息。
8. grabserial - a nice utility from Tim Bird to log and timestamp console output Tim Bird给出的一个用于记录和从控制台打印时间戳的比较好的工具。
9. process trace – 这个patch也是出自Tim Bird,日志执行、建立和退出的系统调用。
10. ptx_ts - Pengutronix' TimeStamper: 这是一个小的过滤器,在STDOUT前添加时间戳, 与grabserial很类似,不一样之处在于没有局限于串行端口。
11. Initcall Debug – 内核命令行选项,用于显示initcall的执行时间。
12. 另外: Kernel Instrumentation 其中列出了一些内核工具。都与衡量内核启动时间有关系。
2.2 Bootup Time优化技术
2.2.1 Bootloader加速
1. Kernel XIP – 容许内核在ROM和FLASH中执行。
2. DMA Copy Of Kernel On Startup – 使用DMA将内核从Flash中复制到RAM中。
3. Uncompressed kernel – 加速内核解压流程。
4. Fast Kernel Decompression
2.2.2 内核加速
- Disable Console – 在系统启动期间,避免控制台输出带来的开销。
- Disable bug and printk – 避免Bug和printk的开销,不方便之处是会丢失不少信息。
- RTC No Sync – 在启动时,应该避免系统时间与RTC同步带来的延迟。
- Short IDE Delays – 减小IDE的启动延时(有效但有风险)。
- Hardcode kernel module info – 减小模块加载的开销:针对relocation information的加载采起硬编码。
- IDE No Probe – 强制内核遵照ide<x>=noprobe选项。
- Preset LPJ – 使用loops_per_jiffy 预设值。
- Asynchronous function calls – 容许探测和其余功能并行处理,使得bootup中耗时能够重叠。
- Reordering of driver initialization – 容许驱动总线尽量快的开始工做。
- Deferred Initcalls – 非必要模块的初始化例程,使之bootup以后再执行。
- NAND ECC improvement - 对于2.6.28以前的内核版本,nand_ecc.c能够实现部分优化,mtd git athttp://git.infradead.org/mtd-2.6.git?a=blob_plain;f=drivers/mtd/nand/nand_ecc.c;hb=HEAD. Documentation for this is in http://git.infradead.org/mtd-2.6.git?a=blob_plain;f=Documentation/mtd/nand_ecc.txt;hb=HEAD. This is only interesting if your system uses software ECC correction.
- 检查所使用的内核内存分配器,slob或者slub可能比slab更好一些。(在一些老版本内涵上slab是默认的缓存分配器)
- 若是系统不须要sysfss和procfs,能够尝试移除它们。Sysfs能够带来20ms的收益。
- 精心地调研一下内核配置选项:哪些是须要的,哪些是不须要的。未使用的配置可能致使内核增大和内核加载时间变长(若是没有使用kernel XIP),配置选项都是须要测试的。好比,选择选项CONFIG_CC_OPTIMIZE_FOR_SIZE (found under general setup) gave in one case a boot improvement of 20 ms. Not dramatic, but when reducing boot time every penny counts!
- 将代码在不一样的编译器上编译可能会使得代码更加精简和速度更快,大部分时候,最新版本的编译器会产生更好的代码。能够尝试新编译器
- 若是内核中使用了initramfs和压缩的内核,那么最好选择一个非压缩的initramfs,避免解压缩两次数据。 A patch for this has been submitted to LKML. See http://lkml.org/lkml/2008/11/22/112
2.2.3 文件系统问题
不一样的文件系统,其初始化(挂载)时间是不一样的,对于相同的数据,须要考虑是否应该讲元数据从存储中读到RAM中,及其在挂在过程当中应该在采起什么算法。
- Filesystem Information – 针对不一样文件洗的bootup time时间。
- File Systems – 嵌入式系统中有关的文件系统,及其优化建议。
- Avoid Initramfs – 解释若是想要最小化boot time,为何要避免。
- Split partitions.若是挂载一个文件系统花费不少时间,那么须要考虑分为两个卷,一个卷中存储bootup须要的信息,另外一个存储boot非必须的信息。
- Ramdisks demasked – 说明为何ramdisk会致使boot time变长,该不是变短。
2.2.4 用户空间和应用加速
1. Optimize RC Scripts – 减小RC脚本运行开销
2. Parallel RC Scripts – 采用并行方式运行RC脚本,而非串行方式。
3. Application XIP – 运行程序和库在ROM或FLASH中执行。
4. Pre Linking – 在第一次加载时应该避免运行时连接。
5. 静态连接应用程序。能够避免了运行时连接的成本。若是你只有几个应用程序,这是颇有用的。在这种状况下,它也能减小image大小,由于不须要加载动态库。
6. GNU_HASH: 在动态连接时,带来大约50% 加速提高。
o 参阅http://sourceware.org/ml/binutils/2006-06/msg00418.html
- Application Init Optimizations – 提升程序的加载和初始化时间:
o use of mmap vs. read
o control over page mapping characteristics.
8. Include modules in kernel image – 将模块编译到内核镜像中,能够避免模块加载带来的额外开销。
9. Speed up module loading – 使用 Alessio Igor Bogani's kernel patches 改善模块加载时间。"Speed up the symbols' resolution process" (Patch 1, Patch 2, Patch 3, Patch 4, Patch 5).
10. 避免使用udev, 它须要至关长一段时间来填充/dev目录。在嵌入式系统中,使用什么设备都是知道,从而能够找到有效的驱动。所以,在/dev下只须要保留必须的驱动就能够了,这些应创建静态的,不是动态的。 mknod是朋友,udev是敌人。
11. 若是仍然使用了udev,但又但愿快速启动。那么须要选择下面的方法:启动系统时udev enabled,为建立的device node创建备份。如今,修改初始化脚本,方法以下:替换运行的udev,复制device nodes(以前建立的副本)到设备tree,而后。启动hotplug线程。这样就能够避免启动时建立设备节点带来的消耗。
12. 若是设备有网络链接设置,建议选择静态Ip,经过DHCP会增长额外的开销。
13. 将代码在不一样的编译器上编译可能会使得代码更加精简和速度更快,大部分时候,最新版本的编译器会产生更好的代码。能够尝试新编译器。
14. 若是能由glibc转为uClibc,那么就这么作吧,可执行文件会变小,所以会加快加载速度。
15. library optimiser tool: http://libraryopt.sourceforge.net/
能够帮助建立一个优化的库。不须要的函数会被移除,能够带来性能提高。正常状况下,库中确定含有未用的代码。通过优化,未用代码量会尽量的减小。
16. Function reordering:http://www.celinux.org/elc08_presentations/DDLink%20FunctionReorder%2008%2004.pdf:新技术,针对可执行文件,将函数按照他们出现的顺序从新排列。会提升应用程序的加载时间,由于全部的初始化代码被分为一组页面,而不是被散落在多个页面。
2.2.5 Suspend related improvements
改善boot time的另外一思路是suspend related mechanism。有两种方案:
- 使用标准的hibernate/resume approach. This is what has been demonstrated by Chan Ju, Park, from Samsung. See sheet 23 and onwards from this PPT and section 2.7 of this paper.
Issue with this approach is that flash write is much slower than flash read, so the actual creation of the hibernate image might take quite a while.
- Implementing snapshot boot. This is done by Hiroki Kaminaga from Sony and is described at snapshot boot for ARM and http://elinux.org/upload/3/37/Snapshot-boot-final.pdf
This is similar to hibernate and resume, but the hibernate file is retained and used upon every boot. Disadvantage is that no writable partitions should be mounted at the time of making the snapshot. Otherwise inconsistencies will occur if a partition is modified, while applications in the hibernate file might have information in the snapshot related to the unmodified partition.
3. 参考文献与项目
- "Boot Time Optimizations" - (Slides | Video)
- "The Right Approach to Boot Time Reduction" - (Slides | YouTube Video)
- Andrew Murray has presented at ELC Europe on October 28, 2010 (Free Electrons video here)
- This included a < 1 second QT cold Linux boot case study for an SH7724 with some additional information about 'function re-ordering' in user-space
- Similar slides with < 1 second case study for OMAP3530EVM can be found here
- "One Second Linux Boot Demonstration (new version)" (Youtube video by MontaVista)
- "Tools and Techniques for Reducing Bootup Time" (PPT | ODP | PDF | video)
- Tim Bird has presented at ELC Europe, on November 7, 2008, his latest collection of tips and tricks for reducing bootup time
- Tims Fastboot Tools has online materials in support of this presentation
- Christopher Hallinan has done a presentation at the MontaVista Vision conference 2008 on the topic of reducing boot time. Slides available here
- Optimizing Linker Load Times
- (introducing various kinds of bootuptime reduction, prelinking, etc.)
- Benchmarking boot latency on x86
- By Gilad Ben-Yossef, July 2008
- A tutorial on using TSC register and the kernel PRINTK_TIMES feature to measure x86 system boot time, including BIOS, bootloader, kernel and time to first user program.
- Fast Booting of Embedded Linux
- By HoJoon Park, Electrons and Telecommunications Research Institute (ETRI), Korea, Presented at the CELF 3rd Korean Technical Jamboree, July 2008
- Explains several different reduction techniques used for different phases of bootup time
- Tim Bird's (Sony) survey of boot-up time reduction techniques:
- Embedded Linux optimizations
- By Free Electrons
- Tutorial to reduce size, RAM, speed, power and cost of a Linux based embedded system]
- Parallelizing Linux Boot on CE Devices
- Parallelize Applications for Faster Linux Boot
- Authored by M. Tim Jones for IBM Developer Works
- This article shows you options to increase the speed with which Linux boots, including two options for parallelizing the initialization process. It also shows you how to visualize graphically the performance of the boot process.
- Android Boot Time Optimization
- Authored by Kan-Ru Chen, 0xlab
- This presentation covers Android boot time measurement and analysis, the proposed reduction approaches, hibernation-based technologies, and potential Android user-space optimizations.
- Texas Instruments Embedded Processors Wiki provides the procedure to optimize Linux/Android boot time:
- Implement Checkpointing for Android
- Authored by Kito Cheng and Jim Huang, 0xlab
- Reasons to Implement Checkpointing for Android
- Resume to stored state for faster Android boot time
- Better product field trial experience due to regular checkpointing
3.1 Case Studies
1. 300 milliseconds from boot loader to shell on ARM with NAND
2. Samsung proof-of-acceptability study for digital still camera: see Boot Up Time Reduction PPT and thepaper describing this.
3. Boot Linux from Processor Reset into user space in less than 1 Second
o In this white paper, Robin Getz describes the techniques used to fast-boot a blackfin development board.
4. Booting Linux dm365 Network Camera in 3.2 seconds
5. Boot of kernel and shell in 0.5 sec (not including u-boot and decompression)
6. Warp2, Lineo Solutions, 2008. 2.97 sec boot, ARM11, 400MHz