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. iPhone safari中Document事件不触发的解决方案 [冒泡]

    写了一个下拉菜单,在单击空白地方的时候隐藏. 第一时间就是用$(document).click(function(){   //隐藏代码  }); 各大浏览器都没问题,唯独iPhone上的不会触发事件 ...

  2. BootStrap入门教程 (四)

    本文转自 http://www.cnblogs.com/ventlam/archive/2012/06/17/2536728.html 上讲回顾:Bootstrap组件丰富同时具有良好可扩展性,能够很 ...

  3. Mobiscroll日期插件使用

    相关资源 官方帮助文档:https://docs.mobiscroll.com/3-0-1 导入资源文件 <link href="${webRoot}/template/green/w ...

  4. Linux shell-grep

    grep --help备忘录 Usage: grep [OPTION]... PATTERN [FILE]...Search for PATTERN in each FILE or standard ...

  5. 【Electron】Electron开发入门(五):项目打包

    一.安装 electron-packager PS:安装之前,先复制一份package.json文件到./app目录下,然后改下./app目录下package.json里 "main&quo ...

  6. 老李推荐:第14章4节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-端口转发 3

    formAdbRequest我们在之前已经分析过,做的事情就是组建好ADB协议的命令以待发送给ADB服务器,在我们558行中最终组建好的ADB协议命令将会如下: “host-serial:xxx:fo ...

  7. Oracle常见错误集锦

    1.ORA-12560:TNS:协议适配器错误 OracleService<SID>服务没有启动 2. ORA-12541:TNS:无监听程序 Oracle<ORACLE_HOME& ...

  8. CSS3——复杂选择器

    今天把视频里的CSS3复杂选择器部分看完了,来整理一下学到的知识点. 1.兄弟选择器:同一位置级别,可称为兄弟元素 a.相邻兄弟选择器:next紧紧跟在[当前元素之后的](一个),指定选择器的元素   ...

  9. ORACLE JOB创建

    Connected Connected as focususer SQL> SQL> --JOB 需要在命令行执行: SQL> --抽数job SQL> CREATE OR R ...

  10. android 学习笔记(1)

    内容来源:高成珍.钟元生<Android编程经典案例>学习笔记 表格布局——TableLayout 表格布局以行和列的方式来管理界面的布局,但并不能明确声明包含几行几列.可通过TableR ...