Linux Bootup Time

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

  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 1Patch 2Patch 3Patch 4Patch 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

相關文章
相關標籤/搜索