Linux Bootup Time

英文原文地址:http://elinux.org/Boot_Time

1.   简介

启动时间这一话题包括很多子话题,比如启动时间的衡量、启动时间的分析、人为因素分析、初始化技术和还原技术等等。

在消费类领域,无论电子设备设计是多么的精心,多么的吸引人,这个产品品所需的启动时间始终是直接影响最终用户体验的第一感知。移动设备达到一个互动的、可用的状态是至关重要的用户体验。因此开机时第一个用户用例。

启动一个设备,包括多个步骤和有序的事件。为了使用一致的术语,CELF工作组提出了一系列的术语和可以被广泛接受的定义。请参阅以下页面:开机时间术语定义列表

2.   技术/项目

下面就介绍与linux系统启动时间有关的技术也项目。

2.1          Bootup Time度量

1.  Printk
Times
 – 为启动过程中的多有printk信息加入时间日志。

2.  Kernel Function Trace – 用于报告函数执行时间内核函数跟踪系统。

3.  Linux Trace Toolkit –针对特定内核和特定事件的时间数据通知系统。

4.  Oprofile - linux系统上系统框架内的剖析工具。

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 内核加速

  1. Disable Console – 在系统启动期间,避免控制台输出带来的开销。
  2. Disable bug and printk – 避免Bug和printk的开销,不方便之处是会丢失很多信息。
  3. RTC No Sync – 在启动时,应该避免系统时间与RTC同步带来的延迟。
  4. Short IDE Delays – 减少IDE的启动延时(有效但有风险)。
  5. Hardcode kernel module info – 减少模块加载的开销:针对relocation information的加载采取硬编码。
  6. IDE No Probe – 强制内核遵守ide<x>=noprobe选项。
  7. Preset LPJ – 使用loops_per_jiffy 预设值。
  8. Asynchronous function calls – 允许探测和其他功能并行处理,使得bootup中耗时可以重叠。
  9. Reordering of driver initialization – 允许驱动总线尽可能快的开始工作。
  10. Deferred Initcalls – 非必要模块的初始化例程,使之bootup之后再执行。
  11. 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.
  12. 检查所使用的内核内存分配器,slob或者slub可能比slab更好一些。(在一些老版本内涵上slab是默认的缓存分配器)
  13. 如果系统不需要sysfss和procfs,可以尝试移除它们。Sysfs可以带来20ms的收益。
  14. 精心地调研一下内核配置选项:哪些是需要的,哪些是不需要的。未使用的配置可能导致内核增大和内核加载时间变长(如果没有使用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!
  15. 将代码在不同的编译器上编译可能会使得代码更加精简和速度更快,大部分时候,最新版本的编译器会产生更好的代码。可以尝试新编译器
  16. 如果内核中使用了initramfs和压缩的内核,那么最好选择一个非压缩的initramfs,避免解压缩两次数据。 A patch for this has been submitted to LKML. See http://lkml.org/lkml/2008/11/22/112

2.2.3 文件系统问题

不同的文件系统,其初始化(挂载)时间是不同的,对于相同的数据,需要考虑是否应该讲元数据从存储中读到RAM中,及其在挂在过程中应该在采取什么算法。

  1. Filesystem Information – 针对不同文件洗的bootup time时间。
  2. File Systems – 嵌入式系统中有关的文件系统,及其优化建议。
  3. Avoid Initramfs – 解释如果想要最小化boot time,为什么要避免。
  4. Split partitions.如果挂载一个文件系统花费很多时间,那么需要考虑分为两个卷,一个卷中存储bootup需要的信息,另一个存储boot非必须的信息。
  5. 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

  1. 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 2Patch 3Patch
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.   参考文献与项目

  1. "Boot Time Optimizations" - (Slides | Video)

  2. "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
  3. "One Second Linux Boot Demonstration (new version)" (Youtube video by MontaVista)
  4. "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
  5. Christopher Hallinan has done a presentation at the MontaVista Vision conference 2008 on the topic of reducing boot time. Slides available here
  6. Optimizing Linker Load Times
    • (introducing various kinds of bootuptime reduction, prelinking, etc.)
  7. 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.
  8. 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
  9. Tim Bird's (Sony) survey of boot-up time reduction techniques:
  10. Embedded Linux optimizations
    • By Free Electrons
    • Tutorial to reduce size, RAM, speed, power and cost of a Linux based embedded system]
  11. Parallelizing Linux Boot on CE Devices
  12. 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.
  13. 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.
  14. Texas Instruments Embedded Processors Wiki provides the procedure to optimize Linux/Android boot time:
  15. 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

Linux Bootup Time的更多相关文章

  1. Linux 驱动开发

    linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...

  2. Linux Default Bootup、Startup、Autoload Configuration file(自启动服务脚本)

    目录 . Linux初始化init系统 . Linux配置文件自动加载过程 1. Linux初始化init系统 Linux初始化init系统在不同操作系统系列下的区别 . RHEL : SysVini ...

  3. linux -目录结构

    摘自:http://www.comptechdoc.org/os/linux/usersguide/linux_ugfilestruct.html 这个目录结构介绍是我目前看到介绍最全的,有时间在翻译 ...

  4. Linux内核的文件预读readahead

    Linux的文件预读readahead,指Linux系统内核将指定文件的某区域预读进页缓存起来,便于接下来对该区域进行读取时,不会因缺页(page fault)而阻塞.因为从内存读取比从磁盘读取要快很 ...

  5. Linux Buffer I/O error on device dm-4, logical block

    Linux服务器日志(Oracle Linux Server release 5.7)里面出现了一些"Buffer I/O error on device dm-4, logical blo ...

  6. Linux 内核日志——dmesg

    有时Linux系统或者系统上运行的mysqld或者其它进程,会发生一些莫名其妙的问题,比如突然挂掉了,比如突然重启等等.在软件上找不到问题所在,此时我们应该怀疑硬件或者内核的问题,此时我们就可以使用 ...

  7. Linux 开机启动方式设置 inittab 详解,开机直接进入“命令行”模式

    Linux下的 /etc/inittab 中的英文解释: This file describes how the INIT process should set up  the system in a ...

  8. Linux内核设计第三周——构造一个简单的Linux系统

    Linux内核设计第三周 ——构造一个简单的Linux系统 一.知识点总结 计算机三个法宝: 存储程序计算机 函数调用堆栈 中断 操作系统两把宝剑: 中断上下文的切换 进程上下文的切换 linux内核 ...

  9. Linux 相关基础笔记

    html,body { } .CodeMirror { height: auto } .CodeMirror-scroll { } .CodeMirror-lines { padding: 4px 0 ...

随机推荐

  1. Oracle-函数大全

    ORACLE函数大全 1. 第一讲 单行函数和组函数详解 PL/SQL单行函数和组函数详解 函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为 ...

  2. laravel 简单的上传图片

     /** * laravel 简单的上传图片* @param Request $request* @return View*/public function upload(Request $reque ...

  3. (25)IO流之转换流InputStreamReader和OutputStreamWriter

    InputStreamReader:字节到字符的桥梁. OutputStreamWriter:字符到字节的桥梁. 它们有转换作用,而本身又是字符流.所以在构造的时候,需要传入字节流对象进来. 构造函数 ...

  4. linux 根分区扩展

    linux根分区扩容 今天网站上传图片出问题了,一开始还以为是程序问题,后来发现原来是服务器存储空间不够,明明有200G的磁盘空间,没理由这么快就用完,查了一下分区情况,原来有两块磁盘,根分区只挂载在 ...

  5. PHP之流程的控制

       在一个公司中,员工肯定会有高层.中层和普通员工的,这样如果在某个公司员工遇到某种问题,需要请假.或者提一些请求的时候,就会需要去申请,申请的时候有的是可以直接和上级申请的,有时比较重要的事情,是 ...

  6. 当git上文件大小写重命名的修改时(git大小写敏感/默认不敏感),如何提交

    git默认是大小写不敏感!!! 加了感叹号是什么意思呢,意思就是这本身就是一个坑,本人使用的IDE是idea(网上说Eclipse可以避开问题),这个IDE本身就集成了git,但是如果要在termin ...

  7. strtol函数 将字符串转换为相应进制的整数

    转自http://hi.baidu.com/qwpsmile/blog/item/9bc44efa4f41018a9f514637.html +----------------+|      strt ...

  8. mybatis generator 插件安装及使用

    现在Mybatis特别火,但是在开发中却要经常写实体类和配置文件,会不会特别烦人,所以可以利用Mybatis的代码生成插件来生成这部分代码: 1,打开eclipse,点击Help>Softwar ...

  9. Linux之第一个shell命令

    今天在学习shell脚本的编写,网上看了一个helloworld的栗子: #!/bin/sh #print hello world in the console window a = "he ...

  10. 程序猿 tensorflow 入门开发及人工智能实战

    tensorflow 中文文档: http://www.tensorfly.cn http://wiki.jikexueyuan.com/project/tensorflow-zh/ tensorfl ...